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
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"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
127 static int processing_has_namespace_info
;
129 static const struct objfile_data
*dwarf2_objfile_data_key
;
131 struct dwarf2_section_info
137 /* True if we have tried to read this section. */
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type
;
145 DEF_VEC_I (offset_type
);
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
151 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size
;
157 /* The hash table. */
158 const offset_type
*index_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type index_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 struct dwarf2_per_objfile
167 struct dwarf2_section_info info
;
168 struct dwarf2_section_info abbrev
;
169 struct dwarf2_section_info line
;
170 struct dwarf2_section_info loc
;
171 struct dwarf2_section_info macinfo
;
172 struct dwarf2_section_info str
;
173 struct dwarf2_section_info ranges
;
174 struct dwarf2_section_info types
;
175 struct dwarf2_section_info frame
;
176 struct dwarf2_section_info eh_frame
;
177 struct dwarf2_section_info gdb_index
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units
;
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data
**type_comp_units
;
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data
*read_in_chain
;
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types
;
203 /* A flag indicating wether this objfile has a section loaded at a
205 int has_section_at_zero
;
207 /* True if we are using the mapped index. */
208 unsigned char using_index
;
210 /* The mapped index. */
211 struct mapped_index
*index_table
;
213 /* Set during partial symbol reading, to prevent queueing of full
215 int reading_partial_symbols
;
217 /* Table mapping type .debug_info DIE offsets to types.
218 This is NULL if not allocated yet.
219 It (currently) makes sense to allocate debug_types_type_hash lazily.
220 To keep things simple we allocate both lazily. */
221 htab_t debug_info_type_hash
;
223 /* Table mapping type .debug_types DIE offsets to types.
224 This is NULL if not allocated yet. */
225 htab_t debug_types_type_hash
;
228 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
230 /* names of the debugging sections */
232 /* Note that if the debugging section has been compressed, it might
233 have a name like .zdebug_info. */
235 #define INFO_SECTION "debug_info"
236 #define ABBREV_SECTION "debug_abbrev"
237 #define LINE_SECTION "debug_line"
238 #define LOC_SECTION "debug_loc"
239 #define MACINFO_SECTION "debug_macinfo"
240 #define STR_SECTION "debug_str"
241 #define RANGES_SECTION "debug_ranges"
242 #define TYPES_SECTION "debug_types"
243 #define FRAME_SECTION "debug_frame"
244 #define EH_FRAME_SECTION "eh_frame"
245 #define GDB_INDEX_SECTION "gdb_index"
247 /* local data types */
249 /* We hold several abbreviation tables in memory at the same time. */
250 #ifndef ABBREV_HASH_SIZE
251 #define ABBREV_HASH_SIZE 121
254 /* The data in a compilation unit header, after target2host
255 translation, looks like this. */
256 struct comp_unit_head
260 unsigned char addr_size
;
261 unsigned char signed_addr_p
;
262 unsigned int abbrev_offset
;
264 /* Size of file offsets; either 4 or 8. */
265 unsigned int offset_size
;
267 /* Size of the length field; either 4 or 12. */
268 unsigned int initial_length_size
;
270 /* Offset to the first byte of this compilation unit header in the
271 .debug_info section, for resolving relative reference dies. */
274 /* Offset to first die in this cu from the start of the cu.
275 This will be the first byte following the compilation unit header. */
276 unsigned int first_die_offset
;
279 /* Type used for delaying computation of method physnames.
280 See comments for compute_delayed_physnames. */
281 struct delayed_method_info
283 /* The type to which the method is attached, i.e., its parent class. */
286 /* The index of the method in the type's function fieldlists. */
289 /* The index of the method in the fieldlist. */
292 /* The name of the DIE. */
295 /* The DIE associated with this method. */
296 struct die_info
*die
;
299 typedef struct delayed_method_info delayed_method_info
;
300 DEF_VEC_O (delayed_method_info
);
302 /* Internal state when decoding a particular compilation unit. */
305 /* The objfile containing this compilation unit. */
306 struct objfile
*objfile
;
308 /* The header of the compilation unit. */
309 struct comp_unit_head header
;
311 /* Base address of this compilation unit. */
312 CORE_ADDR base_address
;
314 /* Non-zero if base_address has been set. */
317 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
319 /* The language we are debugging. */
320 enum language language
;
321 const struct language_defn
*language_defn
;
323 const char *producer
;
325 /* The generic symbol table building routines have separate lists for
326 file scope symbols and all all other scopes (local scopes). So
327 we need to select the right one to pass to add_symbol_to_list().
328 We do it by keeping a pointer to the correct list in list_in_scope.
330 FIXME: The original dwarf code just treated the file scope as the
331 first local scope, and all other local scopes as nested local
332 scopes, and worked fine. Check to see if we really need to
333 distinguish these in buildsym.c. */
334 struct pending
**list_in_scope
;
336 /* DWARF abbreviation table associated with this compilation unit. */
337 struct abbrev_info
**dwarf2_abbrevs
;
339 /* Storage for the abbrev table. */
340 struct obstack abbrev_obstack
;
342 /* Hash table holding all the loaded partial DIEs. */
345 /* Storage for things with the same lifetime as this read-in compilation
346 unit, including partial DIEs. */
347 struct obstack comp_unit_obstack
;
349 /* When multiple dwarf2_cu structures are living in memory, this field
350 chains them all together, so that they can be released efficiently.
351 We will probably also want a generation counter so that most-recently-used
352 compilation units are cached... */
353 struct dwarf2_per_cu_data
*read_in_chain
;
355 /* Backchain to our per_cu entry if the tree has been built. */
356 struct dwarf2_per_cu_data
*per_cu
;
358 /* How many compilation units ago was this CU last referenced? */
361 /* A hash table of die offsets for following references. */
364 /* Full DIEs if read in. */
365 struct die_info
*dies
;
367 /* A set of pointers to dwarf2_per_cu_data objects for compilation
368 units referenced by this one. Only set during full symbol processing;
369 partial symbol tables do not have dependencies. */
372 /* Header data from the line table, during full symbol processing. */
373 struct line_header
*line_header
;
375 /* A list of methods which need to have physnames computed
376 after all type information has been read. */
377 VEC (delayed_method_info
) *method_list
;
379 /* Mark used when releasing cached dies. */
380 unsigned int mark
: 1;
382 /* This flag will be set if this compilation unit might include
383 inter-compilation-unit references. */
384 unsigned int has_form_ref_addr
: 1;
386 /* This flag will be set if this compilation unit includes any
387 DW_TAG_namespace DIEs. If we know that there are explicit
388 DIEs for namespaces, we don't need to try to infer them
389 from mangled names. */
390 unsigned int has_namespace_info
: 1;
393 /* When using the index (and thus not using psymtabs), each CU has an
394 object of this type. This is used to hold information needed by
395 the various "quick" methods. */
396 struct dwarf2_per_cu_quick_data
398 /* The line table. This can be NULL if there was no line table. */
399 struct line_header
*lines
;
401 /* The file names from the line table. */
402 const char **file_names
;
403 /* The file names from the line table after being run through
405 const char **full_names
;
407 /* The corresponding symbol table. This is NULL if symbols for this
408 CU have not yet been read. */
409 struct symtab
*symtab
;
411 /* A temporary mark bit used when iterating over all CUs in
412 expand_symtabs_matching. */
413 unsigned int mark
: 1;
415 /* True if we've tried to read the line table. */
416 unsigned int read_lines
: 1;
419 /* Persistent data held for a compilation unit, even when not
420 processing it. We put a pointer to this structure in the
421 read_symtab_private field of the psymtab. If we encounter
422 inter-compilation-unit references, we also maintain a sorted
423 list of all compilation units. */
425 struct dwarf2_per_cu_data
427 /* The start offset and length of this compilation unit. 2**29-1
428 bytes should suffice to store the length of any compilation unit
429 - if it doesn't, GDB will fall over anyway.
430 NOTE: Unlike comp_unit_head.length, this length includes
431 initial_length_size. */
433 unsigned int length
: 29;
435 /* Flag indicating this compilation unit will be read in before
436 any of the current compilation units are processed. */
437 unsigned int queued
: 1;
439 /* This flag will be set if we need to load absolutely all DIEs
440 for this compilation unit, instead of just the ones we think
441 are interesting. It gets set if we look for a DIE in the
442 hash table and don't find it. */
443 unsigned int load_all_dies
: 1;
445 /* Non-zero if this CU is from .debug_types.
446 Otherwise it's from .debug_info. */
447 unsigned int from_debug_types
: 1;
449 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
450 of the CU cache it gets reset to NULL again. */
451 struct dwarf2_cu
*cu
;
453 /* The corresponding objfile. */
454 struct objfile
*objfile
;
456 /* When using partial symbol tables, the 'psymtab' field is active.
457 Otherwise the 'quick' field is active. */
460 /* The partial symbol table associated with this compilation unit,
461 or NULL for partial units (which do not have an associated
463 struct partial_symtab
*psymtab
;
465 /* Data needed by the "quick" functions. */
466 struct dwarf2_per_cu_quick_data
*quick
;
470 /* Entry in the signatured_types hash table. */
472 struct signatured_type
476 /* Offset in .debug_types of the TU (type_unit) for this type. */
479 /* Offset in .debug_types of the type defined by this TU. */
480 unsigned int type_offset
;
482 /* The CU(/TU) of this type. */
483 struct dwarf2_per_cu_data per_cu
;
486 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
487 which are used for both .debug_info and .debug_types dies.
488 All parameters here are unchanging for the life of the call.
489 This struct exists to abstract away the constant parameters of
492 struct die_reader_specs
494 /* The bfd of this objfile. */
497 /* The CU of the DIE we are parsing. */
498 struct dwarf2_cu
*cu
;
500 /* Pointer to start of section buffer.
501 This is either the start of .debug_info or .debug_types. */
502 const gdb_byte
*buffer
;
505 /* The line number information for a compilation unit (found in the
506 .debug_line section) begins with a "statement program header",
507 which contains the following information. */
510 unsigned int total_length
;
511 unsigned short version
;
512 unsigned int header_length
;
513 unsigned char minimum_instruction_length
;
514 unsigned char maximum_ops_per_instruction
;
515 unsigned char default_is_stmt
;
517 unsigned char line_range
;
518 unsigned char opcode_base
;
520 /* standard_opcode_lengths[i] is the number of operands for the
521 standard opcode whose value is i. This means that
522 standard_opcode_lengths[0] is unused, and the last meaningful
523 element is standard_opcode_lengths[opcode_base - 1]. */
524 unsigned char *standard_opcode_lengths
;
526 /* The include_directories table. NOTE! These strings are not
527 allocated with xmalloc; instead, they are pointers into
528 debug_line_buffer. If you try to free them, `free' will get
530 unsigned int num_include_dirs
, include_dirs_size
;
533 /* The file_names table. NOTE! These strings are not allocated
534 with xmalloc; instead, they are pointers into debug_line_buffer.
535 Don't try to free them directly. */
536 unsigned int num_file_names
, file_names_size
;
540 unsigned int dir_index
;
541 unsigned int mod_time
;
543 int included_p
; /* Non-zero if referenced by the Line Number Program. */
544 struct symtab
*symtab
; /* The associated symbol table, if any. */
547 /* The start and end of the statement program following this
548 header. These point into dwarf2_per_objfile->line_buffer. */
549 gdb_byte
*statement_program_start
, *statement_program_end
;
552 /* When we construct a partial symbol table entry we only
553 need this much information. */
554 struct partial_die_info
556 /* Offset of this DIE. */
559 /* DWARF-2 tag for this DIE. */
560 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
562 /* Assorted flags describing the data found in this DIE. */
563 unsigned int has_children
: 1;
564 unsigned int is_external
: 1;
565 unsigned int is_declaration
: 1;
566 unsigned int has_type
: 1;
567 unsigned int has_specification
: 1;
568 unsigned int has_pc_info
: 1;
570 /* Flag set if the SCOPE field of this structure has been
572 unsigned int scope_set
: 1;
574 /* Flag set if the DIE has a byte_size attribute. */
575 unsigned int has_byte_size
: 1;
577 /* Flag set if any of the DIE's children are template arguments. */
578 unsigned int has_template_arguments
: 1;
580 /* Flag set if fixup_partial_die has been called on this die. */
581 unsigned int fixup_called
: 1;
583 /* The name of this DIE. Normally the value of DW_AT_name, but
584 sometimes a default name for unnamed DIEs. */
587 /* The linkage name, if present. */
588 const char *linkage_name
;
590 /* The scope to prepend to our children. This is generally
591 allocated on the comp_unit_obstack, so will disappear
592 when this compilation unit leaves the cache. */
595 /* The location description associated with this DIE, if any. */
596 struct dwarf_block
*locdesc
;
598 /* If HAS_PC_INFO, the PC range associated with this DIE. */
602 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
603 DW_AT_sibling, if any. */
604 /* NOTE: This member isn't strictly necessary, read_partial_die could
605 return DW_AT_sibling values to its caller load_partial_dies. */
608 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
609 DW_AT_specification (or DW_AT_abstract_origin or
611 unsigned int spec_offset
;
613 /* Pointers to this DIE's parent, first child, and next sibling,
615 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
618 /* This data structure holds the information of an abbrev. */
621 unsigned int number
; /* number identifying abbrev */
622 enum dwarf_tag tag
; /* dwarf tag */
623 unsigned short has_children
; /* boolean */
624 unsigned short num_attrs
; /* number of attributes */
625 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
626 struct abbrev_info
*next
; /* next in chain */
631 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
632 ENUM_BITFIELD(dwarf_form
) form
: 16;
635 /* Attributes have a name and a value */
638 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
639 ENUM_BITFIELD(dwarf_form
) form
: 15;
641 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
642 field should be in u.str (existing only for DW_STRING) but it is kept
643 here for better struct attribute alignment. */
644 unsigned int string_is_canonical
: 1;
649 struct dwarf_block
*blk
;
653 struct signatured_type
*signatured_type
;
658 /* This data structure holds a complete die structure. */
661 /* DWARF-2 tag for this DIE. */
662 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
664 /* Number of attributes */
665 unsigned char num_attrs
;
667 /* True if we're presently building the full type name for the
668 type derived from this DIE. */
669 unsigned char building_fullname
: 1;
674 /* Offset in .debug_info or .debug_types section. */
677 /* The dies in a compilation unit form an n-ary tree. PARENT
678 points to this die's parent; CHILD points to the first child of
679 this node; and all the children of a given node are chained
680 together via their SIBLING fields. */
681 struct die_info
*child
; /* Its first child, if any. */
682 struct die_info
*sibling
; /* Its next sibling, if any. */
683 struct die_info
*parent
; /* Its parent, if any. */
685 /* An array of attributes, with NUM_ATTRS elements. There may be
686 zero, but it's not common and zero-sized arrays are not
687 sufficiently portable C. */
688 struct attribute attrs
[1];
691 struct function_range
694 CORE_ADDR lowpc
, highpc
;
696 struct function_range
*next
;
699 /* Get at parts of an attribute structure */
701 #define DW_STRING(attr) ((attr)->u.str)
702 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
703 #define DW_UNSND(attr) ((attr)->u.unsnd)
704 #define DW_BLOCK(attr) ((attr)->u.blk)
705 #define DW_SND(attr) ((attr)->u.snd)
706 #define DW_ADDR(attr) ((attr)->u.addr)
707 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
709 /* Blocks are a bunch of untyped bytes. */
716 #ifndef ATTR_ALLOC_CHUNK
717 #define ATTR_ALLOC_CHUNK 4
720 /* Allocate fields for structs, unions and enums in this size. */
721 #ifndef DW_FIELD_ALLOC_CHUNK
722 #define DW_FIELD_ALLOC_CHUNK 4
725 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
726 but this would require a corresponding change in unpack_field_as_long
728 static int bits_per_byte
= 8;
730 /* The routines that read and process dies for a C struct or C++ class
731 pass lists of data member fields and lists of member function fields
732 in an instance of a field_info structure, as defined below. */
735 /* List of data member and baseclasses fields. */
738 struct nextfield
*next
;
743 *fields
, *baseclasses
;
745 /* Number of fields (including baseclasses). */
748 /* Number of baseclasses. */
751 /* Set if the accesibility of one of the fields is not public. */
752 int non_public_fields
;
754 /* Member function fields array, entries are allocated in the order they
755 are encountered in the object file. */
758 struct nextfnfield
*next
;
759 struct fn_field fnfield
;
763 /* Member function fieldlist array, contains name of possibly overloaded
764 member function, number of overloaded member functions and a pointer
765 to the head of the member function field chain. */
770 struct nextfnfield
*head
;
774 /* Number of entries in the fnfieldlists array. */
777 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
778 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
779 struct typedef_field_list
781 struct typedef_field field
;
782 struct typedef_field_list
*next
;
785 unsigned typedef_field_list_count
;
788 /* One item on the queue of compilation units to read in full symbols
790 struct dwarf2_queue_item
792 struct dwarf2_per_cu_data
*per_cu
;
793 struct dwarf2_queue_item
*next
;
796 /* The current queue. */
797 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
799 /* Loaded secondary compilation units are kept in memory until they
800 have not been referenced for the processing of this many
801 compilation units. Set this to zero to disable caching. Cache
802 sizes of up to at least twenty will improve startup time for
803 typical inter-CU-reference binaries, at an obvious memory cost. */
804 static int dwarf2_max_cache_age
= 5;
806 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
807 struct cmd_list_element
*c
, const char *value
)
809 fprintf_filtered (file
, _("\
810 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
815 /* Various complaints about symbol reading that don't abort the process */
818 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
820 complaint (&symfile_complaints
,
821 _("statement list doesn't fit in .debug_line section"));
825 dwarf2_debug_line_missing_file_complaint (void)
827 complaint (&symfile_complaints
,
828 _(".debug_line section has line data without a file"));
832 dwarf2_debug_line_missing_end_sequence_complaint (void)
834 complaint (&symfile_complaints
,
835 _(".debug_line section has line 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"), arg1
,
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 malformed macro definition:\n`%s'"),
869 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
871 complaint (&symfile_complaints
,
872 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
875 /* local function prototypes */
877 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
879 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
882 static void dwarf2_build_psymtabs_hard (struct objfile
*);
884 static void scan_partial_symbols (struct partial_die_info
*,
885 CORE_ADDR
*, CORE_ADDR
*,
886 int, struct dwarf2_cu
*);
888 static void add_partial_symbol (struct partial_die_info
*,
891 static void add_partial_namespace (struct partial_die_info
*pdi
,
892 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
893 int need_pc
, struct dwarf2_cu
*cu
);
895 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
896 CORE_ADDR
*highpc
, int need_pc
,
897 struct dwarf2_cu
*cu
);
899 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
900 struct dwarf2_cu
*cu
);
902 static void add_partial_subprogram (struct partial_die_info
*pdi
,
903 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
904 int need_pc
, struct dwarf2_cu
*cu
);
906 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
907 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
908 bfd
*abfd
, struct dwarf2_cu
*cu
);
910 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
912 static void psymtab_to_symtab_1 (struct partial_symtab
*);
914 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
916 static void dwarf2_free_abbrev_table (void *);
918 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
921 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
924 static struct partial_die_info
*load_partial_dies (bfd
*,
925 gdb_byte
*, gdb_byte
*,
926 int, struct dwarf2_cu
*);
928 static gdb_byte
*read_partial_die (struct partial_die_info
*,
929 struct abbrev_info
*abbrev
,
931 gdb_byte
*, gdb_byte
*,
934 static struct partial_die_info
*find_partial_die (unsigned int,
937 static void fixup_partial_die (struct partial_die_info
*,
940 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
941 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
943 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
944 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
946 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
948 static int read_1_signed_byte (bfd
*, gdb_byte
*);
950 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
952 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
954 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
956 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
959 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
961 static LONGEST read_checked_initial_length_and_offset
962 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
963 unsigned int *, unsigned int *);
965 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
968 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
970 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
972 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
974 static char *read_indirect_string (bfd
*, gdb_byte
*,
975 const struct comp_unit_head
*,
978 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
980 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
982 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
984 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
986 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
989 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
993 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
994 struct dwarf2_cu
*cu
);
996 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
998 static struct die_info
*die_specification (struct die_info
*die
,
999 struct dwarf2_cu
**);
1001 static void free_line_header (struct line_header
*lh
);
1003 static void add_file_name (struct line_header
*, char *, unsigned int,
1004 unsigned int, unsigned int);
1006 static struct line_header
*(dwarf_decode_line_header
1007 (unsigned int offset
,
1008 bfd
*abfd
, struct dwarf2_cu
*cu
));
1010 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
1011 struct dwarf2_cu
*, struct partial_symtab
*);
1013 static void dwarf2_start_subfile (char *, char *, char *);
1015 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1016 struct dwarf2_cu
*);
1018 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1019 struct dwarf2_cu
*, struct symbol
*);
1021 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1022 struct dwarf2_cu
*);
1024 static void dwarf2_const_value_attr (struct attribute
*attr
,
1027 struct obstack
*obstack
,
1028 struct dwarf2_cu
*cu
, long *value
,
1030 struct dwarf2_locexpr_baton
**baton
);
1032 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1034 static int need_gnat_info (struct dwarf2_cu
*);
1036 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
1038 static void set_descriptive_type (struct type
*, struct die_info
*,
1039 struct dwarf2_cu
*);
1041 static struct type
*die_containing_type (struct die_info
*,
1042 struct dwarf2_cu
*);
1044 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1045 struct dwarf2_cu
*);
1047 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1049 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1051 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1053 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1054 const char *suffix
, int physname
,
1055 struct dwarf2_cu
*cu
);
1057 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1059 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1061 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1063 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1065 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1066 struct dwarf2_cu
*, struct partial_symtab
*);
1068 static int dwarf2_get_pc_bounds (struct die_info
*,
1069 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1070 struct partial_symtab
*);
1072 static void get_scope_pc_bounds (struct die_info
*,
1073 CORE_ADDR
*, CORE_ADDR
*,
1074 struct dwarf2_cu
*);
1076 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1077 CORE_ADDR
, struct dwarf2_cu
*);
1079 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1080 struct dwarf2_cu
*);
1082 static void dwarf2_attach_fields_to_type (struct field_info
*,
1083 struct type
*, struct dwarf2_cu
*);
1085 static void dwarf2_add_member_fn (struct field_info
*,
1086 struct die_info
*, struct type
*,
1087 struct dwarf2_cu
*);
1089 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1090 struct type
*, struct dwarf2_cu
*);
1092 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1094 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1096 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1098 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1100 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1102 static struct type
*read_module_type (struct die_info
*die
,
1103 struct dwarf2_cu
*cu
);
1105 static const char *namespace_name (struct die_info
*die
,
1106 int *is_anonymous
, struct dwarf2_cu
*);
1108 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1110 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1112 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1113 struct dwarf2_cu
*);
1115 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1117 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1119 gdb_byte
**new_info_ptr
,
1120 struct die_info
*parent
);
1122 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1124 gdb_byte
**new_info_ptr
,
1125 struct die_info
*parent
);
1127 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1129 gdb_byte
**new_info_ptr
,
1130 struct die_info
*parent
);
1132 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1133 struct die_info
**, gdb_byte
*,
1136 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1138 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1141 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1143 static const char *dwarf2_full_name (char *name
,
1144 struct die_info
*die
,
1145 struct dwarf2_cu
*cu
);
1147 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1148 struct dwarf2_cu
**);
1150 static char *dwarf_tag_name (unsigned int);
1152 static char *dwarf_attr_name (unsigned int);
1154 static char *dwarf_form_name (unsigned int);
1156 static char *dwarf_bool_name (unsigned int);
1158 static char *dwarf_type_encoding_name (unsigned int);
1161 static char *dwarf_cfi_name (unsigned int);
1164 static struct die_info
*sibling_die (struct die_info
*);
1166 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1168 static void dump_die_for_error (struct die_info
*);
1170 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1173 /*static*/ void dump_die (struct die_info
*, int max_level
);
1175 static void store_in_ref_table (struct die_info
*,
1176 struct dwarf2_cu
*);
1178 static int is_ref_attr (struct attribute
*);
1180 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1182 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1184 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1186 struct dwarf2_cu
**);
1188 static struct die_info
*follow_die_ref (struct die_info
*,
1190 struct dwarf2_cu
**);
1192 static struct die_info
*follow_die_sig (struct die_info
*,
1194 struct dwarf2_cu
**);
1196 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1197 unsigned int offset
);
1199 static void read_signatured_type (struct objfile
*,
1200 struct signatured_type
*type_sig
);
1202 /* memory allocation interface */
1204 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1206 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1208 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1210 static void initialize_cu_func_list (struct dwarf2_cu
*);
1212 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1213 struct dwarf2_cu
*);
1215 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1216 char *, bfd
*, struct dwarf2_cu
*);
1218 static int attr_form_is_block (struct attribute
*);
1220 static int attr_form_is_section_offset (struct attribute
*);
1222 static int attr_form_is_constant (struct attribute
*);
1224 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1226 struct dwarf2_cu
*cu
);
1228 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1229 struct abbrev_info
*abbrev
,
1230 struct dwarf2_cu
*cu
);
1232 static void free_stack_comp_unit (void *);
1234 static hashval_t
partial_die_hash (const void *item
);
1236 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1238 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1239 (unsigned int offset
, struct objfile
*objfile
);
1241 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1242 (unsigned int offset
, struct objfile
*objfile
);
1244 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1246 static void free_one_comp_unit (void *);
1248 static void free_cached_comp_units (void *);
1250 static void age_cached_comp_units (void);
1252 static void free_one_cached_comp_unit (void *);
1254 static struct type
*set_die_type (struct die_info
*, struct type
*,
1255 struct dwarf2_cu
*);
1257 static void create_all_comp_units (struct objfile
*);
1259 static int create_debug_types_hash_table (struct objfile
*objfile
);
1261 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1264 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1266 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1267 struct dwarf2_per_cu_data
*);
1269 static void dwarf2_mark (struct dwarf2_cu
*);
1271 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1273 static struct type
*get_die_type_at_offset (unsigned int,
1274 struct dwarf2_per_cu_data
*per_cu
);
1276 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1278 static void dwarf2_release_queue (void *dummy
);
1280 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1281 struct objfile
*objfile
);
1283 static void process_queue (struct objfile
*objfile
);
1285 static void find_file_and_directory (struct die_info
*die
,
1286 struct dwarf2_cu
*cu
,
1287 char **name
, char **comp_dir
);
1289 static char *file_full_name (int file
, struct line_header
*lh
,
1290 const char *comp_dir
);
1292 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1295 unsigned int buffer_size
,
1298 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1299 struct dwarf2_cu
*cu
);
1301 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1305 /* Convert VALUE between big- and little-endian. */
1307 byte_swap (offset_type value
)
1311 result
= (value
& 0xff) << 24;
1312 result
|= (value
& 0xff00) << 8;
1313 result
|= (value
& 0xff0000) >> 8;
1314 result
|= (value
& 0xff000000) >> 24;
1318 #define MAYBE_SWAP(V) byte_swap (V)
1321 #define MAYBE_SWAP(V) (V)
1322 #endif /* WORDS_BIGENDIAN */
1324 /* The suffix for an index file. */
1325 #define INDEX_SUFFIX ".gdb-index"
1327 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1328 struct dwarf2_cu
*cu
);
1330 /* Try to locate the sections we need for DWARF 2 debugging
1331 information and return true if we have enough to do something. */
1334 dwarf2_has_info (struct objfile
*objfile
)
1336 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1337 if (!dwarf2_per_objfile
)
1339 /* Initialize per-objfile state. */
1340 struct dwarf2_per_objfile
*data
1341 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1343 memset (data
, 0, sizeof (*data
));
1344 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1345 dwarf2_per_objfile
= data
;
1347 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1348 dwarf2_per_objfile
->objfile
= objfile
;
1350 return (dwarf2_per_objfile
->info
.asection
!= NULL
1351 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1354 /* When loading sections, we can either look for ".<name>", or for
1355 * ".z<name>", which indicates a compressed section. */
1358 section_is_p (const char *section_name
, const char *name
)
1360 return (section_name
[0] == '.'
1361 && (strcmp (section_name
+ 1, name
) == 0
1362 || (section_name
[1] == 'z'
1363 && strcmp (section_name
+ 2, name
) == 0)));
1366 /* This function is mapped across the sections and remembers the
1367 offset and size of each of the debugging sections we are interested
1371 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1373 if (section_is_p (sectp
->name
, INFO_SECTION
))
1375 dwarf2_per_objfile
->info
.asection
= sectp
;
1376 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1378 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1380 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1381 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1383 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1385 dwarf2_per_objfile
->line
.asection
= sectp
;
1386 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1388 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1390 dwarf2_per_objfile
->loc
.asection
= sectp
;
1391 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1393 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1395 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1396 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1398 else if (section_is_p (sectp
->name
, STR_SECTION
))
1400 dwarf2_per_objfile
->str
.asection
= sectp
;
1401 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1403 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1405 dwarf2_per_objfile
->frame
.asection
= sectp
;
1406 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1408 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1410 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1412 if (aflag
& SEC_HAS_CONTENTS
)
1414 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1415 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1418 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1420 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1421 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1423 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1425 dwarf2_per_objfile
->types
.asection
= sectp
;
1426 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1428 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1430 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1431 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1434 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1435 && bfd_section_vma (abfd
, sectp
) == 0)
1436 dwarf2_per_objfile
->has_section_at_zero
= 1;
1439 /* Decompress a section that was compressed using zlib. Store the
1440 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1443 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1444 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1446 bfd
*abfd
= objfile
->obfd
;
1448 error (_("Support for zlib-compressed DWARF data (from '%s') "
1449 "is disabled in this copy of GDB"),
1450 bfd_get_filename (abfd
));
1452 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1453 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1454 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1455 bfd_size_type uncompressed_size
;
1456 gdb_byte
*uncompressed_buffer
;
1459 int header_size
= 12;
1461 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1462 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1463 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1464 bfd_get_filename (abfd
));
1466 /* Read the zlib header. In this case, it should be "ZLIB" followed
1467 by the uncompressed section size, 8 bytes in big-endian order. */
1468 if (compressed_size
< header_size
1469 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1470 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1471 bfd_get_filename (abfd
));
1472 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1473 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1474 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1475 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1476 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1477 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1478 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1479 uncompressed_size
+= compressed_buffer
[11];
1481 /* It is possible the section consists of several compressed
1482 buffers concatenated together, so we uncompress in a loop. */
1486 strm
.avail_in
= compressed_size
- header_size
;
1487 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1488 strm
.avail_out
= uncompressed_size
;
1489 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1491 rc
= inflateInit (&strm
);
1492 while (strm
.avail_in
> 0)
1495 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1496 bfd_get_filename (abfd
), rc
);
1497 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1498 + (uncompressed_size
- strm
.avail_out
));
1499 rc
= inflate (&strm
, Z_FINISH
);
1500 if (rc
!= Z_STREAM_END
)
1501 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1502 bfd_get_filename (abfd
), rc
);
1503 rc
= inflateReset (&strm
);
1505 rc
= inflateEnd (&strm
);
1507 || strm
.avail_out
!= 0)
1508 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1509 bfd_get_filename (abfd
), rc
);
1511 do_cleanups (cleanup
);
1512 *outbuf
= uncompressed_buffer
;
1513 *outsize
= uncompressed_size
;
1517 /* Read the contents of the section SECTP from object file specified by
1518 OBJFILE, store info about the section into INFO.
1519 If the section is compressed, uncompress it before returning. */
1522 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1524 bfd
*abfd
= objfile
->obfd
;
1525 asection
*sectp
= info
->asection
;
1526 gdb_byte
*buf
, *retbuf
;
1527 unsigned char header
[4];
1531 info
->buffer
= NULL
;
1532 info
->was_mmapped
= 0;
1535 if (info
->asection
== NULL
|| info
->size
== 0)
1538 /* Check if the file has a 4-byte header indicating compression. */
1539 if (info
->size
> sizeof (header
)
1540 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1541 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1543 /* Upon decompression, update the buffer and its size. */
1544 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1546 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1554 pagesize
= getpagesize ();
1556 /* Only try to mmap sections which are large enough: we don't want to
1557 waste space due to fragmentation. Also, only try mmap for sections
1558 without relocations. */
1560 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1562 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1563 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1564 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1565 MAP_PRIVATE
, pg_offset
);
1567 if (retbuf
!= MAP_FAILED
)
1569 info
->was_mmapped
= 1;
1570 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1571 #if HAVE_POSIX_MADVISE
1572 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1579 /* If we get here, we are a normal, not-compressed section. */
1581 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1583 /* When debugging .o files, we may need to apply relocations; see
1584 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1585 We never compress sections in .o files, so we only need to
1586 try this when the section is not compressed. */
1587 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1590 info
->buffer
= retbuf
;
1594 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1595 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1596 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1597 bfd_get_filename (abfd
));
1600 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1604 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1605 asection
**sectp
, gdb_byte
**bufp
,
1606 bfd_size_type
*sizep
)
1608 struct dwarf2_per_objfile
*data
1609 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1610 struct dwarf2_section_info
*info
;
1612 /* We may see an objfile without any DWARF, in which case we just
1621 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1622 info
= &data
->eh_frame
;
1623 else if (section_is_p (section_name
, FRAME_SECTION
))
1624 info
= &data
->frame
;
1626 gdb_assert_not_reached ("unexpected section");
1628 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1629 /* We haven't read this section in yet. Do it now. */
1630 dwarf2_read_section (objfile
, info
);
1632 *sectp
= info
->asection
;
1633 *bufp
= info
->buffer
;
1634 *sizep
= info
->size
;
1639 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1642 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1643 struct dwarf2_per_cu_data
*per_cu
)
1645 struct cleanup
*back_to
;
1647 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1649 queue_comp_unit (per_cu
, objfile
);
1651 if (per_cu
->from_debug_types
)
1652 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1654 load_full_comp_unit (per_cu
, objfile
);
1656 process_queue (objfile
);
1658 /* Age the cache, releasing compilation units that have not
1659 been used recently. */
1660 age_cached_comp_units ();
1662 do_cleanups (back_to
);
1665 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1666 the objfile from which this CU came. Returns the resulting symbol
1668 static struct symtab
*
1669 dw2_instantiate_symtab (struct objfile
*objfile
,
1670 struct dwarf2_per_cu_data
*per_cu
)
1672 if (!per_cu
->v
.quick
->symtab
)
1674 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1675 increment_reading_symtab ();
1676 dw2_do_instantiate_symtab (objfile
, per_cu
);
1677 do_cleanups (back_to
);
1679 return per_cu
->v
.quick
->symtab
;
1682 /* Return the CU given its index. */
1683 static struct dwarf2_per_cu_data
*
1684 dw2_get_cu (int index
)
1686 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1688 index
-= dwarf2_per_objfile
->n_comp_units
;
1689 return dwarf2_per_objfile
->type_comp_units
[index
];
1691 return dwarf2_per_objfile
->all_comp_units
[index
];
1694 /* A helper function that knows how to read a 64-bit value in a way
1695 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1698 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1700 if (sizeof (ULONGEST
) < 8)
1704 /* Ignore the upper 4 bytes if they are all zero. */
1705 for (i
= 0; i
< 4; ++i
)
1706 if (bytes
[i
+ 4] != 0)
1709 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1712 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1716 /* Read the CU list from the mapped index, and use it to create all
1717 the CU objects for this objfile. Return 0 if something went wrong,
1718 1 if everything went ok. */
1720 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1721 offset_type cu_list_elements
)
1725 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1726 dwarf2_per_objfile
->all_comp_units
1727 = obstack_alloc (&objfile
->objfile_obstack
,
1728 dwarf2_per_objfile
->n_comp_units
1729 * sizeof (struct dwarf2_per_cu_data
*));
1731 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1733 struct dwarf2_per_cu_data
*the_cu
;
1734 ULONGEST offset
, length
;
1736 if (!extract_cu_value (cu_list
, &offset
)
1737 || !extract_cu_value (cu_list
+ 8, &length
))
1741 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1742 struct dwarf2_per_cu_data
);
1743 the_cu
->offset
= offset
;
1744 the_cu
->length
= length
;
1745 the_cu
->objfile
= objfile
;
1746 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1747 struct dwarf2_per_cu_quick_data
);
1748 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1754 /* Create the signatured type hash table from the index. */
1757 create_signatured_type_table_from_index (struct objfile
*objfile
,
1758 const gdb_byte
*bytes
,
1759 offset_type elements
)
1762 htab_t sig_types_hash
;
1764 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1765 dwarf2_per_objfile
->type_comp_units
1766 = obstack_alloc (&objfile
->objfile_obstack
,
1767 dwarf2_per_objfile
->n_type_comp_units
1768 * sizeof (struct dwarf2_per_cu_data
*));
1770 sig_types_hash
= allocate_signatured_type_table (objfile
);
1772 for (i
= 0; i
< elements
; i
+= 3)
1774 struct signatured_type
*type_sig
;
1775 ULONGEST offset
, type_offset
, signature
;
1778 if (!extract_cu_value (bytes
, &offset
)
1779 || !extract_cu_value (bytes
+ 8, &type_offset
))
1781 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1784 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1785 struct signatured_type
);
1786 type_sig
->signature
= signature
;
1787 type_sig
->offset
= offset
;
1788 type_sig
->type_offset
= type_offset
;
1789 type_sig
->per_cu
.from_debug_types
= 1;
1790 type_sig
->per_cu
.offset
= offset
;
1791 type_sig
->per_cu
.objfile
= objfile
;
1792 type_sig
->per_cu
.v
.quick
1793 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1794 struct dwarf2_per_cu_quick_data
);
1796 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1799 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1802 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1807 /* Read the address map data from the mapped index, and use it to
1808 populate the objfile's psymtabs_addrmap. */
1810 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1812 const gdb_byte
*iter
, *end
;
1813 struct obstack temp_obstack
;
1814 struct addrmap
*mutable_map
;
1815 struct cleanup
*cleanup
;
1818 obstack_init (&temp_obstack
);
1819 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1820 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1822 iter
= index
->address_table
;
1823 end
= iter
+ index
->address_table_size
;
1825 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1829 ULONGEST hi
, lo
, cu_index
;
1830 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1832 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1834 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1837 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1838 dw2_get_cu (cu_index
));
1841 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1842 &objfile
->objfile_obstack
);
1843 do_cleanups (cleanup
);
1846 /* The hash function for strings in the mapped index. This is the
1847 same as the hashtab.c hash function, but we keep a separate copy to
1848 maintain control over the implementation. This is necessary
1849 because the hash function is tied to the format of the mapped index
1852 mapped_index_string_hash (const void *p
)
1854 const unsigned char *str
= (const unsigned char *) p
;
1858 while ((c
= *str
++) != 0)
1859 r
= r
* 67 + c
- 113;
1864 /* Find a slot in the mapped index INDEX for the object named NAME.
1865 If NAME is found, set *VEC_OUT to point to the CU vector in the
1866 constant pool and return 1. If NAME cannot be found, return 0. */
1868 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1869 offset_type
**vec_out
)
1871 offset_type hash
= mapped_index_string_hash (name
);
1872 offset_type slot
, step
;
1874 slot
= hash
& (index
->index_table_slots
- 1);
1875 step
= ((hash
* 17) & (index
->index_table_slots
- 1)) | 1;
1879 /* Convert a slot number to an offset into the table. */
1880 offset_type i
= 2 * slot
;
1882 if (index
->index_table
[i
] == 0 && index
->index_table
[i
+ 1] == 0)
1885 str
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[i
]);
1886 if (!strcmp (name
, str
))
1888 *vec_out
= (offset_type
*) (index
->constant_pool
1889 + MAYBE_SWAP (index
->index_table
[i
+ 1]));
1893 slot
= (slot
+ step
) & (index
->index_table_slots
- 1);
1897 /* Read the index file. If everything went ok, initialize the "quick"
1898 elements of all the CUs and return 1. Otherwise, return 0. */
1900 dwarf2_read_index (struct objfile
*objfile
)
1903 struct mapped_index
*map
;
1904 offset_type
*metadata
;
1905 const gdb_byte
*cu_list
;
1906 const gdb_byte
*types_list
= NULL
;
1907 offset_type version
, cu_list_elements
;
1908 offset_type types_list_elements
= 0;
1911 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1912 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1915 /* Older elfutils strip versions could keep the section in the main
1916 executable while splitting it for the separate debug info file. */
1917 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
1918 & SEC_HAS_CONTENTS
) == 0)
1921 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1923 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1924 /* Version check. */
1925 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1926 /* Versions earlier than 3 emitted every copy of a psymbol. This
1927 causes the index to behave very poorly for certain requests. So,
1928 it seems better to just ignore such indices. */
1932 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1933 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1935 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1938 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1939 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1943 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1944 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1945 - MAYBE_SWAP (metadata
[i
]))
1949 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1950 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1951 - MAYBE_SWAP (metadata
[i
]));
1954 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1955 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1956 - MAYBE_SWAP (metadata
[i
]))
1957 / (2 * sizeof (offset_type
)));
1960 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1962 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1965 if (types_list_elements
1966 && !create_signatured_type_table_from_index (objfile
, types_list
,
1967 types_list_elements
))
1970 create_addrmap_from_index (objfile
, map
);
1972 dwarf2_per_objfile
->index_table
= map
;
1973 dwarf2_per_objfile
->using_index
= 1;
1978 /* A helper for the "quick" functions which sets the global
1979 dwarf2_per_objfile according to OBJFILE. */
1981 dw2_setup (struct objfile
*objfile
)
1983 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1984 gdb_assert (dwarf2_per_objfile
);
1987 /* A helper for the "quick" functions which attempts to read the line
1988 table for THIS_CU. */
1990 dw2_require_line_header (struct objfile
*objfile
,
1991 struct dwarf2_per_cu_data
*this_cu
)
1993 bfd
*abfd
= objfile
->obfd
;
1994 struct line_header
*lh
= NULL
;
1995 struct attribute
*attr
;
1996 struct cleanup
*cleanups
;
1997 struct die_info
*comp_unit_die
;
1998 struct dwarf2_section_info
* sec
;
1999 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2000 int has_children
, i
;
2001 struct dwarf2_cu cu
;
2002 unsigned int bytes_read
, buffer_size
;
2003 struct die_reader_specs reader_specs
;
2004 char *name
, *comp_dir
;
2006 if (this_cu
->v
.quick
->read_lines
)
2008 this_cu
->v
.quick
->read_lines
= 1;
2010 memset (&cu
, 0, sizeof (cu
));
2011 cu
.objfile
= objfile
;
2012 obstack_init (&cu
.comp_unit_obstack
);
2014 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2016 if (this_cu
->from_debug_types
)
2017 sec
= &dwarf2_per_objfile
->types
;
2019 sec
= &dwarf2_per_objfile
->info
;
2020 dwarf2_read_section (objfile
, sec
);
2021 buffer_size
= sec
->size
;
2022 buffer
= sec
->buffer
;
2023 info_ptr
= buffer
+ this_cu
->offset
;
2024 beg_of_comp_unit
= info_ptr
;
2026 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2027 buffer
, buffer_size
,
2030 /* Complete the cu_header. */
2031 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2032 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2035 cu
.per_cu
= this_cu
;
2037 dwarf2_read_abbrevs (abfd
, &cu
);
2038 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2040 if (this_cu
->from_debug_types
)
2041 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2042 init_cu_die_reader (&reader_specs
, &cu
);
2043 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2046 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2049 unsigned int line_offset
= DW_UNSND (attr
);
2050 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2054 do_cleanups (cleanups
);
2058 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2060 this_cu
->v
.quick
->lines
= lh
;
2062 this_cu
->v
.quick
->file_names
2063 = obstack_alloc (&objfile
->objfile_obstack
,
2064 lh
->num_file_names
* sizeof (char *));
2065 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2066 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2068 do_cleanups (cleanups
);
2071 /* A helper for the "quick" functions which computes and caches the
2072 real path for a given file name from the line table.
2073 dw2_require_line_header must have been called before this is
2076 dw2_require_full_path (struct objfile
*objfile
,
2077 struct dwarf2_per_cu_data
*per_cu
,
2080 if (!per_cu
->v
.quick
->full_names
)
2081 per_cu
->v
.quick
->full_names
2082 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2083 per_cu
->v
.quick
->lines
->num_file_names
,
2086 if (!per_cu
->v
.quick
->full_names
[index
])
2087 per_cu
->v
.quick
->full_names
[index
]
2088 = gdb_realpath (per_cu
->v
.quick
->file_names
[index
]);
2090 return per_cu
->v
.quick
->full_names
[index
];
2093 static struct symtab
*
2094 dw2_find_last_source_symtab (struct objfile
*objfile
)
2097 dw2_setup (objfile
);
2098 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2099 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2103 dw2_forget_cached_source_info (struct objfile
*objfile
)
2107 dw2_setup (objfile
);
2108 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2109 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2111 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2113 if (per_cu
->v
.quick
->full_names
)
2117 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2118 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
2124 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2125 const char *full_path
, const char *real_path
,
2126 struct symtab
**result
)
2129 int check_basename
= lbasename (name
) == name
;
2130 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2132 dw2_setup (objfile
);
2133 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2134 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2137 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2139 if (per_cu
->v
.quick
->symtab
)
2142 dw2_require_line_header (objfile
, per_cu
);
2143 if (!per_cu
->v
.quick
->lines
)
2146 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2148 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2150 if (FILENAME_CMP (name
, this_name
) == 0)
2152 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2156 if (check_basename
&& ! base_cu
2157 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2160 if (full_path
!= NULL
)
2162 const char *this_full_name
= dw2_require_full_path (objfile
,
2166 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2168 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2173 if (real_path
!= NULL
)
2175 const char *this_full_name
= dw2_require_full_path (objfile
,
2178 if (this_full_name
!= NULL
)
2180 char *rp
= gdb_realpath (this_full_name
);
2181 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2184 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2195 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2202 static struct symtab
*
2203 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2204 const char *name
, domain_enum domain
)
2206 /* We do all the work in the pre_expand_symtabs_matching hook
2211 /* A helper function that expands all symtabs that hold an object
2214 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2216 dw2_setup (objfile
);
2218 if (dwarf2_per_objfile
->index_table
)
2222 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2225 offset_type i
, len
= MAYBE_SWAP (*vec
);
2226 for (i
= 0; i
< len
; ++i
)
2228 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2229 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2231 dw2_instantiate_symtab (objfile
, per_cu
);
2238 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2239 int kind
, const char *name
,
2242 dw2_do_expand_symtabs_matching (objfile
, name
);
2246 dw2_print_stats (struct objfile
*objfile
)
2250 dw2_setup (objfile
);
2252 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2253 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2255 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2257 if (!per_cu
->v
.quick
->symtab
)
2260 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2264 dw2_dump (struct objfile
*objfile
)
2266 /* Nothing worth printing. */
2270 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2271 struct section_offsets
*delta
)
2273 /* There's nothing to relocate here. */
2277 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2278 const char *func_name
)
2280 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2284 dw2_expand_all_symtabs (struct objfile
*objfile
)
2288 dw2_setup (objfile
);
2290 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2291 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2293 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2295 dw2_instantiate_symtab (objfile
, per_cu
);
2300 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2301 const char *filename
)
2305 dw2_setup (objfile
);
2306 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2307 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2310 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2312 if (per_cu
->v
.quick
->symtab
)
2315 dw2_require_line_header (objfile
, per_cu
);
2316 if (!per_cu
->v
.quick
->lines
)
2319 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2321 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2322 if (strcmp (this_name
, filename
) == 0)
2324 dw2_instantiate_symtab (objfile
, per_cu
);
2332 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2334 struct dwarf2_per_cu_data
*per_cu
;
2337 dw2_setup (objfile
);
2339 if (!dwarf2_per_objfile
->index_table
)
2342 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2346 /* Note that this just looks at the very first one named NAME -- but
2347 actually we are looking for a function. find_main_filename
2348 should be rewritten so that it doesn't require a custom hook. It
2349 could just use the ordinary symbol tables. */
2350 /* vec[0] is the length, which must always be >0. */
2351 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2353 dw2_require_line_header (objfile
, per_cu
);
2354 if (!per_cu
->v
.quick
->lines
)
2357 return per_cu
->v
.quick
->file_names
[per_cu
->v
.quick
->lines
->num_file_names
- 1];
2361 dw2_map_ada_symtabs (struct objfile
*objfile
,
2362 int (*wild_match
) (const char *, int, const char *),
2363 int (*is_name_suffix
) (const char *),
2364 void (*callback
) (struct objfile
*,
2365 struct symtab
*, void *),
2366 const char *name
, int global
,
2367 domain_enum
namespace, int wild
,
2370 /* For now, we don't support Ada. Still the function can be called if the
2371 current language is Ada for a non-Ada objfile using GNU index. As Ada
2372 does not look for non-Ada symbols this function should just return. */
2376 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2377 int (*file_matcher
) (const char *, void *),
2378 int (*name_matcher
) (const char *, void *),
2384 struct mapped_index
*index
;
2386 dw2_setup (objfile
);
2387 if (!dwarf2_per_objfile
->index_table
)
2389 index
= dwarf2_per_objfile
->index_table
;
2391 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2392 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2395 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2397 per_cu
->v
.quick
->mark
= 0;
2398 if (per_cu
->v
.quick
->symtab
)
2401 dw2_require_line_header (objfile
, per_cu
);
2402 if (!per_cu
->v
.quick
->lines
)
2405 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2407 if (file_matcher (per_cu
->v
.quick
->file_names
[j
], data
))
2409 per_cu
->v
.quick
->mark
= 1;
2415 for (iter
= 0; iter
< index
->index_table_slots
; ++iter
)
2417 offset_type idx
= 2 * iter
;
2419 offset_type
*vec
, vec_len
, vec_idx
;
2421 if (index
->index_table
[idx
] == 0 && index
->index_table
[idx
+ 1] == 0)
2424 name
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[idx
]);
2426 if (! (*name_matcher
) (name
, data
))
2429 /* The name was matched, now expand corresponding CUs that were
2431 vec
= (offset_type
*) (index
->constant_pool
2432 + MAYBE_SWAP (index
->index_table
[idx
+ 1]));
2433 vec_len
= MAYBE_SWAP (vec
[0]);
2434 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2436 struct dwarf2_per_cu_data
*per_cu
;
2438 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2439 if (per_cu
->v
.quick
->mark
)
2440 dw2_instantiate_symtab (objfile
, per_cu
);
2445 static struct symtab
*
2446 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2447 struct minimal_symbol
*msymbol
,
2449 struct obj_section
*section
,
2452 struct dwarf2_per_cu_data
*data
;
2454 dw2_setup (objfile
);
2456 if (!objfile
->psymtabs_addrmap
)
2459 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2463 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2464 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2465 paddress (get_objfile_arch (objfile
), pc
));
2467 return dw2_instantiate_symtab (objfile
, data
);
2471 dw2_map_symbol_names (struct objfile
*objfile
,
2472 void (*fun
) (const char *, void *),
2476 struct mapped_index
*index
;
2478 dw2_setup (objfile
);
2480 if (!dwarf2_per_objfile
->index_table
)
2482 index
= dwarf2_per_objfile
->index_table
;
2484 for (iter
= 0; iter
< index
->index_table_slots
; ++iter
)
2486 offset_type idx
= 2 * iter
;
2488 offset_type
*vec
, vec_len
, vec_idx
;
2490 if (index
->index_table
[idx
] == 0 && index
->index_table
[idx
+ 1] == 0)
2493 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[idx
]));
2495 (*fun
) (name
, data
);
2500 dw2_map_symbol_filenames (struct objfile
*objfile
,
2501 void (*fun
) (const char *, const char *, void *),
2506 dw2_setup (objfile
);
2507 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2508 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2511 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2513 if (per_cu
->v
.quick
->symtab
)
2516 dw2_require_line_header (objfile
, per_cu
);
2517 if (!per_cu
->v
.quick
->lines
)
2520 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2522 const char *this_full_name
= dw2_require_full_path (objfile
, per_cu
,
2524 (*fun
) (per_cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2530 dw2_has_symbols (struct objfile
*objfile
)
2535 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2538 dw2_find_last_source_symtab
,
2539 dw2_forget_cached_source_info
,
2542 dw2_pre_expand_symtabs_matching
,
2546 dw2_expand_symtabs_for_function
,
2547 dw2_expand_all_symtabs
,
2548 dw2_expand_symtabs_with_filename
,
2549 dw2_find_symbol_file
,
2550 dw2_map_ada_symtabs
,
2551 dw2_expand_symtabs_matching
,
2552 dw2_find_pc_sect_symtab
,
2553 dw2_map_symbol_names
,
2554 dw2_map_symbol_filenames
2557 /* Initialize for reading DWARF for this objfile. Return 0 if this
2558 file will use psymtabs, or 1 if using the GNU index. */
2561 dwarf2_initialize_objfile (struct objfile
*objfile
)
2563 /* If we're about to read full symbols, don't bother with the
2564 indices. In this case we also don't care if some other debug
2565 format is making psymtabs, because they are all about to be
2567 if ((objfile
->flags
& OBJF_READNOW
))
2571 dwarf2_per_objfile
->using_index
= 1;
2572 create_all_comp_units (objfile
);
2573 create_debug_types_hash_table (objfile
);
2575 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2576 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2578 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2580 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2581 struct dwarf2_per_cu_quick_data
);
2584 /* Return 1 so that gdb sees the "quick" functions. However,
2585 these functions will be no-ops because we will have expanded
2590 if (dwarf2_read_index (objfile
))
2593 dwarf2_build_psymtabs (objfile
);
2599 /* Build a partial symbol table. */
2602 dwarf2_build_psymtabs (struct objfile
*objfile
)
2604 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2606 init_psymbol_list (objfile
, 1024);
2609 dwarf2_build_psymtabs_hard (objfile
);
2612 /* Return TRUE if OFFSET is within CU_HEADER. */
2615 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2617 unsigned int bottom
= cu_header
->offset
;
2618 unsigned int top
= (cu_header
->offset
2620 + cu_header
->initial_length_size
);
2622 return (offset
>= bottom
&& offset
< top
);
2625 /* Read in the comp unit header information from the debug_info at info_ptr.
2626 NOTE: This leaves members offset, first_die_offset to be filled in
2630 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2631 gdb_byte
*info_ptr
, bfd
*abfd
)
2634 unsigned int bytes_read
;
2636 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2637 cu_header
->initial_length_size
= bytes_read
;
2638 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2639 info_ptr
+= bytes_read
;
2640 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2642 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2644 info_ptr
+= bytes_read
;
2645 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2647 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2648 if (signed_addr
< 0)
2649 internal_error (__FILE__
, __LINE__
,
2650 _("read_comp_unit_head: dwarf from non elf file"));
2651 cu_header
->signed_addr_p
= signed_addr
;
2657 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2658 gdb_byte
*buffer
, unsigned int buffer_size
,
2661 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2663 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2665 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2666 error (_("Dwarf Error: wrong version in compilation unit header "
2667 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2668 bfd_get_filename (abfd
));
2670 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2671 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2672 "(offset 0x%lx + 6) [in module %s]"),
2673 (long) header
->abbrev_offset
,
2674 (long) (beg_of_comp_unit
- buffer
),
2675 bfd_get_filename (abfd
));
2677 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2678 > buffer
+ buffer_size
)
2679 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2680 "(offset 0x%lx + 0) [in module %s]"),
2681 (long) header
->length
,
2682 (long) (beg_of_comp_unit
- buffer
),
2683 bfd_get_filename (abfd
));
2688 /* Read in the types comp unit header information from .debug_types entry at
2689 types_ptr. The result is a pointer to one past the end of the header. */
2692 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2693 ULONGEST
*signature
,
2694 gdb_byte
*types_ptr
, bfd
*abfd
)
2696 gdb_byte
*initial_types_ptr
= types_ptr
;
2698 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2699 &dwarf2_per_objfile
->types
);
2700 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2702 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2704 *signature
= read_8_bytes (abfd
, types_ptr
);
2706 types_ptr
+= cu_header
->offset_size
;
2707 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2712 /* Allocate a new partial symtab for file named NAME and mark this new
2713 partial symtab as being an include of PST. */
2716 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2717 struct objfile
*objfile
)
2719 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2721 subpst
->section_offsets
= pst
->section_offsets
;
2722 subpst
->textlow
= 0;
2723 subpst
->texthigh
= 0;
2725 subpst
->dependencies
= (struct partial_symtab
**)
2726 obstack_alloc (&objfile
->objfile_obstack
,
2727 sizeof (struct partial_symtab
*));
2728 subpst
->dependencies
[0] = pst
;
2729 subpst
->number_of_dependencies
= 1;
2731 subpst
->globals_offset
= 0;
2732 subpst
->n_global_syms
= 0;
2733 subpst
->statics_offset
= 0;
2734 subpst
->n_static_syms
= 0;
2735 subpst
->symtab
= NULL
;
2736 subpst
->read_symtab
= pst
->read_symtab
;
2739 /* No private part is necessary for include psymtabs. This property
2740 can be used to differentiate between such include psymtabs and
2741 the regular ones. */
2742 subpst
->read_symtab_private
= NULL
;
2745 /* Read the Line Number Program data and extract the list of files
2746 included by the source file represented by PST. Build an include
2747 partial symtab for each of these included files. */
2750 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2751 struct die_info
*die
,
2752 struct partial_symtab
*pst
)
2754 struct objfile
*objfile
= cu
->objfile
;
2755 bfd
*abfd
= objfile
->obfd
;
2756 struct line_header
*lh
= NULL
;
2757 struct attribute
*attr
;
2759 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2762 unsigned int line_offset
= DW_UNSND (attr
);
2764 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2767 return; /* No linetable, so no includes. */
2769 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2770 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2772 free_line_header (lh
);
2776 hash_type_signature (const void *item
)
2778 const struct signatured_type
*type_sig
= item
;
2780 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2781 return type_sig
->signature
;
2785 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2787 const struct signatured_type
*lhs
= item_lhs
;
2788 const struct signatured_type
*rhs
= item_rhs
;
2790 return lhs
->signature
== rhs
->signature
;
2793 /* Allocate a hash table for signatured types. */
2796 allocate_signatured_type_table (struct objfile
*objfile
)
2798 return htab_create_alloc_ex (41,
2799 hash_type_signature
,
2802 &objfile
->objfile_obstack
,
2803 hashtab_obstack_allocate
,
2804 dummy_obstack_deallocate
);
2807 /* A helper function to add a signatured type CU to a list. */
2810 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2812 struct signatured_type
*sigt
= *slot
;
2813 struct dwarf2_per_cu_data
***datap
= datum
;
2815 **datap
= &sigt
->per_cu
;
2821 /* Create the hash table of all entries in the .debug_types section.
2822 The result is zero if there is an error (e.g. missing .debug_types section),
2823 otherwise non-zero. */
2826 create_debug_types_hash_table (struct objfile
*objfile
)
2830 struct dwarf2_per_cu_data
**iter
;
2832 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2833 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2835 if (info_ptr
== NULL
)
2837 dwarf2_per_objfile
->signatured_types
= NULL
;
2841 types_htab
= allocate_signatured_type_table (objfile
);
2843 if (dwarf2_die_debug
)
2844 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2846 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2848 unsigned int offset
;
2849 unsigned int offset_size
;
2850 unsigned int type_offset
;
2851 unsigned int length
, initial_length_size
;
2852 unsigned short version
;
2854 struct signatured_type
*type_sig
;
2856 gdb_byte
*ptr
= info_ptr
;
2858 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2860 /* We need to read the type's signature in order to build the hash
2861 table, but we don't need to read anything else just yet. */
2863 /* Sanity check to ensure entire cu is present. */
2864 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2865 if (ptr
+ length
+ initial_length_size
2866 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2868 complaint (&symfile_complaints
,
2869 _("debug type entry runs off end of `.debug_types' section, ignored"));
2873 offset_size
= initial_length_size
== 4 ? 4 : 8;
2874 ptr
+= initial_length_size
;
2875 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2877 ptr
+= offset_size
; /* abbrev offset */
2878 ptr
+= 1; /* address size */
2879 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2881 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2883 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2884 memset (type_sig
, 0, sizeof (*type_sig
));
2885 type_sig
->signature
= signature
;
2886 type_sig
->offset
= offset
;
2887 type_sig
->type_offset
= type_offset
;
2888 type_sig
->per_cu
.objfile
= objfile
;
2889 type_sig
->per_cu
.from_debug_types
= 1;
2891 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2892 gdb_assert (slot
!= NULL
);
2895 if (dwarf2_die_debug
)
2896 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2897 offset
, phex (signature
, sizeof (signature
)));
2899 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2902 dwarf2_per_objfile
->signatured_types
= types_htab
;
2904 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2905 dwarf2_per_objfile
->type_comp_units
2906 = obstack_alloc (&objfile
->objfile_obstack
,
2907 dwarf2_per_objfile
->n_type_comp_units
2908 * sizeof (struct dwarf2_per_cu_data
*));
2909 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2910 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2911 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2912 == dwarf2_per_objfile
->n_type_comp_units
);
2917 /* Lookup a signature based type.
2918 Returns NULL if SIG is not present in the table. */
2920 static struct signatured_type
*
2921 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2923 struct signatured_type find_entry
, *entry
;
2925 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2927 complaint (&symfile_complaints
,
2928 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2932 find_entry
.signature
= sig
;
2933 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2937 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2940 init_cu_die_reader (struct die_reader_specs
*reader
,
2941 struct dwarf2_cu
*cu
)
2943 reader
->abfd
= cu
->objfile
->obfd
;
2945 if (cu
->per_cu
->from_debug_types
)
2947 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2948 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2952 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2953 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2957 /* Find the base address of the compilation unit for range lists and
2958 location lists. It will normally be specified by DW_AT_low_pc.
2959 In DWARF-3 draft 4, the base address could be overridden by
2960 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2961 compilation units with discontinuous ranges. */
2964 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2966 struct attribute
*attr
;
2969 cu
->base_address
= 0;
2971 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2974 cu
->base_address
= DW_ADDR (attr
);
2979 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2982 cu
->base_address
= DW_ADDR (attr
);
2988 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2989 to combine the common parts.
2990 Process a compilation unit for a psymtab.
2991 BUFFER is a pointer to the beginning of the dwarf section buffer,
2992 either .debug_info or debug_types.
2993 INFO_PTR is a pointer to the start of the CU.
2994 Returns a pointer to the next CU. */
2997 process_psymtab_comp_unit (struct objfile
*objfile
,
2998 struct dwarf2_per_cu_data
*this_cu
,
2999 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3000 unsigned int buffer_size
)
3002 bfd
*abfd
= objfile
->obfd
;
3003 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3004 struct die_info
*comp_unit_die
;
3005 struct partial_symtab
*pst
;
3007 struct cleanup
*back_to_inner
;
3008 struct dwarf2_cu cu
;
3009 int has_children
, has_pc_info
;
3010 struct attribute
*attr
;
3011 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3012 struct die_reader_specs reader_specs
;
3014 memset (&cu
, 0, sizeof (cu
));
3015 cu
.objfile
= objfile
;
3016 obstack_init (&cu
.comp_unit_obstack
);
3018 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3020 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3021 buffer
, buffer_size
,
3024 /* Complete the cu_header. */
3025 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3026 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3028 cu
.list_in_scope
= &file_symbols
;
3030 /* If this compilation unit was already read in, free the
3031 cached copy in order to read it in again. This is
3032 necessary because we skipped some symbols when we first
3033 read in the compilation unit (see load_partial_dies).
3034 This problem could be avoided, but the benefit is
3036 if (this_cu
->cu
!= NULL
)
3037 free_one_cached_comp_unit (this_cu
->cu
);
3039 /* Note that this is a pointer to our stack frame, being
3040 added to a global data structure. It will be cleaned up
3041 in free_stack_comp_unit when we finish with this
3042 compilation unit. */
3044 cu
.per_cu
= this_cu
;
3046 /* Read the abbrevs for this compilation unit into a table. */
3047 dwarf2_read_abbrevs (abfd
, &cu
);
3048 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3050 /* Read the compilation unit die. */
3051 if (this_cu
->from_debug_types
)
3052 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3053 init_cu_die_reader (&reader_specs
, &cu
);
3054 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3057 if (this_cu
->from_debug_types
)
3059 /* offset,length haven't been set yet for type units. */
3060 this_cu
->offset
= cu
.header
.offset
;
3061 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3063 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3065 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3066 + cu
.header
.initial_length_size
);
3067 do_cleanups (back_to_inner
);
3071 /* Set the language we're debugging. */
3072 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
3074 set_cu_language (DW_UNSND (attr
), &cu
);
3076 set_cu_language (language_minimal
, &cu
);
3078 /* Allocate a new partial symbol table structure. */
3079 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3080 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3081 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3082 /* TEXTLOW and TEXTHIGH are set below. */
3084 objfile
->global_psymbols
.next
,
3085 objfile
->static_psymbols
.next
);
3087 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3089 pst
->dirname
= DW_STRING (attr
);
3091 pst
->read_symtab_private
= this_cu
;
3093 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3095 /* Store the function that reads in the rest of the symbol table */
3096 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3098 this_cu
->v
.psymtab
= pst
;
3100 dwarf2_find_base_address (comp_unit_die
, &cu
);
3102 /* Possibly set the default values of LOWPC and HIGHPC from
3104 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3105 &best_highpc
, &cu
, pst
);
3106 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3107 /* Store the contiguous range if it is not empty; it can be empty for
3108 CUs with no code. */
3109 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3110 best_lowpc
+ baseaddr
,
3111 best_highpc
+ baseaddr
- 1, pst
);
3113 /* Check if comp unit has_children.
3114 If so, read the rest of the partial symbols from this comp unit.
3115 If not, there's no more debug_info for this comp unit. */
3118 struct partial_die_info
*first_die
;
3119 CORE_ADDR lowpc
, highpc
;
3121 lowpc
= ((CORE_ADDR
) -1);
3122 highpc
= ((CORE_ADDR
) 0);
3124 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3126 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3127 ! has_pc_info
, &cu
);
3129 /* If we didn't find a lowpc, set it to highpc to avoid
3130 complaints from `maint check'. */
3131 if (lowpc
== ((CORE_ADDR
) -1))
3134 /* If the compilation unit didn't have an explicit address range,
3135 then use the information extracted from its child dies. */
3139 best_highpc
= highpc
;
3142 pst
->textlow
= best_lowpc
+ baseaddr
;
3143 pst
->texthigh
= best_highpc
+ baseaddr
;
3145 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3146 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3147 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3148 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3149 sort_pst_symbols (pst
);
3151 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3152 + cu
.header
.initial_length_size
);
3154 if (this_cu
->from_debug_types
)
3156 /* It's not clear we want to do anything with stmt lists here.
3157 Waiting to see what gcc ultimately does. */
3161 /* Get the list of files included in the current compilation unit,
3162 and build a psymtab for each of them. */
3163 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3166 do_cleanups (back_to_inner
);
3171 /* Traversal function for htab_traverse_noresize.
3172 Process one .debug_types comp-unit. */
3175 process_type_comp_unit (void **slot
, void *info
)
3177 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3178 struct objfile
*objfile
= (struct objfile
*) info
;
3179 struct dwarf2_per_cu_data
*this_cu
;
3181 this_cu
= &entry
->per_cu
;
3183 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3184 process_psymtab_comp_unit (objfile
, this_cu
,
3185 dwarf2_per_objfile
->types
.buffer
,
3186 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3187 dwarf2_per_objfile
->types
.size
);
3192 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3193 Build partial symbol tables for the .debug_types comp-units. */
3196 build_type_psymtabs (struct objfile
*objfile
)
3198 if (! create_debug_types_hash_table (objfile
))
3201 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3202 process_type_comp_unit
, objfile
);
3205 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3208 psymtabs_addrmap_cleanup (void *o
)
3210 struct objfile
*objfile
= o
;
3212 objfile
->psymtabs_addrmap
= NULL
;
3215 /* Build the partial symbol table by doing a quick pass through the
3216 .debug_info and .debug_abbrev sections. */
3219 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3222 struct cleanup
*back_to
, *addrmap_cleanup
;
3223 struct obstack temp_obstack
;
3225 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3227 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3228 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3230 /* Any cached compilation units will be linked by the per-objfile
3231 read_in_chain. Make sure to free them when we're done. */
3232 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3234 build_type_psymtabs (objfile
);
3236 create_all_comp_units (objfile
);
3238 /* Create a temporary address map on a temporary obstack. We later
3239 copy this to the final obstack. */
3240 obstack_init (&temp_obstack
);
3241 make_cleanup_obstack_free (&temp_obstack
);
3242 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3243 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3245 /* Since the objects we're extracting from .debug_info vary in
3246 length, only the individual functions to extract them (like
3247 read_comp_unit_head and load_partial_die) can really know whether
3248 the buffer is large enough to hold another complete object.
3250 At the moment, they don't actually check that. If .debug_info
3251 holds just one extra byte after the last compilation unit's dies,
3252 then read_comp_unit_head will happily read off the end of the
3253 buffer. read_partial_die is similarly casual. Those functions
3256 For this loop condition, simply checking whether there's any data
3257 left at all should be sufficient. */
3259 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3260 + dwarf2_per_objfile
->info
.size
))
3262 struct dwarf2_per_cu_data
*this_cu
;
3264 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3267 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3268 dwarf2_per_objfile
->info
.buffer
,
3270 dwarf2_per_objfile
->info
.size
);
3273 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3274 &objfile
->objfile_obstack
);
3275 discard_cleanups (addrmap_cleanup
);
3277 do_cleanups (back_to
);
3280 /* Load the partial DIEs for a secondary CU into memory. */
3283 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3284 struct objfile
*objfile
)
3286 bfd
*abfd
= objfile
->obfd
;
3287 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3288 struct die_info
*comp_unit_die
;
3289 struct dwarf2_cu
*cu
;
3290 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3291 struct attribute
*attr
;
3293 struct die_reader_specs reader_specs
;
3296 gdb_assert (! this_cu
->from_debug_types
);
3298 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3299 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3300 beg_of_comp_unit
= info_ptr
;
3302 if (this_cu
->cu
== NULL
)
3304 cu
= alloc_one_comp_unit (objfile
);
3308 /* If an error occurs while loading, release our storage. */
3309 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3311 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3312 dwarf2_per_objfile
->info
.buffer
,
3313 dwarf2_per_objfile
->info
.size
,
3316 /* Complete the cu_header. */
3317 cu
->header
.offset
= this_cu
->offset
;
3318 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3320 /* Link this compilation unit into the compilation unit tree. */
3322 cu
->per_cu
= this_cu
;
3324 /* Link this CU into read_in_chain. */
3325 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3326 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3331 info_ptr
+= cu
->header
.first_die_offset
;
3334 /* Read the abbrevs for this compilation unit into a table. */
3335 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3336 dwarf2_read_abbrevs (abfd
, cu
);
3337 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3339 /* Read the compilation unit die. */
3340 init_cu_die_reader (&reader_specs
, cu
);
3341 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3344 /* Set the language we're debugging. */
3345 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3347 set_cu_language (DW_UNSND (attr
), cu
);
3349 set_cu_language (language_minimal
, cu
);
3351 /* Check if comp unit has_children.
3352 If so, read the rest of the partial symbols from this comp unit.
3353 If not, there's no more debug_info for this comp unit. */
3355 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3357 do_cleanups (free_abbrevs_cleanup
);
3361 /* We've successfully allocated this compilation unit. Let our
3362 caller clean it up when finished with it. */
3363 discard_cleanups (free_cu_cleanup
);
3367 /* Create a list of all compilation units in OBJFILE. We do this only
3368 if an inter-comp-unit reference is found; presumably if there is one,
3369 there will be many, and one will occur early in the .debug_info section.
3370 So there's no point in building this list incrementally. */
3373 create_all_comp_units (struct objfile
*objfile
)
3377 struct dwarf2_per_cu_data
**all_comp_units
;
3380 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3381 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3385 all_comp_units
= xmalloc (n_allocated
3386 * sizeof (struct dwarf2_per_cu_data
*));
3388 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3390 unsigned int length
, initial_length_size
;
3391 struct dwarf2_per_cu_data
*this_cu
;
3392 unsigned int offset
;
3394 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3396 /* Read just enough information to find out where the next
3397 compilation unit is. */
3398 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3399 &initial_length_size
);
3401 /* Save the compilation unit for later lookup. */
3402 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3403 sizeof (struct dwarf2_per_cu_data
));
3404 memset (this_cu
, 0, sizeof (*this_cu
));
3405 this_cu
->offset
= offset
;
3406 this_cu
->length
= length
+ initial_length_size
;
3407 this_cu
->objfile
= objfile
;
3409 if (n_comp_units
== n_allocated
)
3412 all_comp_units
= xrealloc (all_comp_units
,
3414 * sizeof (struct dwarf2_per_cu_data
*));
3416 all_comp_units
[n_comp_units
++] = this_cu
;
3418 info_ptr
= info_ptr
+ this_cu
->length
;
3421 dwarf2_per_objfile
->all_comp_units
3422 = obstack_alloc (&objfile
->objfile_obstack
,
3423 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3424 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3425 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3426 xfree (all_comp_units
);
3427 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3430 /* Process all loaded DIEs for compilation unit CU, starting at
3431 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3432 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3433 DW_AT_ranges). If NEED_PC is set, then this function will set
3434 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3435 and record the covered ranges in the addrmap. */
3438 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3439 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3441 struct partial_die_info
*pdi
;
3443 /* Now, march along the PDI's, descending into ones which have
3444 interesting children but skipping the children of the other ones,
3445 until we reach the end of the compilation unit. */
3451 fixup_partial_die (pdi
, cu
);
3453 /* Anonymous namespaces or modules have no name but have interesting
3454 children, so we need to look at them. Ditto for anonymous
3457 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3458 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3462 case DW_TAG_subprogram
:
3463 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3465 case DW_TAG_constant
:
3466 case DW_TAG_variable
:
3467 case DW_TAG_typedef
:
3468 case DW_TAG_union_type
:
3469 if (!pdi
->is_declaration
)
3471 add_partial_symbol (pdi
, cu
);
3474 case DW_TAG_class_type
:
3475 case DW_TAG_interface_type
:
3476 case DW_TAG_structure_type
:
3477 if (!pdi
->is_declaration
)
3479 add_partial_symbol (pdi
, cu
);
3482 case DW_TAG_enumeration_type
:
3483 if (!pdi
->is_declaration
)
3484 add_partial_enumeration (pdi
, cu
);
3486 case DW_TAG_base_type
:
3487 case DW_TAG_subrange_type
:
3488 /* File scope base type definitions are added to the partial
3490 add_partial_symbol (pdi
, cu
);
3492 case DW_TAG_namespace
:
3493 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3496 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3503 /* If the die has a sibling, skip to the sibling. */
3505 pdi
= pdi
->die_sibling
;
3509 /* Functions used to compute the fully scoped name of a partial DIE.
3511 Normally, this is simple. For C++, the parent DIE's fully scoped
3512 name is concatenated with "::" and the partial DIE's name. For
3513 Java, the same thing occurs except that "." is used instead of "::".
3514 Enumerators are an exception; they use the scope of their parent
3515 enumeration type, i.e. the name of the enumeration type is not
3516 prepended to the enumerator.
3518 There are two complexities. One is DW_AT_specification; in this
3519 case "parent" means the parent of the target of the specification,
3520 instead of the direct parent of the DIE. The other is compilers
3521 which do not emit DW_TAG_namespace; in this case we try to guess
3522 the fully qualified name of structure types from their members'
3523 linkage names. This must be done using the DIE's children rather
3524 than the children of any DW_AT_specification target. We only need
3525 to do this for structures at the top level, i.e. if the target of
3526 any DW_AT_specification (if any; otherwise the DIE itself) does not
3529 /* Compute the scope prefix associated with PDI's parent, in
3530 compilation unit CU. The result will be allocated on CU's
3531 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3532 field. NULL is returned if no prefix is necessary. */
3534 partial_die_parent_scope (struct partial_die_info
*pdi
,
3535 struct dwarf2_cu
*cu
)
3537 char *grandparent_scope
;
3538 struct partial_die_info
*parent
, *real_pdi
;
3540 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3541 then this means the parent of the specification DIE. */
3544 while (real_pdi
->has_specification
)
3545 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3547 parent
= real_pdi
->die_parent
;
3551 if (parent
->scope_set
)
3552 return parent
->scope
;
3554 fixup_partial_die (parent
, cu
);
3556 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3558 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3559 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3560 Work around this problem here. */
3561 if (cu
->language
== language_cplus
3562 && parent
->tag
== DW_TAG_namespace
3563 && strcmp (parent
->name
, "::") == 0
3564 && grandparent_scope
== NULL
)
3566 parent
->scope
= NULL
;
3567 parent
->scope_set
= 1;
3571 if (parent
->tag
== DW_TAG_namespace
3572 || parent
->tag
== DW_TAG_module
3573 || parent
->tag
== DW_TAG_structure_type
3574 || parent
->tag
== DW_TAG_class_type
3575 || parent
->tag
== DW_TAG_interface_type
3576 || parent
->tag
== DW_TAG_union_type
3577 || parent
->tag
== DW_TAG_enumeration_type
)
3579 if (grandparent_scope
== NULL
)
3580 parent
->scope
= parent
->name
;
3582 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3583 parent
->name
, 0, cu
);
3585 else if (parent
->tag
== DW_TAG_enumerator
)
3586 /* Enumerators should not get the name of the enumeration as a prefix. */
3587 parent
->scope
= grandparent_scope
;
3590 /* FIXME drow/2004-04-01: What should we be doing with
3591 function-local names? For partial symbols, we should probably be
3593 complaint (&symfile_complaints
,
3594 _("unhandled containing DIE tag %d for DIE at %d"),
3595 parent
->tag
, pdi
->offset
);
3596 parent
->scope
= grandparent_scope
;
3599 parent
->scope_set
= 1;
3600 return parent
->scope
;
3603 /* Return the fully scoped name associated with PDI, from compilation unit
3604 CU. The result will be allocated with malloc. */
3606 partial_die_full_name (struct partial_die_info
*pdi
,
3607 struct dwarf2_cu
*cu
)
3611 /* If this is a template instantiation, we can not work out the
3612 template arguments from partial DIEs. So, unfortunately, we have
3613 to go through the full DIEs. At least any work we do building
3614 types here will be reused if full symbols are loaded later. */
3615 if (pdi
->has_template_arguments
)
3617 fixup_partial_die (pdi
, cu
);
3619 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3621 struct die_info
*die
;
3622 struct attribute attr
;
3623 struct dwarf2_cu
*ref_cu
= cu
;
3626 attr
.form
= DW_FORM_ref_addr
;
3627 attr
.u
.addr
= pdi
->offset
;
3628 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3630 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3634 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3635 if (parent_scope
== NULL
)
3638 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3642 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3644 struct objfile
*objfile
= cu
->objfile
;
3646 char *actual_name
= NULL
;
3647 const struct partial_symbol
*psym
= NULL
;
3649 int built_actual_name
= 0;
3651 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3653 actual_name
= partial_die_full_name (pdi
, cu
);
3655 built_actual_name
= 1;
3657 if (actual_name
== NULL
)
3658 actual_name
= pdi
->name
;
3662 case DW_TAG_subprogram
:
3663 if (pdi
->is_external
|| cu
->language
== language_ada
)
3665 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3666 of the global scope. But in Ada, we want to be able to access
3667 nested procedures globally. So all Ada subprograms are stored
3668 in the global scope. */
3669 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3670 mst_text, objfile); */
3671 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3673 VAR_DOMAIN
, LOC_BLOCK
,
3674 &objfile
->global_psymbols
,
3675 0, pdi
->lowpc
+ baseaddr
,
3676 cu
->language
, objfile
);
3680 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3681 mst_file_text, objfile); */
3682 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3684 VAR_DOMAIN
, LOC_BLOCK
,
3685 &objfile
->static_psymbols
,
3686 0, pdi
->lowpc
+ baseaddr
,
3687 cu
->language
, objfile
);
3690 case DW_TAG_constant
:
3692 struct psymbol_allocation_list
*list
;
3694 if (pdi
->is_external
)
3695 list
= &objfile
->global_psymbols
;
3697 list
= &objfile
->static_psymbols
;
3698 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3699 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3700 list
, 0, 0, cu
->language
, objfile
);
3704 case DW_TAG_variable
:
3706 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3710 && !dwarf2_per_objfile
->has_section_at_zero
)
3712 /* A global or static variable may also have been stripped
3713 out by the linker if unused, in which case its address
3714 will be nullified; do not add such variables into partial
3715 symbol table then. */
3717 else if (pdi
->is_external
)
3720 Don't enter into the minimal symbol tables as there is
3721 a minimal symbol table entry from the ELF symbols already.
3722 Enter into partial symbol table if it has a location
3723 descriptor or a type.
3724 If the location descriptor is missing, new_symbol will create
3725 a LOC_UNRESOLVED symbol, the address of the variable will then
3726 be determined from the minimal symbol table whenever the variable
3728 The address for the partial symbol table entry is not
3729 used by GDB, but it comes in handy for debugging partial symbol
3732 if (pdi
->locdesc
|| pdi
->has_type
)
3733 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3735 VAR_DOMAIN
, LOC_STATIC
,
3736 &objfile
->global_psymbols
,
3738 cu
->language
, objfile
);
3742 /* Static Variable. Skip symbols without location descriptors. */
3743 if (pdi
->locdesc
== NULL
)
3745 if (built_actual_name
)
3746 xfree (actual_name
);
3749 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3750 mst_file_data, objfile); */
3751 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3753 VAR_DOMAIN
, LOC_STATIC
,
3754 &objfile
->static_psymbols
,
3756 cu
->language
, objfile
);
3759 case DW_TAG_typedef
:
3760 case DW_TAG_base_type
:
3761 case DW_TAG_subrange_type
:
3762 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3764 VAR_DOMAIN
, LOC_TYPEDEF
,
3765 &objfile
->static_psymbols
,
3766 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3768 case DW_TAG_namespace
:
3769 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3771 VAR_DOMAIN
, LOC_TYPEDEF
,
3772 &objfile
->global_psymbols
,
3773 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3775 case DW_TAG_class_type
:
3776 case DW_TAG_interface_type
:
3777 case DW_TAG_structure_type
:
3778 case DW_TAG_union_type
:
3779 case DW_TAG_enumeration_type
:
3780 /* Skip external references. The DWARF standard says in the section
3781 about "Structure, Union, and Class Type Entries": "An incomplete
3782 structure, union or class type is represented by a structure,
3783 union or class entry that does not have a byte size attribute
3784 and that has a DW_AT_declaration attribute." */
3785 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3787 if (built_actual_name
)
3788 xfree (actual_name
);
3792 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3793 static vs. global. */
3794 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3796 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3797 (cu
->language
== language_cplus
3798 || cu
->language
== language_java
)
3799 ? &objfile
->global_psymbols
3800 : &objfile
->static_psymbols
,
3801 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3804 case DW_TAG_enumerator
:
3805 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3807 VAR_DOMAIN
, LOC_CONST
,
3808 (cu
->language
== language_cplus
3809 || cu
->language
== language_java
)
3810 ? &objfile
->global_psymbols
3811 : &objfile
->static_psymbols
,
3812 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3818 if (built_actual_name
)
3819 xfree (actual_name
);
3822 /* Read a partial die corresponding to a namespace; also, add a symbol
3823 corresponding to that namespace to the symbol table. NAMESPACE is
3824 the name of the enclosing namespace. */
3827 add_partial_namespace (struct partial_die_info
*pdi
,
3828 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3829 int need_pc
, struct dwarf2_cu
*cu
)
3831 /* Add a symbol for the namespace. */
3833 add_partial_symbol (pdi
, cu
);
3835 /* Now scan partial symbols in that namespace. */
3837 if (pdi
->has_children
)
3838 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3841 /* Read a partial die corresponding to a Fortran module. */
3844 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3845 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3847 /* Now scan partial symbols in that module. */
3849 if (pdi
->has_children
)
3850 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3853 /* Read a partial die corresponding to a subprogram and create a partial
3854 symbol for that subprogram. When the CU language allows it, this
3855 routine also defines a partial symbol for each nested subprogram
3856 that this subprogram contains.
3858 DIE my also be a lexical block, in which case we simply search
3859 recursively for suprograms defined inside that lexical block.
3860 Again, this is only performed when the CU language allows this
3861 type of definitions. */
3864 add_partial_subprogram (struct partial_die_info
*pdi
,
3865 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3866 int need_pc
, struct dwarf2_cu
*cu
)
3868 if (pdi
->tag
== DW_TAG_subprogram
)
3870 if (pdi
->has_pc_info
)
3872 if (pdi
->lowpc
< *lowpc
)
3873 *lowpc
= pdi
->lowpc
;
3874 if (pdi
->highpc
> *highpc
)
3875 *highpc
= pdi
->highpc
;
3879 struct objfile
*objfile
= cu
->objfile
;
3881 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3882 SECT_OFF_TEXT (objfile
));
3883 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3884 pdi
->lowpc
+ baseaddr
,
3885 pdi
->highpc
- 1 + baseaddr
,
3886 cu
->per_cu
->v
.psymtab
);
3888 if (!pdi
->is_declaration
)
3889 /* Ignore subprogram DIEs that do not have a name, they are
3890 illegal. Do not emit a complaint at this point, we will
3891 do so when we convert this psymtab into a symtab. */
3893 add_partial_symbol (pdi
, cu
);
3897 if (! pdi
->has_children
)
3900 if (cu
->language
== language_ada
)
3902 pdi
= pdi
->die_child
;
3905 fixup_partial_die (pdi
, cu
);
3906 if (pdi
->tag
== DW_TAG_subprogram
3907 || pdi
->tag
== DW_TAG_lexical_block
)
3908 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3909 pdi
= pdi
->die_sibling
;
3914 /* Read a partial die corresponding to an enumeration type. */
3917 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3918 struct dwarf2_cu
*cu
)
3920 struct partial_die_info
*pdi
;
3922 if (enum_pdi
->name
!= NULL
)
3923 add_partial_symbol (enum_pdi
, cu
);
3925 pdi
= enum_pdi
->die_child
;
3928 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3929 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3931 add_partial_symbol (pdi
, cu
);
3932 pdi
= pdi
->die_sibling
;
3936 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3937 Return the corresponding abbrev, or NULL if the number is zero (indicating
3938 an empty DIE). In either case *BYTES_READ will be set to the length of
3939 the initial number. */
3941 static struct abbrev_info
*
3942 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3943 struct dwarf2_cu
*cu
)
3945 bfd
*abfd
= cu
->objfile
->obfd
;
3946 unsigned int abbrev_number
;
3947 struct abbrev_info
*abbrev
;
3949 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3951 if (abbrev_number
== 0)
3954 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3957 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3958 bfd_get_filename (abfd
));
3964 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3965 Returns a pointer to the end of a series of DIEs, terminated by an empty
3966 DIE. Any children of the skipped DIEs will also be skipped. */
3969 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3971 struct abbrev_info
*abbrev
;
3972 unsigned int bytes_read
;
3976 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3978 return info_ptr
+ bytes_read
;
3980 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3984 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3985 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3986 abbrev corresponding to that skipped uleb128 should be passed in
3987 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3991 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3992 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
3994 unsigned int bytes_read
;
3995 struct attribute attr
;
3996 bfd
*abfd
= cu
->objfile
->obfd
;
3997 unsigned int form
, i
;
3999 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4001 /* The only abbrev we care about is DW_AT_sibling. */
4002 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4004 read_attribute (&attr
, &abbrev
->attrs
[i
],
4005 abfd
, info_ptr
, cu
);
4006 if (attr
.form
== DW_FORM_ref_addr
)
4007 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4009 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4012 /* If it isn't DW_AT_sibling, skip this attribute. */
4013 form
= abbrev
->attrs
[i
].form
;
4017 case DW_FORM_ref_addr
:
4018 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4019 and later it is offset sized. */
4020 if (cu
->header
.version
== 2)
4021 info_ptr
+= cu
->header
.addr_size
;
4023 info_ptr
+= cu
->header
.offset_size
;
4026 info_ptr
+= cu
->header
.addr_size
;
4033 case DW_FORM_flag_present
:
4048 case DW_FORM_string
:
4049 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4050 info_ptr
+= bytes_read
;
4052 case DW_FORM_sec_offset
:
4054 info_ptr
+= cu
->header
.offset_size
;
4056 case DW_FORM_exprloc
:
4058 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4059 info_ptr
+= bytes_read
;
4061 case DW_FORM_block1
:
4062 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4064 case DW_FORM_block2
:
4065 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4067 case DW_FORM_block4
:
4068 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4072 case DW_FORM_ref_udata
:
4073 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4075 case DW_FORM_indirect
:
4076 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4077 info_ptr
+= bytes_read
;
4078 /* We need to continue parsing from here, so just go back to
4080 goto skip_attribute
;
4083 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4084 dwarf_form_name (form
),
4085 bfd_get_filename (abfd
));
4089 if (abbrev
->has_children
)
4090 return skip_children (buffer
, info_ptr
, cu
);
4095 /* Locate ORIG_PDI's sibling.
4096 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4100 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4101 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4102 bfd
*abfd
, struct dwarf2_cu
*cu
)
4104 /* Do we know the sibling already? */
4106 if (orig_pdi
->sibling
)
4107 return orig_pdi
->sibling
;
4109 /* Are there any children to deal with? */
4111 if (!orig_pdi
->has_children
)
4114 /* Skip the children the long way. */
4116 return skip_children (buffer
, info_ptr
, cu
);
4119 /* Expand this partial symbol table into a full symbol table. */
4122 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4128 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4134 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4135 gdb_flush (gdb_stdout
);
4138 /* Restore our global data. */
4139 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4140 dwarf2_objfile_data_key
);
4142 /* If this psymtab is constructed from a debug-only objfile, the
4143 has_section_at_zero flag will not necessarily be correct. We
4144 can get the correct value for this flag by looking at the data
4145 associated with the (presumably stripped) associated objfile. */
4146 if (pst
->objfile
->separate_debug_objfile_backlink
)
4148 struct dwarf2_per_objfile
*dpo_backlink
4149 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4150 dwarf2_objfile_data_key
);
4152 dwarf2_per_objfile
->has_section_at_zero
4153 = dpo_backlink
->has_section_at_zero
;
4156 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4158 psymtab_to_symtab_1 (pst
);
4160 /* Finish up the debug error message. */
4162 printf_filtered (_("done.\n"));
4167 /* Add PER_CU to the queue. */
4170 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4172 struct dwarf2_queue_item
*item
;
4175 item
= xmalloc (sizeof (*item
));
4176 item
->per_cu
= per_cu
;
4179 if (dwarf2_queue
== NULL
)
4180 dwarf2_queue
= item
;
4182 dwarf2_queue_tail
->next
= item
;
4184 dwarf2_queue_tail
= item
;
4187 /* Process the queue. */
4190 process_queue (struct objfile
*objfile
)
4192 struct dwarf2_queue_item
*item
, *next_item
;
4194 /* The queue starts out with one item, but following a DIE reference
4195 may load a new CU, adding it to the end of the queue. */
4196 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4198 if (dwarf2_per_objfile
->using_index
4199 ? !item
->per_cu
->v
.quick
->symtab
4200 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4201 process_full_comp_unit (item
->per_cu
);
4203 item
->per_cu
->queued
= 0;
4204 next_item
= item
->next
;
4208 dwarf2_queue_tail
= NULL
;
4211 /* Free all allocated queue entries. This function only releases anything if
4212 an error was thrown; if the queue was processed then it would have been
4213 freed as we went along. */
4216 dwarf2_release_queue (void *dummy
)
4218 struct dwarf2_queue_item
*item
, *last
;
4220 item
= dwarf2_queue
;
4223 /* Anything still marked queued is likely to be in an
4224 inconsistent state, so discard it. */
4225 if (item
->per_cu
->queued
)
4227 if (item
->per_cu
->cu
!= NULL
)
4228 free_one_cached_comp_unit (item
->per_cu
->cu
);
4229 item
->per_cu
->queued
= 0;
4237 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4240 /* Read in full symbols for PST, and anything it depends on. */
4243 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4245 struct dwarf2_per_cu_data
*per_cu
;
4246 struct cleanup
*back_to
;
4249 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4250 if (!pst
->dependencies
[i
]->readin
)
4252 /* Inform about additional files that need to be read in. */
4255 /* FIXME: i18n: Need to make this a single string. */
4256 fputs_filtered (" ", gdb_stdout
);
4258 fputs_filtered ("and ", gdb_stdout
);
4260 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4261 wrap_here (""); /* Flush output */
4262 gdb_flush (gdb_stdout
);
4264 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4267 per_cu
= pst
->read_symtab_private
;
4271 /* It's an include file, no symbols to read for it.
4272 Everything is in the parent symtab. */
4277 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4280 /* Load the DIEs associated with PER_CU into memory. */
4283 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4285 bfd
*abfd
= objfile
->obfd
;
4286 struct dwarf2_cu
*cu
;
4287 unsigned int offset
;
4288 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4289 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4290 struct attribute
*attr
;
4293 gdb_assert (! per_cu
->from_debug_types
);
4295 /* Set local variables from the partial symbol table info. */
4296 offset
= per_cu
->offset
;
4298 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4299 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4300 beg_of_comp_unit
= info_ptr
;
4302 if (per_cu
->cu
== NULL
)
4304 cu
= alloc_one_comp_unit (objfile
);
4308 /* If an error occurs while loading, release our storage. */
4309 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4311 /* Read in the comp_unit header. */
4312 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4314 /* Complete the cu_header. */
4315 cu
->header
.offset
= offset
;
4316 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4318 /* Read the abbrevs for this compilation unit. */
4319 dwarf2_read_abbrevs (abfd
, cu
);
4320 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4322 /* Link this compilation unit into the compilation unit tree. */
4324 cu
->per_cu
= per_cu
;
4326 /* Link this CU into read_in_chain. */
4327 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4328 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4333 info_ptr
+= cu
->header
.first_die_offset
;
4336 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4338 /* We try not to read any attributes in this function, because not
4339 all objfiles needed for references have been loaded yet, and symbol
4340 table processing isn't initialized. But we have to set the CU language,
4341 or we won't be able to build types correctly. */
4342 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4344 set_cu_language (DW_UNSND (attr
), cu
);
4346 set_cu_language (language_minimal
, cu
);
4348 /* Similarly, if we do not read the producer, we can not apply
4349 producer-specific interpretation. */
4350 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4352 cu
->producer
= DW_STRING (attr
);
4356 do_cleanups (free_abbrevs_cleanup
);
4358 /* We've successfully allocated this compilation unit. Let our
4359 caller clean it up when finished with it. */
4360 discard_cleanups (free_cu_cleanup
);
4364 /* Add a DIE to the delayed physname list. */
4367 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4368 const char *name
, struct die_info
*die
,
4369 struct dwarf2_cu
*cu
)
4371 struct delayed_method_info mi
;
4373 mi
.fnfield_index
= fnfield_index
;
4377 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4380 /* A cleanup for freeing the delayed method list. */
4383 free_delayed_list (void *ptr
)
4385 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4386 if (cu
->method_list
!= NULL
)
4388 VEC_free (delayed_method_info
, cu
->method_list
);
4389 cu
->method_list
= NULL
;
4393 /* Compute the physnames of any methods on the CU's method list.
4395 The computation of method physnames is delayed in order to avoid the
4396 (bad) condition that one of the method's formal parameters is of an as yet
4400 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4403 struct delayed_method_info
*mi
;
4404 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4407 struct fn_fieldlist
*fn_flp
4408 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4409 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4410 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4414 /* Generate full symbol information for PST and CU, whose DIEs have
4415 already been loaded into memory. */
4418 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4420 struct dwarf2_cu
*cu
= per_cu
->cu
;
4421 struct objfile
*objfile
= per_cu
->objfile
;
4422 CORE_ADDR lowpc
, highpc
;
4423 struct symtab
*symtab
;
4424 struct cleanup
*back_to
, *delayed_list_cleanup
;
4427 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4430 back_to
= make_cleanup (really_free_pendings
, NULL
);
4431 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4433 cu
->list_in_scope
= &file_symbols
;
4435 dwarf2_find_base_address (cu
->dies
, cu
);
4437 /* Do line number decoding in read_file_scope () */
4438 process_die (cu
->dies
, cu
);
4440 /* Now that we have processed all the DIEs in the CU, all the types
4441 should be complete, and it should now be safe to compute all of the
4443 compute_delayed_physnames (cu
);
4444 do_cleanups (delayed_list_cleanup
);
4446 /* Some compilers don't define a DW_AT_high_pc attribute for the
4447 compilation unit. If the DW_AT_high_pc is missing, synthesize
4448 it, by scanning the DIE's below the compilation unit. */
4449 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4451 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4453 /* Set symtab language to language from DW_AT_language.
4454 If the compilation is from a C file generated by language preprocessors,
4455 do not set the language if it was already deduced by start_subfile. */
4457 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4459 symtab
->language
= cu
->language
;
4462 if (dwarf2_per_objfile
->using_index
)
4463 per_cu
->v
.quick
->symtab
= symtab
;
4466 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4467 pst
->symtab
= symtab
;
4471 do_cleanups (back_to
);
4474 /* Process a die and its children. */
4477 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4481 case DW_TAG_padding
:
4483 case DW_TAG_compile_unit
:
4484 read_file_scope (die
, cu
);
4486 case DW_TAG_type_unit
:
4487 read_type_unit_scope (die
, cu
);
4489 case DW_TAG_subprogram
:
4490 case DW_TAG_inlined_subroutine
:
4491 read_func_scope (die
, cu
);
4493 case DW_TAG_lexical_block
:
4494 case DW_TAG_try_block
:
4495 case DW_TAG_catch_block
:
4496 read_lexical_block_scope (die
, cu
);
4498 case DW_TAG_class_type
:
4499 case DW_TAG_interface_type
:
4500 case DW_TAG_structure_type
:
4501 case DW_TAG_union_type
:
4502 process_structure_scope (die
, cu
);
4504 case DW_TAG_enumeration_type
:
4505 process_enumeration_scope (die
, cu
);
4508 /* These dies have a type, but processing them does not create
4509 a symbol or recurse to process the children. Therefore we can
4510 read them on-demand through read_type_die. */
4511 case DW_TAG_subroutine_type
:
4512 case DW_TAG_set_type
:
4513 case DW_TAG_array_type
:
4514 case DW_TAG_pointer_type
:
4515 case DW_TAG_ptr_to_member_type
:
4516 case DW_TAG_reference_type
:
4517 case DW_TAG_string_type
:
4520 case DW_TAG_base_type
:
4521 case DW_TAG_subrange_type
:
4522 case DW_TAG_typedef
:
4523 /* Add a typedef symbol for the type definition, if it has a
4525 new_symbol (die
, read_type_die (die
, cu
), cu
);
4527 case DW_TAG_common_block
:
4528 read_common_block (die
, cu
);
4530 case DW_TAG_common_inclusion
:
4532 case DW_TAG_namespace
:
4533 processing_has_namespace_info
= 1;
4534 read_namespace (die
, cu
);
4537 processing_has_namespace_info
= 1;
4538 read_module (die
, cu
);
4540 case DW_TAG_imported_declaration
:
4541 case DW_TAG_imported_module
:
4542 processing_has_namespace_info
= 1;
4543 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4544 || cu
->language
!= language_fortran
))
4545 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4546 dwarf_tag_name (die
->tag
));
4547 read_import_statement (die
, cu
);
4550 new_symbol (die
, NULL
, cu
);
4555 /* A helper function for dwarf2_compute_name which determines whether DIE
4556 needs to have the name of the scope prepended to the name listed in the
4560 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4562 struct attribute
*attr
;
4566 case DW_TAG_namespace
:
4567 case DW_TAG_typedef
:
4568 case DW_TAG_class_type
:
4569 case DW_TAG_interface_type
:
4570 case DW_TAG_structure_type
:
4571 case DW_TAG_union_type
:
4572 case DW_TAG_enumeration_type
:
4573 case DW_TAG_enumerator
:
4574 case DW_TAG_subprogram
:
4578 case DW_TAG_variable
:
4579 case DW_TAG_constant
:
4580 /* We only need to prefix "globally" visible variables. These include
4581 any variable marked with DW_AT_external or any variable that
4582 lives in a namespace. [Variables in anonymous namespaces
4583 require prefixing, but they are not DW_AT_external.] */
4585 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4587 struct dwarf2_cu
*spec_cu
= cu
;
4589 return die_needs_namespace (die_specification (die
, &spec_cu
),
4593 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4594 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4595 && die
->parent
->tag
!= DW_TAG_module
)
4597 /* A variable in a lexical block of some kind does not need a
4598 namespace, even though in C++ such variables may be external
4599 and have a mangled name. */
4600 if (die
->parent
->tag
== DW_TAG_lexical_block
4601 || die
->parent
->tag
== DW_TAG_try_block
4602 || die
->parent
->tag
== DW_TAG_catch_block
4603 || die
->parent
->tag
== DW_TAG_subprogram
)
4612 /* Retrieve the last character from a mem_file. */
4615 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4617 char *last_char_p
= (char *) object
;
4620 *last_char_p
= buffer
[length
- 1];
4623 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4624 compute the physname for the object, which include a method's
4625 formal parameters (C++/Java) and return type (Java).
4627 For Ada, return the DIE's linkage name rather than the fully qualified
4628 name. PHYSNAME is ignored..
4630 The result is allocated on the objfile_obstack and canonicalized. */
4633 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4637 name
= dwarf2_name (die
, cu
);
4639 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4640 compute it by typename_concat inside GDB. */
4641 if (cu
->language
== language_ada
4642 || (cu
->language
== language_fortran
&& physname
))
4644 /* For Ada unit, we prefer the linkage name over the name, as
4645 the former contains the exported name, which the user expects
4646 to be able to reference. Ideally, we want the user to be able
4647 to reference this entity using either natural or linkage name,
4648 but we haven't started looking at this enhancement yet. */
4649 struct attribute
*attr
;
4651 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4653 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4654 if (attr
&& DW_STRING (attr
))
4655 return DW_STRING (attr
);
4658 /* These are the only languages we know how to qualify names in. */
4660 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4661 || cu
->language
== language_fortran
))
4663 if (die_needs_namespace (die
, cu
))
4667 struct ui_file
*buf
;
4669 prefix
= determine_prefix (die
, cu
);
4670 buf
= mem_fileopen ();
4671 if (*prefix
!= '\0')
4673 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4676 fputs_unfiltered (prefixed_name
, buf
);
4677 xfree (prefixed_name
);
4680 fputs_unfiltered (name
? name
: "", buf
);
4682 /* Template parameters may be specified in the DIE's DW_AT_name, or
4683 as children with DW_TAG_template_type_param or
4684 DW_TAG_value_type_param. If the latter, add them to the name
4685 here. If the name already has template parameters, then
4686 skip this step; some versions of GCC emit both, and
4687 it is more efficient to use the pre-computed name.
4689 Something to keep in mind about this process: it is very
4690 unlikely, or in some cases downright impossible, to produce
4691 something that will match the mangled name of a function.
4692 If the definition of the function has the same debug info,
4693 we should be able to match up with it anyway. But fallbacks
4694 using the minimal symbol, for instance to find a method
4695 implemented in a stripped copy of libstdc++, will not work.
4696 If we do not have debug info for the definition, we will have to
4697 match them up some other way.
4699 When we do name matching there is a related problem with function
4700 templates; two instantiated function templates are allowed to
4701 differ only by their return types, which we do not add here. */
4703 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4705 struct attribute
*attr
;
4706 struct die_info
*child
;
4709 die
->building_fullname
= 1;
4711 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4716 struct dwarf2_locexpr_baton
*baton
;
4719 if (child
->tag
!= DW_TAG_template_type_param
4720 && child
->tag
!= DW_TAG_template_value_param
)
4725 fputs_unfiltered ("<", buf
);
4729 fputs_unfiltered (", ", buf
);
4731 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4734 complaint (&symfile_complaints
,
4735 _("template parameter missing DW_AT_type"));
4736 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4739 type
= die_type (child
, cu
);
4741 if (child
->tag
== DW_TAG_template_type_param
)
4743 c_print_type (type
, "", buf
, -1, 0);
4747 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4750 complaint (&symfile_complaints
,
4751 _("template parameter missing DW_AT_const_value"));
4752 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4756 dwarf2_const_value_attr (attr
, type
, name
,
4757 &cu
->comp_unit_obstack
, cu
,
4758 &value
, &bytes
, &baton
);
4760 if (TYPE_NOSIGN (type
))
4761 /* GDB prints characters as NUMBER 'CHAR'. If that's
4762 changed, this can use value_print instead. */
4763 c_printchar (value
, type
, buf
);
4766 struct value_print_options opts
;
4769 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4773 else if (bytes
!= NULL
)
4775 v
= allocate_value (type
);
4776 memcpy (value_contents_writeable (v
), bytes
,
4777 TYPE_LENGTH (type
));
4780 v
= value_from_longest (type
, value
);
4782 /* Specify decimal so that we do not depend on the radix. */
4783 get_formatted_print_options (&opts
, 'd');
4785 value_print (v
, buf
, &opts
);
4791 die
->building_fullname
= 0;
4795 /* Close the argument list, with a space if necessary
4796 (nested templates). */
4797 char last_char
= '\0';
4798 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4799 if (last_char
== '>')
4800 fputs_unfiltered (" >", buf
);
4802 fputs_unfiltered (">", buf
);
4806 /* For Java and C++ methods, append formal parameter type
4807 information, if PHYSNAME. */
4809 if (physname
&& die
->tag
== DW_TAG_subprogram
4810 && (cu
->language
== language_cplus
4811 || cu
->language
== language_java
))
4813 struct type
*type
= read_type_die (die
, cu
);
4815 c_type_print_args (type
, buf
, 0, cu
->language
);
4817 if (cu
->language
== language_java
)
4819 /* For java, we must append the return type to method
4821 if (die
->tag
== DW_TAG_subprogram
)
4822 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4825 else if (cu
->language
== language_cplus
)
4827 /* Assume that an artificial first parameter is
4828 "this", but do not crash if it is not. RealView
4829 marks unnamed (and thus unused) parameters as
4830 artificial; there is no way to differentiate
4832 if (TYPE_NFIELDS (type
) > 0
4833 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4834 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4835 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4836 fputs_unfiltered (" const", buf
);
4840 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4842 ui_file_delete (buf
);
4844 if (cu
->language
== language_cplus
)
4847 = dwarf2_canonicalize_name (name
, cu
,
4848 &cu
->objfile
->objfile_obstack
);
4859 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4860 If scope qualifiers are appropriate they will be added. The result
4861 will be allocated on the objfile_obstack, or NULL if the DIE does
4862 not have a name. NAME may either be from a previous call to
4863 dwarf2_name or NULL.
4865 The output string will be canonicalized (if C++/Java). */
4868 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4870 return dwarf2_compute_name (name
, die
, cu
, 0);
4873 /* Construct a physname for the given DIE in CU. NAME may either be
4874 from a previous call to dwarf2_name or NULL. The result will be
4875 allocated on the objfile_objstack or NULL if the DIE does not have a
4878 The output string will be canonicalized (if C++/Java). */
4881 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4883 return dwarf2_compute_name (name
, die
, cu
, 1);
4886 /* Read the import statement specified by the given die and record it. */
4889 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4891 struct attribute
*import_attr
;
4892 struct die_info
*imported_die
;
4893 struct dwarf2_cu
*imported_cu
;
4894 const char *imported_name
;
4895 const char *imported_name_prefix
;
4896 const char *canonical_name
;
4897 const char *import_alias
;
4898 const char *imported_declaration
= NULL
;
4899 const char *import_prefix
;
4903 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4904 if (import_attr
== NULL
)
4906 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4907 dwarf_tag_name (die
->tag
));
4912 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4913 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4914 if (imported_name
== NULL
)
4916 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4918 The import in the following code:
4932 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4933 <52> DW_AT_decl_file : 1
4934 <53> DW_AT_decl_line : 6
4935 <54> DW_AT_import : <0x75>
4936 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4938 <5b> DW_AT_decl_file : 1
4939 <5c> DW_AT_decl_line : 2
4940 <5d> DW_AT_type : <0x6e>
4942 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4943 <76> DW_AT_byte_size : 4
4944 <77> DW_AT_encoding : 5 (signed)
4946 imports the wrong die ( 0x75 instead of 0x58 ).
4947 This case will be ignored until the gcc bug is fixed. */
4951 /* Figure out the local name after import. */
4952 import_alias
= dwarf2_name (die
, cu
);
4954 /* Figure out where the statement is being imported to. */
4955 import_prefix
= determine_prefix (die
, cu
);
4957 /* Figure out what the scope of the imported die is and prepend it
4958 to the name of the imported die. */
4959 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4961 if (imported_die
->tag
!= DW_TAG_namespace
4962 && imported_die
->tag
!= DW_TAG_module
)
4964 imported_declaration
= imported_name
;
4965 canonical_name
= imported_name_prefix
;
4967 else if (strlen (imported_name_prefix
) > 0)
4969 temp
= alloca (strlen (imported_name_prefix
)
4970 + 2 + strlen (imported_name
) + 1);
4971 strcpy (temp
, imported_name_prefix
);
4972 strcat (temp
, "::");
4973 strcat (temp
, imported_name
);
4974 canonical_name
= temp
;
4977 canonical_name
= imported_name
;
4979 cp_add_using_directive (import_prefix
,
4982 imported_declaration
,
4983 &cu
->objfile
->objfile_obstack
);
4987 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4989 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4993 free_cu_line_header (void *arg
)
4995 struct dwarf2_cu
*cu
= arg
;
4997 free_line_header (cu
->line_header
);
4998 cu
->line_header
= NULL
;
5002 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5003 char **name
, char **comp_dir
)
5005 struct attribute
*attr
;
5010 /* Find the filename. Do not use dwarf2_name here, since the filename
5011 is not a source language identifier. */
5012 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5015 *name
= DW_STRING (attr
);
5018 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5020 *comp_dir
= DW_STRING (attr
);
5021 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5023 *comp_dir
= ldirname (*name
);
5024 if (*comp_dir
!= NULL
)
5025 make_cleanup (xfree
, *comp_dir
);
5027 if (*comp_dir
!= NULL
)
5029 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5030 directory, get rid of it. */
5031 char *cp
= strchr (*comp_dir
, ':');
5033 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5038 *name
= "<unknown>";
5042 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5044 struct objfile
*objfile
= cu
->objfile
;
5045 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5046 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5047 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5048 struct attribute
*attr
;
5050 char *comp_dir
= NULL
;
5051 struct die_info
*child_die
;
5052 bfd
*abfd
= objfile
->obfd
;
5053 struct line_header
*line_header
= 0;
5056 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5058 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5060 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5061 from finish_block. */
5062 if (lowpc
== ((CORE_ADDR
) -1))
5067 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5069 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5072 set_cu_language (DW_UNSND (attr
), cu
);
5075 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5077 cu
->producer
= DW_STRING (attr
);
5079 /* We assume that we're processing GCC output. */
5080 processing_gcc_compilation
= 2;
5082 processing_has_namespace_info
= 0;
5084 start_symtab (name
, comp_dir
, lowpc
);
5085 record_debugformat ("DWARF 2");
5086 record_producer (cu
->producer
);
5088 initialize_cu_func_list (cu
);
5090 /* Decode line number information if present. We do this before
5091 processing child DIEs, so that the line header table is available
5092 for DW_AT_decl_file. */
5093 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5096 unsigned int line_offset
= DW_UNSND (attr
);
5097 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5100 cu
->line_header
= line_header
;
5101 make_cleanup (free_cu_line_header
, cu
);
5102 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5106 /* Process all dies in compilation unit. */
5107 if (die
->child
!= NULL
)
5109 child_die
= die
->child
;
5110 while (child_die
&& child_die
->tag
)
5112 process_die (child_die
, cu
);
5113 child_die
= sibling_die (child_die
);
5117 /* Decode macro information, if present. Dwarf 2 macro information
5118 refers to information in the line number info statement program
5119 header, so we can only read it if we've read the header
5121 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5122 if (attr
&& line_header
)
5124 unsigned int macro_offset
= DW_UNSND (attr
);
5126 dwarf_decode_macros (line_header
, macro_offset
,
5127 comp_dir
, abfd
, cu
);
5129 do_cleanups (back_to
);
5132 /* For TUs we want to skip the first top level sibling if it's not the
5133 actual type being defined by this TU. In this case the first top
5134 level sibling is there to provide context only. */
5137 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5139 struct objfile
*objfile
= cu
->objfile
;
5140 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5142 struct attribute
*attr
;
5144 char *comp_dir
= NULL
;
5145 struct die_info
*child_die
;
5146 bfd
*abfd
= objfile
->obfd
;
5148 /* start_symtab needs a low pc, but we don't really have one.
5149 Do what read_file_scope would do in the absence of such info. */
5150 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5152 /* Find the filename. Do not use dwarf2_name here, since the filename
5153 is not a source language identifier. */
5154 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5156 name
= DW_STRING (attr
);
5158 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5160 comp_dir
= DW_STRING (attr
);
5161 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5163 comp_dir
= ldirname (name
);
5164 if (comp_dir
!= NULL
)
5165 make_cleanup (xfree
, comp_dir
);
5171 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5173 set_cu_language (DW_UNSND (attr
), cu
);
5175 /* This isn't technically needed today. It is done for symmetry
5176 with read_file_scope. */
5177 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5179 cu
->producer
= DW_STRING (attr
);
5181 /* We assume that we're processing GCC output. */
5182 processing_gcc_compilation
= 2;
5184 processing_has_namespace_info
= 0;
5186 start_symtab (name
, comp_dir
, lowpc
);
5187 record_debugformat ("DWARF 2");
5188 record_producer (cu
->producer
);
5190 /* Process the dies in the type unit. */
5191 if (die
->child
== NULL
)
5193 dump_die_for_error (die
);
5194 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5195 bfd_get_filename (abfd
));
5198 child_die
= die
->child
;
5200 while (child_die
&& child_die
->tag
)
5202 process_die (child_die
, cu
);
5204 child_die
= sibling_die (child_die
);
5207 do_cleanups (back_to
);
5211 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5212 struct dwarf2_cu
*cu
)
5214 struct function_range
*thisfn
;
5216 thisfn
= (struct function_range
*)
5217 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5218 thisfn
->name
= name
;
5219 thisfn
->lowpc
= lowpc
;
5220 thisfn
->highpc
= highpc
;
5221 thisfn
->seen_line
= 0;
5222 thisfn
->next
= NULL
;
5224 if (cu
->last_fn
== NULL
)
5225 cu
->first_fn
= thisfn
;
5227 cu
->last_fn
->next
= thisfn
;
5229 cu
->last_fn
= thisfn
;
5232 /* qsort helper for inherit_abstract_dies. */
5235 unsigned_int_compar (const void *ap
, const void *bp
)
5237 unsigned int a
= *(unsigned int *) ap
;
5238 unsigned int b
= *(unsigned int *) bp
;
5240 return (a
> b
) - (b
> a
);
5243 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5244 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5245 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5248 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5250 struct die_info
*child_die
;
5251 unsigned die_children_count
;
5252 /* CU offsets which were referenced by children of the current DIE. */
5254 unsigned *offsets_end
, *offsetp
;
5255 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5256 struct die_info
*origin_die
;
5257 /* Iterator of the ORIGIN_DIE children. */
5258 struct die_info
*origin_child_die
;
5259 struct cleanup
*cleanups
;
5260 struct attribute
*attr
;
5261 struct dwarf2_cu
*origin_cu
;
5262 struct pending
**origin_previous_list_in_scope
;
5264 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5268 /* Note that following die references may follow to a die in a
5272 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5274 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5276 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5277 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5279 if (die
->tag
!= origin_die
->tag
5280 && !(die
->tag
== DW_TAG_inlined_subroutine
5281 && origin_die
->tag
== DW_TAG_subprogram
))
5282 complaint (&symfile_complaints
,
5283 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5284 die
->offset
, origin_die
->offset
);
5286 child_die
= die
->child
;
5287 die_children_count
= 0;
5288 while (child_die
&& child_die
->tag
)
5290 child_die
= sibling_die (child_die
);
5291 die_children_count
++;
5293 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5294 cleanups
= make_cleanup (xfree
, offsets
);
5296 offsets_end
= offsets
;
5297 child_die
= die
->child
;
5298 while (child_die
&& child_die
->tag
)
5300 /* For each CHILD_DIE, find the corresponding child of
5301 ORIGIN_DIE. If there is more than one layer of
5302 DW_AT_abstract_origin, follow them all; there shouldn't be,
5303 but GCC versions at least through 4.4 generate this (GCC PR
5305 struct die_info
*child_origin_die
= child_die
;
5306 struct dwarf2_cu
*child_origin_cu
= cu
;
5310 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5314 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5318 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5319 counterpart may exist. */
5320 if (child_origin_die
!= child_die
)
5322 if (child_die
->tag
!= child_origin_die
->tag
5323 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5324 && child_origin_die
->tag
== DW_TAG_subprogram
))
5325 complaint (&symfile_complaints
,
5326 _("Child DIE 0x%x and its abstract origin 0x%x have "
5327 "different tags"), child_die
->offset
,
5328 child_origin_die
->offset
);
5329 if (child_origin_die
->parent
!= origin_die
)
5330 complaint (&symfile_complaints
,
5331 _("Child DIE 0x%x and its abstract origin 0x%x have "
5332 "different parents"), child_die
->offset
,
5333 child_origin_die
->offset
);
5335 *offsets_end
++ = child_origin_die
->offset
;
5337 child_die
= sibling_die (child_die
);
5339 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5340 unsigned_int_compar
);
5341 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5342 if (offsetp
[-1] == *offsetp
)
5343 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5344 "to DIE 0x%x as their abstract origin"),
5345 die
->offset
, *offsetp
);
5348 origin_child_die
= origin_die
->child
;
5349 while (origin_child_die
&& origin_child_die
->tag
)
5351 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5352 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5354 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5356 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5357 process_die (origin_child_die
, origin_cu
);
5359 origin_child_die
= sibling_die (origin_child_die
);
5361 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5363 do_cleanups (cleanups
);
5367 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5369 struct objfile
*objfile
= cu
->objfile
;
5370 struct context_stack
*new;
5373 struct die_info
*child_die
;
5374 struct attribute
*attr
, *call_line
, *call_file
;
5377 struct block
*block
;
5378 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5379 VEC (symbolp
) *template_args
= NULL
;
5380 struct template_symbol
*templ_func
= NULL
;
5384 /* If we do not have call site information, we can't show the
5385 caller of this inlined function. That's too confusing, so
5386 only use the scope for local variables. */
5387 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5388 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5389 if (call_line
== NULL
|| call_file
== NULL
)
5391 read_lexical_block_scope (die
, cu
);
5396 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5398 name
= dwarf2_name (die
, cu
);
5400 /* Ignore functions with missing or empty names. These are actually
5401 illegal according to the DWARF standard. */
5404 complaint (&symfile_complaints
,
5405 _("missing name for subprogram DIE at %d"), die
->offset
);
5409 /* Ignore functions with missing or invalid low and high pc attributes. */
5410 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5412 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5413 if (!attr
|| !DW_UNSND (attr
))
5414 complaint (&symfile_complaints
,
5415 _("cannot get low and high bounds for subprogram DIE at %d"),
5423 /* Record the function range for dwarf_decode_lines. */
5424 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5426 /* If we have any template arguments, then we must allocate a
5427 different sort of symbol. */
5428 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5430 if (child_die
->tag
== DW_TAG_template_type_param
5431 || child_die
->tag
== DW_TAG_template_value_param
)
5433 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5434 struct template_symbol
);
5435 templ_func
->base
.is_cplus_template_function
= 1;
5440 new = push_context (0, lowpc
);
5441 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5442 (struct symbol
*) templ_func
);
5444 /* If there is a location expression for DW_AT_frame_base, record
5446 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5448 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5449 expression is being recorded directly in the function's symbol
5450 and not in a separate frame-base object. I guess this hack is
5451 to avoid adding some sort of frame-base adjunct/annex to the
5452 function's symbol :-(. The problem with doing this is that it
5453 results in a function symbol with a location expression that
5454 has nothing to do with the location of the function, ouch! The
5455 relationship should be: a function's symbol has-a frame base; a
5456 frame-base has-a location expression. */
5457 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5459 cu
->list_in_scope
= &local_symbols
;
5461 if (die
->child
!= NULL
)
5463 child_die
= die
->child
;
5464 while (child_die
&& child_die
->tag
)
5466 if (child_die
->tag
== DW_TAG_template_type_param
5467 || child_die
->tag
== DW_TAG_template_value_param
)
5469 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5472 VEC_safe_push (symbolp
, template_args
, arg
);
5475 process_die (child_die
, cu
);
5476 child_die
= sibling_die (child_die
);
5480 inherit_abstract_dies (die
, cu
);
5482 /* If we have a DW_AT_specification, we might need to import using
5483 directives from the context of the specification DIE. See the
5484 comment in determine_prefix. */
5485 if (cu
->language
== language_cplus
5486 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5488 struct dwarf2_cu
*spec_cu
= cu
;
5489 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5493 child_die
= spec_die
->child
;
5494 while (child_die
&& child_die
->tag
)
5496 if (child_die
->tag
== DW_TAG_imported_module
)
5497 process_die (child_die
, spec_cu
);
5498 child_die
= sibling_die (child_die
);
5501 /* In some cases, GCC generates specification DIEs that
5502 themselves contain DW_AT_specification attributes. */
5503 spec_die
= die_specification (spec_die
, &spec_cu
);
5507 new = pop_context ();
5508 /* Make a block for the local symbols within. */
5509 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5510 lowpc
, highpc
, objfile
);
5512 /* For C++, set the block's scope. */
5513 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5514 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5515 determine_prefix (die
, cu
),
5516 processing_has_namespace_info
);
5518 /* If we have address ranges, record them. */
5519 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5521 /* Attach template arguments to function. */
5522 if (! VEC_empty (symbolp
, template_args
))
5524 gdb_assert (templ_func
!= NULL
);
5526 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5527 templ_func
->template_arguments
5528 = obstack_alloc (&objfile
->objfile_obstack
,
5529 (templ_func
->n_template_arguments
5530 * sizeof (struct symbol
*)));
5531 memcpy (templ_func
->template_arguments
,
5532 VEC_address (symbolp
, template_args
),
5533 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5534 VEC_free (symbolp
, template_args
);
5537 /* In C++, we can have functions nested inside functions (e.g., when
5538 a function declares a class that has methods). This means that
5539 when we finish processing a function scope, we may need to go
5540 back to building a containing block's symbol lists. */
5541 local_symbols
= new->locals
;
5542 param_symbols
= new->params
;
5543 using_directives
= new->using_directives
;
5545 /* If we've finished processing a top-level function, subsequent
5546 symbols go in the file symbol list. */
5547 if (outermost_context_p ())
5548 cu
->list_in_scope
= &file_symbols
;
5551 /* Process all the DIES contained within a lexical block scope. Start
5552 a new scope, process the dies, and then close the scope. */
5555 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5557 struct objfile
*objfile
= cu
->objfile
;
5558 struct context_stack
*new;
5559 CORE_ADDR lowpc
, highpc
;
5560 struct die_info
*child_die
;
5563 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5565 /* Ignore blocks with missing or invalid low and high pc attributes. */
5566 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5567 as multiple lexical blocks? Handling children in a sane way would
5568 be nasty. Might be easier to properly extend generic blocks to
5570 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5575 push_context (0, lowpc
);
5576 if (die
->child
!= NULL
)
5578 child_die
= die
->child
;
5579 while (child_die
&& child_die
->tag
)
5581 process_die (child_die
, cu
);
5582 child_die
= sibling_die (child_die
);
5585 new = pop_context ();
5587 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5590 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5593 /* Note that recording ranges after traversing children, as we
5594 do here, means that recording a parent's ranges entails
5595 walking across all its children's ranges as they appear in
5596 the address map, which is quadratic behavior.
5598 It would be nicer to record the parent's ranges before
5599 traversing its children, simply overriding whatever you find
5600 there. But since we don't even decide whether to create a
5601 block until after we've traversed its children, that's hard
5603 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5605 local_symbols
= new->locals
;
5606 using_directives
= new->using_directives
;
5609 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5610 Return 1 if the attributes are present and valid, otherwise, return 0.
5611 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5614 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5615 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5616 struct partial_symtab
*ranges_pst
)
5618 struct objfile
*objfile
= cu
->objfile
;
5619 struct comp_unit_head
*cu_header
= &cu
->header
;
5620 bfd
*obfd
= objfile
->obfd
;
5621 unsigned int addr_size
= cu_header
->addr_size
;
5622 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5623 /* Base address selection entry. */
5634 found_base
= cu
->base_known
;
5635 base
= cu
->base_address
;
5637 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5638 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5640 complaint (&symfile_complaints
,
5641 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5645 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5647 /* Read in the largest possible address. */
5648 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5649 if ((marker
& mask
) == mask
)
5651 /* If we found the largest possible address, then
5652 read the base address. */
5653 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5654 buffer
+= 2 * addr_size
;
5655 offset
+= 2 * addr_size
;
5661 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5665 CORE_ADDR range_beginning
, range_end
;
5667 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5668 buffer
+= addr_size
;
5669 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5670 buffer
+= addr_size
;
5671 offset
+= 2 * addr_size
;
5673 /* An end of list marker is a pair of zero addresses. */
5674 if (range_beginning
== 0 && range_end
== 0)
5675 /* Found the end of list entry. */
5678 /* Each base address selection entry is a pair of 2 values.
5679 The first is the largest possible address, the second is
5680 the base address. Check for a base address here. */
5681 if ((range_beginning
& mask
) == mask
)
5683 /* If we found the largest possible address, then
5684 read the base address. */
5685 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5692 /* We have no valid base address for the ranges
5694 complaint (&symfile_complaints
,
5695 _("Invalid .debug_ranges data (no base address)"));
5699 range_beginning
+= base
;
5702 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5703 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5704 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5707 /* FIXME: This is recording everything as a low-high
5708 segment of consecutive addresses. We should have a
5709 data structure for discontiguous block ranges
5713 low
= range_beginning
;
5719 if (range_beginning
< low
)
5720 low
= range_beginning
;
5721 if (range_end
> high
)
5727 /* If the first entry is an end-of-list marker, the range
5728 describes an empty scope, i.e. no instructions. */
5734 *high_return
= high
;
5738 /* Get low and high pc attributes from a die. Return 1 if the attributes
5739 are present and valid, otherwise, return 0. Return -1 if the range is
5740 discontinuous, i.e. derived from DW_AT_ranges information. */
5742 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5743 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5744 struct partial_symtab
*pst
)
5746 struct attribute
*attr
;
5751 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5754 high
= DW_ADDR (attr
);
5755 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5757 low
= DW_ADDR (attr
);
5759 /* Found high w/o low attribute. */
5762 /* Found consecutive range of addresses. */
5767 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5770 /* Value of the DW_AT_ranges attribute is the offset in the
5771 .debug_ranges section. */
5772 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5774 /* Found discontinuous range of addresses. */
5782 /* When using the GNU linker, .gnu.linkonce. sections are used to
5783 eliminate duplicate copies of functions and vtables and such.
5784 The linker will arbitrarily choose one and discard the others.
5785 The AT_*_pc values for such functions refer to local labels in
5786 these sections. If the section from that file was discarded, the
5787 labels are not in the output, so the relocs get a value of 0.
5788 If this is a discarded function, mark the pc bounds as invalid,
5789 so that GDB will ignore it. */
5790 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5798 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5799 its low and high PC addresses. Do nothing if these addresses could not
5800 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5801 and HIGHPC to the high address if greater than HIGHPC. */
5804 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5805 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5806 struct dwarf2_cu
*cu
)
5808 CORE_ADDR low
, high
;
5809 struct die_info
*child
= die
->child
;
5811 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5813 *lowpc
= min (*lowpc
, low
);
5814 *highpc
= max (*highpc
, high
);
5817 /* If the language does not allow nested subprograms (either inside
5818 subprograms or lexical blocks), we're done. */
5819 if (cu
->language
!= language_ada
)
5822 /* Check all the children of the given DIE. If it contains nested
5823 subprograms, then check their pc bounds. Likewise, we need to
5824 check lexical blocks as well, as they may also contain subprogram
5826 while (child
&& child
->tag
)
5828 if (child
->tag
== DW_TAG_subprogram
5829 || child
->tag
== DW_TAG_lexical_block
)
5830 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5831 child
= sibling_die (child
);
5835 /* Get the low and high pc's represented by the scope DIE, and store
5836 them in *LOWPC and *HIGHPC. If the correct values can't be
5837 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5840 get_scope_pc_bounds (struct die_info
*die
,
5841 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5842 struct dwarf2_cu
*cu
)
5844 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5845 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5846 CORE_ADDR current_low
, current_high
;
5848 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5850 best_low
= current_low
;
5851 best_high
= current_high
;
5855 struct die_info
*child
= die
->child
;
5857 while (child
&& child
->tag
)
5859 switch (child
->tag
) {
5860 case DW_TAG_subprogram
:
5861 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5863 case DW_TAG_namespace
:
5865 /* FIXME: carlton/2004-01-16: Should we do this for
5866 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5867 that current GCC's always emit the DIEs corresponding
5868 to definitions of methods of classes as children of a
5869 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5870 the DIEs giving the declarations, which could be
5871 anywhere). But I don't see any reason why the
5872 standards says that they have to be there. */
5873 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5875 if (current_low
!= ((CORE_ADDR
) -1))
5877 best_low
= min (best_low
, current_low
);
5878 best_high
= max (best_high
, current_high
);
5886 child
= sibling_die (child
);
5891 *highpc
= best_high
;
5894 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5897 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5898 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5900 struct attribute
*attr
;
5902 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5905 CORE_ADDR high
= DW_ADDR (attr
);
5907 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5910 CORE_ADDR low
= DW_ADDR (attr
);
5912 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5916 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5919 bfd
*obfd
= cu
->objfile
->obfd
;
5921 /* The value of the DW_AT_ranges attribute is the offset of the
5922 address range list in the .debug_ranges section. */
5923 unsigned long offset
= DW_UNSND (attr
);
5924 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5926 /* For some target architectures, but not others, the
5927 read_address function sign-extends the addresses it returns.
5928 To recognize base address selection entries, we need a
5930 unsigned int addr_size
= cu
->header
.addr_size
;
5931 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5933 /* The base address, to which the next pair is relative. Note
5934 that this 'base' is a DWARF concept: most entries in a range
5935 list are relative, to reduce the number of relocs against the
5936 debugging information. This is separate from this function's
5937 'baseaddr' argument, which GDB uses to relocate debugging
5938 information from a shared library based on the address at
5939 which the library was loaded. */
5940 CORE_ADDR base
= cu
->base_address
;
5941 int base_known
= cu
->base_known
;
5943 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5944 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5946 complaint (&symfile_complaints
,
5947 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5954 unsigned int bytes_read
;
5955 CORE_ADDR start
, end
;
5957 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5958 buffer
+= bytes_read
;
5959 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5960 buffer
+= bytes_read
;
5962 /* Did we find the end of the range list? */
5963 if (start
== 0 && end
== 0)
5966 /* Did we find a base address selection entry? */
5967 else if ((start
& base_select_mask
) == base_select_mask
)
5973 /* We found an ordinary address range. */
5978 complaint (&symfile_complaints
,
5979 _("Invalid .debug_ranges data (no base address)"));
5983 record_block_range (block
,
5984 baseaddr
+ base
+ start
,
5985 baseaddr
+ base
+ end
- 1);
5991 /* Add an aggregate field to the field list. */
5994 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
5995 struct dwarf2_cu
*cu
)
5997 struct objfile
*objfile
= cu
->objfile
;
5998 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5999 struct nextfield
*new_field
;
6000 struct attribute
*attr
;
6002 char *fieldname
= "";
6004 /* Allocate a new field list entry and link it in. */
6005 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6006 make_cleanup (xfree
, new_field
);
6007 memset (new_field
, 0, sizeof (struct nextfield
));
6009 if (die
->tag
== DW_TAG_inheritance
)
6011 new_field
->next
= fip
->baseclasses
;
6012 fip
->baseclasses
= new_field
;
6016 new_field
->next
= fip
->fields
;
6017 fip
->fields
= new_field
;
6021 /* Handle accessibility and virtuality of field.
6022 The default accessibility for members is public, the default
6023 accessibility for inheritance is private. */
6024 if (die
->tag
!= DW_TAG_inheritance
)
6025 new_field
->accessibility
= DW_ACCESS_public
;
6027 new_field
->accessibility
= DW_ACCESS_private
;
6028 new_field
->virtuality
= DW_VIRTUALITY_none
;
6030 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6032 new_field
->accessibility
= DW_UNSND (attr
);
6033 if (new_field
->accessibility
!= DW_ACCESS_public
)
6034 fip
->non_public_fields
= 1;
6035 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6037 new_field
->virtuality
= DW_UNSND (attr
);
6039 fp
= &new_field
->field
;
6041 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6043 /* Data member other than a C++ static data member. */
6045 /* Get type of field. */
6046 fp
->type
= die_type (die
, cu
);
6048 SET_FIELD_BITPOS (*fp
, 0);
6050 /* Get bit size of field (zero if none). */
6051 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6054 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6058 FIELD_BITSIZE (*fp
) = 0;
6061 /* Get bit offset of field. */
6062 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6065 int byte_offset
= 0;
6067 if (attr_form_is_section_offset (attr
))
6068 dwarf2_complex_location_expr_complaint ();
6069 else if (attr_form_is_constant (attr
))
6070 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6071 else if (attr_form_is_block (attr
))
6072 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6074 dwarf2_complex_location_expr_complaint ();
6076 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6078 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6081 if (gdbarch_bits_big_endian (gdbarch
))
6083 /* For big endian bits, the DW_AT_bit_offset gives the
6084 additional bit offset from the MSB of the containing
6085 anonymous object to the MSB of the field. We don't
6086 have to do anything special since we don't need to
6087 know the size of the anonymous object. */
6088 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6092 /* For little endian bits, compute the bit offset to the
6093 MSB of the anonymous object, subtract off the number of
6094 bits from the MSB of the field to the MSB of the
6095 object, and then subtract off the number of bits of
6096 the field itself. The result is the bit offset of
6097 the LSB of the field. */
6099 int bit_offset
= DW_UNSND (attr
);
6101 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6104 /* The size of the anonymous object containing
6105 the bit field is explicit, so use the
6106 indicated size (in bytes). */
6107 anonymous_size
= DW_UNSND (attr
);
6111 /* The size of the anonymous object containing
6112 the bit field must be inferred from the type
6113 attribute of the data member containing the
6115 anonymous_size
= TYPE_LENGTH (fp
->type
);
6117 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6118 - bit_offset
- FIELD_BITSIZE (*fp
);
6122 /* Get name of field. */
6123 fieldname
= dwarf2_name (die
, cu
);
6124 if (fieldname
== NULL
)
6127 /* The name is already allocated along with this objfile, so we don't
6128 need to duplicate it for the type. */
6129 fp
->name
= fieldname
;
6131 /* Change accessibility for artificial fields (e.g. virtual table
6132 pointer or virtual base class pointer) to private. */
6133 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6135 FIELD_ARTIFICIAL (*fp
) = 1;
6136 new_field
->accessibility
= DW_ACCESS_private
;
6137 fip
->non_public_fields
= 1;
6140 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6142 /* C++ static member. */
6144 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6145 is a declaration, but all versions of G++ as of this writing
6146 (so through at least 3.2.1) incorrectly generate
6147 DW_TAG_variable tags. */
6151 /* Get name of field. */
6152 fieldname
= dwarf2_name (die
, cu
);
6153 if (fieldname
== NULL
)
6156 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6158 /* Only create a symbol if this is an external value.
6159 new_symbol checks this and puts the value in the global symbol
6160 table, which we want. If it is not external, new_symbol
6161 will try to put the value in cu->list_in_scope which is wrong. */
6162 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6164 /* A static const member, not much different than an enum as far as
6165 we're concerned, except that we can support more types. */
6166 new_symbol (die
, NULL
, cu
);
6169 /* Get physical name. */
6170 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6172 /* The name is already allocated along with this objfile, so we don't
6173 need to duplicate it for the type. */
6174 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6175 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6176 FIELD_NAME (*fp
) = fieldname
;
6178 else if (die
->tag
== DW_TAG_inheritance
)
6180 /* C++ base class field. */
6181 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6184 int byte_offset
= 0;
6186 if (attr_form_is_section_offset (attr
))
6187 dwarf2_complex_location_expr_complaint ();
6188 else if (attr_form_is_constant (attr
))
6189 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6190 else if (attr_form_is_block (attr
))
6191 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6193 dwarf2_complex_location_expr_complaint ();
6195 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6197 FIELD_BITSIZE (*fp
) = 0;
6198 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6199 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6200 fip
->nbaseclasses
++;
6204 /* Add a typedef defined in the scope of the FIP's class. */
6207 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6208 struct dwarf2_cu
*cu
)
6210 struct objfile
*objfile
= cu
->objfile
;
6211 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6212 struct typedef_field_list
*new_field
;
6213 struct attribute
*attr
;
6214 struct typedef_field
*fp
;
6215 char *fieldname
= "";
6217 /* Allocate a new field list entry and link it in. */
6218 new_field
= xzalloc (sizeof (*new_field
));
6219 make_cleanup (xfree
, new_field
);
6221 gdb_assert (die
->tag
== DW_TAG_typedef
);
6223 fp
= &new_field
->field
;
6225 /* Get name of field. */
6226 fp
->name
= dwarf2_name (die
, cu
);
6227 if (fp
->name
== NULL
)
6230 fp
->type
= read_type_die (die
, cu
);
6232 new_field
->next
= fip
->typedef_field_list
;
6233 fip
->typedef_field_list
= new_field
;
6234 fip
->typedef_field_list_count
++;
6237 /* Create the vector of fields, and attach it to the type. */
6240 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6241 struct dwarf2_cu
*cu
)
6243 int nfields
= fip
->nfields
;
6245 /* Record the field count, allocate space for the array of fields,
6246 and create blank accessibility bitfields if necessary. */
6247 TYPE_NFIELDS (type
) = nfields
;
6248 TYPE_FIELDS (type
) = (struct field
*)
6249 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6250 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6252 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6254 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6256 TYPE_FIELD_PRIVATE_BITS (type
) =
6257 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6258 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6260 TYPE_FIELD_PROTECTED_BITS (type
) =
6261 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6262 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6264 TYPE_FIELD_IGNORE_BITS (type
) =
6265 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6266 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6269 /* If the type has baseclasses, allocate and clear a bit vector for
6270 TYPE_FIELD_VIRTUAL_BITS. */
6271 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6273 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6274 unsigned char *pointer
;
6276 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6277 pointer
= TYPE_ALLOC (type
, num_bytes
);
6278 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6279 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6280 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6283 /* Copy the saved-up fields into the field vector. Start from the head
6284 of the list, adding to the tail of the field array, so that they end
6285 up in the same order in the array in which they were added to the list. */
6286 while (nfields
-- > 0)
6288 struct nextfield
*fieldp
;
6292 fieldp
= fip
->fields
;
6293 fip
->fields
= fieldp
->next
;
6297 fieldp
= fip
->baseclasses
;
6298 fip
->baseclasses
= fieldp
->next
;
6301 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6302 switch (fieldp
->accessibility
)
6304 case DW_ACCESS_private
:
6305 if (cu
->language
!= language_ada
)
6306 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6309 case DW_ACCESS_protected
:
6310 if (cu
->language
!= language_ada
)
6311 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6314 case DW_ACCESS_public
:
6318 /* Unknown accessibility. Complain and treat it as public. */
6320 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6321 fieldp
->accessibility
);
6325 if (nfields
< fip
->nbaseclasses
)
6327 switch (fieldp
->virtuality
)
6329 case DW_VIRTUALITY_virtual
:
6330 case DW_VIRTUALITY_pure_virtual
:
6331 if (cu
->language
== language_ada
)
6332 error ("unexpected virtuality in component of Ada type");
6333 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6340 /* Add a member function to the proper fieldlist. */
6343 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6344 struct type
*type
, struct dwarf2_cu
*cu
)
6346 struct objfile
*objfile
= cu
->objfile
;
6347 struct attribute
*attr
;
6348 struct fnfieldlist
*flp
;
6350 struct fn_field
*fnp
;
6352 struct nextfnfield
*new_fnfield
;
6353 struct type
*this_type
;
6355 if (cu
->language
== language_ada
)
6356 error ("unexpected member function in Ada type");
6358 /* Get name of member function. */
6359 fieldname
= dwarf2_name (die
, cu
);
6360 if (fieldname
== NULL
)
6363 /* Look up member function name in fieldlist. */
6364 for (i
= 0; i
< fip
->nfnfields
; i
++)
6366 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6370 /* Create new list element if necessary. */
6371 if (i
< fip
->nfnfields
)
6372 flp
= &fip
->fnfieldlists
[i
];
6375 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6377 fip
->fnfieldlists
= (struct fnfieldlist
*)
6378 xrealloc (fip
->fnfieldlists
,
6379 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6380 * sizeof (struct fnfieldlist
));
6381 if (fip
->nfnfields
== 0)
6382 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6384 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6385 flp
->name
= fieldname
;
6388 i
= fip
->nfnfields
++;
6391 /* Create a new member function field and chain it to the field list
6393 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6394 make_cleanup (xfree
, new_fnfield
);
6395 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6396 new_fnfield
->next
= flp
->head
;
6397 flp
->head
= new_fnfield
;
6400 /* Fill in the member function field info. */
6401 fnp
= &new_fnfield
->fnfield
;
6403 /* Delay processing of the physname until later. */
6404 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6406 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6411 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6412 fnp
->physname
= physname
? physname
: "";
6415 fnp
->type
= alloc_type (objfile
);
6416 this_type
= read_type_die (die
, cu
);
6417 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6419 int nparams
= TYPE_NFIELDS (this_type
);
6421 /* TYPE is the domain of this method, and THIS_TYPE is the type
6422 of the method itself (TYPE_CODE_METHOD). */
6423 smash_to_method_type (fnp
->type
, type
,
6424 TYPE_TARGET_TYPE (this_type
),
6425 TYPE_FIELDS (this_type
),
6426 TYPE_NFIELDS (this_type
),
6427 TYPE_VARARGS (this_type
));
6429 /* Handle static member functions.
6430 Dwarf2 has no clean way to discern C++ static and non-static
6431 member functions. G++ helps GDB by marking the first
6432 parameter for non-static member functions (which is the
6433 this pointer) as artificial. We obtain this information
6434 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6435 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6436 fnp
->voffset
= VOFFSET_STATIC
;
6439 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6440 dwarf2_full_name (fieldname
, die
, cu
));
6442 /* Get fcontext from DW_AT_containing_type if present. */
6443 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6444 fnp
->fcontext
= die_containing_type (die
, cu
);
6446 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6447 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6449 /* Get accessibility. */
6450 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6453 switch (DW_UNSND (attr
))
6455 case DW_ACCESS_private
:
6456 fnp
->is_private
= 1;
6458 case DW_ACCESS_protected
:
6459 fnp
->is_protected
= 1;
6464 /* Check for artificial methods. */
6465 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6466 if (attr
&& DW_UNSND (attr
) != 0)
6467 fnp
->is_artificial
= 1;
6469 /* Get index in virtual function table if it is a virtual member
6470 function. For older versions of GCC, this is an offset in the
6471 appropriate virtual table, as specified by DW_AT_containing_type.
6472 For everyone else, it is an expression to be evaluated relative
6473 to the object address. */
6475 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6478 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6480 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6482 /* Old-style GCC. */
6483 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6485 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6486 || (DW_BLOCK (attr
)->size
> 1
6487 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6488 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6490 struct dwarf_block blk
;
6493 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6495 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6496 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6497 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6498 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6499 dwarf2_complex_location_expr_complaint ();
6501 fnp
->voffset
/= cu
->header
.addr_size
;
6505 dwarf2_complex_location_expr_complaint ();
6508 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6510 else if (attr_form_is_section_offset (attr
))
6512 dwarf2_complex_location_expr_complaint ();
6516 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6522 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6523 if (attr
&& DW_UNSND (attr
))
6525 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6526 complaint (&symfile_complaints
,
6527 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6528 fieldname
, die
->offset
);
6529 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6530 TYPE_CPLUS_DYNAMIC (type
) = 1;
6535 /* Create the vector of member function fields, and attach it to the type. */
6538 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6539 struct dwarf2_cu
*cu
)
6541 struct fnfieldlist
*flp
;
6542 int total_length
= 0;
6545 if (cu
->language
== language_ada
)
6546 error ("unexpected member functions in Ada type");
6548 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6549 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6550 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6552 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6554 struct nextfnfield
*nfp
= flp
->head
;
6555 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6558 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6559 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6560 fn_flp
->fn_fields
= (struct fn_field
*)
6561 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6562 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6563 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6565 total_length
+= flp
->length
;
6568 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6569 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6572 /* Returns non-zero if NAME is the name of a vtable member in CU's
6573 language, zero otherwise. */
6575 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6577 static const char vptr
[] = "_vptr";
6578 static const char vtable
[] = "vtable";
6580 /* Look for the C++ and Java forms of the vtable. */
6581 if ((cu
->language
== language_java
6582 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6583 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6584 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6590 /* GCC outputs unnamed structures that are really pointers to member
6591 functions, with the ABI-specified layout. If TYPE describes
6592 such a structure, smash it into a member function type.
6594 GCC shouldn't do this; it should just output pointer to member DIEs.
6595 This is GCC PR debug/28767. */
6598 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6600 struct type
*pfn_type
, *domain_type
, *new_type
;
6602 /* Check for a structure with no name and two children. */
6603 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6606 /* Check for __pfn and __delta members. */
6607 if (TYPE_FIELD_NAME (type
, 0) == NULL
6608 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6609 || TYPE_FIELD_NAME (type
, 1) == NULL
6610 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6613 /* Find the type of the method. */
6614 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6615 if (pfn_type
== NULL
6616 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6617 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6620 /* Look for the "this" argument. */
6621 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6622 if (TYPE_NFIELDS (pfn_type
) == 0
6623 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6624 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6627 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6628 new_type
= alloc_type (objfile
);
6629 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6630 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6631 TYPE_VARARGS (pfn_type
));
6632 smash_to_methodptr_type (type
, new_type
);
6635 /* Called when we find the DIE that starts a structure or union scope
6636 (definition) to create a type for the structure or union. Fill in
6637 the type's name and general properties; the members will not be
6638 processed until process_structure_type.
6640 NOTE: we need to call these functions regardless of whether or not the
6641 DIE has a DW_AT_name attribute, since it might be an anonymous
6642 structure or union. This gets the type entered into our set of
6645 However, if the structure is incomplete (an opaque struct/union)
6646 then suppress creating a symbol table entry for it since gdb only
6647 wants to find the one with the complete definition. Note that if
6648 it is complete, we just call new_symbol, which does it's own
6649 checking about whether the struct/union is anonymous or not (and
6650 suppresses creating a symbol table entry itself). */
6652 static struct type
*
6653 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6655 struct objfile
*objfile
= cu
->objfile
;
6657 struct attribute
*attr
;
6660 /* If the definition of this type lives in .debug_types, read that type.
6661 Don't follow DW_AT_specification though, that will take us back up
6662 the chain and we want to go down. */
6663 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6666 struct dwarf2_cu
*type_cu
= cu
;
6667 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6669 /* We could just recurse on read_structure_type, but we need to call
6670 get_die_type to ensure only one type for this DIE is created.
6671 This is important, for example, because for c++ classes we need
6672 TYPE_NAME set which is only done by new_symbol. Blech. */
6673 type
= read_type_die (type_die
, type_cu
);
6675 /* TYPE_CU may not be the same as CU.
6676 Ensure TYPE is recorded in CU's type_hash table. */
6677 return set_die_type (die
, type
, cu
);
6680 type
= alloc_type (objfile
);
6681 INIT_CPLUS_SPECIFIC (type
);
6683 name
= dwarf2_name (die
, cu
);
6686 if (cu
->language
== language_cplus
6687 || cu
->language
== language_java
)
6689 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6691 /* dwarf2_full_name might have already finished building the DIE's
6692 type. If so, there is no need to continue. */
6693 if (get_die_type (die
, cu
) != NULL
)
6694 return get_die_type (die
, cu
);
6696 TYPE_TAG_NAME (type
) = full_name
;
6697 if (die
->tag
== DW_TAG_structure_type
6698 || die
->tag
== DW_TAG_class_type
)
6699 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6703 /* The name is already allocated along with this objfile, so
6704 we don't need to duplicate it for the type. */
6705 TYPE_TAG_NAME (type
) = (char *) name
;
6706 if (die
->tag
== DW_TAG_class_type
)
6707 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6711 if (die
->tag
== DW_TAG_structure_type
)
6713 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6715 else if (die
->tag
== DW_TAG_union_type
)
6717 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6721 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6724 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6725 TYPE_DECLARED_CLASS (type
) = 1;
6727 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6730 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6734 TYPE_LENGTH (type
) = 0;
6737 TYPE_STUB_SUPPORTED (type
) = 1;
6738 if (die_is_declaration (die
, cu
))
6739 TYPE_STUB (type
) = 1;
6740 else if (attr
== NULL
&& die
->child
== NULL
6741 && producer_is_realview (cu
->producer
))
6742 /* RealView does not output the required DW_AT_declaration
6743 on incomplete types. */
6744 TYPE_STUB (type
) = 1;
6746 /* We need to add the type field to the die immediately so we don't
6747 infinitely recurse when dealing with pointers to the structure
6748 type within the structure itself. */
6749 set_die_type (die
, type
, cu
);
6751 /* set_die_type should be already done. */
6752 set_descriptive_type (type
, die
, cu
);
6757 /* Finish creating a structure or union type, including filling in
6758 its members and creating a symbol for it. */
6761 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6763 struct objfile
*objfile
= cu
->objfile
;
6764 struct die_info
*child_die
= die
->child
;
6767 type
= get_die_type (die
, cu
);
6769 type
= read_structure_type (die
, cu
);
6771 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6773 struct field_info fi
;
6774 struct die_info
*child_die
;
6775 VEC (symbolp
) *template_args
= NULL
;
6776 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6778 memset (&fi
, 0, sizeof (struct field_info
));
6780 child_die
= die
->child
;
6782 while (child_die
&& child_die
->tag
)
6784 if (child_die
->tag
== DW_TAG_member
6785 || child_die
->tag
== DW_TAG_variable
)
6787 /* NOTE: carlton/2002-11-05: A C++ static data member
6788 should be a DW_TAG_member that is a declaration, but
6789 all versions of G++ as of this writing (so through at
6790 least 3.2.1) incorrectly generate DW_TAG_variable
6791 tags for them instead. */
6792 dwarf2_add_field (&fi
, child_die
, cu
);
6794 else if (child_die
->tag
== DW_TAG_subprogram
)
6796 /* C++ member function. */
6797 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6799 else if (child_die
->tag
== DW_TAG_inheritance
)
6801 /* C++ base class field. */
6802 dwarf2_add_field (&fi
, child_die
, cu
);
6804 else if (child_die
->tag
== DW_TAG_typedef
)
6805 dwarf2_add_typedef (&fi
, child_die
, cu
);
6806 else if (child_die
->tag
== DW_TAG_template_type_param
6807 || child_die
->tag
== DW_TAG_template_value_param
)
6809 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6812 VEC_safe_push (symbolp
, template_args
, arg
);
6815 child_die
= sibling_die (child_die
);
6818 /* Attach template arguments to type. */
6819 if (! VEC_empty (symbolp
, template_args
))
6821 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6822 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6823 = VEC_length (symbolp
, template_args
);
6824 TYPE_TEMPLATE_ARGUMENTS (type
)
6825 = obstack_alloc (&objfile
->objfile_obstack
,
6826 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6827 * sizeof (struct symbol
*)));
6828 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6829 VEC_address (symbolp
, template_args
),
6830 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6831 * sizeof (struct symbol
*)));
6832 VEC_free (symbolp
, template_args
);
6835 /* Attach fields and member functions to the type. */
6837 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6840 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6842 /* Get the type which refers to the base class (possibly this
6843 class itself) which contains the vtable pointer for the current
6844 class from the DW_AT_containing_type attribute. This use of
6845 DW_AT_containing_type is a GNU extension. */
6847 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6849 struct type
*t
= die_containing_type (die
, cu
);
6851 TYPE_VPTR_BASETYPE (type
) = t
;
6856 /* Our own class provides vtbl ptr. */
6857 for (i
= TYPE_NFIELDS (t
) - 1;
6858 i
>= TYPE_N_BASECLASSES (t
);
6861 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6863 if (is_vtable_name (fieldname
, cu
))
6865 TYPE_VPTR_FIELDNO (type
) = i
;
6870 /* Complain if virtual function table field not found. */
6871 if (i
< TYPE_N_BASECLASSES (t
))
6872 complaint (&symfile_complaints
,
6873 _("virtual function table pointer not found when defining class '%s'"),
6874 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6879 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6882 else if (cu
->producer
6883 && strncmp (cu
->producer
,
6884 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6886 /* The IBM XLC compiler does not provide direct indication
6887 of the containing type, but the vtable pointer is
6888 always named __vfp. */
6892 for (i
= TYPE_NFIELDS (type
) - 1;
6893 i
>= TYPE_N_BASECLASSES (type
);
6896 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6898 TYPE_VPTR_FIELDNO (type
) = i
;
6899 TYPE_VPTR_BASETYPE (type
) = type
;
6906 /* Copy fi.typedef_field_list linked list elements content into the
6907 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6908 if (fi
.typedef_field_list
)
6910 int i
= fi
.typedef_field_list_count
;
6912 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6913 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6914 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6915 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6917 /* Reverse the list order to keep the debug info elements order. */
6920 struct typedef_field
*dest
, *src
;
6922 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6923 src
= &fi
.typedef_field_list
->field
;
6924 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6929 do_cleanups (back_to
);
6932 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6934 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6935 snapshots) has been known to create a die giving a declaration
6936 for a class that has, as a child, a die giving a definition for a
6937 nested class. So we have to process our children even if the
6938 current die is a declaration. Normally, of course, a declaration
6939 won't have any children at all. */
6941 while (child_die
!= NULL
&& child_die
->tag
)
6943 if (child_die
->tag
== DW_TAG_member
6944 || child_die
->tag
== DW_TAG_variable
6945 || child_die
->tag
== DW_TAG_inheritance
6946 || child_die
->tag
== DW_TAG_template_value_param
6947 || child_die
->tag
== DW_TAG_template_type_param
)
6952 process_die (child_die
, cu
);
6954 child_die
= sibling_die (child_die
);
6957 /* Do not consider external references. According to the DWARF standard,
6958 these DIEs are identified by the fact that they have no byte_size
6959 attribute, and a declaration attribute. */
6960 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6961 || !die_is_declaration (die
, cu
))
6962 new_symbol (die
, type
, cu
);
6965 /* Given a DW_AT_enumeration_type die, set its type. We do not
6966 complete the type's fields yet, or create any symbols. */
6968 static struct type
*
6969 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6971 struct objfile
*objfile
= cu
->objfile
;
6973 struct attribute
*attr
;
6976 /* If the definition of this type lives in .debug_types, read that type.
6977 Don't follow DW_AT_specification though, that will take us back up
6978 the chain and we want to go down. */
6979 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6982 struct dwarf2_cu
*type_cu
= cu
;
6983 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6985 type
= read_type_die (type_die
, type_cu
);
6987 /* TYPE_CU may not be the same as CU.
6988 Ensure TYPE is recorded in CU's type_hash table. */
6989 return set_die_type (die
, type
, cu
);
6992 type
= alloc_type (objfile
);
6994 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
6995 name
= dwarf2_full_name (NULL
, die
, cu
);
6997 TYPE_TAG_NAME (type
) = (char *) name
;
6999 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7002 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7006 TYPE_LENGTH (type
) = 0;
7009 /* The enumeration DIE can be incomplete. In Ada, any type can be
7010 declared as private in the package spec, and then defined only
7011 inside the package body. Such types are known as Taft Amendment
7012 Types. When another package uses such a type, an incomplete DIE
7013 may be generated by the compiler. */
7014 if (die_is_declaration (die
, cu
))
7015 TYPE_STUB (type
) = 1;
7017 return set_die_type (die
, type
, cu
);
7020 /* Given a pointer to a die which begins an enumeration, process all
7021 the dies that define the members of the enumeration, and create the
7022 symbol for the enumeration type.
7024 NOTE: We reverse the order of the element list. */
7027 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7029 struct type
*this_type
;
7031 this_type
= get_die_type (die
, cu
);
7032 if (this_type
== NULL
)
7033 this_type
= read_enumeration_type (die
, cu
);
7035 if (die
->child
!= NULL
)
7037 struct die_info
*child_die
;
7039 struct field
*fields
= NULL
;
7041 int unsigned_enum
= 1;
7044 child_die
= die
->child
;
7045 while (child_die
&& child_die
->tag
)
7047 if (child_die
->tag
!= DW_TAG_enumerator
)
7049 process_die (child_die
, cu
);
7053 name
= dwarf2_name (child_die
, cu
);
7056 sym
= new_symbol (child_die
, this_type
, cu
);
7057 if (SYMBOL_VALUE (sym
) < 0)
7060 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7062 fields
= (struct field
*)
7064 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7065 * sizeof (struct field
));
7068 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7069 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7070 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7071 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7077 child_die
= sibling_die (child_die
);
7082 TYPE_NFIELDS (this_type
) = num_fields
;
7083 TYPE_FIELDS (this_type
) = (struct field
*)
7084 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7085 memcpy (TYPE_FIELDS (this_type
), fields
,
7086 sizeof (struct field
) * num_fields
);
7090 TYPE_UNSIGNED (this_type
) = 1;
7093 new_symbol (die
, this_type
, cu
);
7096 /* Extract all information from a DW_TAG_array_type DIE and put it in
7097 the DIE's type field. For now, this only handles one dimensional
7100 static struct type
*
7101 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7103 struct objfile
*objfile
= cu
->objfile
;
7104 struct die_info
*child_die
;
7106 struct type
*element_type
, *range_type
, *index_type
;
7107 struct type
**range_types
= NULL
;
7108 struct attribute
*attr
;
7110 struct cleanup
*back_to
;
7113 element_type
= die_type (die
, cu
);
7115 /* The die_type call above may have already set the type for this DIE. */
7116 type
= get_die_type (die
, cu
);
7120 /* Irix 6.2 native cc creates array types without children for
7121 arrays with unspecified length. */
7122 if (die
->child
== NULL
)
7124 index_type
= objfile_type (objfile
)->builtin_int
;
7125 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7126 type
= create_array_type (NULL
, element_type
, range_type
);
7127 return set_die_type (die
, type
, cu
);
7130 back_to
= make_cleanup (null_cleanup
, NULL
);
7131 child_die
= die
->child
;
7132 while (child_die
&& child_die
->tag
)
7134 if (child_die
->tag
== DW_TAG_subrange_type
)
7136 struct type
*child_type
= read_type_die (child_die
, cu
);
7138 if (child_type
!= NULL
)
7140 /* The range type was succesfully read. Save it for
7141 the array type creation. */
7142 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7144 range_types
= (struct type
**)
7145 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7146 * sizeof (struct type
*));
7148 make_cleanup (free_current_contents
, &range_types
);
7150 range_types
[ndim
++] = child_type
;
7153 child_die
= sibling_die (child_die
);
7156 /* Dwarf2 dimensions are output from left to right, create the
7157 necessary array types in backwards order. */
7159 type
= element_type
;
7161 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7166 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7171 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7174 /* Understand Dwarf2 support for vector types (like they occur on
7175 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7176 array type. This is not part of the Dwarf2/3 standard yet, but a
7177 custom vendor extension. The main difference between a regular
7178 array and the vector variant is that vectors are passed by value
7180 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7182 make_vector_type (type
);
7184 name
= dwarf2_name (die
, cu
);
7186 TYPE_NAME (type
) = name
;
7188 /* Install the type in the die. */
7189 set_die_type (die
, type
, cu
);
7191 /* set_die_type should be already done. */
7192 set_descriptive_type (type
, die
, cu
);
7194 do_cleanups (back_to
);
7199 static enum dwarf_array_dim_ordering
7200 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7202 struct attribute
*attr
;
7204 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7206 if (attr
) return DW_SND (attr
);
7209 GNU F77 is a special case, as at 08/2004 array type info is the
7210 opposite order to the dwarf2 specification, but data is still
7211 laid out as per normal fortran.
7213 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7217 if (cu
->language
== language_fortran
7218 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7220 return DW_ORD_row_major
;
7223 switch (cu
->language_defn
->la_array_ordering
)
7225 case array_column_major
:
7226 return DW_ORD_col_major
;
7227 case array_row_major
:
7229 return DW_ORD_row_major
;
7233 /* Extract all information from a DW_TAG_set_type DIE and put it in
7234 the DIE's type field. */
7236 static struct type
*
7237 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7239 struct type
*domain_type
, *set_type
;
7240 struct attribute
*attr
;
7242 domain_type
= die_type (die
, cu
);
7244 /* The die_type call above may have already set the type for this DIE. */
7245 set_type
= get_die_type (die
, cu
);
7249 set_type
= create_set_type (NULL
, domain_type
);
7251 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7253 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7255 return set_die_type (die
, set_type
, cu
);
7258 /* First cut: install each common block member as a global variable. */
7261 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7263 struct die_info
*child_die
;
7264 struct attribute
*attr
;
7266 CORE_ADDR base
= (CORE_ADDR
) 0;
7268 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7271 /* Support the .debug_loc offsets */
7272 if (attr_form_is_block (attr
))
7274 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7276 else if (attr_form_is_section_offset (attr
))
7278 dwarf2_complex_location_expr_complaint ();
7282 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7283 "common block member");
7286 if (die
->child
!= NULL
)
7288 child_die
= die
->child
;
7289 while (child_die
&& child_die
->tag
)
7291 sym
= new_symbol (child_die
, NULL
, cu
);
7292 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7293 if (sym
!= NULL
&& attr
!= NULL
)
7295 CORE_ADDR byte_offset
= 0;
7297 if (attr_form_is_section_offset (attr
))
7298 dwarf2_complex_location_expr_complaint ();
7299 else if (attr_form_is_constant (attr
))
7300 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7301 else if (attr_form_is_block (attr
))
7302 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7304 dwarf2_complex_location_expr_complaint ();
7306 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7307 add_symbol_to_list (sym
, &global_symbols
);
7309 child_die
= sibling_die (child_die
);
7314 /* Create a type for a C++ namespace. */
7316 static struct type
*
7317 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7319 struct objfile
*objfile
= cu
->objfile
;
7320 const char *previous_prefix
, *name
;
7324 /* For extensions, reuse the type of the original namespace. */
7325 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7327 struct die_info
*ext_die
;
7328 struct dwarf2_cu
*ext_cu
= cu
;
7330 ext_die
= dwarf2_extension (die
, &ext_cu
);
7331 type
= read_type_die (ext_die
, ext_cu
);
7333 /* EXT_CU may not be the same as CU.
7334 Ensure TYPE is recorded in CU's type_hash table. */
7335 return set_die_type (die
, type
, cu
);
7338 name
= namespace_name (die
, &is_anonymous
, cu
);
7340 /* Now build the name of the current namespace. */
7342 previous_prefix
= determine_prefix (die
, cu
);
7343 if (previous_prefix
[0] != '\0')
7344 name
= typename_concat (&objfile
->objfile_obstack
,
7345 previous_prefix
, name
, 0, cu
);
7347 /* Create the type. */
7348 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7350 TYPE_NAME (type
) = (char *) name
;
7351 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7353 return set_die_type (die
, type
, cu
);
7356 /* Read a C++ namespace. */
7359 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7361 struct objfile
*objfile
= cu
->objfile
;
7365 /* Add a symbol associated to this if we haven't seen the namespace
7366 before. Also, add a using directive if it's an anonymous
7369 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7373 type
= read_type_die (die
, cu
);
7374 new_symbol (die
, type
, cu
);
7376 name
= namespace_name (die
, &is_anonymous
, cu
);
7379 const char *previous_prefix
= determine_prefix (die
, cu
);
7381 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7382 NULL
, &objfile
->objfile_obstack
);
7386 if (die
->child
!= NULL
)
7388 struct die_info
*child_die
= die
->child
;
7390 while (child_die
&& child_die
->tag
)
7392 process_die (child_die
, cu
);
7393 child_die
= sibling_die (child_die
);
7398 /* Read a Fortran module as type. This DIE can be only a declaration used for
7399 imported module. Still we need that type as local Fortran "use ... only"
7400 declaration imports depend on the created type in determine_prefix. */
7402 static struct type
*
7403 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7405 struct objfile
*objfile
= cu
->objfile
;
7409 module_name
= dwarf2_name (die
, cu
);
7411 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7413 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7415 /* determine_prefix uses TYPE_TAG_NAME. */
7416 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7418 return set_die_type (die
, type
, cu
);
7421 /* Read a Fortran module. */
7424 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7426 struct die_info
*child_die
= die
->child
;
7428 while (child_die
&& child_die
->tag
)
7430 process_die (child_die
, cu
);
7431 child_die
= sibling_die (child_die
);
7435 /* Return the name of the namespace represented by DIE. Set
7436 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7440 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7442 struct die_info
*current_die
;
7443 const char *name
= NULL
;
7445 /* Loop through the extensions until we find a name. */
7447 for (current_die
= die
;
7448 current_die
!= NULL
;
7449 current_die
= dwarf2_extension (die
, &cu
))
7451 name
= dwarf2_name (current_die
, cu
);
7456 /* Is it an anonymous namespace? */
7458 *is_anonymous
= (name
== NULL
);
7460 name
= "(anonymous namespace)";
7465 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7466 the user defined type vector. */
7468 static struct type
*
7469 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7471 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7472 struct comp_unit_head
*cu_header
= &cu
->header
;
7474 struct attribute
*attr_byte_size
;
7475 struct attribute
*attr_address_class
;
7476 int byte_size
, addr_class
;
7477 struct type
*target_type
;
7479 target_type
= die_type (die
, cu
);
7481 /* The die_type call above may have already set the type for this DIE. */
7482 type
= get_die_type (die
, cu
);
7486 type
= lookup_pointer_type (target_type
);
7488 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7490 byte_size
= DW_UNSND (attr_byte_size
);
7492 byte_size
= cu_header
->addr_size
;
7494 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7495 if (attr_address_class
)
7496 addr_class
= DW_UNSND (attr_address_class
);
7498 addr_class
= DW_ADDR_none
;
7500 /* If the pointer size or address class is different than the
7501 default, create a type variant marked as such and set the
7502 length accordingly. */
7503 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7505 if (gdbarch_address_class_type_flags_p (gdbarch
))
7509 type_flags
= gdbarch_address_class_type_flags
7510 (gdbarch
, byte_size
, addr_class
);
7511 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7513 type
= make_type_with_address_space (type
, type_flags
);
7515 else if (TYPE_LENGTH (type
) != byte_size
)
7517 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7521 /* Should we also complain about unhandled address classes? */
7525 TYPE_LENGTH (type
) = byte_size
;
7526 return set_die_type (die
, type
, cu
);
7529 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7530 the user defined type vector. */
7532 static struct type
*
7533 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7536 struct type
*to_type
;
7537 struct type
*domain
;
7539 to_type
= die_type (die
, cu
);
7540 domain
= die_containing_type (die
, cu
);
7542 /* The calls above may have already set the type for this DIE. */
7543 type
= get_die_type (die
, cu
);
7547 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7548 type
= lookup_methodptr_type (to_type
);
7550 type
= lookup_memberptr_type (to_type
, domain
);
7552 return set_die_type (die
, type
, cu
);
7555 /* Extract all information from a DW_TAG_reference_type DIE and add to
7556 the user defined type vector. */
7558 static struct type
*
7559 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7561 struct comp_unit_head
*cu_header
= &cu
->header
;
7562 struct type
*type
, *target_type
;
7563 struct attribute
*attr
;
7565 target_type
= die_type (die
, cu
);
7567 /* The die_type call above may have already set the type for this DIE. */
7568 type
= get_die_type (die
, cu
);
7572 type
= lookup_reference_type (target_type
);
7573 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7576 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7580 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7582 return set_die_type (die
, type
, cu
);
7585 static struct type
*
7586 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7588 struct type
*base_type
, *cv_type
;
7590 base_type
= die_type (die
, cu
);
7592 /* The die_type call above may have already set the type for this DIE. */
7593 cv_type
= get_die_type (die
, cu
);
7597 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7598 return set_die_type (die
, cv_type
, cu
);
7601 static struct type
*
7602 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7604 struct type
*base_type
, *cv_type
;
7606 base_type
= die_type (die
, cu
);
7608 /* The die_type call above may have already set the type for this DIE. */
7609 cv_type
= get_die_type (die
, cu
);
7613 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7614 return set_die_type (die
, cv_type
, cu
);
7617 /* Extract all information from a DW_TAG_string_type DIE and add to
7618 the user defined type vector. It isn't really a user defined type,
7619 but it behaves like one, with other DIE's using an AT_user_def_type
7620 attribute to reference it. */
7622 static struct type
*
7623 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7625 struct objfile
*objfile
= cu
->objfile
;
7626 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7627 struct type
*type
, *range_type
, *index_type
, *char_type
;
7628 struct attribute
*attr
;
7629 unsigned int length
;
7631 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7634 length
= DW_UNSND (attr
);
7638 /* check for the DW_AT_byte_size attribute */
7639 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7642 length
= DW_UNSND (attr
);
7650 index_type
= objfile_type (objfile
)->builtin_int
;
7651 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7652 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7653 type
= create_string_type (NULL
, char_type
, range_type
);
7655 return set_die_type (die
, type
, cu
);
7658 /* Handle DIES due to C code like:
7662 int (*funcp)(int a, long l);
7666 ('funcp' generates a DW_TAG_subroutine_type DIE)
7669 static struct type
*
7670 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7672 struct type
*type
; /* Type that this function returns */
7673 struct type
*ftype
; /* Function that returns above type */
7674 struct attribute
*attr
;
7676 type
= die_type (die
, cu
);
7678 /* The die_type call above may have already set the type for this DIE. */
7679 ftype
= get_die_type (die
, cu
);
7683 ftype
= lookup_function_type (type
);
7685 /* All functions in C++, Pascal and Java have prototypes. */
7686 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7687 if ((attr
&& (DW_UNSND (attr
) != 0))
7688 || cu
->language
== language_cplus
7689 || cu
->language
== language_java
7690 || cu
->language
== language_pascal
)
7691 TYPE_PROTOTYPED (ftype
) = 1;
7692 else if (producer_is_realview (cu
->producer
))
7693 /* RealView does not emit DW_AT_prototyped. We can not
7694 distinguish prototyped and unprototyped functions; default to
7695 prototyped, since that is more common in modern code (and
7696 RealView warns about unprototyped functions). */
7697 TYPE_PROTOTYPED (ftype
) = 1;
7699 /* Store the calling convention in the type if it's available in
7700 the subroutine die. Otherwise set the calling convention to
7701 the default value DW_CC_normal. */
7702 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7703 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7705 /* We need to add the subroutine type to the die immediately so
7706 we don't infinitely recurse when dealing with parameters
7707 declared as the same subroutine type. */
7708 set_die_type (die
, ftype
, cu
);
7710 if (die
->child
!= NULL
)
7712 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7713 struct die_info
*child_die
;
7714 int nparams
, iparams
;
7716 /* Count the number of parameters.
7717 FIXME: GDB currently ignores vararg functions, but knows about
7718 vararg member functions. */
7720 child_die
= die
->child
;
7721 while (child_die
&& child_die
->tag
)
7723 if (child_die
->tag
== DW_TAG_formal_parameter
)
7725 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7726 TYPE_VARARGS (ftype
) = 1;
7727 child_die
= sibling_die (child_die
);
7730 /* Allocate storage for parameters and fill them in. */
7731 TYPE_NFIELDS (ftype
) = nparams
;
7732 TYPE_FIELDS (ftype
) = (struct field
*)
7733 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7735 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7736 even if we error out during the parameters reading below. */
7737 for (iparams
= 0; iparams
< nparams
; iparams
++)
7738 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7741 child_die
= die
->child
;
7742 while (child_die
&& child_die
->tag
)
7744 if (child_die
->tag
== DW_TAG_formal_parameter
)
7746 struct type
*arg_type
;
7748 /* DWARF version 2 has no clean way to discern C++
7749 static and non-static member functions. G++ helps
7750 GDB by marking the first parameter for non-static
7751 member functions (which is the this pointer) as
7752 artificial. We pass this information to
7753 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7755 DWARF version 3 added DW_AT_object_pointer, which GCC
7756 4.5 does not yet generate. */
7757 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7759 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7762 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7764 /* GCC/43521: In java, the formal parameter
7765 "this" is sometimes not marked with DW_AT_artificial. */
7766 if (cu
->language
== language_java
)
7768 const char *name
= dwarf2_name (child_die
, cu
);
7770 if (name
&& !strcmp (name
, "this"))
7771 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7774 arg_type
= die_type (child_die
, cu
);
7776 /* RealView does not mark THIS as const, which the testsuite
7777 expects. GCC marks THIS as const in method definitions,
7778 but not in the class specifications (GCC PR 43053). */
7779 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7780 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7783 struct dwarf2_cu
*arg_cu
= cu
;
7784 const char *name
= dwarf2_name (child_die
, cu
);
7786 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7789 /* If the compiler emits this, use it. */
7790 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7793 else if (name
&& strcmp (name
, "this") == 0)
7794 /* Function definitions will have the argument names. */
7796 else if (name
== NULL
&& iparams
== 0)
7797 /* Declarations may not have the names, so like
7798 elsewhere in GDB, assume an artificial first
7799 argument is "this". */
7803 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7807 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7810 child_die
= sibling_die (child_die
);
7817 static struct type
*
7818 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7820 struct objfile
*objfile
= cu
->objfile
;
7821 const char *name
= NULL
;
7822 struct type
*this_type
;
7824 name
= dwarf2_full_name (NULL
, die
, cu
);
7825 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7826 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7827 TYPE_NAME (this_type
) = (char *) name
;
7828 set_die_type (die
, this_type
, cu
);
7829 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7833 /* Find a representation of a given base type and install
7834 it in the TYPE field of the die. */
7836 static struct type
*
7837 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7839 struct objfile
*objfile
= cu
->objfile
;
7841 struct attribute
*attr
;
7842 int encoding
= 0, size
= 0;
7844 enum type_code code
= TYPE_CODE_INT
;
7846 struct type
*target_type
= NULL
;
7848 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7851 encoding
= DW_UNSND (attr
);
7853 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7856 size
= DW_UNSND (attr
);
7858 name
= dwarf2_name (die
, cu
);
7861 complaint (&symfile_complaints
,
7862 _("DW_AT_name missing from DW_TAG_base_type"));
7867 case DW_ATE_address
:
7868 /* Turn DW_ATE_address into a void * pointer. */
7869 code
= TYPE_CODE_PTR
;
7870 type_flags
|= TYPE_FLAG_UNSIGNED
;
7871 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7873 case DW_ATE_boolean
:
7874 code
= TYPE_CODE_BOOL
;
7875 type_flags
|= TYPE_FLAG_UNSIGNED
;
7877 case DW_ATE_complex_float
:
7878 code
= TYPE_CODE_COMPLEX
;
7879 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7881 case DW_ATE_decimal_float
:
7882 code
= TYPE_CODE_DECFLOAT
;
7885 code
= TYPE_CODE_FLT
;
7889 case DW_ATE_unsigned
:
7890 type_flags
|= TYPE_FLAG_UNSIGNED
;
7892 case DW_ATE_signed_char
:
7893 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7894 || cu
->language
== language_pascal
)
7895 code
= TYPE_CODE_CHAR
;
7897 case DW_ATE_unsigned_char
:
7898 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7899 || cu
->language
== language_pascal
)
7900 code
= TYPE_CODE_CHAR
;
7901 type_flags
|= TYPE_FLAG_UNSIGNED
;
7904 /* We just treat this as an integer and then recognize the
7905 type by name elsewhere. */
7909 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7910 dwarf_type_encoding_name (encoding
));
7914 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7915 TYPE_NAME (type
) = name
;
7916 TYPE_TARGET_TYPE (type
) = target_type
;
7918 if (name
&& strcmp (name
, "char") == 0)
7919 TYPE_NOSIGN (type
) = 1;
7921 return set_die_type (die
, type
, cu
);
7924 /* Read the given DW_AT_subrange DIE. */
7926 static struct type
*
7927 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7929 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7930 struct type
*base_type
;
7931 struct type
*range_type
;
7932 struct attribute
*attr
;
7936 LONGEST negative_mask
;
7938 base_type
= die_type (die
, cu
);
7939 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7940 check_typedef (base_type
);
7942 /* The die_type call above may have already set the type for this DIE. */
7943 range_type
= get_die_type (die
, cu
);
7947 if (cu
->language
== language_fortran
)
7949 /* FORTRAN implies a lower bound of 1, if not given. */
7953 /* FIXME: For variable sized arrays either of these could be
7954 a variable rather than a constant value. We'll allow it,
7955 but we don't know how to handle it. */
7956 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7958 low
= dwarf2_get_attr_constant_value (attr
, 0);
7960 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7963 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7965 /* GCC encodes arrays with unspecified or dynamic length
7966 with a DW_FORM_block1 attribute or a reference attribute.
7967 FIXME: GDB does not yet know how to handle dynamic
7968 arrays properly, treat them as arrays with unspecified
7971 FIXME: jimb/2003-09-22: GDB does not really know
7972 how to handle arrays of unspecified length
7973 either; we just represent them as zero-length
7974 arrays. Choose an appropriate upper bound given
7975 the lower bound we've computed above. */
7979 high
= dwarf2_get_attr_constant_value (attr
, 1);
7983 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
7986 int count
= dwarf2_get_attr_constant_value (attr
, 1);
7987 high
= low
+ count
- 1;
7991 /* Dwarf-2 specifications explicitly allows to create subrange types
7992 without specifying a base type.
7993 In that case, the base type must be set to the type of
7994 the lower bound, upper bound or count, in that order, if any of these
7995 three attributes references an object that has a type.
7996 If no base type is found, the Dwarf-2 specifications say that
7997 a signed integer type of size equal to the size of an address should
7999 For the following C code: `extern char gdb_int [];'
8000 GCC produces an empty range DIE.
8001 FIXME: muller/2010-05-28: Possible references to object for low bound,
8002 high bound or count are not yet handled by this code.
8004 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8006 struct objfile
*objfile
= cu
->objfile
;
8007 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8008 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8009 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8011 /* Test "int", "long int", and "long long int" objfile types,
8012 and select the first one having a size above or equal to the
8013 architecture address size. */
8014 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8015 base_type
= int_type
;
8018 int_type
= objfile_type (objfile
)->builtin_long
;
8019 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8020 base_type
= int_type
;
8023 int_type
= objfile_type (objfile
)->builtin_long_long
;
8024 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8025 base_type
= int_type
;
8031 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8032 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8033 low
|= negative_mask
;
8034 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8035 high
|= negative_mask
;
8037 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8039 /* Mark arrays with dynamic length at least as an array of unspecified
8040 length. GDB could check the boundary but before it gets implemented at
8041 least allow accessing the array elements. */
8042 if (attr
&& attr
->form
== DW_FORM_block1
)
8043 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8045 name
= dwarf2_name (die
, cu
);
8047 TYPE_NAME (range_type
) = name
;
8049 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8051 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8053 set_die_type (die
, range_type
, cu
);
8055 /* set_die_type should be already done. */
8056 set_descriptive_type (range_type
, die
, cu
);
8061 static struct type
*
8062 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8066 /* For now, we only support the C meaning of an unspecified type: void. */
8068 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8069 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8071 return set_die_type (die
, type
, cu
);
8074 /* Trivial hash function for die_info: the hash value of a DIE
8075 is its offset in .debug_info for this objfile. */
8078 die_hash (const void *item
)
8080 const struct die_info
*die
= item
;
8085 /* Trivial comparison function for die_info structures: two DIEs
8086 are equal if they have the same offset. */
8089 die_eq (const void *item_lhs
, const void *item_rhs
)
8091 const struct die_info
*die_lhs
= item_lhs
;
8092 const struct die_info
*die_rhs
= item_rhs
;
8094 return die_lhs
->offset
== die_rhs
->offset
;
8097 /* Read a whole compilation unit into a linked list of dies. */
8099 static struct die_info
*
8100 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8102 struct die_reader_specs reader_specs
;
8103 int read_abbrevs
= 0;
8104 struct cleanup
*back_to
= NULL
;
8105 struct die_info
*die
;
8107 if (cu
->dwarf2_abbrevs
== NULL
)
8109 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8110 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8114 gdb_assert (cu
->die_hash
== NULL
);
8116 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8120 &cu
->comp_unit_obstack
,
8121 hashtab_obstack_allocate
,
8122 dummy_obstack_deallocate
);
8124 init_cu_die_reader (&reader_specs
, cu
);
8126 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8129 do_cleanups (back_to
);
8134 /* Main entry point for reading a DIE and all children.
8135 Read the DIE and dump it if requested. */
8137 static struct die_info
*
8138 read_die_and_children (const struct die_reader_specs
*reader
,
8140 gdb_byte
**new_info_ptr
,
8141 struct die_info
*parent
)
8143 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8144 new_info_ptr
, parent
);
8146 if (dwarf2_die_debug
)
8148 fprintf_unfiltered (gdb_stdlog
,
8149 "\nRead die from %s of %s:\n",
8150 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8152 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8154 : "unknown section",
8155 reader
->abfd
->filename
);
8156 dump_die (result
, dwarf2_die_debug
);
8162 /* Read a single die and all its descendents. Set the die's sibling
8163 field to NULL; set other fields in the die correctly, and set all
8164 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8165 location of the info_ptr after reading all of those dies. PARENT
8166 is the parent of the die in question. */
8168 static struct die_info
*
8169 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8171 gdb_byte
**new_info_ptr
,
8172 struct die_info
*parent
)
8174 struct die_info
*die
;
8178 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8181 *new_info_ptr
= cur_ptr
;
8184 store_in_ref_table (die
, reader
->cu
);
8187 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8191 *new_info_ptr
= cur_ptr
;
8194 die
->sibling
= NULL
;
8195 die
->parent
= parent
;
8199 /* Read a die, all of its descendents, and all of its siblings; set
8200 all of the fields of all of the dies correctly. Arguments are as
8201 in read_die_and_children. */
8203 static struct die_info
*
8204 read_die_and_siblings (const struct die_reader_specs
*reader
,
8206 gdb_byte
**new_info_ptr
,
8207 struct die_info
*parent
)
8209 struct die_info
*first_die
, *last_sibling
;
8213 first_die
= last_sibling
= NULL
;
8217 struct die_info
*die
8218 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8222 *new_info_ptr
= cur_ptr
;
8229 last_sibling
->sibling
= die
;
8235 /* Read the die from the .debug_info section buffer. Set DIEP to
8236 point to a newly allocated die with its information, except for its
8237 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8238 whether the die has children or not. */
8241 read_full_die (const struct die_reader_specs
*reader
,
8242 struct die_info
**diep
, gdb_byte
*info_ptr
,
8245 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8246 struct abbrev_info
*abbrev
;
8247 struct die_info
*die
;
8248 struct dwarf2_cu
*cu
= reader
->cu
;
8249 bfd
*abfd
= reader
->abfd
;
8251 offset
= info_ptr
- reader
->buffer
;
8252 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8253 info_ptr
+= bytes_read
;
8261 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8263 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8265 bfd_get_filename (abfd
));
8267 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8268 die
->offset
= offset
;
8269 die
->tag
= abbrev
->tag
;
8270 die
->abbrev
= abbrev_number
;
8272 die
->num_attrs
= abbrev
->num_attrs
;
8274 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8275 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8276 abfd
, info_ptr
, cu
);
8279 *has_children
= abbrev
->has_children
;
8283 /* In DWARF version 2, the description of the debugging information is
8284 stored in a separate .debug_abbrev section. Before we read any
8285 dies from a section we read in all abbreviations and install them
8286 in a hash table. This function also sets flags in CU describing
8287 the data found in the abbrev table. */
8290 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8292 struct comp_unit_head
*cu_header
= &cu
->header
;
8293 gdb_byte
*abbrev_ptr
;
8294 struct abbrev_info
*cur_abbrev
;
8295 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8296 unsigned int abbrev_form
, hash_number
;
8297 struct attr_abbrev
*cur_attrs
;
8298 unsigned int allocated_attrs
;
8300 /* Initialize dwarf2 abbrevs */
8301 obstack_init (&cu
->abbrev_obstack
);
8302 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8304 * sizeof (struct abbrev_info
*)));
8305 memset (cu
->dwarf2_abbrevs
, 0,
8306 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8308 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8309 &dwarf2_per_objfile
->abbrev
);
8310 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8311 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8312 abbrev_ptr
+= bytes_read
;
8314 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8315 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8317 /* loop until we reach an abbrev number of 0 */
8318 while (abbrev_number
)
8320 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8322 /* read in abbrev header */
8323 cur_abbrev
->number
= abbrev_number
;
8324 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8325 abbrev_ptr
+= bytes_read
;
8326 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8329 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8330 cu
->has_namespace_info
= 1;
8332 /* now read in declarations */
8333 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8334 abbrev_ptr
+= bytes_read
;
8335 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8336 abbrev_ptr
+= bytes_read
;
8339 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8341 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8343 = xrealloc (cur_attrs
, (allocated_attrs
8344 * sizeof (struct attr_abbrev
)));
8347 /* Record whether this compilation unit might have
8348 inter-compilation-unit references. If we don't know what form
8349 this attribute will have, then it might potentially be a
8350 DW_FORM_ref_addr, so we conservatively expect inter-CU
8353 if (abbrev_form
== DW_FORM_ref_addr
8354 || abbrev_form
== DW_FORM_indirect
)
8355 cu
->has_form_ref_addr
= 1;
8357 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8358 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8359 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8360 abbrev_ptr
+= bytes_read
;
8361 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8362 abbrev_ptr
+= bytes_read
;
8365 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8366 (cur_abbrev
->num_attrs
8367 * sizeof (struct attr_abbrev
)));
8368 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8369 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8371 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8372 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8373 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8375 /* Get next abbreviation.
8376 Under Irix6 the abbreviations for a compilation unit are not
8377 always properly terminated with an abbrev number of 0.
8378 Exit loop if we encounter an abbreviation which we have
8379 already read (which means we are about to read the abbreviations
8380 for the next compile unit) or if the end of the abbreviation
8381 table is reached. */
8382 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8383 >= dwarf2_per_objfile
->abbrev
.size
)
8385 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8386 abbrev_ptr
+= bytes_read
;
8387 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8394 /* Release the memory used by the abbrev table for a compilation unit. */
8397 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8399 struct dwarf2_cu
*cu
= ptr_to_cu
;
8401 obstack_free (&cu
->abbrev_obstack
, NULL
);
8402 cu
->dwarf2_abbrevs
= NULL
;
8405 /* Lookup an abbrev_info structure in the abbrev hash table. */
8407 static struct abbrev_info
*
8408 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8410 unsigned int hash_number
;
8411 struct abbrev_info
*abbrev
;
8413 hash_number
= number
% ABBREV_HASH_SIZE
;
8414 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8418 if (abbrev
->number
== number
)
8421 abbrev
= abbrev
->next
;
8426 /* Returns nonzero if TAG represents a type that we might generate a partial
8430 is_type_tag_for_partial (int tag
)
8435 /* Some types that would be reasonable to generate partial symbols for,
8436 that we don't at present. */
8437 case DW_TAG_array_type
:
8438 case DW_TAG_file_type
:
8439 case DW_TAG_ptr_to_member_type
:
8440 case DW_TAG_set_type
:
8441 case DW_TAG_string_type
:
8442 case DW_TAG_subroutine_type
:
8444 case DW_TAG_base_type
:
8445 case DW_TAG_class_type
:
8446 case DW_TAG_interface_type
:
8447 case DW_TAG_enumeration_type
:
8448 case DW_TAG_structure_type
:
8449 case DW_TAG_subrange_type
:
8450 case DW_TAG_typedef
:
8451 case DW_TAG_union_type
:
8458 /* Load all DIEs that are interesting for partial symbols into memory. */
8460 static struct partial_die_info
*
8461 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8462 int building_psymtab
, struct dwarf2_cu
*cu
)
8464 struct partial_die_info
*part_die
;
8465 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8466 struct abbrev_info
*abbrev
;
8467 unsigned int bytes_read
;
8468 unsigned int load_all
= 0;
8470 int nesting_level
= 1;
8475 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8479 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8483 &cu
->comp_unit_obstack
,
8484 hashtab_obstack_allocate
,
8485 dummy_obstack_deallocate
);
8487 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8488 sizeof (struct partial_die_info
));
8492 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8494 /* A NULL abbrev means the end of a series of children. */
8497 if (--nesting_level
== 0)
8499 /* PART_DIE was probably the last thing allocated on the
8500 comp_unit_obstack, so we could call obstack_free
8501 here. We don't do that because the waste is small,
8502 and will be cleaned up when we're done with this
8503 compilation unit. This way, we're also more robust
8504 against other users of the comp_unit_obstack. */
8507 info_ptr
+= bytes_read
;
8508 last_die
= parent_die
;
8509 parent_die
= parent_die
->die_parent
;
8513 /* Check for template arguments. We never save these; if
8514 they're seen, we just mark the parent, and go on our way. */
8515 if (parent_die
!= NULL
8516 && cu
->language
== language_cplus
8517 && (abbrev
->tag
== DW_TAG_template_type_param
8518 || abbrev
->tag
== DW_TAG_template_value_param
))
8520 parent_die
->has_template_arguments
= 1;
8524 /* We don't need a partial DIE for the template argument. */
8525 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8531 /* We only recurse into subprograms looking for template arguments.
8532 Skip their other children. */
8534 && cu
->language
== language_cplus
8535 && parent_die
!= NULL
8536 && parent_die
->tag
== DW_TAG_subprogram
)
8538 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8542 /* Check whether this DIE is interesting enough to save. Normally
8543 we would not be interested in members here, but there may be
8544 later variables referencing them via DW_AT_specification (for
8547 && !is_type_tag_for_partial (abbrev
->tag
)
8548 && abbrev
->tag
!= DW_TAG_constant
8549 && abbrev
->tag
!= DW_TAG_enumerator
8550 && abbrev
->tag
!= DW_TAG_subprogram
8551 && abbrev
->tag
!= DW_TAG_lexical_block
8552 && abbrev
->tag
!= DW_TAG_variable
8553 && abbrev
->tag
!= DW_TAG_namespace
8554 && abbrev
->tag
!= DW_TAG_module
8555 && abbrev
->tag
!= DW_TAG_member
)
8557 /* Otherwise we skip to the next sibling, if any. */
8558 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8562 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8563 buffer
, info_ptr
, cu
);
8565 /* This two-pass algorithm for processing partial symbols has a
8566 high cost in cache pressure. Thus, handle some simple cases
8567 here which cover the majority of C partial symbols. DIEs
8568 which neither have specification tags in them, nor could have
8569 specification tags elsewhere pointing at them, can simply be
8570 processed and discarded.
8572 This segment is also optional; scan_partial_symbols and
8573 add_partial_symbol will handle these DIEs if we chain
8574 them in normally. When compilers which do not emit large
8575 quantities of duplicate debug information are more common,
8576 this code can probably be removed. */
8578 /* Any complete simple types at the top level (pretty much all
8579 of them, for a language without namespaces), can be processed
8581 if (parent_die
== NULL
8582 && part_die
->has_specification
== 0
8583 && part_die
->is_declaration
== 0
8584 && (part_die
->tag
== DW_TAG_typedef
8585 || part_die
->tag
== DW_TAG_base_type
8586 || part_die
->tag
== DW_TAG_subrange_type
))
8588 if (building_psymtab
&& part_die
->name
!= NULL
)
8589 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8590 VAR_DOMAIN
, LOC_TYPEDEF
,
8591 &cu
->objfile
->static_psymbols
,
8592 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8593 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8597 /* If we're at the second level, and we're an enumerator, and
8598 our parent has no specification (meaning possibly lives in a
8599 namespace elsewhere), then we can add the partial symbol now
8600 instead of queueing it. */
8601 if (part_die
->tag
== DW_TAG_enumerator
8602 && parent_die
!= NULL
8603 && parent_die
->die_parent
== NULL
8604 && parent_die
->tag
== DW_TAG_enumeration_type
8605 && parent_die
->has_specification
== 0)
8607 if (part_die
->name
== NULL
)
8608 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8609 else if (building_psymtab
)
8610 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8611 VAR_DOMAIN
, LOC_CONST
,
8612 (cu
->language
== language_cplus
8613 || cu
->language
== language_java
)
8614 ? &cu
->objfile
->global_psymbols
8615 : &cu
->objfile
->static_psymbols
,
8616 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8618 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8622 /* We'll save this DIE so link it in. */
8623 part_die
->die_parent
= parent_die
;
8624 part_die
->die_sibling
= NULL
;
8625 part_die
->die_child
= NULL
;
8627 if (last_die
&& last_die
== parent_die
)
8628 last_die
->die_child
= part_die
;
8630 last_die
->die_sibling
= part_die
;
8632 last_die
= part_die
;
8634 if (first_die
== NULL
)
8635 first_die
= part_die
;
8637 /* Maybe add the DIE to the hash table. Not all DIEs that we
8638 find interesting need to be in the hash table, because we
8639 also have the parent/sibling/child chains; only those that we
8640 might refer to by offset later during partial symbol reading.
8642 For now this means things that might have be the target of a
8643 DW_AT_specification, DW_AT_abstract_origin, or
8644 DW_AT_extension. DW_AT_extension will refer only to
8645 namespaces; DW_AT_abstract_origin refers to functions (and
8646 many things under the function DIE, but we do not recurse
8647 into function DIEs during partial symbol reading) and
8648 possibly variables as well; DW_AT_specification refers to
8649 declarations. Declarations ought to have the DW_AT_declaration
8650 flag. It happens that GCC forgets to put it in sometimes, but
8651 only for functions, not for types.
8653 Adding more things than necessary to the hash table is harmless
8654 except for the performance cost. Adding too few will result in
8655 wasted time in find_partial_die, when we reread the compilation
8656 unit with load_all_dies set. */
8659 || abbrev
->tag
== DW_TAG_constant
8660 || abbrev
->tag
== DW_TAG_subprogram
8661 || abbrev
->tag
== DW_TAG_variable
8662 || abbrev
->tag
== DW_TAG_namespace
8663 || part_die
->is_declaration
)
8667 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8668 part_die
->offset
, INSERT
);
8672 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8673 sizeof (struct partial_die_info
));
8675 /* For some DIEs we want to follow their children (if any). For C
8676 we have no reason to follow the children of structures; for other
8677 languages we have to, so that we can get at method physnames
8678 to infer fully qualified class names, for DW_AT_specification,
8679 and for C++ template arguments. For C++, we also look one level
8680 inside functions to find template arguments (if the name of the
8681 function does not already contain the template arguments).
8683 For Ada, we need to scan the children of subprograms and lexical
8684 blocks as well because Ada allows the definition of nested
8685 entities that could be interesting for the debugger, such as
8686 nested subprograms for instance. */
8687 if (last_die
->has_children
8689 || last_die
->tag
== DW_TAG_namespace
8690 || last_die
->tag
== DW_TAG_module
8691 || last_die
->tag
== DW_TAG_enumeration_type
8692 || (cu
->language
== language_cplus
8693 && last_die
->tag
== DW_TAG_subprogram
8694 && (last_die
->name
== NULL
8695 || strchr (last_die
->name
, '<') == NULL
))
8696 || (cu
->language
!= language_c
8697 && (last_die
->tag
== DW_TAG_class_type
8698 || last_die
->tag
== DW_TAG_interface_type
8699 || last_die
->tag
== DW_TAG_structure_type
8700 || last_die
->tag
== DW_TAG_union_type
))
8701 || (cu
->language
== language_ada
8702 && (last_die
->tag
== DW_TAG_subprogram
8703 || last_die
->tag
== DW_TAG_lexical_block
))))
8706 parent_die
= last_die
;
8710 /* Otherwise we skip to the next sibling, if any. */
8711 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8713 /* Back to the top, do it again. */
8717 /* Read a minimal amount of information into the minimal die structure. */
8720 read_partial_die (struct partial_die_info
*part_die
,
8721 struct abbrev_info
*abbrev
,
8722 unsigned int abbrev_len
, bfd
*abfd
,
8723 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8724 struct dwarf2_cu
*cu
)
8727 struct attribute attr
;
8728 int has_low_pc_attr
= 0;
8729 int has_high_pc_attr
= 0;
8731 memset (part_die
, 0, sizeof (struct partial_die_info
));
8733 part_die
->offset
= info_ptr
- buffer
;
8735 info_ptr
+= abbrev_len
;
8740 part_die
->tag
= abbrev
->tag
;
8741 part_die
->has_children
= abbrev
->has_children
;
8743 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8745 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8747 /* Store the data if it is of an attribute we want to keep in a
8748 partial symbol table. */
8752 switch (part_die
->tag
)
8754 case DW_TAG_compile_unit
:
8755 case DW_TAG_type_unit
:
8756 /* Compilation units have a DW_AT_name that is a filename, not
8757 a source language identifier. */
8758 case DW_TAG_enumeration_type
:
8759 case DW_TAG_enumerator
:
8760 /* These tags always have simple identifiers already; no need
8761 to canonicalize them. */
8762 part_die
->name
= DW_STRING (&attr
);
8766 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8767 &cu
->objfile
->objfile_obstack
);
8771 case DW_AT_linkage_name
:
8772 case DW_AT_MIPS_linkage_name
:
8773 /* Note that both forms of linkage name might appear. We
8774 assume they will be the same, and we only store the last
8776 if (cu
->language
== language_ada
)
8777 part_die
->name
= DW_STRING (&attr
);
8778 part_die
->linkage_name
= DW_STRING (&attr
);
8781 has_low_pc_attr
= 1;
8782 part_die
->lowpc
= DW_ADDR (&attr
);
8785 has_high_pc_attr
= 1;
8786 part_die
->highpc
= DW_ADDR (&attr
);
8788 case DW_AT_location
:
8789 /* Support the .debug_loc offsets */
8790 if (attr_form_is_block (&attr
))
8792 part_die
->locdesc
= DW_BLOCK (&attr
);
8794 else if (attr_form_is_section_offset (&attr
))
8796 dwarf2_complex_location_expr_complaint ();
8800 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8801 "partial symbol information");
8804 case DW_AT_external
:
8805 part_die
->is_external
= DW_UNSND (&attr
);
8807 case DW_AT_declaration
:
8808 part_die
->is_declaration
= DW_UNSND (&attr
);
8811 part_die
->has_type
= 1;
8813 case DW_AT_abstract_origin
:
8814 case DW_AT_specification
:
8815 case DW_AT_extension
:
8816 part_die
->has_specification
= 1;
8817 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8820 /* Ignore absolute siblings, they might point outside of
8821 the current compile unit. */
8822 if (attr
.form
== DW_FORM_ref_addr
)
8823 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8825 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8827 case DW_AT_byte_size
:
8828 part_die
->has_byte_size
= 1;
8830 case DW_AT_calling_convention
:
8831 /* DWARF doesn't provide a way to identify a program's source-level
8832 entry point. DW_AT_calling_convention attributes are only meant
8833 to describe functions' calling conventions.
8835 However, because it's a necessary piece of information in
8836 Fortran, and because DW_CC_program is the only piece of debugging
8837 information whose definition refers to a 'main program' at all,
8838 several compilers have begun marking Fortran main programs with
8839 DW_CC_program --- even when those functions use the standard
8840 calling conventions.
8842 So until DWARF specifies a way to provide this information and
8843 compilers pick up the new representation, we'll support this
8845 if (DW_UNSND (&attr
) == DW_CC_program
8846 && cu
->language
== language_fortran
)
8847 set_main_name (part_die
->name
);
8854 /* When using the GNU linker, .gnu.linkonce. sections are used to
8855 eliminate duplicate copies of functions and vtables and such.
8856 The linker will arbitrarily choose one and discard the others.
8857 The AT_*_pc values for such functions refer to local labels in
8858 these sections. If the section from that file was discarded, the
8859 labels are not in the output, so the relocs get a value of 0.
8860 If this is a discarded function, mark the pc bounds as invalid,
8861 so that GDB will ignore it. */
8862 if (has_low_pc_attr
&& has_high_pc_attr
8863 && part_die
->lowpc
< part_die
->highpc
8864 && (part_die
->lowpc
!= 0
8865 || dwarf2_per_objfile
->has_section_at_zero
))
8866 part_die
->has_pc_info
= 1;
8871 /* Find a cached partial DIE at OFFSET in CU. */
8873 static struct partial_die_info
*
8874 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8876 struct partial_die_info
*lookup_die
= NULL
;
8877 struct partial_die_info part_die
;
8879 part_die
.offset
= offset
;
8880 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8885 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8886 except in the case of .debug_types DIEs which do not reference
8887 outside their CU (they do however referencing other types via
8890 static struct partial_die_info
*
8891 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8893 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8894 struct partial_die_info
*pd
= NULL
;
8896 if (cu
->per_cu
->from_debug_types
)
8898 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8904 if (offset_in_cu_p (&cu
->header
, offset
))
8906 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8911 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8913 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8914 load_partial_comp_unit (per_cu
, cu
->objfile
);
8916 per_cu
->cu
->last_used
= 0;
8917 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8919 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8921 struct cleanup
*back_to
;
8922 struct partial_die_info comp_unit_die
;
8923 struct abbrev_info
*abbrev
;
8924 unsigned int bytes_read
;
8927 per_cu
->load_all_dies
= 1;
8929 /* Re-read the DIEs. */
8930 back_to
= make_cleanup (null_cleanup
, 0);
8931 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8933 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8934 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8936 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8937 + per_cu
->cu
->header
.offset
8938 + per_cu
->cu
->header
.first_die_offset
);
8939 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8940 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8941 per_cu
->cu
->objfile
->obfd
,
8942 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8944 if (comp_unit_die
.has_children
)
8945 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8946 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8948 do_cleanups (back_to
);
8950 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8956 internal_error (__FILE__
, __LINE__
,
8957 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8958 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8962 /* See if we can figure out if the class lives in a namespace. We do
8963 this by looking for a member function; its demangled name will
8964 contain namespace info, if there is any. */
8967 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
8968 struct dwarf2_cu
*cu
)
8970 /* NOTE: carlton/2003-10-07: Getting the info this way changes
8971 what template types look like, because the demangler
8972 frequently doesn't give the same name as the debug info. We
8973 could fix this by only using the demangled name to get the
8974 prefix (but see comment in read_structure_type). */
8976 struct partial_die_info
*real_pdi
;
8977 struct partial_die_info
*child_pdi
;
8979 /* If this DIE (this DIE's specification, if any) has a parent, then
8980 we should not do this. We'll prepend the parent's fully qualified
8981 name when we create the partial symbol. */
8983 real_pdi
= struct_pdi
;
8984 while (real_pdi
->has_specification
)
8985 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
8987 if (real_pdi
->die_parent
!= NULL
)
8990 for (child_pdi
= struct_pdi
->die_child
;
8992 child_pdi
= child_pdi
->die_sibling
)
8994 if (child_pdi
->tag
== DW_TAG_subprogram
8995 && child_pdi
->linkage_name
!= NULL
)
8997 char *actual_class_name
8998 = language_class_name_from_physname (cu
->language_defn
,
8999 child_pdi
->linkage_name
);
9000 if (actual_class_name
!= NULL
)
9003 = obsavestring (actual_class_name
,
9004 strlen (actual_class_name
),
9005 &cu
->objfile
->objfile_obstack
);
9006 xfree (actual_class_name
);
9013 /* Adjust PART_DIE before generating a symbol for it. This function
9014 may set the is_external flag or change the DIE's name. */
9017 fixup_partial_die (struct partial_die_info
*part_die
,
9018 struct dwarf2_cu
*cu
)
9020 /* Once we've fixed up a die, there's no point in doing so again.
9021 This also avoids a memory leak if we were to call
9022 guess_partial_die_structure_name multiple times. */
9023 if (part_die
->fixup_called
)
9026 /* If we found a reference attribute and the DIE has no name, try
9027 to find a name in the referred to DIE. */
9029 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9031 struct partial_die_info
*spec_die
;
9033 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9035 fixup_partial_die (spec_die
, cu
);
9039 part_die
->name
= spec_die
->name
;
9041 /* Copy DW_AT_external attribute if it is set. */
9042 if (spec_die
->is_external
)
9043 part_die
->is_external
= spec_die
->is_external
;
9047 /* Set default names for some unnamed DIEs. */
9049 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9050 part_die
->name
= "(anonymous namespace)";
9052 /* If there is no parent die to provide a namespace, and there are
9053 children, see if we can determine the namespace from their linkage
9055 NOTE: We need to do this even if cu->has_namespace_info != 0.
9056 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9057 if (cu
->language
== language_cplus
9058 && dwarf2_per_objfile
->types
.asection
!= NULL
9059 && part_die
->die_parent
== NULL
9060 && part_die
->has_children
9061 && (part_die
->tag
== DW_TAG_class_type
9062 || part_die
->tag
== DW_TAG_structure_type
9063 || part_die
->tag
== DW_TAG_union_type
))
9064 guess_partial_die_structure_name (part_die
, cu
);
9066 part_die
->fixup_called
= 1;
9069 /* Read an attribute value described by an attribute form. */
9072 read_attribute_value (struct attribute
*attr
, unsigned form
,
9073 bfd
*abfd
, gdb_byte
*info_ptr
,
9074 struct dwarf2_cu
*cu
)
9076 struct comp_unit_head
*cu_header
= &cu
->header
;
9077 unsigned int bytes_read
;
9078 struct dwarf_block
*blk
;
9083 case DW_FORM_ref_addr
:
9084 if (cu
->header
.version
== 2)
9085 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9087 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9088 info_ptr
+= bytes_read
;
9091 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9092 info_ptr
+= bytes_read
;
9094 case DW_FORM_block2
:
9095 blk
= dwarf_alloc_block (cu
);
9096 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9098 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9099 info_ptr
+= blk
->size
;
9100 DW_BLOCK (attr
) = blk
;
9102 case DW_FORM_block4
:
9103 blk
= dwarf_alloc_block (cu
);
9104 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9106 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9107 info_ptr
+= blk
->size
;
9108 DW_BLOCK (attr
) = blk
;
9111 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9115 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9119 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9122 case DW_FORM_sec_offset
:
9123 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9124 info_ptr
+= bytes_read
;
9126 case DW_FORM_string
:
9127 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9128 DW_STRING_IS_CANONICAL (attr
) = 0;
9129 info_ptr
+= bytes_read
;
9132 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9134 DW_STRING_IS_CANONICAL (attr
) = 0;
9135 info_ptr
+= bytes_read
;
9137 case DW_FORM_exprloc
:
9139 blk
= dwarf_alloc_block (cu
);
9140 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9141 info_ptr
+= bytes_read
;
9142 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9143 info_ptr
+= blk
->size
;
9144 DW_BLOCK (attr
) = blk
;
9146 case DW_FORM_block1
:
9147 blk
= dwarf_alloc_block (cu
);
9148 blk
->size
= read_1_byte (abfd
, info_ptr
);
9150 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9151 info_ptr
+= blk
->size
;
9152 DW_BLOCK (attr
) = blk
;
9155 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9159 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9162 case DW_FORM_flag_present
:
9163 DW_UNSND (attr
) = 1;
9166 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9167 info_ptr
+= bytes_read
;
9170 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9171 info_ptr
+= bytes_read
;
9174 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9178 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9182 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9186 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9190 /* Convert the signature to something we can record in DW_UNSND
9192 NOTE: This is NULL if the type wasn't found. */
9193 DW_SIGNATURED_TYPE (attr
) =
9194 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9197 case DW_FORM_ref_udata
:
9198 DW_ADDR (attr
) = (cu
->header
.offset
9199 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9200 info_ptr
+= bytes_read
;
9202 case DW_FORM_indirect
:
9203 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9204 info_ptr
+= bytes_read
;
9205 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9208 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9209 dwarf_form_name (form
),
9210 bfd_get_filename (abfd
));
9213 /* We have seen instances where the compiler tried to emit a byte
9214 size attribute of -1 which ended up being encoded as an unsigned
9215 0xffffffff. Although 0xffffffff is technically a valid size value,
9216 an object of this size seems pretty unlikely so we can relatively
9217 safely treat these cases as if the size attribute was invalid and
9218 treat them as zero by default. */
9219 if (attr
->name
== DW_AT_byte_size
9220 && form
== DW_FORM_data4
9221 && DW_UNSND (attr
) >= 0xffffffff)
9224 (&symfile_complaints
,
9225 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9226 hex_string (DW_UNSND (attr
)));
9227 DW_UNSND (attr
) = 0;
9233 /* Read an attribute described by an abbreviated attribute. */
9236 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9237 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9239 attr
->name
= abbrev
->name
;
9240 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9243 /* read dwarf information from a buffer */
9246 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9248 return bfd_get_8 (abfd
, buf
);
9252 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9254 return bfd_get_signed_8 (abfd
, buf
);
9258 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9260 return bfd_get_16 (abfd
, buf
);
9264 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9266 return bfd_get_signed_16 (abfd
, buf
);
9270 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9272 return bfd_get_32 (abfd
, buf
);
9276 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9278 return bfd_get_signed_32 (abfd
, buf
);
9282 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9284 return bfd_get_64 (abfd
, buf
);
9288 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9289 unsigned int *bytes_read
)
9291 struct comp_unit_head
*cu_header
= &cu
->header
;
9292 CORE_ADDR retval
= 0;
9294 if (cu_header
->signed_addr_p
)
9296 switch (cu_header
->addr_size
)
9299 retval
= bfd_get_signed_16 (abfd
, buf
);
9302 retval
= bfd_get_signed_32 (abfd
, buf
);
9305 retval
= bfd_get_signed_64 (abfd
, buf
);
9308 internal_error (__FILE__
, __LINE__
,
9309 _("read_address: bad switch, signed [in module %s]"),
9310 bfd_get_filename (abfd
));
9315 switch (cu_header
->addr_size
)
9318 retval
= bfd_get_16 (abfd
, buf
);
9321 retval
= bfd_get_32 (abfd
, buf
);
9324 retval
= bfd_get_64 (abfd
, buf
);
9327 internal_error (__FILE__
, __LINE__
,
9328 _("read_address: bad switch, unsigned [in module %s]"),
9329 bfd_get_filename (abfd
));
9333 *bytes_read
= cu_header
->addr_size
;
9337 /* Read the initial length from a section. The (draft) DWARF 3
9338 specification allows the initial length to take up either 4 bytes
9339 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9340 bytes describe the length and all offsets will be 8 bytes in length
9343 An older, non-standard 64-bit format is also handled by this
9344 function. The older format in question stores the initial length
9345 as an 8-byte quantity without an escape value. Lengths greater
9346 than 2^32 aren't very common which means that the initial 4 bytes
9347 is almost always zero. Since a length value of zero doesn't make
9348 sense for the 32-bit format, this initial zero can be considered to
9349 be an escape value which indicates the presence of the older 64-bit
9350 format. As written, the code can't detect (old format) lengths
9351 greater than 4GB. If it becomes necessary to handle lengths
9352 somewhat larger than 4GB, we could allow other small values (such
9353 as the non-sensical values of 1, 2, and 3) to also be used as
9354 escape values indicating the presence of the old format.
9356 The value returned via bytes_read should be used to increment the
9357 relevant pointer after calling read_initial_length().
9359 [ Note: read_initial_length() and read_offset() are based on the
9360 document entitled "DWARF Debugging Information Format", revision
9361 3, draft 8, dated November 19, 2001. This document was obtained
9364 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9366 This document is only a draft and is subject to change. (So beware.)
9368 Details regarding the older, non-standard 64-bit format were
9369 determined empirically by examining 64-bit ELF files produced by
9370 the SGI toolchain on an IRIX 6.5 machine.
9372 - Kevin, July 16, 2002
9376 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9378 LONGEST length
= bfd_get_32 (abfd
, buf
);
9380 if (length
== 0xffffffff)
9382 length
= bfd_get_64 (abfd
, buf
+ 4);
9385 else if (length
== 0)
9387 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9388 length
= bfd_get_64 (abfd
, buf
);
9399 /* Cover function for read_initial_length.
9400 Returns the length of the object at BUF, and stores the size of the
9401 initial length in *BYTES_READ and stores the size that offsets will be in
9403 If the initial length size is not equivalent to that specified in
9404 CU_HEADER then issue a complaint.
9405 This is useful when reading non-comp-unit headers. */
9408 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9409 const struct comp_unit_head
*cu_header
,
9410 unsigned int *bytes_read
,
9411 unsigned int *offset_size
)
9413 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9415 gdb_assert (cu_header
->initial_length_size
== 4
9416 || cu_header
->initial_length_size
== 8
9417 || cu_header
->initial_length_size
== 12);
9419 if (cu_header
->initial_length_size
!= *bytes_read
)
9420 complaint (&symfile_complaints
,
9421 _("intermixed 32-bit and 64-bit DWARF sections"));
9423 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9427 /* Read an offset from the data stream. The size of the offset is
9428 given by cu_header->offset_size. */
9431 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9432 unsigned int *bytes_read
)
9434 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9436 *bytes_read
= cu_header
->offset_size
;
9440 /* Read an offset from the data stream. */
9443 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9447 switch (offset_size
)
9450 retval
= bfd_get_32 (abfd
, buf
);
9453 retval
= bfd_get_64 (abfd
, buf
);
9456 internal_error (__FILE__
, __LINE__
,
9457 _("read_offset_1: bad switch [in module %s]"),
9458 bfd_get_filename (abfd
));
9465 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9467 /* If the size of a host char is 8 bits, we can return a pointer
9468 to the buffer, otherwise we have to copy the data to a buffer
9469 allocated on the temporary obstack. */
9470 gdb_assert (HOST_CHAR_BIT
== 8);
9475 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9477 /* If the size of a host char is 8 bits, we can return a pointer
9478 to the string, otherwise we have to copy the string to a buffer
9479 allocated on the temporary obstack. */
9480 gdb_assert (HOST_CHAR_BIT
== 8);
9483 *bytes_read_ptr
= 1;
9486 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9487 return (char *) buf
;
9491 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9492 const struct comp_unit_head
*cu_header
,
9493 unsigned int *bytes_read_ptr
)
9495 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9497 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9498 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9500 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9501 bfd_get_filename (abfd
));
9504 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9506 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9507 bfd_get_filename (abfd
));
9510 gdb_assert (HOST_CHAR_BIT
== 8);
9511 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9513 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9516 static unsigned long
9517 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9519 unsigned long result
;
9520 unsigned int num_read
;
9530 byte
= bfd_get_8 (abfd
, buf
);
9533 result
|= ((unsigned long)(byte
& 127) << shift
);
9534 if ((byte
& 128) == 0)
9540 *bytes_read_ptr
= num_read
;
9545 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9548 int i
, shift
, num_read
;
9557 byte
= bfd_get_8 (abfd
, buf
);
9560 result
|= ((long)(byte
& 127) << shift
);
9562 if ((byte
& 128) == 0)
9567 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9568 result
|= -(((long)1) << shift
);
9569 *bytes_read_ptr
= num_read
;
9573 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9576 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9582 byte
= bfd_get_8 (abfd
, buf
);
9584 if ((byte
& 128) == 0)
9590 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9597 cu
->language
= language_c
;
9599 case DW_LANG_C_plus_plus
:
9600 cu
->language
= language_cplus
;
9603 cu
->language
= language_d
;
9605 case DW_LANG_Fortran77
:
9606 case DW_LANG_Fortran90
:
9607 case DW_LANG_Fortran95
:
9608 cu
->language
= language_fortran
;
9610 case DW_LANG_Mips_Assembler
:
9611 cu
->language
= language_asm
;
9614 cu
->language
= language_java
;
9618 cu
->language
= language_ada
;
9620 case DW_LANG_Modula2
:
9621 cu
->language
= language_m2
;
9623 case DW_LANG_Pascal83
:
9624 cu
->language
= language_pascal
;
9627 cu
->language
= language_objc
;
9629 case DW_LANG_Cobol74
:
9630 case DW_LANG_Cobol85
:
9632 cu
->language
= language_minimal
;
9635 cu
->language_defn
= language_def (cu
->language
);
9638 /* Return the named attribute or NULL if not there. */
9640 static struct attribute
*
9641 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9644 struct attribute
*spec
= NULL
;
9646 for (i
= 0; i
< die
->num_attrs
; ++i
)
9648 if (die
->attrs
[i
].name
== name
)
9649 return &die
->attrs
[i
];
9650 if (die
->attrs
[i
].name
== DW_AT_specification
9651 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9652 spec
= &die
->attrs
[i
];
9657 die
= follow_die_ref (die
, spec
, &cu
);
9658 return dwarf2_attr (die
, name
, cu
);
9664 /* Return the named attribute or NULL if not there,
9665 but do not follow DW_AT_specification, etc.
9666 This is for use in contexts where we're reading .debug_types dies.
9667 Following DW_AT_specification, DW_AT_abstract_origin will take us
9668 back up the chain, and we want to go down. */
9670 static struct attribute
*
9671 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9672 struct dwarf2_cu
*cu
)
9676 for (i
= 0; i
< die
->num_attrs
; ++i
)
9677 if (die
->attrs
[i
].name
== name
)
9678 return &die
->attrs
[i
];
9683 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9684 and holds a non-zero value. This function should only be used for
9685 DW_FORM_flag or DW_FORM_flag_present attributes. */
9688 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9690 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9692 return (attr
&& DW_UNSND (attr
));
9696 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9698 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9699 which value is non-zero. However, we have to be careful with
9700 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9701 (via dwarf2_flag_true_p) follows this attribute. So we may
9702 end up accidently finding a declaration attribute that belongs
9703 to a different DIE referenced by the specification attribute,
9704 even though the given DIE does not have a declaration attribute. */
9705 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9706 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9709 /* Return the die giving the specification for DIE, if there is
9710 one. *SPEC_CU is the CU containing DIE on input, and the CU
9711 containing the return value on output. If there is no
9712 specification, but there is an abstract origin, that is
9715 static struct die_info
*
9716 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9718 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9721 if (spec_attr
== NULL
)
9722 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9724 if (spec_attr
== NULL
)
9727 return follow_die_ref (die
, spec_attr
, spec_cu
);
9730 /* Free the line_header structure *LH, and any arrays and strings it
9733 free_line_header (struct line_header
*lh
)
9735 if (lh
->standard_opcode_lengths
)
9736 xfree (lh
->standard_opcode_lengths
);
9738 /* Remember that all the lh->file_names[i].name pointers are
9739 pointers into debug_line_buffer, and don't need to be freed. */
9741 xfree (lh
->file_names
);
9743 /* Similarly for the include directory names. */
9744 if (lh
->include_dirs
)
9745 xfree (lh
->include_dirs
);
9751 /* Add an entry to LH's include directory table. */
9753 add_include_dir (struct line_header
*lh
, char *include_dir
)
9755 /* Grow the array if necessary. */
9756 if (lh
->include_dirs_size
== 0)
9758 lh
->include_dirs_size
= 1; /* for testing */
9759 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9760 * sizeof (*lh
->include_dirs
));
9762 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9764 lh
->include_dirs_size
*= 2;
9765 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9766 (lh
->include_dirs_size
9767 * sizeof (*lh
->include_dirs
)));
9770 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9774 /* Add an entry to LH's file name table. */
9776 add_file_name (struct line_header
*lh
,
9778 unsigned int dir_index
,
9779 unsigned int mod_time
,
9780 unsigned int length
)
9782 struct file_entry
*fe
;
9784 /* Grow the array if necessary. */
9785 if (lh
->file_names_size
== 0)
9787 lh
->file_names_size
= 1; /* for testing */
9788 lh
->file_names
= xmalloc (lh
->file_names_size
9789 * sizeof (*lh
->file_names
));
9791 else if (lh
->num_file_names
>= lh
->file_names_size
)
9793 lh
->file_names_size
*= 2;
9794 lh
->file_names
= xrealloc (lh
->file_names
,
9795 (lh
->file_names_size
9796 * sizeof (*lh
->file_names
)));
9799 fe
= &lh
->file_names
[lh
->num_file_names
++];
9801 fe
->dir_index
= dir_index
;
9802 fe
->mod_time
= mod_time
;
9803 fe
->length
= length
;
9809 /* Read the statement program header starting at OFFSET in
9810 .debug_line, according to the endianness of ABFD. Return a pointer
9811 to a struct line_header, allocated using xmalloc.
9813 NOTE: the strings in the include directory and file name tables of
9814 the returned object point into debug_line_buffer, and must not be
9816 static struct line_header
*
9817 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9818 struct dwarf2_cu
*cu
)
9820 struct cleanup
*back_to
;
9821 struct line_header
*lh
;
9823 unsigned int bytes_read
, offset_size
;
9825 char *cur_dir
, *cur_file
;
9827 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9828 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9830 complaint (&symfile_complaints
, _("missing .debug_line section"));
9834 /* Make sure that at least there's room for the total_length field.
9835 That could be 12 bytes long, but we're just going to fudge that. */
9836 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9838 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9842 lh
= xmalloc (sizeof (*lh
));
9843 memset (lh
, 0, sizeof (*lh
));
9844 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9847 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9849 /* Read in the header. */
9851 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9852 &bytes_read
, &offset_size
);
9853 line_ptr
+= bytes_read
;
9854 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9855 + dwarf2_per_objfile
->line
.size
))
9857 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9860 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9861 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9863 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9864 line_ptr
+= offset_size
;
9865 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9867 if (lh
->version
>= 4)
9869 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9873 lh
->maximum_ops_per_instruction
= 1;
9875 if (lh
->maximum_ops_per_instruction
== 0)
9877 lh
->maximum_ops_per_instruction
= 1;
9878 complaint (&symfile_complaints
,
9879 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9882 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9884 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9886 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9888 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9890 lh
->standard_opcode_lengths
9891 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9893 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9894 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9896 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9900 /* Read directory table. */
9901 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9903 line_ptr
+= bytes_read
;
9904 add_include_dir (lh
, cur_dir
);
9906 line_ptr
+= bytes_read
;
9908 /* Read file name table. */
9909 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9911 unsigned int dir_index
, mod_time
, length
;
9913 line_ptr
+= bytes_read
;
9914 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9915 line_ptr
+= bytes_read
;
9916 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9917 line_ptr
+= bytes_read
;
9918 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9919 line_ptr
+= bytes_read
;
9921 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9923 line_ptr
+= bytes_read
;
9924 lh
->statement_program_start
= line_ptr
;
9926 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9927 + dwarf2_per_objfile
->line
.size
))
9928 complaint (&symfile_complaints
,
9929 _("line number info header doesn't fit in `.debug_line' section"));
9931 discard_cleanups (back_to
);
9935 /* This function exists to work around a bug in certain compilers
9936 (particularly GCC 2.95), in which the first line number marker of a
9937 function does not show up until after the prologue, right before
9938 the second line number marker. This function shifts ADDRESS down
9939 to the beginning of the function if necessary, and is called on
9940 addresses passed to record_line. */
9943 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9945 struct function_range
*fn
;
9947 /* Find the function_range containing address. */
9952 cu
->cached_fn
= cu
->first_fn
;
9956 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9962 while (fn
&& fn
!= cu
->cached_fn
)
9963 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9973 if (address
!= fn
->lowpc
)
9974 complaint (&symfile_complaints
,
9975 _("misplaced first line number at 0x%lx for '%s'"),
9976 (unsigned long) address
, fn
->name
);
9981 /* Subroutine of dwarf_decode_lines to simplify it.
9982 Return the file name of the psymtab for included file FILE_INDEX
9983 in line header LH of PST.
9984 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
9985 If space for the result is malloc'd, it will be freed by a cleanup.
9986 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
9989 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
9990 const struct partial_symtab
*pst
,
9991 const char *comp_dir
)
9993 const struct file_entry fe
= lh
->file_names
[file_index
];
9994 char *include_name
= fe
.name
;
9995 char *include_name_to_compare
= include_name
;
9996 char *dir_name
= NULL
;
10001 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10003 if (!IS_ABSOLUTE_PATH (include_name
)
10004 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10006 /* Avoid creating a duplicate psymtab for PST.
10007 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10008 Before we do the comparison, however, we need to account
10009 for DIR_NAME and COMP_DIR.
10010 First prepend dir_name (if non-NULL). If we still don't
10011 have an absolute path prepend comp_dir (if non-NULL).
10012 However, the directory we record in the include-file's
10013 psymtab does not contain COMP_DIR (to match the
10014 corresponding symtab(s)).
10019 bash$ gcc -g ./hello.c
10020 include_name = "hello.c"
10022 DW_AT_comp_dir = comp_dir = "/tmp"
10023 DW_AT_name = "./hello.c" */
10025 if (dir_name
!= NULL
)
10027 include_name
= concat (dir_name
, SLASH_STRING
,
10028 include_name
, (char *)NULL
);
10029 include_name_to_compare
= include_name
;
10030 make_cleanup (xfree
, include_name
);
10032 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10034 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10035 include_name
, (char *)NULL
);
10039 pst_filename
= pst
->filename
;
10040 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10042 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
10043 pst_filename
, (char *)NULL
);
10046 file_is_pst
= strcmp (include_name_to_compare
, pst_filename
) == 0;
10048 if (include_name_to_compare
!= include_name
)
10049 xfree (include_name_to_compare
);
10050 if (pst_filename
!= pst
->filename
)
10051 xfree (pst_filename
);
10055 return include_name
;
10058 /* Decode the Line Number Program (LNP) for the given line_header
10059 structure and CU. The actual information extracted and the type
10060 of structures created from the LNP depends on the value of PST.
10062 1. If PST is NULL, then this procedure uses the data from the program
10063 to create all necessary symbol tables, and their linetables.
10065 2. If PST is not NULL, this procedure reads the program to determine
10066 the list of files included by the unit represented by PST, and
10067 builds all the associated partial symbol tables.
10069 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10070 It is used for relative paths in the line table.
10071 NOTE: When processing partial symtabs (pst != NULL),
10072 comp_dir == pst->dirname.
10074 NOTE: It is important that psymtabs have the same file name (via strcmp)
10075 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10076 symtab we don't use it in the name of the psymtabs we create.
10077 E.g. expand_line_sal requires this when finding psymtabs to expand.
10078 A good testcase for this is mb-inline.exp. */
10081 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
10082 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10084 gdb_byte
*line_ptr
, *extended_end
;
10085 gdb_byte
*line_end
;
10086 unsigned int bytes_read
, extended_len
;
10087 unsigned char op_code
, extended_op
, adj_opcode
;
10088 CORE_ADDR baseaddr
;
10089 struct objfile
*objfile
= cu
->objfile
;
10090 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10091 const int decode_for_pst_p
= (pst
!= NULL
);
10092 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10094 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10096 line_ptr
= lh
->statement_program_start
;
10097 line_end
= lh
->statement_program_end
;
10099 /* Read the statement sequences until there's nothing left. */
10100 while (line_ptr
< line_end
)
10102 /* state machine registers */
10103 CORE_ADDR address
= 0;
10104 unsigned int file
= 1;
10105 unsigned int line
= 1;
10106 unsigned int column
= 0;
10107 int is_stmt
= lh
->default_is_stmt
;
10108 int basic_block
= 0;
10109 int end_sequence
= 0;
10111 unsigned char op_index
= 0;
10113 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10115 /* Start a subfile for the current file of the state machine. */
10116 /* lh->include_dirs and lh->file_names are 0-based, but the
10117 directory and file name numbers in the statement program
10119 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10123 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10125 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10128 /* Decode the table. */
10129 while (!end_sequence
)
10131 op_code
= read_1_byte (abfd
, line_ptr
);
10133 if (line_ptr
> line_end
)
10135 dwarf2_debug_line_missing_end_sequence_complaint ();
10139 if (op_code
>= lh
->opcode_base
)
10141 /* Special operand. */
10142 adj_opcode
= op_code
- lh
->opcode_base
;
10143 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10144 / lh
->maximum_ops_per_instruction
)
10145 * lh
->minimum_instruction_length
);
10146 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10147 % lh
->maximum_ops_per_instruction
);
10148 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10149 if (lh
->num_file_names
< file
|| file
== 0)
10150 dwarf2_debug_line_missing_file_complaint ();
10151 /* For now we ignore lines not starting on an
10152 instruction boundary. */
10153 else if (op_index
== 0)
10155 lh
->file_names
[file
- 1].included_p
= 1;
10156 if (!decode_for_pst_p
&& is_stmt
)
10158 if (last_subfile
!= current_subfile
)
10160 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10162 record_line (last_subfile
, 0, addr
);
10163 last_subfile
= current_subfile
;
10165 /* Append row to matrix using current values. */
10166 addr
= check_cu_functions (address
, cu
);
10167 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10168 record_line (current_subfile
, line
, addr
);
10173 else switch (op_code
)
10175 case DW_LNS_extended_op
:
10176 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10177 line_ptr
+= bytes_read
;
10178 extended_end
= line_ptr
+ extended_len
;
10179 extended_op
= read_1_byte (abfd
, line_ptr
);
10181 switch (extended_op
)
10183 case DW_LNE_end_sequence
:
10186 case DW_LNE_set_address
:
10187 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10189 line_ptr
+= bytes_read
;
10190 address
+= baseaddr
;
10192 case DW_LNE_define_file
:
10195 unsigned int dir_index
, mod_time
, length
;
10197 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10198 line_ptr
+= bytes_read
;
10200 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10201 line_ptr
+= bytes_read
;
10203 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10204 line_ptr
+= bytes_read
;
10206 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10207 line_ptr
+= bytes_read
;
10208 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10211 case DW_LNE_set_discriminator
:
10212 /* The discriminator is not interesting to the debugger;
10214 line_ptr
= extended_end
;
10217 complaint (&symfile_complaints
,
10218 _("mangled .debug_line section"));
10221 /* Make sure that we parsed the extended op correctly. If e.g.
10222 we expected a different address size than the producer used,
10223 we may have read the wrong number of bytes. */
10224 if (line_ptr
!= extended_end
)
10226 complaint (&symfile_complaints
,
10227 _("mangled .debug_line section"));
10232 if (lh
->num_file_names
< file
|| file
== 0)
10233 dwarf2_debug_line_missing_file_complaint ();
10236 lh
->file_names
[file
- 1].included_p
= 1;
10237 if (!decode_for_pst_p
&& is_stmt
)
10239 if (last_subfile
!= current_subfile
)
10241 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10243 record_line (last_subfile
, 0, addr
);
10244 last_subfile
= current_subfile
;
10246 addr
= check_cu_functions (address
, cu
);
10247 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10248 record_line (current_subfile
, line
, addr
);
10253 case DW_LNS_advance_pc
:
10256 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10258 address
+= (((op_index
+ adjust
)
10259 / lh
->maximum_ops_per_instruction
)
10260 * lh
->minimum_instruction_length
);
10261 op_index
= ((op_index
+ adjust
)
10262 % lh
->maximum_ops_per_instruction
);
10263 line_ptr
+= bytes_read
;
10266 case DW_LNS_advance_line
:
10267 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10268 line_ptr
+= bytes_read
;
10270 case DW_LNS_set_file
:
10272 /* The arrays lh->include_dirs and lh->file_names are
10273 0-based, but the directory and file name numbers in
10274 the statement program are 1-based. */
10275 struct file_entry
*fe
;
10278 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10279 line_ptr
+= bytes_read
;
10280 if (lh
->num_file_names
< file
|| file
== 0)
10281 dwarf2_debug_line_missing_file_complaint ();
10284 fe
= &lh
->file_names
[file
- 1];
10286 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10287 if (!decode_for_pst_p
)
10289 last_subfile
= current_subfile
;
10290 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10295 case DW_LNS_set_column
:
10296 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10297 line_ptr
+= bytes_read
;
10299 case DW_LNS_negate_stmt
:
10300 is_stmt
= (!is_stmt
);
10302 case DW_LNS_set_basic_block
:
10305 /* Add to the address register of the state machine the
10306 address increment value corresponding to special opcode
10307 255. I.e., this value is scaled by the minimum
10308 instruction length since special opcode 255 would have
10309 scaled the the increment. */
10310 case DW_LNS_const_add_pc
:
10312 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10314 address
+= (((op_index
+ adjust
)
10315 / lh
->maximum_ops_per_instruction
)
10316 * lh
->minimum_instruction_length
);
10317 op_index
= ((op_index
+ adjust
)
10318 % lh
->maximum_ops_per_instruction
);
10321 case DW_LNS_fixed_advance_pc
:
10322 address
+= read_2_bytes (abfd
, line_ptr
);
10328 /* Unknown standard opcode, ignore it. */
10331 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10333 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10334 line_ptr
+= bytes_read
;
10339 if (lh
->num_file_names
< file
|| file
== 0)
10340 dwarf2_debug_line_missing_file_complaint ();
10343 lh
->file_names
[file
- 1].included_p
= 1;
10344 if (!decode_for_pst_p
)
10346 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10347 record_line (current_subfile
, 0, addr
);
10352 if (decode_for_pst_p
)
10356 /* Now that we're done scanning the Line Header Program, we can
10357 create the psymtab of each included file. */
10358 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10359 if (lh
->file_names
[file_index
].included_p
== 1)
10361 char *include_name
=
10362 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10363 if (include_name
!= NULL
)
10364 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10369 /* Make sure a symtab is created for every file, even files
10370 which contain only variables (i.e. no code with associated
10374 struct file_entry
*fe
;
10376 for (i
= 0; i
< lh
->num_file_names
; i
++)
10380 fe
= &lh
->file_names
[i
];
10382 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10383 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10385 /* Skip the main file; we don't need it, and it must be
10386 allocated last, so that it will show up before the
10387 non-primary symtabs in the objfile's symtab list. */
10388 if (current_subfile
== first_subfile
)
10391 if (current_subfile
->symtab
== NULL
)
10392 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10394 fe
->symtab
= current_subfile
->symtab
;
10399 /* Start a subfile for DWARF. FILENAME is the name of the file and
10400 DIRNAME the name of the source directory which contains FILENAME
10401 or NULL if not known. COMP_DIR is the compilation directory for the
10402 linetable's compilation unit or NULL if not known.
10403 This routine tries to keep line numbers from identical absolute and
10404 relative file names in a common subfile.
10406 Using the `list' example from the GDB testsuite, which resides in
10407 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10408 of /srcdir/list0.c yields the following debugging information for list0.c:
10410 DW_AT_name: /srcdir/list0.c
10411 DW_AT_comp_dir: /compdir
10412 files.files[0].name: list0.h
10413 files.files[0].dir: /srcdir
10414 files.files[1].name: list0.c
10415 files.files[1].dir: /srcdir
10417 The line number information for list0.c has to end up in a single
10418 subfile, so that `break /srcdir/list0.c:1' works as expected.
10419 start_subfile will ensure that this happens provided that we pass the
10420 concatenation of files.files[1].dir and files.files[1].name as the
10424 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
10428 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10429 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10430 second argument to start_subfile. To be consistent, we do the
10431 same here. In order not to lose the line information directory,
10432 we concatenate it to the filename when it makes sense.
10433 Note that the Dwarf3 standard says (speaking of filenames in line
10434 information): ``The directory index is ignored for file names
10435 that represent full path names''. Thus ignoring dirname in the
10436 `else' branch below isn't an issue. */
10438 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10439 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10441 fullname
= filename
;
10443 start_subfile (fullname
, comp_dir
);
10445 if (fullname
!= filename
)
10450 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10451 struct dwarf2_cu
*cu
)
10453 struct objfile
*objfile
= cu
->objfile
;
10454 struct comp_unit_head
*cu_header
= &cu
->header
;
10456 /* NOTE drow/2003-01-30: There used to be a comment and some special
10457 code here to turn a symbol with DW_AT_external and a
10458 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10459 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10460 with some versions of binutils) where shared libraries could have
10461 relocations against symbols in their debug information - the
10462 minimal symbol would have the right address, but the debug info
10463 would not. It's no longer necessary, because we will explicitly
10464 apply relocations when we read in the debug information now. */
10466 /* A DW_AT_location attribute with no contents indicates that a
10467 variable has been optimized away. */
10468 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10470 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10474 /* Handle one degenerate form of location expression specially, to
10475 preserve GDB's previous behavior when section offsets are
10476 specified. If this is just a DW_OP_addr then mark this symbol
10479 if (attr_form_is_block (attr
)
10480 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10481 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10483 unsigned int dummy
;
10485 SYMBOL_VALUE_ADDRESS (sym
) =
10486 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10487 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10488 fixup_symbol_section (sym
, objfile
);
10489 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10490 SYMBOL_SECTION (sym
));
10494 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10495 expression evaluator, and use LOC_COMPUTED only when necessary
10496 (i.e. when the value of a register or memory location is
10497 referenced, or a thread-local block, etc.). Then again, it might
10498 not be worthwhile. I'm assuming that it isn't unless performance
10499 or memory numbers show me otherwise. */
10501 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10502 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10505 /* Given a pointer to a DWARF information entry, figure out if we need
10506 to make a symbol table entry for it, and if so, create a new entry
10507 and return a pointer to it.
10508 If TYPE is NULL, determine symbol type from the die, otherwise
10509 used the passed type.
10510 If SPACE is not NULL, use it to hold the new symbol. If it is
10511 NULL, allocate a new symbol on the objfile's obstack. */
10513 static struct symbol
*
10514 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10515 struct symbol
*space
)
10517 struct objfile
*objfile
= cu
->objfile
;
10518 struct symbol
*sym
= NULL
;
10520 struct attribute
*attr
= NULL
;
10521 struct attribute
*attr2
= NULL
;
10522 CORE_ADDR baseaddr
;
10523 struct pending
**list_to_add
= NULL
;
10525 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10527 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10529 name
= dwarf2_name (die
, cu
);
10532 const char *linkagename
;
10533 int suppress_add
= 0;
10538 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10539 OBJSTAT (objfile
, n_syms
++);
10541 /* Cache this symbol's name and the name's demangled form (if any). */
10542 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10543 linkagename
= dwarf2_physname (name
, die
, cu
);
10544 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10546 /* Fortran does not have mangling standard and the mangling does differ
10547 between gfortran, iFort etc. */
10548 if (cu
->language
== language_fortran
10549 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10550 symbol_set_demangled_name (&(sym
->ginfo
),
10551 (char *) dwarf2_full_name (name
, die
, cu
),
10554 /* Default assumptions.
10555 Use the passed type or decode it from the die. */
10556 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10557 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10559 SYMBOL_TYPE (sym
) = type
;
10561 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10562 attr
= dwarf2_attr (die
,
10563 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10567 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10570 attr
= dwarf2_attr (die
,
10571 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10575 int file_index
= DW_UNSND (attr
);
10577 if (cu
->line_header
== NULL
10578 || file_index
> cu
->line_header
->num_file_names
)
10579 complaint (&symfile_complaints
,
10580 _("file index out of range"));
10581 else if (file_index
> 0)
10583 struct file_entry
*fe
;
10585 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10586 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10593 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10596 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10598 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10599 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10600 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10601 add_symbol_to_list (sym
, cu
->list_in_scope
);
10603 case DW_TAG_subprogram
:
10604 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10606 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10607 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10608 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10609 || cu
->language
== language_ada
)
10611 /* Subprograms marked external are stored as a global symbol.
10612 Ada subprograms, whether marked external or not, are always
10613 stored as a global symbol, because we want to be able to
10614 access them globally. For instance, we want to be able
10615 to break on a nested subprogram without having to
10616 specify the context. */
10617 list_to_add
= &global_symbols
;
10621 list_to_add
= cu
->list_in_scope
;
10624 case DW_TAG_inlined_subroutine
:
10625 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10627 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10628 SYMBOL_INLINED (sym
) = 1;
10629 /* Do not add the symbol to any lists. It will be found via
10630 BLOCK_FUNCTION from the blockvector. */
10632 case DW_TAG_template_value_param
:
10634 /* Fall through. */
10635 case DW_TAG_constant
:
10636 case DW_TAG_variable
:
10637 case DW_TAG_member
:
10638 /* Compilation with minimal debug info may result in variables
10639 with missing type entries. Change the misleading `void' type
10640 to something sensible. */
10641 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10643 = objfile_type (objfile
)->nodebug_data_symbol
;
10645 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10646 /* In the case of DW_TAG_member, we should only be called for
10647 static const members. */
10648 if (die
->tag
== DW_TAG_member
)
10650 /* dwarf2_add_field uses die_is_declaration,
10651 so we do the same. */
10652 gdb_assert (die_is_declaration (die
, cu
));
10657 dwarf2_const_value (attr
, sym
, cu
);
10658 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10661 if (attr2
&& (DW_UNSND (attr2
) != 0))
10662 list_to_add
= &global_symbols
;
10664 list_to_add
= cu
->list_in_scope
;
10668 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10671 var_decode_location (attr
, sym
, cu
);
10672 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10673 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10674 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10675 && !dwarf2_per_objfile
->has_section_at_zero
)
10677 /* When a static variable is eliminated by the linker,
10678 the corresponding debug information is not stripped
10679 out, but the variable address is set to null;
10680 do not add such variables into symbol table. */
10682 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10684 /* Workaround gfortran PR debug/40040 - it uses
10685 DW_AT_location for variables in -fPIC libraries which may
10686 get overriden by other libraries/executable and get
10687 a different address. Resolve it by the minimal symbol
10688 which may come from inferior's executable using copy
10689 relocation. Make this workaround only for gfortran as for
10690 other compilers GDB cannot guess the minimal symbol
10691 Fortran mangling kind. */
10692 if (cu
->language
== language_fortran
&& die
->parent
10693 && die
->parent
->tag
== DW_TAG_module
10695 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10696 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10698 /* A variable with DW_AT_external is never static,
10699 but it may be block-scoped. */
10700 list_to_add
= (cu
->list_in_scope
== &file_symbols
10701 ? &global_symbols
: cu
->list_in_scope
);
10704 list_to_add
= cu
->list_in_scope
;
10708 /* We do not know the address of this symbol.
10709 If it is an external symbol and we have type information
10710 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10711 The address of the variable will then be determined from
10712 the minimal symbol table whenever the variable is
10714 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10715 if (attr2
&& (DW_UNSND (attr2
) != 0)
10716 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10718 /* A variable with DW_AT_external is never static, but it
10719 may be block-scoped. */
10720 list_to_add
= (cu
->list_in_scope
== &file_symbols
10721 ? &global_symbols
: cu
->list_in_scope
);
10723 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10725 else if (!die_is_declaration (die
, cu
))
10727 /* Use the default LOC_OPTIMIZED_OUT class. */
10728 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10730 list_to_add
= cu
->list_in_scope
;
10734 case DW_TAG_formal_parameter
:
10735 /* If we are inside a function, mark this as an argument. If
10736 not, we might be looking at an argument to an inlined function
10737 when we do not have enough information to show inlined frames;
10738 pretend it's a local variable in that case so that the user can
10740 if (context_stack_depth
> 0
10741 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10742 SYMBOL_IS_ARGUMENT (sym
) = 1;
10743 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10746 var_decode_location (attr
, sym
, cu
);
10748 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10751 dwarf2_const_value (attr
, sym
, cu
);
10753 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10754 if (attr
&& DW_UNSND (attr
))
10756 struct type
*ref_type
;
10758 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10759 SYMBOL_TYPE (sym
) = ref_type
;
10762 list_to_add
= cu
->list_in_scope
;
10764 case DW_TAG_unspecified_parameters
:
10765 /* From varargs functions; gdb doesn't seem to have any
10766 interest in this information, so just ignore it for now.
10769 case DW_TAG_template_type_param
:
10771 /* Fall through. */
10772 case DW_TAG_class_type
:
10773 case DW_TAG_interface_type
:
10774 case DW_TAG_structure_type
:
10775 case DW_TAG_union_type
:
10776 case DW_TAG_set_type
:
10777 case DW_TAG_enumeration_type
:
10778 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10779 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10782 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10783 really ever be static objects: otherwise, if you try
10784 to, say, break of a class's method and you're in a file
10785 which doesn't mention that class, it won't work unless
10786 the check for all static symbols in lookup_symbol_aux
10787 saves you. See the OtherFileClass tests in
10788 gdb.c++/namespace.exp. */
10792 list_to_add
= (cu
->list_in_scope
== &file_symbols
10793 && (cu
->language
== language_cplus
10794 || cu
->language
== language_java
)
10795 ? &global_symbols
: cu
->list_in_scope
);
10797 /* The semantics of C++ state that "struct foo {
10798 ... }" also defines a typedef for "foo". A Java
10799 class declaration also defines a typedef for the
10801 if (cu
->language
== language_cplus
10802 || cu
->language
== language_java
10803 || cu
->language
== language_ada
)
10805 /* The symbol's name is already allocated along
10806 with this objfile, so we don't need to
10807 duplicate it for the type. */
10808 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10809 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10814 case DW_TAG_typedef
:
10815 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10816 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10817 list_to_add
= cu
->list_in_scope
;
10819 case DW_TAG_base_type
:
10820 case DW_TAG_subrange_type
:
10821 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10822 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10823 list_to_add
= cu
->list_in_scope
;
10825 case DW_TAG_enumerator
:
10826 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10829 dwarf2_const_value (attr
, sym
, cu
);
10832 /* NOTE: carlton/2003-11-10: See comment above in the
10833 DW_TAG_class_type, etc. block. */
10835 list_to_add
= (cu
->list_in_scope
== &file_symbols
10836 && (cu
->language
== language_cplus
10837 || cu
->language
== language_java
)
10838 ? &global_symbols
: cu
->list_in_scope
);
10841 case DW_TAG_namespace
:
10842 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10843 list_to_add
= &global_symbols
;
10846 /* Not a tag we recognize. Hopefully we aren't processing
10847 trash data, but since we must specifically ignore things
10848 we don't recognize, there is nothing else we should do at
10850 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10851 dwarf_tag_name (die
->tag
));
10857 sym
->hash_next
= objfile
->template_symbols
;
10858 objfile
->template_symbols
= sym
;
10859 list_to_add
= NULL
;
10862 if (list_to_add
!= NULL
)
10863 add_symbol_to_list (sym
, list_to_add
);
10865 /* For the benefit of old versions of GCC, check for anonymous
10866 namespaces based on the demangled name. */
10867 if (!processing_has_namespace_info
10868 && cu
->language
== language_cplus
)
10869 cp_scan_for_anonymous_namespaces (sym
);
10874 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10876 static struct symbol
*
10877 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10879 return new_symbol_full (die
, type
, cu
, NULL
);
10882 /* Given an attr with a DW_FORM_dataN value in host byte order,
10883 zero-extend it as appropriate for the symbol's type. The DWARF
10884 standard (v4) is not entirely clear about the meaning of using
10885 DW_FORM_dataN for a constant with a signed type, where the type is
10886 wider than the data. The conclusion of a discussion on the DWARF
10887 list was that this is unspecified. We choose to always zero-extend
10888 because that is the interpretation long in use by GCC. */
10891 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10892 const char *name
, struct obstack
*obstack
,
10893 struct dwarf2_cu
*cu
, long *value
, int bits
)
10895 struct objfile
*objfile
= cu
->objfile
;
10896 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10897 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10898 LONGEST l
= DW_UNSND (attr
);
10900 if (bits
< sizeof (*value
) * 8)
10902 l
&= ((LONGEST
) 1 << bits
) - 1;
10905 else if (bits
== sizeof (*value
) * 8)
10909 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10910 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10917 /* Read a constant value from an attribute. Either set *VALUE, or if
10918 the value does not fit in *VALUE, set *BYTES - either already
10919 allocated on the objfile obstack, or newly allocated on OBSTACK,
10920 or, set *BATON, if we translated the constant to a location
10924 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10925 const char *name
, struct obstack
*obstack
,
10926 struct dwarf2_cu
*cu
,
10927 long *value
, gdb_byte
**bytes
,
10928 struct dwarf2_locexpr_baton
**baton
)
10930 struct objfile
*objfile
= cu
->objfile
;
10931 struct comp_unit_head
*cu_header
= &cu
->header
;
10932 struct dwarf_block
*blk
;
10933 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10934 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10940 switch (attr
->form
)
10946 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10947 dwarf2_const_value_length_mismatch_complaint (name
,
10948 cu_header
->addr_size
,
10949 TYPE_LENGTH (type
));
10950 /* Symbols of this form are reasonably rare, so we just
10951 piggyback on the existing location code rather than writing
10952 a new implementation of symbol_computed_ops. */
10953 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
10954 sizeof (struct dwarf2_locexpr_baton
));
10955 (*baton
)->per_cu
= cu
->per_cu
;
10956 gdb_assert ((*baton
)->per_cu
);
10958 (*baton
)->size
= 2 + cu_header
->addr_size
;
10959 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
10960 (*baton
)->data
= data
;
10962 data
[0] = DW_OP_addr
;
10963 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10964 byte_order
, DW_ADDR (attr
));
10965 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10968 case DW_FORM_string
:
10970 /* DW_STRING is already allocated on the objfile obstack, point
10972 *bytes
= (gdb_byte
*) DW_STRING (attr
);
10974 case DW_FORM_block1
:
10975 case DW_FORM_block2
:
10976 case DW_FORM_block4
:
10977 case DW_FORM_block
:
10978 case DW_FORM_exprloc
:
10979 blk
= DW_BLOCK (attr
);
10980 if (TYPE_LENGTH (type
) != blk
->size
)
10981 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
10982 TYPE_LENGTH (type
));
10983 *bytes
= blk
->data
;
10986 /* The DW_AT_const_value attributes are supposed to carry the
10987 symbol's value "represented as it would be on the target
10988 architecture." By the time we get here, it's already been
10989 converted to host endianness, so we just need to sign- or
10990 zero-extend it as appropriate. */
10991 case DW_FORM_data1
:
10992 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
10994 case DW_FORM_data2
:
10995 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
10997 case DW_FORM_data4
:
10998 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
11000 case DW_FORM_data8
:
11001 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
11004 case DW_FORM_sdata
:
11005 *value
= DW_SND (attr
);
11008 case DW_FORM_udata
:
11009 *value
= DW_UNSND (attr
);
11013 complaint (&symfile_complaints
,
11014 _("unsupported const value attribute form: '%s'"),
11015 dwarf_form_name (attr
->form
));
11022 /* Copy constant value from an attribute to a symbol. */
11025 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11026 struct dwarf2_cu
*cu
)
11028 struct objfile
*objfile
= cu
->objfile
;
11029 struct comp_unit_head
*cu_header
= &cu
->header
;
11032 struct dwarf2_locexpr_baton
*baton
;
11034 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11035 SYMBOL_PRINT_NAME (sym
),
11036 &objfile
->objfile_obstack
, cu
,
11037 &value
, &bytes
, &baton
);
11041 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11042 SYMBOL_LOCATION_BATON (sym
) = baton
;
11043 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11045 else if (bytes
!= NULL
)
11047 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11048 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11052 SYMBOL_VALUE (sym
) = value
;
11053 SYMBOL_CLASS (sym
) = LOC_CONST
;
11057 /* Return the type of the die in question using its DW_AT_type attribute. */
11059 static struct type
*
11060 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11062 struct attribute
*type_attr
;
11064 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11067 /* A missing DW_AT_type represents a void type. */
11068 return objfile_type (cu
->objfile
)->builtin_void
;
11071 return lookup_die_type (die
, type_attr
, cu
);
11074 /* True iff CU's producer generates GNAT Ada auxiliary information
11075 that allows to find parallel types through that information instead
11076 of having to do expensive parallel lookups by type name. */
11079 need_gnat_info (struct dwarf2_cu
*cu
)
11081 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11082 of GNAT produces this auxiliary information, without any indication
11083 that it is produced. Part of enhancing the FSF version of GNAT
11084 to produce that information will be to put in place an indicator
11085 that we can use in order to determine whether the descriptive type
11086 info is available or not. One suggestion that has been made is
11087 to use a new attribute, attached to the CU die. For now, assume
11088 that the descriptive type info is not available. */
11092 /* Return the auxiliary type of the die in question using its
11093 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11094 attribute is not present. */
11096 static struct type
*
11097 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11099 struct attribute
*type_attr
;
11101 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11105 return lookup_die_type (die
, type_attr
, cu
);
11108 /* If DIE has a descriptive_type attribute, then set the TYPE's
11109 descriptive type accordingly. */
11112 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11113 struct dwarf2_cu
*cu
)
11115 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11117 if (descriptive_type
)
11119 ALLOCATE_GNAT_AUX_TYPE (type
);
11120 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11124 /* Return the containing type of the die in question using its
11125 DW_AT_containing_type attribute. */
11127 static struct type
*
11128 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11130 struct attribute
*type_attr
;
11132 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11134 error (_("Dwarf Error: Problem turning containing type into gdb type "
11135 "[in module %s]"), cu
->objfile
->name
);
11137 return lookup_die_type (die
, type_attr
, cu
);
11140 /* Look up the type of DIE in CU using its type attribute ATTR.
11141 If there is no type substitute an error marker. */
11143 static struct type
*
11144 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11145 struct dwarf2_cu
*cu
)
11147 struct type
*this_type
;
11149 /* First see if we have it cached. */
11151 if (is_ref_attr (attr
))
11153 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11155 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11157 else if (attr
->form
== DW_FORM_sig8
)
11159 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11160 struct dwarf2_cu
*sig_cu
;
11161 unsigned int offset
;
11163 /* sig_type will be NULL if the signatured type is missing from
11165 if (sig_type
== NULL
)
11166 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11167 "at 0x%x [in module %s]"),
11168 die
->offset
, cu
->objfile
->name
);
11170 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11171 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11172 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11176 dump_die_for_error (die
);
11177 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11178 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11181 /* If not cached we need to read it in. */
11183 if (this_type
== NULL
)
11185 struct die_info
*type_die
;
11186 struct dwarf2_cu
*type_cu
= cu
;
11188 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11189 /* If the type is cached, we should have found it above. */
11190 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11191 this_type
= read_type_die_1 (type_die
, type_cu
);
11194 /* If we still don't have a type use an error marker. */
11196 if (this_type
== NULL
)
11198 char *message
, *saved
;
11200 /* read_type_die already issued a complaint. */
11201 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11205 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11206 message
, strlen (message
));
11209 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11215 /* Return the type in DIE, CU.
11216 Returns NULL for invalid types.
11218 This first does a lookup in the appropriate type_hash table,
11219 and only reads the die in if necessary.
11221 NOTE: This can be called when reading in partial or full symbols. */
11223 static struct type
*
11224 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11226 struct type
*this_type
;
11228 this_type
= get_die_type (die
, cu
);
11232 return read_type_die_1 (die
, cu
);
11235 /* Read the type in DIE, CU.
11236 Returns NULL for invalid types. */
11238 static struct type
*
11239 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11241 struct type
*this_type
= NULL
;
11245 case DW_TAG_class_type
:
11246 case DW_TAG_interface_type
:
11247 case DW_TAG_structure_type
:
11248 case DW_TAG_union_type
:
11249 this_type
= read_structure_type (die
, cu
);
11251 case DW_TAG_enumeration_type
:
11252 this_type
= read_enumeration_type (die
, cu
);
11254 case DW_TAG_subprogram
:
11255 case DW_TAG_subroutine_type
:
11256 case DW_TAG_inlined_subroutine
:
11257 this_type
= read_subroutine_type (die
, cu
);
11259 case DW_TAG_array_type
:
11260 this_type
= read_array_type (die
, cu
);
11262 case DW_TAG_set_type
:
11263 this_type
= read_set_type (die
, cu
);
11265 case DW_TAG_pointer_type
:
11266 this_type
= read_tag_pointer_type (die
, cu
);
11268 case DW_TAG_ptr_to_member_type
:
11269 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11271 case DW_TAG_reference_type
:
11272 this_type
= read_tag_reference_type (die
, cu
);
11274 case DW_TAG_const_type
:
11275 this_type
= read_tag_const_type (die
, cu
);
11277 case DW_TAG_volatile_type
:
11278 this_type
= read_tag_volatile_type (die
, cu
);
11280 case DW_TAG_string_type
:
11281 this_type
= read_tag_string_type (die
, cu
);
11283 case DW_TAG_typedef
:
11284 this_type
= read_typedef (die
, cu
);
11286 case DW_TAG_subrange_type
:
11287 this_type
= read_subrange_type (die
, cu
);
11289 case DW_TAG_base_type
:
11290 this_type
= read_base_type (die
, cu
);
11292 case DW_TAG_unspecified_type
:
11293 this_type
= read_unspecified_type (die
, cu
);
11295 case DW_TAG_namespace
:
11296 this_type
= read_namespace_type (die
, cu
);
11298 case DW_TAG_module
:
11299 this_type
= read_module_type (die
, cu
);
11302 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11303 dwarf_tag_name (die
->tag
));
11310 /* See if we can figure out if the class lives in a namespace. We do
11311 this by looking for a member function; its demangled name will
11312 contain namespace info, if there is any.
11313 Return the computed name or NULL.
11314 Space for the result is allocated on the objfile's obstack.
11315 This is the full-die version of guess_partial_die_structure_name.
11316 In this case we know DIE has no useful parent. */
11319 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11321 struct die_info
*spec_die
;
11322 struct dwarf2_cu
*spec_cu
;
11323 struct die_info
*child
;
11326 spec_die
= die_specification (die
, &spec_cu
);
11327 if (spec_die
!= NULL
)
11333 for (child
= die
->child
;
11335 child
= child
->sibling
)
11337 if (child
->tag
== DW_TAG_subprogram
)
11339 struct attribute
*attr
;
11341 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11343 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11347 = language_class_name_from_physname (cu
->language_defn
,
11351 if (actual_name
!= NULL
)
11353 char *die_name
= dwarf2_name (die
, cu
);
11355 if (die_name
!= NULL
11356 && strcmp (die_name
, actual_name
) != 0)
11358 /* Strip off the class name from the full name.
11359 We want the prefix. */
11360 int die_name_len
= strlen (die_name
);
11361 int actual_name_len
= strlen (actual_name
);
11363 /* Test for '::' as a sanity check. */
11364 if (actual_name_len
> die_name_len
+ 2
11365 && actual_name
[actual_name_len
- die_name_len
- 1] == ':')
11367 obsavestring (actual_name
,
11368 actual_name_len
- die_name_len
- 2,
11369 &cu
->objfile
->objfile_obstack
);
11372 xfree (actual_name
);
11381 /* Return the name of the namespace/class that DIE is defined within,
11382 or "" if we can't tell. The caller should not xfree the result.
11384 For example, if we're within the method foo() in the following
11394 then determine_prefix on foo's die will return "N::C". */
11397 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11399 struct die_info
*parent
, *spec_die
;
11400 struct dwarf2_cu
*spec_cu
;
11401 struct type
*parent_type
;
11403 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11404 && cu
->language
!= language_fortran
)
11407 /* We have to be careful in the presence of DW_AT_specification.
11408 For example, with GCC 3.4, given the code
11412 // Definition of N::foo.
11416 then we'll have a tree of DIEs like this:
11418 1: DW_TAG_compile_unit
11419 2: DW_TAG_namespace // N
11420 3: DW_TAG_subprogram // declaration of N::foo
11421 4: DW_TAG_subprogram // definition of N::foo
11422 DW_AT_specification // refers to die #3
11424 Thus, when processing die #4, we have to pretend that we're in
11425 the context of its DW_AT_specification, namely the contex of die
11428 spec_die
= die_specification (die
, &spec_cu
);
11429 if (spec_die
== NULL
)
11430 parent
= die
->parent
;
11433 parent
= spec_die
->parent
;
11437 if (parent
== NULL
)
11439 else if (parent
->building_fullname
)
11442 const char *parent_name
;
11444 /* It has been seen on RealView 2.2 built binaries,
11445 DW_TAG_template_type_param types actually _defined_ as
11446 children of the parent class:
11449 template class <class Enum> Class{};
11450 Class<enum E> class_e;
11452 1: DW_TAG_class_type (Class)
11453 2: DW_TAG_enumeration_type (E)
11454 3: DW_TAG_enumerator (enum1:0)
11455 3: DW_TAG_enumerator (enum2:1)
11457 2: DW_TAG_template_type_param
11458 DW_AT_type DW_FORM_ref_udata (E)
11460 Besides being broken debug info, it can put GDB into an
11461 infinite loop. Consider:
11463 When we're building the full name for Class<E>, we'll start
11464 at Class, and go look over its template type parameters,
11465 finding E. We'll then try to build the full name of E, and
11466 reach here. We're now trying to build the full name of E,
11467 and look over the parent DIE for containing scope. In the
11468 broken case, if we followed the parent DIE of E, we'd again
11469 find Class, and once again go look at its template type
11470 arguments, etc., etc. Simply don't consider such parent die
11471 as source-level parent of this die (it can't be, the language
11472 doesn't allow it), and break the loop here. */
11473 name
= dwarf2_name (die
, cu
);
11474 parent_name
= dwarf2_name (parent
, cu
);
11475 complaint (&symfile_complaints
,
11476 _("template param type '%s' defined within parent '%s'"),
11477 name
? name
: "<unknown>",
11478 parent_name
? parent_name
: "<unknown>");
11482 switch (parent
->tag
)
11484 case DW_TAG_namespace
:
11485 parent_type
= read_type_die (parent
, cu
);
11486 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11487 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11488 Work around this problem here. */
11489 if (cu
->language
== language_cplus
11490 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11492 /* We give a name to even anonymous namespaces. */
11493 return TYPE_TAG_NAME (parent_type
);
11494 case DW_TAG_class_type
:
11495 case DW_TAG_interface_type
:
11496 case DW_TAG_structure_type
:
11497 case DW_TAG_union_type
:
11498 case DW_TAG_module
:
11499 parent_type
= read_type_die (parent
, cu
);
11500 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11501 return TYPE_TAG_NAME (parent_type
);
11503 /* An anonymous structure is only allowed non-static data
11504 members; no typedefs, no member functions, et cetera.
11505 So it does not need a prefix. */
11507 case DW_TAG_compile_unit
:
11508 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11509 if (cu
->language
== language_cplus
11510 && dwarf2_per_objfile
->types
.asection
!= NULL
11511 && die
->child
!= NULL
11512 && (die
->tag
== DW_TAG_class_type
11513 || die
->tag
== DW_TAG_structure_type
11514 || die
->tag
== DW_TAG_union_type
))
11516 char *name
= guess_full_die_structure_name (die
, cu
);
11522 return determine_prefix (parent
, cu
);
11526 /* Return a newly-allocated string formed by concatenating PREFIX and
11527 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11528 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11529 perform an obconcat, otherwise allocate storage for the result. The CU argument
11530 is used to determine the language and hence, the appropriate separator. */
11532 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11535 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11536 int physname
, struct dwarf2_cu
*cu
)
11538 const char *lead
= "";
11541 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11543 else if (cu
->language
== language_java
)
11545 else if (cu
->language
== language_fortran
&& physname
)
11547 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11548 DW_AT_MIPS_linkage_name is preferred and used instead. */
11556 if (prefix
== NULL
)
11558 if (suffix
== NULL
)
11563 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11565 strcpy (retval
, lead
);
11566 strcat (retval
, prefix
);
11567 strcat (retval
, sep
);
11568 strcat (retval
, suffix
);
11573 /* We have an obstack. */
11574 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11578 /* Return sibling of die, NULL if no sibling. */
11580 static struct die_info
*
11581 sibling_die (struct die_info
*die
)
11583 return die
->sibling
;
11586 /* Get name of a die, return NULL if not found. */
11589 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11590 struct obstack
*obstack
)
11592 if (name
&& cu
->language
== language_cplus
)
11594 char *canon_name
= cp_canonicalize_string (name
);
11596 if (canon_name
!= NULL
)
11598 if (strcmp (canon_name
, name
) != 0)
11599 name
= obsavestring (canon_name
, strlen (canon_name
),
11601 xfree (canon_name
);
11608 /* Get name of a die, return NULL if not found. */
11611 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11613 struct attribute
*attr
;
11615 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11616 if (!attr
|| !DW_STRING (attr
))
11621 case DW_TAG_compile_unit
:
11622 /* Compilation units have a DW_AT_name that is a filename, not
11623 a source language identifier. */
11624 case DW_TAG_enumeration_type
:
11625 case DW_TAG_enumerator
:
11626 /* These tags always have simple identifiers already; no need
11627 to canonicalize them. */
11628 return DW_STRING (attr
);
11630 case DW_TAG_subprogram
:
11631 /* Java constructors will all be named "<init>", so return
11632 the class name when we see this special case. */
11633 if (cu
->language
== language_java
11634 && DW_STRING (attr
) != NULL
11635 && strcmp (DW_STRING (attr
), "<init>") == 0)
11637 struct dwarf2_cu
*spec_cu
= cu
;
11638 struct die_info
*spec_die
;
11640 /* GCJ will output '<init>' for Java constructor names.
11641 For this special case, return the name of the parent class. */
11643 /* GCJ may output suprogram DIEs with AT_specification set.
11644 If so, use the name of the specified DIE. */
11645 spec_die
= die_specification (die
, &spec_cu
);
11646 if (spec_die
!= NULL
)
11647 return dwarf2_name (spec_die
, spec_cu
);
11652 if (die
->tag
== DW_TAG_class_type
)
11653 return dwarf2_name (die
, cu
);
11655 while (die
->tag
!= DW_TAG_compile_unit
);
11659 case DW_TAG_class_type
:
11660 case DW_TAG_interface_type
:
11661 case DW_TAG_structure_type
:
11662 case DW_TAG_union_type
:
11663 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11664 structures or unions. These were of the form "._%d" in GCC 4.1,
11665 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11666 and GCC 4.4. We work around this problem by ignoring these. */
11667 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11668 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11676 if (!DW_STRING_IS_CANONICAL (attr
))
11679 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11680 &cu
->objfile
->objfile_obstack
);
11681 DW_STRING_IS_CANONICAL (attr
) = 1;
11683 return DW_STRING (attr
);
11686 /* Return the die that this die in an extension of, or NULL if there
11687 is none. *EXT_CU is the CU containing DIE on input, and the CU
11688 containing the return value on output. */
11690 static struct die_info
*
11691 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11693 struct attribute
*attr
;
11695 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11699 return follow_die_ref (die
, attr
, ext_cu
);
11702 /* Convert a DIE tag into its string name. */
11705 dwarf_tag_name (unsigned tag
)
11709 case DW_TAG_padding
:
11710 return "DW_TAG_padding";
11711 case DW_TAG_array_type
:
11712 return "DW_TAG_array_type";
11713 case DW_TAG_class_type
:
11714 return "DW_TAG_class_type";
11715 case DW_TAG_entry_point
:
11716 return "DW_TAG_entry_point";
11717 case DW_TAG_enumeration_type
:
11718 return "DW_TAG_enumeration_type";
11719 case DW_TAG_formal_parameter
:
11720 return "DW_TAG_formal_parameter";
11721 case DW_TAG_imported_declaration
:
11722 return "DW_TAG_imported_declaration";
11724 return "DW_TAG_label";
11725 case DW_TAG_lexical_block
:
11726 return "DW_TAG_lexical_block";
11727 case DW_TAG_member
:
11728 return "DW_TAG_member";
11729 case DW_TAG_pointer_type
:
11730 return "DW_TAG_pointer_type";
11731 case DW_TAG_reference_type
:
11732 return "DW_TAG_reference_type";
11733 case DW_TAG_compile_unit
:
11734 return "DW_TAG_compile_unit";
11735 case DW_TAG_string_type
:
11736 return "DW_TAG_string_type";
11737 case DW_TAG_structure_type
:
11738 return "DW_TAG_structure_type";
11739 case DW_TAG_subroutine_type
:
11740 return "DW_TAG_subroutine_type";
11741 case DW_TAG_typedef
:
11742 return "DW_TAG_typedef";
11743 case DW_TAG_union_type
:
11744 return "DW_TAG_union_type";
11745 case DW_TAG_unspecified_parameters
:
11746 return "DW_TAG_unspecified_parameters";
11747 case DW_TAG_variant
:
11748 return "DW_TAG_variant";
11749 case DW_TAG_common_block
:
11750 return "DW_TAG_common_block";
11751 case DW_TAG_common_inclusion
:
11752 return "DW_TAG_common_inclusion";
11753 case DW_TAG_inheritance
:
11754 return "DW_TAG_inheritance";
11755 case DW_TAG_inlined_subroutine
:
11756 return "DW_TAG_inlined_subroutine";
11757 case DW_TAG_module
:
11758 return "DW_TAG_module";
11759 case DW_TAG_ptr_to_member_type
:
11760 return "DW_TAG_ptr_to_member_type";
11761 case DW_TAG_set_type
:
11762 return "DW_TAG_set_type";
11763 case DW_TAG_subrange_type
:
11764 return "DW_TAG_subrange_type";
11765 case DW_TAG_with_stmt
:
11766 return "DW_TAG_with_stmt";
11767 case DW_TAG_access_declaration
:
11768 return "DW_TAG_access_declaration";
11769 case DW_TAG_base_type
:
11770 return "DW_TAG_base_type";
11771 case DW_TAG_catch_block
:
11772 return "DW_TAG_catch_block";
11773 case DW_TAG_const_type
:
11774 return "DW_TAG_const_type";
11775 case DW_TAG_constant
:
11776 return "DW_TAG_constant";
11777 case DW_TAG_enumerator
:
11778 return "DW_TAG_enumerator";
11779 case DW_TAG_file_type
:
11780 return "DW_TAG_file_type";
11781 case DW_TAG_friend
:
11782 return "DW_TAG_friend";
11783 case DW_TAG_namelist
:
11784 return "DW_TAG_namelist";
11785 case DW_TAG_namelist_item
:
11786 return "DW_TAG_namelist_item";
11787 case DW_TAG_packed_type
:
11788 return "DW_TAG_packed_type";
11789 case DW_TAG_subprogram
:
11790 return "DW_TAG_subprogram";
11791 case DW_TAG_template_type_param
:
11792 return "DW_TAG_template_type_param";
11793 case DW_TAG_template_value_param
:
11794 return "DW_TAG_template_value_param";
11795 case DW_TAG_thrown_type
:
11796 return "DW_TAG_thrown_type";
11797 case DW_TAG_try_block
:
11798 return "DW_TAG_try_block";
11799 case DW_TAG_variant_part
:
11800 return "DW_TAG_variant_part";
11801 case DW_TAG_variable
:
11802 return "DW_TAG_variable";
11803 case DW_TAG_volatile_type
:
11804 return "DW_TAG_volatile_type";
11805 case DW_TAG_dwarf_procedure
:
11806 return "DW_TAG_dwarf_procedure";
11807 case DW_TAG_restrict_type
:
11808 return "DW_TAG_restrict_type";
11809 case DW_TAG_interface_type
:
11810 return "DW_TAG_interface_type";
11811 case DW_TAG_namespace
:
11812 return "DW_TAG_namespace";
11813 case DW_TAG_imported_module
:
11814 return "DW_TAG_imported_module";
11815 case DW_TAG_unspecified_type
:
11816 return "DW_TAG_unspecified_type";
11817 case DW_TAG_partial_unit
:
11818 return "DW_TAG_partial_unit";
11819 case DW_TAG_imported_unit
:
11820 return "DW_TAG_imported_unit";
11821 case DW_TAG_condition
:
11822 return "DW_TAG_condition";
11823 case DW_TAG_shared_type
:
11824 return "DW_TAG_shared_type";
11825 case DW_TAG_type_unit
:
11826 return "DW_TAG_type_unit";
11827 case DW_TAG_MIPS_loop
:
11828 return "DW_TAG_MIPS_loop";
11829 case DW_TAG_HP_array_descriptor
:
11830 return "DW_TAG_HP_array_descriptor";
11831 case DW_TAG_format_label
:
11832 return "DW_TAG_format_label";
11833 case DW_TAG_function_template
:
11834 return "DW_TAG_function_template";
11835 case DW_TAG_class_template
:
11836 return "DW_TAG_class_template";
11837 case DW_TAG_GNU_BINCL
:
11838 return "DW_TAG_GNU_BINCL";
11839 case DW_TAG_GNU_EINCL
:
11840 return "DW_TAG_GNU_EINCL";
11841 case DW_TAG_upc_shared_type
:
11842 return "DW_TAG_upc_shared_type";
11843 case DW_TAG_upc_strict_type
:
11844 return "DW_TAG_upc_strict_type";
11845 case DW_TAG_upc_relaxed_type
:
11846 return "DW_TAG_upc_relaxed_type";
11847 case DW_TAG_PGI_kanji_type
:
11848 return "DW_TAG_PGI_kanji_type";
11849 case DW_TAG_PGI_interface_block
:
11850 return "DW_TAG_PGI_interface_block";
11852 return "DW_TAG_<unknown>";
11856 /* Convert a DWARF attribute code into its string name. */
11859 dwarf_attr_name (unsigned attr
)
11863 case DW_AT_sibling
:
11864 return "DW_AT_sibling";
11865 case DW_AT_location
:
11866 return "DW_AT_location";
11868 return "DW_AT_name";
11869 case DW_AT_ordering
:
11870 return "DW_AT_ordering";
11871 case DW_AT_subscr_data
:
11872 return "DW_AT_subscr_data";
11873 case DW_AT_byte_size
:
11874 return "DW_AT_byte_size";
11875 case DW_AT_bit_offset
:
11876 return "DW_AT_bit_offset";
11877 case DW_AT_bit_size
:
11878 return "DW_AT_bit_size";
11879 case DW_AT_element_list
:
11880 return "DW_AT_element_list";
11881 case DW_AT_stmt_list
:
11882 return "DW_AT_stmt_list";
11884 return "DW_AT_low_pc";
11885 case DW_AT_high_pc
:
11886 return "DW_AT_high_pc";
11887 case DW_AT_language
:
11888 return "DW_AT_language";
11890 return "DW_AT_member";
11892 return "DW_AT_discr";
11893 case DW_AT_discr_value
:
11894 return "DW_AT_discr_value";
11895 case DW_AT_visibility
:
11896 return "DW_AT_visibility";
11898 return "DW_AT_import";
11899 case DW_AT_string_length
:
11900 return "DW_AT_string_length";
11901 case DW_AT_common_reference
:
11902 return "DW_AT_common_reference";
11903 case DW_AT_comp_dir
:
11904 return "DW_AT_comp_dir";
11905 case DW_AT_const_value
:
11906 return "DW_AT_const_value";
11907 case DW_AT_containing_type
:
11908 return "DW_AT_containing_type";
11909 case DW_AT_default_value
:
11910 return "DW_AT_default_value";
11912 return "DW_AT_inline";
11913 case DW_AT_is_optional
:
11914 return "DW_AT_is_optional";
11915 case DW_AT_lower_bound
:
11916 return "DW_AT_lower_bound";
11917 case DW_AT_producer
:
11918 return "DW_AT_producer";
11919 case DW_AT_prototyped
:
11920 return "DW_AT_prototyped";
11921 case DW_AT_return_addr
:
11922 return "DW_AT_return_addr";
11923 case DW_AT_start_scope
:
11924 return "DW_AT_start_scope";
11925 case DW_AT_bit_stride
:
11926 return "DW_AT_bit_stride";
11927 case DW_AT_upper_bound
:
11928 return "DW_AT_upper_bound";
11929 case DW_AT_abstract_origin
:
11930 return "DW_AT_abstract_origin";
11931 case DW_AT_accessibility
:
11932 return "DW_AT_accessibility";
11933 case DW_AT_address_class
:
11934 return "DW_AT_address_class";
11935 case DW_AT_artificial
:
11936 return "DW_AT_artificial";
11937 case DW_AT_base_types
:
11938 return "DW_AT_base_types";
11939 case DW_AT_calling_convention
:
11940 return "DW_AT_calling_convention";
11942 return "DW_AT_count";
11943 case DW_AT_data_member_location
:
11944 return "DW_AT_data_member_location";
11945 case DW_AT_decl_column
:
11946 return "DW_AT_decl_column";
11947 case DW_AT_decl_file
:
11948 return "DW_AT_decl_file";
11949 case DW_AT_decl_line
:
11950 return "DW_AT_decl_line";
11951 case DW_AT_declaration
:
11952 return "DW_AT_declaration";
11953 case DW_AT_discr_list
:
11954 return "DW_AT_discr_list";
11955 case DW_AT_encoding
:
11956 return "DW_AT_encoding";
11957 case DW_AT_external
:
11958 return "DW_AT_external";
11959 case DW_AT_frame_base
:
11960 return "DW_AT_frame_base";
11962 return "DW_AT_friend";
11963 case DW_AT_identifier_case
:
11964 return "DW_AT_identifier_case";
11965 case DW_AT_macro_info
:
11966 return "DW_AT_macro_info";
11967 case DW_AT_namelist_items
:
11968 return "DW_AT_namelist_items";
11969 case DW_AT_priority
:
11970 return "DW_AT_priority";
11971 case DW_AT_segment
:
11972 return "DW_AT_segment";
11973 case DW_AT_specification
:
11974 return "DW_AT_specification";
11975 case DW_AT_static_link
:
11976 return "DW_AT_static_link";
11978 return "DW_AT_type";
11979 case DW_AT_use_location
:
11980 return "DW_AT_use_location";
11981 case DW_AT_variable_parameter
:
11982 return "DW_AT_variable_parameter";
11983 case DW_AT_virtuality
:
11984 return "DW_AT_virtuality";
11985 case DW_AT_vtable_elem_location
:
11986 return "DW_AT_vtable_elem_location";
11987 /* DWARF 3 values. */
11988 case DW_AT_allocated
:
11989 return "DW_AT_allocated";
11990 case DW_AT_associated
:
11991 return "DW_AT_associated";
11992 case DW_AT_data_location
:
11993 return "DW_AT_data_location";
11994 case DW_AT_byte_stride
:
11995 return "DW_AT_byte_stride";
11996 case DW_AT_entry_pc
:
11997 return "DW_AT_entry_pc";
11998 case DW_AT_use_UTF8
:
11999 return "DW_AT_use_UTF8";
12000 case DW_AT_extension
:
12001 return "DW_AT_extension";
12003 return "DW_AT_ranges";
12004 case DW_AT_trampoline
:
12005 return "DW_AT_trampoline";
12006 case DW_AT_call_column
:
12007 return "DW_AT_call_column";
12008 case DW_AT_call_file
:
12009 return "DW_AT_call_file";
12010 case DW_AT_call_line
:
12011 return "DW_AT_call_line";
12012 case DW_AT_description
:
12013 return "DW_AT_description";
12014 case DW_AT_binary_scale
:
12015 return "DW_AT_binary_scale";
12016 case DW_AT_decimal_scale
:
12017 return "DW_AT_decimal_scale";
12019 return "DW_AT_small";
12020 case DW_AT_decimal_sign
:
12021 return "DW_AT_decimal_sign";
12022 case DW_AT_digit_count
:
12023 return "DW_AT_digit_count";
12024 case DW_AT_picture_string
:
12025 return "DW_AT_picture_string";
12026 case DW_AT_mutable
:
12027 return "DW_AT_mutable";
12028 case DW_AT_threads_scaled
:
12029 return "DW_AT_threads_scaled";
12030 case DW_AT_explicit
:
12031 return "DW_AT_explicit";
12032 case DW_AT_object_pointer
:
12033 return "DW_AT_object_pointer";
12034 case DW_AT_endianity
:
12035 return "DW_AT_endianity";
12036 case DW_AT_elemental
:
12037 return "DW_AT_elemental";
12039 return "DW_AT_pure";
12040 case DW_AT_recursive
:
12041 return "DW_AT_recursive";
12042 /* DWARF 4 values. */
12043 case DW_AT_signature
:
12044 return "DW_AT_signature";
12045 case DW_AT_linkage_name
:
12046 return "DW_AT_linkage_name";
12047 /* SGI/MIPS extensions. */
12048 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12049 case DW_AT_MIPS_fde
:
12050 return "DW_AT_MIPS_fde";
12052 case DW_AT_MIPS_loop_begin
:
12053 return "DW_AT_MIPS_loop_begin";
12054 case DW_AT_MIPS_tail_loop_begin
:
12055 return "DW_AT_MIPS_tail_loop_begin";
12056 case DW_AT_MIPS_epilog_begin
:
12057 return "DW_AT_MIPS_epilog_begin";
12058 case DW_AT_MIPS_loop_unroll_factor
:
12059 return "DW_AT_MIPS_loop_unroll_factor";
12060 case DW_AT_MIPS_software_pipeline_depth
:
12061 return "DW_AT_MIPS_software_pipeline_depth";
12062 case DW_AT_MIPS_linkage_name
:
12063 return "DW_AT_MIPS_linkage_name";
12064 case DW_AT_MIPS_stride
:
12065 return "DW_AT_MIPS_stride";
12066 case DW_AT_MIPS_abstract_name
:
12067 return "DW_AT_MIPS_abstract_name";
12068 case DW_AT_MIPS_clone_origin
:
12069 return "DW_AT_MIPS_clone_origin";
12070 case DW_AT_MIPS_has_inlines
:
12071 return "DW_AT_MIPS_has_inlines";
12072 /* HP extensions. */
12073 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12074 case DW_AT_HP_block_index
:
12075 return "DW_AT_HP_block_index";
12077 case DW_AT_HP_unmodifiable
:
12078 return "DW_AT_HP_unmodifiable";
12079 case DW_AT_HP_actuals_stmt_list
:
12080 return "DW_AT_HP_actuals_stmt_list";
12081 case DW_AT_HP_proc_per_section
:
12082 return "DW_AT_HP_proc_per_section";
12083 case DW_AT_HP_raw_data_ptr
:
12084 return "DW_AT_HP_raw_data_ptr";
12085 case DW_AT_HP_pass_by_reference
:
12086 return "DW_AT_HP_pass_by_reference";
12087 case DW_AT_HP_opt_level
:
12088 return "DW_AT_HP_opt_level";
12089 case DW_AT_HP_prof_version_id
:
12090 return "DW_AT_HP_prof_version_id";
12091 case DW_AT_HP_opt_flags
:
12092 return "DW_AT_HP_opt_flags";
12093 case DW_AT_HP_cold_region_low_pc
:
12094 return "DW_AT_HP_cold_region_low_pc";
12095 case DW_AT_HP_cold_region_high_pc
:
12096 return "DW_AT_HP_cold_region_high_pc";
12097 case DW_AT_HP_all_variables_modifiable
:
12098 return "DW_AT_HP_all_variables_modifiable";
12099 case DW_AT_HP_linkage_name
:
12100 return "DW_AT_HP_linkage_name";
12101 case DW_AT_HP_prof_flags
:
12102 return "DW_AT_HP_prof_flags";
12103 /* GNU extensions. */
12104 case DW_AT_sf_names
:
12105 return "DW_AT_sf_names";
12106 case DW_AT_src_info
:
12107 return "DW_AT_src_info";
12108 case DW_AT_mac_info
:
12109 return "DW_AT_mac_info";
12110 case DW_AT_src_coords
:
12111 return "DW_AT_src_coords";
12112 case DW_AT_body_begin
:
12113 return "DW_AT_body_begin";
12114 case DW_AT_body_end
:
12115 return "DW_AT_body_end";
12116 case DW_AT_GNU_vector
:
12117 return "DW_AT_GNU_vector";
12118 case DW_AT_GNU_odr_signature
:
12119 return "DW_AT_GNU_odr_signature";
12120 /* VMS extensions. */
12121 case DW_AT_VMS_rtnbeg_pd_address
:
12122 return "DW_AT_VMS_rtnbeg_pd_address";
12123 /* UPC extension. */
12124 case DW_AT_upc_threads_scaled
:
12125 return "DW_AT_upc_threads_scaled";
12126 /* PGI (STMicroelectronics) extensions. */
12127 case DW_AT_PGI_lbase
:
12128 return "DW_AT_PGI_lbase";
12129 case DW_AT_PGI_soffset
:
12130 return "DW_AT_PGI_soffset";
12131 case DW_AT_PGI_lstride
:
12132 return "DW_AT_PGI_lstride";
12134 return "DW_AT_<unknown>";
12138 /* Convert a DWARF value form code into its string name. */
12141 dwarf_form_name (unsigned form
)
12146 return "DW_FORM_addr";
12147 case DW_FORM_block2
:
12148 return "DW_FORM_block2";
12149 case DW_FORM_block4
:
12150 return "DW_FORM_block4";
12151 case DW_FORM_data2
:
12152 return "DW_FORM_data2";
12153 case DW_FORM_data4
:
12154 return "DW_FORM_data4";
12155 case DW_FORM_data8
:
12156 return "DW_FORM_data8";
12157 case DW_FORM_string
:
12158 return "DW_FORM_string";
12159 case DW_FORM_block
:
12160 return "DW_FORM_block";
12161 case DW_FORM_block1
:
12162 return "DW_FORM_block1";
12163 case DW_FORM_data1
:
12164 return "DW_FORM_data1";
12166 return "DW_FORM_flag";
12167 case DW_FORM_sdata
:
12168 return "DW_FORM_sdata";
12170 return "DW_FORM_strp";
12171 case DW_FORM_udata
:
12172 return "DW_FORM_udata";
12173 case DW_FORM_ref_addr
:
12174 return "DW_FORM_ref_addr";
12176 return "DW_FORM_ref1";
12178 return "DW_FORM_ref2";
12180 return "DW_FORM_ref4";
12182 return "DW_FORM_ref8";
12183 case DW_FORM_ref_udata
:
12184 return "DW_FORM_ref_udata";
12185 case DW_FORM_indirect
:
12186 return "DW_FORM_indirect";
12187 case DW_FORM_sec_offset
:
12188 return "DW_FORM_sec_offset";
12189 case DW_FORM_exprloc
:
12190 return "DW_FORM_exprloc";
12191 case DW_FORM_flag_present
:
12192 return "DW_FORM_flag_present";
12194 return "DW_FORM_sig8";
12196 return "DW_FORM_<unknown>";
12200 /* Convert a DWARF stack opcode into its string name. */
12203 dwarf_stack_op_name (unsigned op
, int def
)
12208 return "DW_OP_addr";
12210 return "DW_OP_deref";
12211 case DW_OP_const1u
:
12212 return "DW_OP_const1u";
12213 case DW_OP_const1s
:
12214 return "DW_OP_const1s";
12215 case DW_OP_const2u
:
12216 return "DW_OP_const2u";
12217 case DW_OP_const2s
:
12218 return "DW_OP_const2s";
12219 case DW_OP_const4u
:
12220 return "DW_OP_const4u";
12221 case DW_OP_const4s
:
12222 return "DW_OP_const4s";
12223 case DW_OP_const8u
:
12224 return "DW_OP_const8u";
12225 case DW_OP_const8s
:
12226 return "DW_OP_const8s";
12228 return "DW_OP_constu";
12230 return "DW_OP_consts";
12232 return "DW_OP_dup";
12234 return "DW_OP_drop";
12236 return "DW_OP_over";
12238 return "DW_OP_pick";
12240 return "DW_OP_swap";
12242 return "DW_OP_rot";
12244 return "DW_OP_xderef";
12246 return "DW_OP_abs";
12248 return "DW_OP_and";
12250 return "DW_OP_div";
12252 return "DW_OP_minus";
12254 return "DW_OP_mod";
12256 return "DW_OP_mul";
12258 return "DW_OP_neg";
12260 return "DW_OP_not";
12264 return "DW_OP_plus";
12265 case DW_OP_plus_uconst
:
12266 return "DW_OP_plus_uconst";
12268 return "DW_OP_shl";
12270 return "DW_OP_shr";
12272 return "DW_OP_shra";
12274 return "DW_OP_xor";
12276 return "DW_OP_bra";
12290 return "DW_OP_skip";
12292 return "DW_OP_lit0";
12294 return "DW_OP_lit1";
12296 return "DW_OP_lit2";
12298 return "DW_OP_lit3";
12300 return "DW_OP_lit4";
12302 return "DW_OP_lit5";
12304 return "DW_OP_lit6";
12306 return "DW_OP_lit7";
12308 return "DW_OP_lit8";
12310 return "DW_OP_lit9";
12312 return "DW_OP_lit10";
12314 return "DW_OP_lit11";
12316 return "DW_OP_lit12";
12318 return "DW_OP_lit13";
12320 return "DW_OP_lit14";
12322 return "DW_OP_lit15";
12324 return "DW_OP_lit16";
12326 return "DW_OP_lit17";
12328 return "DW_OP_lit18";
12330 return "DW_OP_lit19";
12332 return "DW_OP_lit20";
12334 return "DW_OP_lit21";
12336 return "DW_OP_lit22";
12338 return "DW_OP_lit23";
12340 return "DW_OP_lit24";
12342 return "DW_OP_lit25";
12344 return "DW_OP_lit26";
12346 return "DW_OP_lit27";
12348 return "DW_OP_lit28";
12350 return "DW_OP_lit29";
12352 return "DW_OP_lit30";
12354 return "DW_OP_lit31";
12356 return "DW_OP_reg0";
12358 return "DW_OP_reg1";
12360 return "DW_OP_reg2";
12362 return "DW_OP_reg3";
12364 return "DW_OP_reg4";
12366 return "DW_OP_reg5";
12368 return "DW_OP_reg6";
12370 return "DW_OP_reg7";
12372 return "DW_OP_reg8";
12374 return "DW_OP_reg9";
12376 return "DW_OP_reg10";
12378 return "DW_OP_reg11";
12380 return "DW_OP_reg12";
12382 return "DW_OP_reg13";
12384 return "DW_OP_reg14";
12386 return "DW_OP_reg15";
12388 return "DW_OP_reg16";
12390 return "DW_OP_reg17";
12392 return "DW_OP_reg18";
12394 return "DW_OP_reg19";
12396 return "DW_OP_reg20";
12398 return "DW_OP_reg21";
12400 return "DW_OP_reg22";
12402 return "DW_OP_reg23";
12404 return "DW_OP_reg24";
12406 return "DW_OP_reg25";
12408 return "DW_OP_reg26";
12410 return "DW_OP_reg27";
12412 return "DW_OP_reg28";
12414 return "DW_OP_reg29";
12416 return "DW_OP_reg30";
12418 return "DW_OP_reg31";
12420 return "DW_OP_breg0";
12422 return "DW_OP_breg1";
12424 return "DW_OP_breg2";
12426 return "DW_OP_breg3";
12428 return "DW_OP_breg4";
12430 return "DW_OP_breg5";
12432 return "DW_OP_breg6";
12434 return "DW_OP_breg7";
12436 return "DW_OP_breg8";
12438 return "DW_OP_breg9";
12440 return "DW_OP_breg10";
12442 return "DW_OP_breg11";
12444 return "DW_OP_breg12";
12446 return "DW_OP_breg13";
12448 return "DW_OP_breg14";
12450 return "DW_OP_breg15";
12452 return "DW_OP_breg16";
12454 return "DW_OP_breg17";
12456 return "DW_OP_breg18";
12458 return "DW_OP_breg19";
12460 return "DW_OP_breg20";
12462 return "DW_OP_breg21";
12464 return "DW_OP_breg22";
12466 return "DW_OP_breg23";
12468 return "DW_OP_breg24";
12470 return "DW_OP_breg25";
12472 return "DW_OP_breg26";
12474 return "DW_OP_breg27";
12476 return "DW_OP_breg28";
12478 return "DW_OP_breg29";
12480 return "DW_OP_breg30";
12482 return "DW_OP_breg31";
12484 return "DW_OP_regx";
12486 return "DW_OP_fbreg";
12488 return "DW_OP_bregx";
12490 return "DW_OP_piece";
12491 case DW_OP_deref_size
:
12492 return "DW_OP_deref_size";
12493 case DW_OP_xderef_size
:
12494 return "DW_OP_xderef_size";
12496 return "DW_OP_nop";
12497 /* DWARF 3 extensions. */
12498 case DW_OP_push_object_address
:
12499 return "DW_OP_push_object_address";
12501 return "DW_OP_call2";
12503 return "DW_OP_call4";
12504 case DW_OP_call_ref
:
12505 return "DW_OP_call_ref";
12506 case DW_OP_form_tls_address
:
12507 return "DW_OP_form_tls_address";
12508 case DW_OP_call_frame_cfa
:
12509 return "DW_OP_call_frame_cfa";
12510 case DW_OP_bit_piece
:
12511 return "DW_OP_bit_piece";
12512 /* DWARF 4 extensions. */
12513 case DW_OP_implicit_value
:
12514 return "DW_OP_implicit_value";
12515 case DW_OP_stack_value
:
12516 return "DW_OP_stack_value";
12517 /* GNU extensions. */
12518 case DW_OP_GNU_push_tls_address
:
12519 return "DW_OP_GNU_push_tls_address";
12520 case DW_OP_GNU_uninit
:
12521 return "DW_OP_GNU_uninit";
12523 return def
? "OP_<unknown>" : NULL
;
12528 dwarf_bool_name (unsigned mybool
)
12536 /* Convert a DWARF type code into its string name. */
12539 dwarf_type_encoding_name (unsigned enc
)
12544 return "DW_ATE_void";
12545 case DW_ATE_address
:
12546 return "DW_ATE_address";
12547 case DW_ATE_boolean
:
12548 return "DW_ATE_boolean";
12549 case DW_ATE_complex_float
:
12550 return "DW_ATE_complex_float";
12552 return "DW_ATE_float";
12553 case DW_ATE_signed
:
12554 return "DW_ATE_signed";
12555 case DW_ATE_signed_char
:
12556 return "DW_ATE_signed_char";
12557 case DW_ATE_unsigned
:
12558 return "DW_ATE_unsigned";
12559 case DW_ATE_unsigned_char
:
12560 return "DW_ATE_unsigned_char";
12562 case DW_ATE_imaginary_float
:
12563 return "DW_ATE_imaginary_float";
12564 case DW_ATE_packed_decimal
:
12565 return "DW_ATE_packed_decimal";
12566 case DW_ATE_numeric_string
:
12567 return "DW_ATE_numeric_string";
12568 case DW_ATE_edited
:
12569 return "DW_ATE_edited";
12570 case DW_ATE_signed_fixed
:
12571 return "DW_ATE_signed_fixed";
12572 case DW_ATE_unsigned_fixed
:
12573 return "DW_ATE_unsigned_fixed";
12574 case DW_ATE_decimal_float
:
12575 return "DW_ATE_decimal_float";
12578 return "DW_ATE_UTF";
12579 /* HP extensions. */
12580 case DW_ATE_HP_float80
:
12581 return "DW_ATE_HP_float80";
12582 case DW_ATE_HP_complex_float80
:
12583 return "DW_ATE_HP_complex_float80";
12584 case DW_ATE_HP_float128
:
12585 return "DW_ATE_HP_float128";
12586 case DW_ATE_HP_complex_float128
:
12587 return "DW_ATE_HP_complex_float128";
12588 case DW_ATE_HP_floathpintel
:
12589 return "DW_ATE_HP_floathpintel";
12590 case DW_ATE_HP_imaginary_float80
:
12591 return "DW_ATE_HP_imaginary_float80";
12592 case DW_ATE_HP_imaginary_float128
:
12593 return "DW_ATE_HP_imaginary_float128";
12595 return "DW_ATE_<unknown>";
12599 /* Convert a DWARF call frame info operation to its string name. */
12603 dwarf_cfi_name (unsigned cfi_opc
)
12607 case DW_CFA_advance_loc
:
12608 return "DW_CFA_advance_loc";
12609 case DW_CFA_offset
:
12610 return "DW_CFA_offset";
12611 case DW_CFA_restore
:
12612 return "DW_CFA_restore";
12614 return "DW_CFA_nop";
12615 case DW_CFA_set_loc
:
12616 return "DW_CFA_set_loc";
12617 case DW_CFA_advance_loc1
:
12618 return "DW_CFA_advance_loc1";
12619 case DW_CFA_advance_loc2
:
12620 return "DW_CFA_advance_loc2";
12621 case DW_CFA_advance_loc4
:
12622 return "DW_CFA_advance_loc4";
12623 case DW_CFA_offset_extended
:
12624 return "DW_CFA_offset_extended";
12625 case DW_CFA_restore_extended
:
12626 return "DW_CFA_restore_extended";
12627 case DW_CFA_undefined
:
12628 return "DW_CFA_undefined";
12629 case DW_CFA_same_value
:
12630 return "DW_CFA_same_value";
12631 case DW_CFA_register
:
12632 return "DW_CFA_register";
12633 case DW_CFA_remember_state
:
12634 return "DW_CFA_remember_state";
12635 case DW_CFA_restore_state
:
12636 return "DW_CFA_restore_state";
12637 case DW_CFA_def_cfa
:
12638 return "DW_CFA_def_cfa";
12639 case DW_CFA_def_cfa_register
:
12640 return "DW_CFA_def_cfa_register";
12641 case DW_CFA_def_cfa_offset
:
12642 return "DW_CFA_def_cfa_offset";
12644 case DW_CFA_def_cfa_expression
:
12645 return "DW_CFA_def_cfa_expression";
12646 case DW_CFA_expression
:
12647 return "DW_CFA_expression";
12648 case DW_CFA_offset_extended_sf
:
12649 return "DW_CFA_offset_extended_sf";
12650 case DW_CFA_def_cfa_sf
:
12651 return "DW_CFA_def_cfa_sf";
12652 case DW_CFA_def_cfa_offset_sf
:
12653 return "DW_CFA_def_cfa_offset_sf";
12654 case DW_CFA_val_offset
:
12655 return "DW_CFA_val_offset";
12656 case DW_CFA_val_offset_sf
:
12657 return "DW_CFA_val_offset_sf";
12658 case DW_CFA_val_expression
:
12659 return "DW_CFA_val_expression";
12660 /* SGI/MIPS specific. */
12661 case DW_CFA_MIPS_advance_loc8
:
12662 return "DW_CFA_MIPS_advance_loc8";
12663 /* GNU extensions. */
12664 case DW_CFA_GNU_window_save
:
12665 return "DW_CFA_GNU_window_save";
12666 case DW_CFA_GNU_args_size
:
12667 return "DW_CFA_GNU_args_size";
12668 case DW_CFA_GNU_negative_offset_extended
:
12669 return "DW_CFA_GNU_negative_offset_extended";
12671 return "DW_CFA_<unknown>";
12677 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12681 print_spaces (indent
, f
);
12682 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12683 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12685 if (die
->parent
!= NULL
)
12687 print_spaces (indent
, f
);
12688 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12689 die
->parent
->offset
);
12692 print_spaces (indent
, f
);
12693 fprintf_unfiltered (f
, " has children: %s\n",
12694 dwarf_bool_name (die
->child
!= NULL
));
12696 print_spaces (indent
, f
);
12697 fprintf_unfiltered (f
, " attributes:\n");
12699 for (i
= 0; i
< die
->num_attrs
; ++i
)
12701 print_spaces (indent
, f
);
12702 fprintf_unfiltered (f
, " %s (%s) ",
12703 dwarf_attr_name (die
->attrs
[i
].name
),
12704 dwarf_form_name (die
->attrs
[i
].form
));
12706 switch (die
->attrs
[i
].form
)
12708 case DW_FORM_ref_addr
:
12710 fprintf_unfiltered (f
, "address: ");
12711 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12713 case DW_FORM_block2
:
12714 case DW_FORM_block4
:
12715 case DW_FORM_block
:
12716 case DW_FORM_block1
:
12717 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12719 case DW_FORM_exprloc
:
12720 fprintf_unfiltered (f
, "expression: size %u",
12721 DW_BLOCK (&die
->attrs
[i
])->size
);
12726 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12727 (long) (DW_ADDR (&die
->attrs
[i
])));
12729 case DW_FORM_data1
:
12730 case DW_FORM_data2
:
12731 case DW_FORM_data4
:
12732 case DW_FORM_data8
:
12733 case DW_FORM_udata
:
12734 case DW_FORM_sdata
:
12735 fprintf_unfiltered (f
, "constant: %s",
12736 pulongest (DW_UNSND (&die
->attrs
[i
])));
12738 case DW_FORM_sec_offset
:
12739 fprintf_unfiltered (f
, "section offset: %s",
12740 pulongest (DW_UNSND (&die
->attrs
[i
])));
12743 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12744 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12745 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12747 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12749 case DW_FORM_string
:
12751 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12752 DW_STRING (&die
->attrs
[i
])
12753 ? DW_STRING (&die
->attrs
[i
]) : "",
12754 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12757 if (DW_UNSND (&die
->attrs
[i
]))
12758 fprintf_unfiltered (f
, "flag: TRUE");
12760 fprintf_unfiltered (f
, "flag: FALSE");
12762 case DW_FORM_flag_present
:
12763 fprintf_unfiltered (f
, "flag: TRUE");
12765 case DW_FORM_indirect
:
12766 /* the reader will have reduced the indirect form to
12767 the "base form" so this form should not occur */
12768 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12771 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12772 die
->attrs
[i
].form
);
12775 fprintf_unfiltered (f
, "\n");
12780 dump_die_for_error (struct die_info
*die
)
12782 dump_die_shallow (gdb_stderr
, 0, die
);
12786 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12788 int indent
= level
* 4;
12790 gdb_assert (die
!= NULL
);
12792 if (level
>= max_level
)
12795 dump_die_shallow (f
, indent
, die
);
12797 if (die
->child
!= NULL
)
12799 print_spaces (indent
, f
);
12800 fprintf_unfiltered (f
, " Children:");
12801 if (level
+ 1 < max_level
)
12803 fprintf_unfiltered (f
, "\n");
12804 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12808 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12812 if (die
->sibling
!= NULL
&& level
> 0)
12814 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12818 /* This is called from the pdie macro in gdbinit.in.
12819 It's not static so gcc will keep a copy callable from gdb. */
12822 dump_die (struct die_info
*die
, int max_level
)
12824 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12828 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12832 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12838 is_ref_attr (struct attribute
*attr
)
12840 switch (attr
->form
)
12842 case DW_FORM_ref_addr
:
12847 case DW_FORM_ref_udata
:
12854 static unsigned int
12855 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12857 if (is_ref_attr (attr
))
12858 return DW_ADDR (attr
);
12860 complaint (&symfile_complaints
,
12861 _("unsupported die ref attribute form: '%s'"),
12862 dwarf_form_name (attr
->form
));
12866 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12867 * the value held by the attribute is not constant. */
12870 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12872 if (attr
->form
== DW_FORM_sdata
)
12873 return DW_SND (attr
);
12874 else if (attr
->form
== DW_FORM_udata
12875 || attr
->form
== DW_FORM_data1
12876 || attr
->form
== DW_FORM_data2
12877 || attr
->form
== DW_FORM_data4
12878 || attr
->form
== DW_FORM_data8
)
12879 return DW_UNSND (attr
);
12882 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12883 dwarf_form_name (attr
->form
));
12884 return default_value
;
12888 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12889 unit and add it to our queue.
12890 The result is non-zero if PER_CU was queued, otherwise the result is zero
12891 meaning either PER_CU is already queued or it is already loaded. */
12894 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12895 struct dwarf2_per_cu_data
*per_cu
)
12897 /* We may arrive here during partial symbol reading, if we need full
12898 DIEs to process an unusual case (e.g. template arguments). Do
12899 not queue PER_CU, just tell our caller to load its DIEs. */
12900 if (dwarf2_per_objfile
->reading_partial_symbols
)
12902 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12907 /* Mark the dependence relation so that we don't flush PER_CU
12909 dwarf2_add_dependence (this_cu
, per_cu
);
12911 /* If it's already on the queue, we have nothing to do. */
12912 if (per_cu
->queued
)
12915 /* If the compilation unit is already loaded, just mark it as
12917 if (per_cu
->cu
!= NULL
)
12919 per_cu
->cu
->last_used
= 0;
12923 /* Add it to the queue. */
12924 queue_comp_unit (per_cu
, this_cu
->objfile
);
12929 /* Follow reference or signature attribute ATTR of SRC_DIE.
12930 On entry *REF_CU is the CU of SRC_DIE.
12931 On exit *REF_CU is the CU of the result. */
12933 static struct die_info
*
12934 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12935 struct dwarf2_cu
**ref_cu
)
12937 struct die_info
*die
;
12939 if (is_ref_attr (attr
))
12940 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12941 else if (attr
->form
== DW_FORM_sig8
)
12942 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12945 dump_die_for_error (src_die
);
12946 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12947 (*ref_cu
)->objfile
->name
);
12953 /* Follow reference OFFSET.
12954 On entry *REF_CU is the CU of the source die referencing OFFSET.
12955 On exit *REF_CU is the CU of the result.
12956 Returns NULL if OFFSET is invalid. */
12958 static struct die_info
*
12959 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
12961 struct die_info temp_die
;
12962 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
12964 gdb_assert (cu
->per_cu
!= NULL
);
12968 if (cu
->per_cu
->from_debug_types
)
12970 /* .debug_types CUs cannot reference anything outside their CU.
12971 If they need to, they have to reference a signatured type via
12973 if (! offset_in_cu_p (&cu
->header
, offset
))
12976 else if (! offset_in_cu_p (&cu
->header
, offset
))
12978 struct dwarf2_per_cu_data
*per_cu
;
12980 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
12982 /* If necessary, add it to the queue and load its DIEs. */
12983 if (maybe_queue_comp_unit (cu
, per_cu
))
12984 load_full_comp_unit (per_cu
, cu
->objfile
);
12986 target_cu
= per_cu
->cu
;
12988 else if (cu
->dies
== NULL
)
12990 /* We're loading full DIEs during partial symbol reading. */
12991 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
12992 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
12995 *ref_cu
= target_cu
;
12996 temp_die
.offset
= offset
;
12997 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13000 /* Follow reference attribute ATTR of SRC_DIE.
13001 On entry *REF_CU is the CU of SRC_DIE.
13002 On exit *REF_CU is the CU of the result. */
13004 static struct die_info
*
13005 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13006 struct dwarf2_cu
**ref_cu
)
13008 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13009 struct dwarf2_cu
*cu
= *ref_cu
;
13010 struct die_info
*die
;
13012 die
= follow_die_offset (offset
, ref_cu
);
13014 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13015 "at 0x%x [in module %s]"),
13016 offset
, src_die
->offset
, cu
->objfile
->name
);
13021 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13022 value is intended for DW_OP_call*. */
13024 struct dwarf2_locexpr_baton
13025 dwarf2_fetch_die_location_block (unsigned int offset
,
13026 struct dwarf2_per_cu_data
*per_cu
)
13028 struct dwarf2_cu
*cu
= per_cu
->cu
;
13029 struct die_info
*die
;
13030 struct attribute
*attr
;
13031 struct dwarf2_locexpr_baton retval
;
13033 die
= follow_die_offset (offset
, &cu
);
13035 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13036 offset
, per_cu
->cu
->objfile
->name
);
13038 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13041 /* DWARF: "If there is no such attribute, then there is no effect.". */
13043 retval
.data
= NULL
;
13048 if (!attr_form_is_block (attr
))
13049 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13050 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13051 offset
, per_cu
->cu
->objfile
->name
);
13053 retval
.data
= DW_BLOCK (attr
)->data
;
13054 retval
.size
= DW_BLOCK (attr
)->size
;
13056 retval
.per_cu
= cu
->per_cu
;
13060 /* Follow the signature attribute ATTR in SRC_DIE.
13061 On entry *REF_CU is the CU of SRC_DIE.
13062 On exit *REF_CU is the CU of the result. */
13064 static struct die_info
*
13065 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13066 struct dwarf2_cu
**ref_cu
)
13068 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13069 struct die_info temp_die
;
13070 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13071 struct dwarf2_cu
*sig_cu
;
13072 struct die_info
*die
;
13074 /* sig_type will be NULL if the signatured type is missing from
13076 if (sig_type
== NULL
)
13077 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13078 "at 0x%x [in module %s]"),
13079 src_die
->offset
, objfile
->name
);
13081 /* If necessary, add it to the queue and load its DIEs. */
13083 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13084 read_signatured_type (objfile
, sig_type
);
13086 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13088 sig_cu
= sig_type
->per_cu
.cu
;
13089 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13090 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13097 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
13098 "at 0x%x [in module %s]"),
13099 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13102 /* Given an offset of a signatured type, return its signatured_type. */
13104 static struct signatured_type
*
13105 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13107 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13108 unsigned int length
, initial_length_size
;
13109 unsigned int sig_offset
;
13110 struct signatured_type find_entry
, *type_sig
;
13112 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13113 sig_offset
= (initial_length_size
13115 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13116 + 1 /*address_size*/);
13117 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13118 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13120 /* This is only used to lookup previously recorded types.
13121 If we didn't find it, it's our bug. */
13122 gdb_assert (type_sig
!= NULL
);
13123 gdb_assert (offset
== type_sig
->offset
);
13128 /* Read in signatured type at OFFSET and build its CU and die(s). */
13131 read_signatured_type_at_offset (struct objfile
*objfile
,
13132 unsigned int offset
)
13134 struct signatured_type
*type_sig
;
13136 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13138 /* We have the section offset, but we need the signature to do the
13139 hash table lookup. */
13140 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13142 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13144 read_signatured_type (objfile
, type_sig
);
13146 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13149 /* Read in a signatured type and build its CU and DIEs. */
13152 read_signatured_type (struct objfile
*objfile
,
13153 struct signatured_type
*type_sig
)
13155 gdb_byte
*types_ptr
;
13156 struct die_reader_specs reader_specs
;
13157 struct dwarf2_cu
*cu
;
13158 ULONGEST signature
;
13159 struct cleanup
*back_to
, *free_cu_cleanup
;
13160 struct attribute
*attr
;
13162 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13163 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13165 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13167 cu
= xmalloc (sizeof (struct dwarf2_cu
));
13168 memset (cu
, 0, sizeof (struct dwarf2_cu
));
13169 obstack_init (&cu
->comp_unit_obstack
);
13170 cu
->objfile
= objfile
;
13171 type_sig
->per_cu
.cu
= cu
;
13172 cu
->per_cu
= &type_sig
->per_cu
;
13174 /* If an error occurs while loading, release our storage. */
13175 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13177 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13178 types_ptr
, objfile
->obfd
);
13179 gdb_assert (signature
== type_sig
->signature
);
13182 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13186 &cu
->comp_unit_obstack
,
13187 hashtab_obstack_allocate
,
13188 dummy_obstack_deallocate
);
13190 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13191 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13193 init_cu_die_reader (&reader_specs
, cu
);
13195 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13198 /* We try not to read any attributes in this function, because not
13199 all objfiles needed for references have been loaded yet, and symbol
13200 table processing isn't initialized. But we have to set the CU language,
13201 or we won't be able to build types correctly. */
13202 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
13204 set_cu_language (DW_UNSND (attr
), cu
);
13206 set_cu_language (language_minimal
, cu
);
13208 do_cleanups (back_to
);
13210 /* We've successfully allocated this compilation unit. Let our caller
13211 clean it up when finished with it. */
13212 discard_cleanups (free_cu_cleanup
);
13214 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13215 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13218 /* Decode simple location descriptions.
13219 Given a pointer to a dwarf block that defines a location, compute
13220 the location and return the value.
13222 NOTE drow/2003-11-18: This function is called in two situations
13223 now: for the address of static or global variables (partial symbols
13224 only) and for offsets into structures which are expected to be
13225 (more or less) constant. The partial symbol case should go away,
13226 and only the constant case should remain. That will let this
13227 function complain more accurately. A few special modes are allowed
13228 without complaint for global variables (for instance, global
13229 register values and thread-local values).
13231 A location description containing no operations indicates that the
13232 object is optimized out. The return value is 0 for that case.
13233 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13234 callers will only want a very basic result and this can become a
13237 Note that stack[0] is unused except as a default error return.
13238 Note that stack overflow is not yet handled. */
13241 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13243 struct objfile
*objfile
= cu
->objfile
;
13245 int size
= blk
->size
;
13246 gdb_byte
*data
= blk
->data
;
13247 CORE_ADDR stack
[64];
13249 unsigned int bytes_read
, unsnd
;
13293 stack
[++stacki
] = op
- DW_OP_lit0
;
13328 stack
[++stacki
] = op
- DW_OP_reg0
;
13330 dwarf2_complex_location_expr_complaint ();
13334 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13336 stack
[++stacki
] = unsnd
;
13338 dwarf2_complex_location_expr_complaint ();
13342 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13347 case DW_OP_const1u
:
13348 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13352 case DW_OP_const1s
:
13353 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13357 case DW_OP_const2u
:
13358 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13362 case DW_OP_const2s
:
13363 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13367 case DW_OP_const4u
:
13368 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13372 case DW_OP_const4s
:
13373 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13378 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13384 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13389 stack
[stacki
+ 1] = stack
[stacki
];
13394 stack
[stacki
- 1] += stack
[stacki
];
13398 case DW_OP_plus_uconst
:
13399 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13404 stack
[stacki
- 1] -= stack
[stacki
];
13409 /* If we're not the last op, then we definitely can't encode
13410 this using GDB's address_class enum. This is valid for partial
13411 global symbols, although the variable's address will be bogus
13414 dwarf2_complex_location_expr_complaint ();
13417 case DW_OP_GNU_push_tls_address
:
13418 /* The top of the stack has the offset from the beginning
13419 of the thread control block at which the variable is located. */
13420 /* Nothing should follow this operator, so the top of stack would
13422 /* This is valid for partial global symbols, but the variable's
13423 address will be bogus in the psymtab. */
13425 dwarf2_complex_location_expr_complaint ();
13428 case DW_OP_GNU_uninit
:
13432 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13433 dwarf_stack_op_name (op
, 1));
13434 return (stack
[stacki
]);
13437 return (stack
[stacki
]);
13440 /* memory allocation interface */
13442 static struct dwarf_block
*
13443 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13445 struct dwarf_block
*blk
;
13447 blk
= (struct dwarf_block
*)
13448 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13452 static struct abbrev_info
*
13453 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13455 struct abbrev_info
*abbrev
;
13457 abbrev
= (struct abbrev_info
*)
13458 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13459 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13463 static struct die_info
*
13464 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13466 struct die_info
*die
;
13467 size_t size
= sizeof (struct die_info
);
13470 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13472 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13473 memset (die
, 0, sizeof (struct die_info
));
13478 /* Macro support. */
13481 /* Return the full name of file number I in *LH's file name table.
13482 Use COMP_DIR as the name of the current directory of the
13483 compilation. The result is allocated using xmalloc; the caller is
13484 responsible for freeing it. */
13486 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13488 /* Is the file number a valid index into the line header's file name
13489 table? Remember that file numbers start with one, not zero. */
13490 if (1 <= file
&& file
<= lh
->num_file_names
)
13492 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13494 if (IS_ABSOLUTE_PATH (fe
->name
))
13495 return xstrdup (fe
->name
);
13503 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13509 dir_len
= strlen (dir
);
13510 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13511 strcpy (full_name
, dir
);
13512 full_name
[dir_len
] = '/';
13513 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13517 return xstrdup (fe
->name
);
13522 /* The compiler produced a bogus file number. We can at least
13523 record the macro definitions made in the file, even if we
13524 won't be able to find the file by name. */
13525 char fake_name
[80];
13527 sprintf (fake_name
, "<bad macro file number %d>", file
);
13529 complaint (&symfile_complaints
,
13530 _("bad file number in macro information (%d)"),
13533 return xstrdup (fake_name
);
13538 static struct macro_source_file
*
13539 macro_start_file (int file
, int line
,
13540 struct macro_source_file
*current_file
,
13541 const char *comp_dir
,
13542 struct line_header
*lh
, struct objfile
*objfile
)
13544 /* The full name of this source file. */
13545 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13547 /* We don't create a macro table for this compilation unit
13548 at all until we actually get a filename. */
13549 if (! pending_macros
)
13550 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13551 objfile
->macro_cache
);
13553 if (! current_file
)
13554 /* If we have no current file, then this must be the start_file
13555 directive for the compilation unit's main source file. */
13556 current_file
= macro_set_main (pending_macros
, full_name
);
13558 current_file
= macro_include (current_file
, line
, full_name
);
13562 return current_file
;
13566 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13567 followed by a null byte. */
13569 copy_string (const char *buf
, int len
)
13571 char *s
= xmalloc (len
+ 1);
13573 memcpy (s
, buf
, len
);
13579 static const char *
13580 consume_improper_spaces (const char *p
, const char *body
)
13584 complaint (&symfile_complaints
,
13585 _("macro definition contains spaces in formal argument list:\n`%s'"),
13597 parse_macro_definition (struct macro_source_file
*file
, int line
,
13602 /* The body string takes one of two forms. For object-like macro
13603 definitions, it should be:
13605 <macro name> " " <definition>
13607 For function-like macro definitions, it should be:
13609 <macro name> "() " <definition>
13611 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13613 Spaces may appear only where explicitly indicated, and in the
13616 The Dwarf 2 spec says that an object-like macro's name is always
13617 followed by a space, but versions of GCC around March 2002 omit
13618 the space when the macro's definition is the empty string.
13620 The Dwarf 2 spec says that there should be no spaces between the
13621 formal arguments in a function-like macro's formal argument list,
13622 but versions of GCC around March 2002 include spaces after the
13626 /* Find the extent of the macro name. The macro name is terminated
13627 by either a space or null character (for an object-like macro) or
13628 an opening paren (for a function-like macro). */
13629 for (p
= body
; *p
; p
++)
13630 if (*p
== ' ' || *p
== '(')
13633 if (*p
== ' ' || *p
== '\0')
13635 /* It's an object-like macro. */
13636 int name_len
= p
- body
;
13637 char *name
= copy_string (body
, name_len
);
13638 const char *replacement
;
13641 replacement
= body
+ name_len
+ 1;
13644 dwarf2_macro_malformed_definition_complaint (body
);
13645 replacement
= body
+ name_len
;
13648 macro_define_object (file
, line
, name
, replacement
);
13652 else if (*p
== '(')
13654 /* It's a function-like macro. */
13655 char *name
= copy_string (body
, p
- body
);
13658 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13662 p
= consume_improper_spaces (p
, body
);
13664 /* Parse the formal argument list. */
13665 while (*p
&& *p
!= ')')
13667 /* Find the extent of the current argument name. */
13668 const char *arg_start
= p
;
13670 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13673 if (! *p
|| p
== arg_start
)
13674 dwarf2_macro_malformed_definition_complaint (body
);
13677 /* Make sure argv has room for the new argument. */
13678 if (argc
>= argv_size
)
13681 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13684 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13687 p
= consume_improper_spaces (p
, body
);
13689 /* Consume the comma, if present. */
13694 p
= consume_improper_spaces (p
, body
);
13703 /* Perfectly formed definition, no complaints. */
13704 macro_define_function (file
, line
, name
,
13705 argc
, (const char **) argv
,
13707 else if (*p
== '\0')
13709 /* Complain, but do define it. */
13710 dwarf2_macro_malformed_definition_complaint (body
);
13711 macro_define_function (file
, line
, name
,
13712 argc
, (const char **) argv
,
13716 /* Just complain. */
13717 dwarf2_macro_malformed_definition_complaint (body
);
13720 /* Just complain. */
13721 dwarf2_macro_malformed_definition_complaint (body
);
13727 for (i
= 0; i
< argc
; i
++)
13733 dwarf2_macro_malformed_definition_complaint (body
);
13738 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13739 char *comp_dir
, bfd
*abfd
,
13740 struct dwarf2_cu
*cu
)
13742 gdb_byte
*mac_ptr
, *mac_end
;
13743 struct macro_source_file
*current_file
= 0;
13744 enum dwarf_macinfo_record_type macinfo_type
;
13745 int at_commandline
;
13747 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13748 &dwarf2_per_objfile
->macinfo
);
13749 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13751 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13755 /* First pass: Find the name of the base filename.
13756 This filename is needed in order to process all macros whose definition
13757 (or undefinition) comes from the command line. These macros are defined
13758 before the first DW_MACINFO_start_file entry, and yet still need to be
13759 associated to the base file.
13761 To determine the base file name, we scan the macro definitions until we
13762 reach the first DW_MACINFO_start_file entry. We then initialize
13763 CURRENT_FILE accordingly so that any macro definition found before the
13764 first DW_MACINFO_start_file can still be associated to the base file. */
13766 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13767 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13768 + dwarf2_per_objfile
->macinfo
.size
;
13772 /* Do we at least have room for a macinfo type byte? */
13773 if (mac_ptr
>= mac_end
)
13775 /* Complaint is printed during the second pass as GDB will probably
13776 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13780 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13783 switch (macinfo_type
)
13785 /* A zero macinfo type indicates the end of the macro
13790 case DW_MACINFO_define
:
13791 case DW_MACINFO_undef
:
13792 /* Only skip the data by MAC_PTR. */
13794 unsigned int bytes_read
;
13796 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13797 mac_ptr
+= bytes_read
;
13798 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13799 mac_ptr
+= bytes_read
;
13803 case DW_MACINFO_start_file
:
13805 unsigned int bytes_read
;
13808 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13809 mac_ptr
+= bytes_read
;
13810 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13811 mac_ptr
+= bytes_read
;
13813 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13818 case DW_MACINFO_end_file
:
13819 /* No data to skip by MAC_PTR. */
13822 case DW_MACINFO_vendor_ext
:
13823 /* Only skip the data by MAC_PTR. */
13825 unsigned int bytes_read
;
13827 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13828 mac_ptr
+= bytes_read
;
13829 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13830 mac_ptr
+= bytes_read
;
13837 } while (macinfo_type
!= 0 && current_file
== NULL
);
13839 /* Second pass: Process all entries.
13841 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13842 command-line macro definitions/undefinitions. This flag is unset when we
13843 reach the first DW_MACINFO_start_file entry. */
13845 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13847 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13848 GDB is still reading the definitions from command line. First
13849 DW_MACINFO_start_file will need to be ignored as it was already executed
13850 to create CURRENT_FILE for the main source holding also the command line
13851 definitions. On first met DW_MACINFO_start_file this flag is reset to
13852 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13854 at_commandline
= 1;
13858 /* Do we at least have room for a macinfo type byte? */
13859 if (mac_ptr
>= mac_end
)
13861 dwarf2_macros_too_long_complaint ();
13865 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13868 switch (macinfo_type
)
13870 /* A zero macinfo type indicates the end of the macro
13875 case DW_MACINFO_define
:
13876 case DW_MACINFO_undef
:
13878 unsigned int bytes_read
;
13882 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13883 mac_ptr
+= bytes_read
;
13884 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13885 mac_ptr
+= bytes_read
;
13887 if (! current_file
)
13889 /* DWARF violation as no main source is present. */
13890 complaint (&symfile_complaints
,
13891 _("debug info with no main source gives macro %s "
13893 macinfo_type
== DW_MACINFO_define
?
13895 macinfo_type
== DW_MACINFO_undef
?
13896 _("undefinition") :
13897 _("something-or-other"), line
, body
);
13900 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13901 complaint (&symfile_complaints
,
13902 _("debug info gives %s macro %s with %s line %d: %s"),
13903 at_commandline
? _("command-line") : _("in-file"),
13904 macinfo_type
== DW_MACINFO_define
?
13906 macinfo_type
== DW_MACINFO_undef
?
13907 _("undefinition") :
13908 _("something-or-other"),
13909 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13911 if (macinfo_type
== DW_MACINFO_define
)
13912 parse_macro_definition (current_file
, line
, body
);
13913 else if (macinfo_type
== DW_MACINFO_undef
)
13914 macro_undef (current_file
, line
, body
);
13918 case DW_MACINFO_start_file
:
13920 unsigned int bytes_read
;
13923 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13924 mac_ptr
+= bytes_read
;
13925 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13926 mac_ptr
+= bytes_read
;
13928 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13929 complaint (&symfile_complaints
,
13930 _("debug info gives source %d included "
13931 "from %s at %s line %d"),
13932 file
, at_commandline
? _("command-line") : _("file"),
13933 line
== 0 ? _("zero") : _("non-zero"), line
);
13935 if (at_commandline
)
13937 /* This DW_MACINFO_start_file was executed in the pass one. */
13938 at_commandline
= 0;
13941 current_file
= macro_start_file (file
, line
,
13942 current_file
, comp_dir
,
13947 case DW_MACINFO_end_file
:
13948 if (! current_file
)
13949 complaint (&symfile_complaints
,
13950 _("macro debug info has an unmatched `close_file' directive"));
13953 current_file
= current_file
->included_by
;
13954 if (! current_file
)
13956 enum dwarf_macinfo_record_type next_type
;
13958 /* GCC circa March 2002 doesn't produce the zero
13959 type byte marking the end of the compilation
13960 unit. Complain if it's not there, but exit no
13963 /* Do we at least have room for a macinfo type byte? */
13964 if (mac_ptr
>= mac_end
)
13966 dwarf2_macros_too_long_complaint ();
13970 /* We don't increment mac_ptr here, so this is just
13972 next_type
= read_1_byte (abfd
, mac_ptr
);
13973 if (next_type
!= 0)
13974 complaint (&symfile_complaints
,
13975 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13982 case DW_MACINFO_vendor_ext
:
13984 unsigned int bytes_read
;
13988 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13989 mac_ptr
+= bytes_read
;
13990 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13991 mac_ptr
+= bytes_read
;
13993 /* We don't recognize any vendor extensions. */
13997 } while (macinfo_type
!= 0);
14000 /* Check if the attribute's form is a DW_FORM_block*
14001 if so return true else false. */
14003 attr_form_is_block (struct attribute
*attr
)
14005 return (attr
== NULL
? 0 :
14006 attr
->form
== DW_FORM_block1
14007 || attr
->form
== DW_FORM_block2
14008 || attr
->form
== DW_FORM_block4
14009 || attr
->form
== DW_FORM_block
14010 || attr
->form
== DW_FORM_exprloc
);
14013 /* Return non-zero if ATTR's value is a section offset --- classes
14014 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14015 You may use DW_UNSND (attr) to retrieve such offsets.
14017 Section 7.5.4, "Attribute Encodings", explains that no attribute
14018 may have a value that belongs to more than one of these classes; it
14019 would be ambiguous if we did, because we use the same forms for all
14022 attr_form_is_section_offset (struct attribute
*attr
)
14024 return (attr
->form
== DW_FORM_data4
14025 || attr
->form
== DW_FORM_data8
14026 || attr
->form
== DW_FORM_sec_offset
);
14030 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14031 zero otherwise. When this function returns true, you can apply
14032 dwarf2_get_attr_constant_value to it.
14034 However, note that for some attributes you must check
14035 attr_form_is_section_offset before using this test. DW_FORM_data4
14036 and DW_FORM_data8 are members of both the constant class, and of
14037 the classes that contain offsets into other debug sections
14038 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14039 that, if an attribute's can be either a constant or one of the
14040 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14041 taken as section offsets, not constants. */
14043 attr_form_is_constant (struct attribute
*attr
)
14045 switch (attr
->form
)
14047 case DW_FORM_sdata
:
14048 case DW_FORM_udata
:
14049 case DW_FORM_data1
:
14050 case DW_FORM_data2
:
14051 case DW_FORM_data4
:
14052 case DW_FORM_data8
:
14060 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14061 struct dwarf2_cu
*cu
)
14063 if (attr_form_is_section_offset (attr
)
14064 /* ".debug_loc" may not exist at all, or the offset may be outside
14065 the section. If so, fall through to the complaint in the
14067 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
14069 struct dwarf2_loclist_baton
*baton
;
14071 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14072 sizeof (struct dwarf2_loclist_baton
));
14073 baton
->per_cu
= cu
->per_cu
;
14074 gdb_assert (baton
->per_cu
);
14076 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14077 &dwarf2_per_objfile
->loc
);
14079 /* We don't know how long the location list is, but make sure we
14080 don't run off the edge of the section. */
14081 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14082 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14083 baton
->base_address
= cu
->base_address
;
14084 if (cu
->base_known
== 0)
14085 complaint (&symfile_complaints
,
14086 _("Location list used without specifying the CU base address."));
14088 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14089 SYMBOL_LOCATION_BATON (sym
) = baton
;
14093 struct dwarf2_locexpr_baton
*baton
;
14095 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14096 sizeof (struct dwarf2_locexpr_baton
));
14097 baton
->per_cu
= cu
->per_cu
;
14098 gdb_assert (baton
->per_cu
);
14100 if (attr_form_is_block (attr
))
14102 /* Note that we're just copying the block's data pointer
14103 here, not the actual data. We're still pointing into the
14104 info_buffer for SYM's objfile; right now we never release
14105 that buffer, but when we do clean up properly this may
14107 baton
->size
= DW_BLOCK (attr
)->size
;
14108 baton
->data
= DW_BLOCK (attr
)->data
;
14112 dwarf2_invalid_attrib_class_complaint ("location description",
14113 SYMBOL_NATURAL_NAME (sym
));
14115 baton
->data
= NULL
;
14118 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14119 SYMBOL_LOCATION_BATON (sym
) = baton
;
14123 /* Return the OBJFILE associated with the compilation unit CU. If CU
14124 came from a separate debuginfo file, then the master objfile is
14128 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14130 struct objfile
*objfile
= per_cu
->objfile
;
14132 /* Return the master objfile, so that we can report and look up the
14133 correct file containing this variable. */
14134 if (objfile
->separate_debug_objfile_backlink
)
14135 objfile
= objfile
->separate_debug_objfile_backlink
;
14140 /* Return the address size given in the compilation unit header for CU. */
14143 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14146 return per_cu
->cu
->header
.addr_size
;
14149 /* If the CU is not currently read in, we re-read its header. */
14150 struct objfile
*objfile
= per_cu
->objfile
;
14151 struct dwarf2_per_objfile
*per_objfile
14152 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14153 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14154 struct comp_unit_head cu_header
;
14156 memset (&cu_header
, 0, sizeof cu_header
);
14157 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14158 return cu_header
.addr_size
;
14162 /* Return the offset size given in the compilation unit header for CU. */
14165 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14168 return per_cu
->cu
->header
.offset_size
;
14171 /* If the CU is not currently read in, we re-read its header. */
14172 struct objfile
*objfile
= per_cu
->objfile
;
14173 struct dwarf2_per_objfile
*per_objfile
14174 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14175 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14176 struct comp_unit_head cu_header
;
14178 memset (&cu_header
, 0, sizeof cu_header
);
14179 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14180 return cu_header
.offset_size
;
14184 /* Return the text offset of the CU. The returned offset comes from
14185 this CU's objfile. If this objfile came from a separate debuginfo
14186 file, then the offset may be different from the corresponding
14187 offset in the parent objfile. */
14190 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14192 struct objfile
*objfile
= per_cu
->objfile
;
14194 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14197 /* Locate the .debug_info compilation unit from CU's objfile which contains
14198 the DIE at OFFSET. Raises an error on failure. */
14200 static struct dwarf2_per_cu_data
*
14201 dwarf2_find_containing_comp_unit (unsigned int offset
,
14202 struct objfile
*objfile
)
14204 struct dwarf2_per_cu_data
*this_cu
;
14208 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14211 int mid
= low
+ (high
- low
) / 2;
14213 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14218 gdb_assert (low
== high
);
14219 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14222 error (_("Dwarf Error: could not find partial DIE containing "
14223 "offset 0x%lx [in module %s]"),
14224 (long) offset
, bfd_get_filename (objfile
->obfd
));
14226 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14227 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14231 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14232 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14233 && offset
>= this_cu
->offset
+ this_cu
->length
)
14234 error (_("invalid dwarf2 offset %u"), offset
);
14235 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14240 /* Locate the compilation unit from OBJFILE which is located at exactly
14241 OFFSET. Raises an error on failure. */
14243 static struct dwarf2_per_cu_data
*
14244 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14246 struct dwarf2_per_cu_data
*this_cu
;
14248 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14249 if (this_cu
->offset
!= offset
)
14250 error (_("no compilation unit with offset %u."), offset
);
14254 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
14256 static struct dwarf2_cu
*
14257 alloc_one_comp_unit (struct objfile
*objfile
)
14259 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
14260 cu
->objfile
= objfile
;
14261 obstack_init (&cu
->comp_unit_obstack
);
14265 /* Release one cached compilation unit, CU. We unlink it from the tree
14266 of compilation units, but we don't remove it from the read_in_chain;
14267 the caller is responsible for that.
14268 NOTE: DATA is a void * because this function is also used as a
14269 cleanup routine. */
14272 free_one_comp_unit (void *data
)
14274 struct dwarf2_cu
*cu
= data
;
14276 if (cu
->per_cu
!= NULL
)
14277 cu
->per_cu
->cu
= NULL
;
14280 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14285 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14286 when we're finished with it. We can't free the pointer itself, but be
14287 sure to unlink it from the cache. Also release any associated storage
14288 and perform cache maintenance.
14290 Only used during partial symbol parsing. */
14293 free_stack_comp_unit (void *data
)
14295 struct dwarf2_cu
*cu
= data
;
14297 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14298 cu
->partial_dies
= NULL
;
14300 if (cu
->per_cu
!= NULL
)
14302 /* This compilation unit is on the stack in our caller, so we
14303 should not xfree it. Just unlink it. */
14304 cu
->per_cu
->cu
= NULL
;
14307 /* If we had a per-cu pointer, then we may have other compilation
14308 units loaded, so age them now. */
14309 age_cached_comp_units ();
14313 /* Free all cached compilation units. */
14316 free_cached_comp_units (void *data
)
14318 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14320 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14321 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14322 while (per_cu
!= NULL
)
14324 struct dwarf2_per_cu_data
*next_cu
;
14326 next_cu
= per_cu
->cu
->read_in_chain
;
14328 free_one_comp_unit (per_cu
->cu
);
14329 *last_chain
= next_cu
;
14335 /* Increase the age counter on each cached compilation unit, and free
14336 any that are too old. */
14339 age_cached_comp_units (void)
14341 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14343 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14344 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14345 while (per_cu
!= NULL
)
14347 per_cu
->cu
->last_used
++;
14348 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14349 dwarf2_mark (per_cu
->cu
);
14350 per_cu
= per_cu
->cu
->read_in_chain
;
14353 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14354 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14355 while (per_cu
!= NULL
)
14357 struct dwarf2_per_cu_data
*next_cu
;
14359 next_cu
= per_cu
->cu
->read_in_chain
;
14361 if (!per_cu
->cu
->mark
)
14363 free_one_comp_unit (per_cu
->cu
);
14364 *last_chain
= next_cu
;
14367 last_chain
= &per_cu
->cu
->read_in_chain
;
14373 /* Remove a single compilation unit from the cache. */
14376 free_one_cached_comp_unit (void *target_cu
)
14378 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14380 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14381 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14382 while (per_cu
!= NULL
)
14384 struct dwarf2_per_cu_data
*next_cu
;
14386 next_cu
= per_cu
->cu
->read_in_chain
;
14388 if (per_cu
->cu
== target_cu
)
14390 free_one_comp_unit (per_cu
->cu
);
14391 *last_chain
= next_cu
;
14395 last_chain
= &per_cu
->cu
->read_in_chain
;
14401 /* Release all extra memory associated with OBJFILE. */
14404 dwarf2_free_objfile (struct objfile
*objfile
)
14406 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14408 if (dwarf2_per_objfile
== NULL
)
14411 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14412 free_cached_comp_units (NULL
);
14414 if (dwarf2_per_objfile
->using_index
)
14418 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14421 struct dwarf2_per_cu_data
*per_cu
=
14422 dwarf2_per_objfile
->all_comp_units
[i
];
14424 if (!per_cu
->v
.quick
->lines
)
14427 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
14429 if (per_cu
->v
.quick
->file_names
)
14430 xfree ((void *) per_cu
->v
.quick
->file_names
[j
]);
14431 if (per_cu
->v
.quick
->full_names
)
14432 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
14435 free_line_header (per_cu
->v
.quick
->lines
);
14439 /* Everything else should be on the objfile obstack. */
14442 /* A pair of DIE offset and GDB type pointer. We store these
14443 in a hash table separate from the DIEs, and preserve them
14444 when the DIEs are flushed out of cache. */
14446 struct dwarf2_offset_and_type
14448 unsigned int offset
;
14452 /* Hash function for a dwarf2_offset_and_type. */
14455 offset_and_type_hash (const void *item
)
14457 const struct dwarf2_offset_and_type
*ofs
= item
;
14459 return ofs
->offset
;
14462 /* Equality function for a dwarf2_offset_and_type. */
14465 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14467 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14468 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14470 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14473 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14474 table if necessary. For convenience, return TYPE.
14476 The DIEs reading must have careful ordering to:
14477 * Not cause infite loops trying to read in DIEs as a prerequisite for
14478 reading current DIE.
14479 * Not trying to dereference contents of still incompletely read in types
14480 while reading in other DIEs.
14481 * Enable referencing still incompletely read in types just by a pointer to
14482 the type without accessing its fields.
14484 Therefore caller should follow these rules:
14485 * Try to fetch any prerequisite types we may need to build this DIE type
14486 before building the type and calling set_die_type.
14487 * After building type call set_die_type for current DIE as soon as
14488 possible before fetching more types to complete the current type.
14489 * Make the type as complete as possible before fetching more types. */
14491 static struct type
*
14492 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14494 struct dwarf2_offset_and_type
**slot
, ofs
;
14495 struct objfile
*objfile
= cu
->objfile
;
14496 htab_t
*type_hash_ptr
;
14498 /* For Ada types, make sure that the gnat-specific data is always
14499 initialized (if not already set). There are a few types where
14500 we should not be doing so, because the type-specific area is
14501 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14502 where the type-specific area is used to store the floatformat).
14503 But this is not a problem, because the gnat-specific information
14504 is actually not needed for these types. */
14505 if (need_gnat_info (cu
)
14506 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14507 && TYPE_CODE (type
) != TYPE_CODE_FLT
14508 && !HAVE_GNAT_AUX_INFO (type
))
14509 INIT_GNAT_SPECIFIC (type
);
14511 if (cu
->per_cu
->from_debug_types
)
14512 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14514 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14516 if (*type_hash_ptr
== NULL
)
14519 = htab_create_alloc_ex (127,
14520 offset_and_type_hash
,
14521 offset_and_type_eq
,
14523 &objfile
->objfile_obstack
,
14524 hashtab_obstack_allocate
,
14525 dummy_obstack_deallocate
);
14528 ofs
.offset
= die
->offset
;
14530 slot
= (struct dwarf2_offset_and_type
**)
14531 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14533 complaint (&symfile_complaints
,
14534 _("A problem internal to GDB: DIE 0x%x has type already set"),
14536 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14541 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14542 table, or return NULL if the die does not have a saved type. */
14544 static struct type
*
14545 get_die_type_at_offset (unsigned int offset
,
14546 struct dwarf2_per_cu_data
*per_cu
)
14548 struct dwarf2_offset_and_type
*slot
, ofs
;
14551 if (per_cu
->from_debug_types
)
14552 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14554 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14555 if (type_hash
== NULL
)
14558 ofs
.offset
= offset
;
14559 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14566 /* Look up the type for DIE in the appropriate type_hash table,
14567 or return NULL if DIE does not have a saved type. */
14569 static struct type
*
14570 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14572 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14575 /* Add a dependence relationship from CU to REF_PER_CU. */
14578 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14579 struct dwarf2_per_cu_data
*ref_per_cu
)
14583 if (cu
->dependencies
== NULL
)
14585 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14586 NULL
, &cu
->comp_unit_obstack
,
14587 hashtab_obstack_allocate
,
14588 dummy_obstack_deallocate
);
14590 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14592 *slot
= ref_per_cu
;
14595 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14596 Set the mark field in every compilation unit in the
14597 cache that we must keep because we are keeping CU. */
14600 dwarf2_mark_helper (void **slot
, void *data
)
14602 struct dwarf2_per_cu_data
*per_cu
;
14604 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14605 if (per_cu
->cu
->mark
)
14607 per_cu
->cu
->mark
= 1;
14609 if (per_cu
->cu
->dependencies
!= NULL
)
14610 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14615 /* Set the mark field in CU and in every other compilation unit in the
14616 cache that we must keep because we are keeping CU. */
14619 dwarf2_mark (struct dwarf2_cu
*cu
)
14624 if (cu
->dependencies
!= NULL
)
14625 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14629 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14633 per_cu
->cu
->mark
= 0;
14634 per_cu
= per_cu
->cu
->read_in_chain
;
14638 /* Trivial hash function for partial_die_info: the hash value of a DIE
14639 is its offset in .debug_info for this objfile. */
14642 partial_die_hash (const void *item
)
14644 const struct partial_die_info
*part_die
= item
;
14646 return part_die
->offset
;
14649 /* Trivial comparison function for partial_die_info structures: two DIEs
14650 are equal if they have the same offset. */
14653 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14655 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14656 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14658 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14661 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14662 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14665 set_dwarf2_cmd (char *args
, int from_tty
)
14667 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14671 show_dwarf2_cmd (char *args
, int from_tty
)
14673 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14676 /* If section described by INFO was mmapped, munmap it now. */
14679 munmap_section_buffer (struct dwarf2_section_info
*info
)
14681 if (info
->was_mmapped
)
14684 intptr_t begin
= (intptr_t) info
->buffer
;
14685 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14686 size_t map_length
= info
->size
+ begin
- map_begin
;
14688 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14690 /* Without HAVE_MMAP, we should never be here to begin with. */
14691 gdb_assert_not_reached ("no mmap support");
14696 /* munmap debug sections for OBJFILE, if necessary. */
14699 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14701 struct dwarf2_per_objfile
*data
= d
;
14703 /* This is sorted according to the order they're defined in to make it easier
14704 to keep in sync. */
14705 munmap_section_buffer (&data
->info
);
14706 munmap_section_buffer (&data
->abbrev
);
14707 munmap_section_buffer (&data
->line
);
14708 munmap_section_buffer (&data
->loc
);
14709 munmap_section_buffer (&data
->macinfo
);
14710 munmap_section_buffer (&data
->str
);
14711 munmap_section_buffer (&data
->ranges
);
14712 munmap_section_buffer (&data
->types
);
14713 munmap_section_buffer (&data
->frame
);
14714 munmap_section_buffer (&data
->eh_frame
);
14715 munmap_section_buffer (&data
->gdb_index
);
14720 /* The contents of the hash table we create when building the string
14722 struct strtab_entry
14724 offset_type offset
;
14728 /* Hash function for a strtab_entry. */
14730 hash_strtab_entry (const void *e
)
14732 const struct strtab_entry
*entry
= e
;
14733 return mapped_index_string_hash (entry
->str
);
14736 /* Equality function for a strtab_entry. */
14738 eq_strtab_entry (const void *a
, const void *b
)
14740 const struct strtab_entry
*ea
= a
;
14741 const struct strtab_entry
*eb
= b
;
14742 return !strcmp (ea
->str
, eb
->str
);
14745 /* Create a strtab_entry hash table. */
14747 create_strtab (void)
14749 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14750 xfree
, xcalloc
, xfree
);
14753 /* Add a string to the constant pool. Return the string's offset in
14756 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14759 struct strtab_entry entry
;
14760 struct strtab_entry
*result
;
14763 slot
= htab_find_slot (table
, &entry
, INSERT
);
14768 result
= XNEW (struct strtab_entry
);
14769 result
->offset
= obstack_object_size (cpool
);
14771 obstack_grow_str0 (cpool
, str
);
14774 return result
->offset
;
14777 /* An entry in the symbol table. */
14778 struct symtab_index_entry
14780 /* The name of the symbol. */
14782 /* The offset of the name in the constant pool. */
14783 offset_type index_offset
;
14784 /* A sorted vector of the indices of all the CUs that hold an object
14786 VEC (offset_type
) *cu_indices
;
14789 /* The symbol table. This is a power-of-2-sized hash table. */
14790 struct mapped_symtab
14792 offset_type n_elements
;
14794 struct symtab_index_entry
**data
;
14797 /* Hash function for a symtab_index_entry. */
14799 hash_symtab_entry (const void *e
)
14801 const struct symtab_index_entry
*entry
= e
;
14802 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14803 sizeof (offset_type
) * VEC_length (offset_type
,
14804 entry
->cu_indices
),
14808 /* Equality function for a symtab_index_entry. */
14810 eq_symtab_entry (const void *a
, const void *b
)
14812 const struct symtab_index_entry
*ea
= a
;
14813 const struct symtab_index_entry
*eb
= b
;
14814 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14815 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14817 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14818 VEC_address (offset_type
, eb
->cu_indices
),
14819 sizeof (offset_type
) * len
);
14822 /* Destroy a symtab_index_entry. */
14824 delete_symtab_entry (void *p
)
14826 struct symtab_index_entry
*entry
= p
;
14827 VEC_free (offset_type
, entry
->cu_indices
);
14831 /* Create a hash table holding symtab_index_entry objects. */
14833 create_index_table (void)
14835 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14836 delete_symtab_entry
, xcalloc
, xfree
);
14839 /* Create a new mapped symtab object. */
14840 static struct mapped_symtab
*
14841 create_mapped_symtab (void)
14843 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14844 symtab
->n_elements
= 0;
14845 symtab
->size
= 1024;
14846 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14850 /* Destroy a mapped_symtab. */
14852 cleanup_mapped_symtab (void *p
)
14854 struct mapped_symtab
*symtab
= p
;
14855 /* The contents of the array are freed when the other hash table is
14857 xfree (symtab
->data
);
14861 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14863 static struct symtab_index_entry
**
14864 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14866 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14868 index
= hash
& (symtab
->size
- 1);
14869 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14873 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14874 return &symtab
->data
[index
];
14875 index
= (index
+ step
) & (symtab
->size
- 1);
14879 /* Expand SYMTAB's hash table. */
14881 hash_expand (struct mapped_symtab
*symtab
)
14883 offset_type old_size
= symtab
->size
;
14885 struct symtab_index_entry
**old_entries
= symtab
->data
;
14888 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14890 for (i
= 0; i
< old_size
; ++i
)
14892 if (old_entries
[i
])
14894 struct symtab_index_entry
**slot
= find_slot (symtab
,
14895 old_entries
[i
]->name
);
14896 *slot
= old_entries
[i
];
14900 xfree (old_entries
);
14903 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14904 is the index of the CU in which the symbol appears. */
14906 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
14907 offset_type cu_index
)
14909 struct symtab_index_entry
**slot
;
14911 ++symtab
->n_elements
;
14912 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
14913 hash_expand (symtab
);
14915 slot
= find_slot (symtab
, name
);
14918 *slot
= XNEW (struct symtab_index_entry
);
14919 (*slot
)->name
= name
;
14920 (*slot
)->cu_indices
= NULL
;
14922 /* Don't push an index twice. Due to how we add entries we only
14923 have to check the last one. */
14924 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
14925 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
14926 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
14929 /* Add a vector of indices to the constant pool. */
14931 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
14932 struct symtab_index_entry
*entry
)
14936 slot
= htab_find_slot (index_table
, entry
, INSERT
);
14939 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
14940 offset_type val
= MAYBE_SWAP (len
);
14945 entry
->index_offset
= obstack_object_size (cpool
);
14947 obstack_grow (cpool
, &val
, sizeof (val
));
14949 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
14952 val
= MAYBE_SWAP (iter
);
14953 obstack_grow (cpool
, &val
, sizeof (val
));
14958 struct symtab_index_entry
*old_entry
= *slot
;
14959 entry
->index_offset
= old_entry
->index_offset
;
14962 return entry
->index_offset
;
14965 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14966 constant pool entries going into the obstack CPOOL. */
14968 write_hash_table (struct mapped_symtab
*symtab
,
14969 struct obstack
*output
, struct obstack
*cpool
)
14972 htab_t index_table
;
14975 index_table
= create_index_table ();
14976 str_table
= create_strtab ();
14977 /* We add all the index vectors to the constant pool first, to
14978 ensure alignment is ok. */
14979 for (i
= 0; i
< symtab
->size
; ++i
)
14981 if (symtab
->data
[i
])
14982 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
14985 /* Now write out the hash table. */
14986 for (i
= 0; i
< symtab
->size
; ++i
)
14988 offset_type str_off
, vec_off
;
14990 if (symtab
->data
[i
])
14992 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
14993 vec_off
= symtab
->data
[i
]->index_offset
;
14997 /* While 0 is a valid constant pool index, it is not valid
14998 to have 0 for both offsets. */
15003 str_off
= MAYBE_SWAP (str_off
);
15004 vec_off
= MAYBE_SWAP (vec_off
);
15006 obstack_grow (output
, &str_off
, sizeof (str_off
));
15007 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15010 htab_delete (str_table
);
15011 htab_delete (index_table
);
15014 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
15015 from PST; CU_INDEX is the index of the CU in the vector of all
15018 add_address_entry (struct objfile
*objfile
,
15019 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
15020 unsigned int cu_index
)
15022 offset_type offset
;
15024 CORE_ADDR baseaddr
;
15026 /* Don't bother recording empty ranges. */
15027 if (pst
->textlow
== pst
->texthigh
)
15030 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15032 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
15033 obstack_grow (addr_obstack
, addr
, 8);
15034 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
15035 obstack_grow (addr_obstack
, addr
, 8);
15036 offset
= MAYBE_SWAP (cu_index
);
15037 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
15040 /* Add a list of partial symbols to SYMTAB. */
15042 write_psymbols (struct mapped_symtab
*symtab
,
15044 struct partial_symbol
**psymp
,
15046 offset_type cu_index
,
15049 for (; count
-- > 0; ++psymp
)
15051 void **slot
, *lookup
;
15053 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15054 error (_("Ada is not currently supported by the index"));
15056 /* We only want to add a given psymbol once. However, we also
15057 want to account for whether it is global or static. So, we
15058 may add it twice, using slightly different values. */
15061 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15063 lookup
= (void *) val
;
15068 /* Only add a given psymbol once. */
15069 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15073 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15078 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15079 exception if there is an error. */
15081 write_obstack (FILE *file
, struct obstack
*obstack
)
15083 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15085 != obstack_object_size (obstack
))
15086 error (_("couldn't data write to file"));
15089 /* Unlink a file if the argument is not NULL. */
15091 unlink_if_set (void *p
)
15093 char **filename
= p
;
15095 unlink (*filename
);
15098 /* A helper struct used when iterating over debug_types. */
15099 struct signatured_type_index_data
15101 struct objfile
*objfile
;
15102 struct mapped_symtab
*symtab
;
15103 struct obstack
*types_list
;
15108 /* A helper function that writes a single signatured_type to an
15111 write_one_signatured_type (void **slot
, void *d
)
15113 struct signatured_type_index_data
*info
= d
;
15114 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15115 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15116 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15119 write_psymbols (info
->symtab
,
15121 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15122 psymtab
->n_global_syms
, info
->cu_index
,
15124 write_psymbols (info
->symtab
,
15126 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15127 psymtab
->n_static_syms
, info
->cu_index
,
15130 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15131 obstack_grow (info
->types_list
, val
, 8);
15132 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15133 obstack_grow (info
->types_list
, val
, 8);
15134 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15135 obstack_grow (info
->types_list
, val
, 8);
15142 /* A cleanup function for an htab_t. */
15145 cleanup_htab (void *arg
)
15150 /* Create an index file for OBJFILE in the directory DIR. */
15152 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15154 struct cleanup
*cleanup
;
15155 char *filename
, *cleanup_filename
;
15156 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15157 struct obstack cu_list
, types_cu_list
;
15160 struct mapped_symtab
*symtab
;
15161 offset_type val
, size_of_contents
, total_len
;
15166 if (!objfile
->psymtabs
)
15168 if (dwarf2_per_objfile
->using_index
)
15169 error (_("Cannot use an index to create the index"));
15171 if (stat (objfile
->name
, &st
) < 0)
15172 perror_with_name (_("Could not stat"));
15174 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15175 INDEX_SUFFIX
, (char *) NULL
);
15176 cleanup
= make_cleanup (xfree
, filename
);
15178 out_file
= fopen (filename
, "wb");
15180 error (_("Can't open `%s' for writing"), filename
);
15182 cleanup_filename
= filename
;
15183 make_cleanup (unlink_if_set
, &cleanup_filename
);
15185 symtab
= create_mapped_symtab ();
15186 make_cleanup (cleanup_mapped_symtab
, symtab
);
15188 obstack_init (&addr_obstack
);
15189 make_cleanup_obstack_free (&addr_obstack
);
15191 obstack_init (&cu_list
);
15192 make_cleanup_obstack_free (&cu_list
);
15194 obstack_init (&types_cu_list
);
15195 make_cleanup_obstack_free (&types_cu_list
);
15197 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15198 NULL
, xcalloc
, xfree
);
15199 make_cleanup (cleanup_htab
, psyms_seen
);
15201 /* The list is already sorted, so we don't need to do additional
15202 work here. Also, the debug_types entries do not appear in
15203 all_comp_units, but only in their own hash table. */
15204 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15206 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15207 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15210 write_psymbols (symtab
,
15212 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15213 psymtab
->n_global_syms
, i
,
15215 write_psymbols (symtab
,
15217 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15218 psymtab
->n_static_syms
, i
,
15221 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
15223 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15224 obstack_grow (&cu_list
, val
, 8);
15225 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15226 obstack_grow (&cu_list
, val
, 8);
15229 /* Write out the .debug_type entries, if any. */
15230 if (dwarf2_per_objfile
->signatured_types
)
15232 struct signatured_type_index_data sig_data
;
15234 sig_data
.objfile
= objfile
;
15235 sig_data
.symtab
= symtab
;
15236 sig_data
.types_list
= &types_cu_list
;
15237 sig_data
.psyms_seen
= psyms_seen
;
15238 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15239 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15240 write_one_signatured_type
, &sig_data
);
15243 obstack_init (&constant_pool
);
15244 make_cleanup_obstack_free (&constant_pool
);
15245 obstack_init (&symtab_obstack
);
15246 make_cleanup_obstack_free (&symtab_obstack
);
15247 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15249 obstack_init (&contents
);
15250 make_cleanup_obstack_free (&contents
);
15251 size_of_contents
= 6 * sizeof (offset_type
);
15252 total_len
= size_of_contents
;
15254 /* The version number. */
15255 val
= MAYBE_SWAP (3);
15256 obstack_grow (&contents
, &val
, sizeof (val
));
15258 /* The offset of the CU list from the start of the file. */
15259 val
= MAYBE_SWAP (total_len
);
15260 obstack_grow (&contents
, &val
, sizeof (val
));
15261 total_len
+= obstack_object_size (&cu_list
);
15263 /* The offset of the types CU list from the start of the file. */
15264 val
= MAYBE_SWAP (total_len
);
15265 obstack_grow (&contents
, &val
, sizeof (val
));
15266 total_len
+= obstack_object_size (&types_cu_list
);
15268 /* The offset of the address table from the start of the file. */
15269 val
= MAYBE_SWAP (total_len
);
15270 obstack_grow (&contents
, &val
, sizeof (val
));
15271 total_len
+= obstack_object_size (&addr_obstack
);
15273 /* The offset of the symbol table from the start of the file. */
15274 val
= MAYBE_SWAP (total_len
);
15275 obstack_grow (&contents
, &val
, sizeof (val
));
15276 total_len
+= obstack_object_size (&symtab_obstack
);
15278 /* The offset of the constant pool from the start of the file. */
15279 val
= MAYBE_SWAP (total_len
);
15280 obstack_grow (&contents
, &val
, sizeof (val
));
15281 total_len
+= obstack_object_size (&constant_pool
);
15283 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15285 write_obstack (out_file
, &contents
);
15286 write_obstack (out_file
, &cu_list
);
15287 write_obstack (out_file
, &types_cu_list
);
15288 write_obstack (out_file
, &addr_obstack
);
15289 write_obstack (out_file
, &symtab_obstack
);
15290 write_obstack (out_file
, &constant_pool
);
15294 /* We want to keep the file, so we set cleanup_filename to NULL
15295 here. See unlink_if_set. */
15296 cleanup_filename
= NULL
;
15298 do_cleanups (cleanup
);
15301 /* The mapped index file format is designed to be directly mmap()able
15302 on any architecture. In most cases, a datum is represented using a
15303 little-endian 32-bit integer value, called an offset_type. Big
15304 endian machines must byte-swap the values before using them.
15305 Exceptions to this rule are noted. The data is laid out such that
15306 alignment is always respected.
15308 A mapped index consists of several sections.
15310 1. The file header. This is a sequence of values, of offset_type
15311 unless otherwise noted:
15313 [0] The version number, currently 3. Versions 1 and 2 are
15315 [1] The offset, from the start of the file, of the CU list.
15316 [2] The offset, from the start of the file, of the types CU list.
15317 Note that this section can be empty, in which case this offset will
15318 be equal to the next offset.
15319 [3] The offset, from the start of the file, of the address section.
15320 [4] The offset, from the start of the file, of the symbol table.
15321 [5] The offset, from the start of the file, of the constant pool.
15323 2. The CU list. This is a sequence of pairs of 64-bit
15324 little-endian values, sorted by the CU offset. The first element
15325 in each pair is the offset of a CU in the .debug_info section. The
15326 second element in each pair is the length of that CU. References
15327 to a CU elsewhere in the map are done using a CU index, which is
15328 just the 0-based index into this table. Note that if there are
15329 type CUs, then conceptually CUs and type CUs form a single list for
15330 the purposes of CU indices.
15332 3. The types CU list. This is a sequence of triplets of 64-bit
15333 little-endian values. In a triplet, the first value is the CU
15334 offset, the second value is the type offset in the CU, and the
15335 third value is the type signature. The types CU list is not
15338 4. The address section. The address section consists of a sequence
15339 of address entries. Each address entry has three elements.
15340 [0] The low address. This is a 64-bit little-endian value.
15341 [1] The high address. This is a 64-bit little-endian value.
15342 [2] The CU index. This is an offset_type value.
15344 5. The symbol table. This is a hash table. The size of the hash
15345 table is always a power of 2. The initial hash and the step are
15346 currently defined by the `find_slot' function.
15348 Each slot in the hash table consists of a pair of offset_type
15349 values. The first value is the offset of the symbol's name in the
15350 constant pool. The second value is the offset of the CU vector in
15353 If both values are 0, then this slot in the hash table is empty.
15354 This is ok because while 0 is a valid constant pool index, it
15355 cannot be a valid index for both a string and a CU vector.
15357 A string in the constant pool is stored as a \0-terminated string,
15360 A CU vector in the constant pool is a sequence of offset_type
15361 values. The first value is the number of CU indices in the vector.
15362 Each subsequent value is the index of a CU in the CU list. This
15363 element in the hash table is used to indicate which CUs define the
15366 6. The constant pool. This is simply a bunch of bytes. It is
15367 organized so that alignment is correct: CU vectors are stored
15368 first, followed by strings. */
15370 save_gdb_index_command (char *arg
, int from_tty
)
15372 struct objfile
*objfile
;
15375 error (_("usage: save gdb-index DIRECTORY"));
15377 ALL_OBJFILES (objfile
)
15381 /* If the objfile does not correspond to an actual file, skip it. */
15382 if (stat (objfile
->name
, &st
) < 0)
15385 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15386 if (dwarf2_per_objfile
)
15388 volatile struct gdb_exception except
;
15390 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15392 write_psymtabs_to_index (objfile
, arg
);
15394 if (except
.reason
< 0)
15395 exception_fprintf (gdb_stderr
, except
,
15396 _("Error while writing index for `%s': "),
15404 int dwarf2_always_disassemble
;
15407 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15408 struct cmd_list_element
*c
, const char *value
)
15410 fprintf_filtered (file
, _("\
15411 Whether to always disassemble DWARF expressions is %s.\n"),
15415 void _initialize_dwarf2_read (void);
15418 _initialize_dwarf2_read (void)
15420 struct cmd_list_element
*c
;
15422 dwarf2_objfile_data_key
15423 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15425 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15426 Set DWARF 2 specific variables.\n\
15427 Configure DWARF 2 variables such as the cache size"),
15428 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15429 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15431 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15432 Show DWARF 2 specific variables\n\
15433 Show DWARF 2 variables such as the cache size"),
15434 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15435 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15437 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15438 &dwarf2_max_cache_age
, _("\
15439 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15440 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15441 A higher limit means that cached compilation units will be stored\n\
15442 in memory longer, and more total memory will be used. Zero disables\n\
15443 caching, which can slow down startup."),
15445 show_dwarf2_max_cache_age
,
15446 &set_dwarf2_cmdlist
,
15447 &show_dwarf2_cmdlist
);
15449 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15450 &dwarf2_always_disassemble
, _("\
15451 Set whether `info address' always disassembles DWARF expressions."), _("\
15452 Show whether `info address' always disassembles DWARF expressions."), _("\
15453 When enabled, DWARF expressions are always printed in an assembly-like\n\
15454 syntax. When disabled, expressions will be printed in a more\n\
15455 conversational style, when possible."),
15457 show_dwarf2_always_disassemble
,
15458 &set_dwarf2_cmdlist
,
15459 &show_dwarf2_cmdlist
);
15461 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15462 Set debugging of the dwarf2 DIE reader."), _("\
15463 Show debugging of the dwarf2 DIE reader."), _("\
15464 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15465 The value is the maximum depth to print."),
15468 &setdebuglist
, &showdebuglist
);
15470 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15471 _("Save a .gdb-index file"),
15473 set_cmd_completer (c
, filename_completer
);