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 symbol table, implemented as a hash table. */
158 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_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
*, const char *, bfd
*,
1011 struct dwarf2_cu
*, struct partial_symtab
*);
1013 static void dwarf2_start_subfile (char *, const char *, const 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
1643 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1644 struct dwarf2_per_cu_data
*per_cu
)
1646 struct cleanup
*back_to
;
1648 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1650 queue_comp_unit (per_cu
, objfile
);
1652 if (per_cu
->from_debug_types
)
1653 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1655 load_full_comp_unit (per_cu
, objfile
);
1657 process_queue (objfile
);
1659 /* Age the cache, releasing compilation units that have not
1660 been used recently. */
1661 age_cached_comp_units ();
1663 do_cleanups (back_to
);
1666 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1667 the objfile from which this CU came. Returns the resulting symbol
1670 static struct symtab
*
1671 dw2_instantiate_symtab (struct objfile
*objfile
,
1672 struct dwarf2_per_cu_data
*per_cu
)
1674 if (!per_cu
->v
.quick
->symtab
)
1676 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1677 increment_reading_symtab ();
1678 dw2_do_instantiate_symtab (objfile
, per_cu
);
1679 do_cleanups (back_to
);
1681 return per_cu
->v
.quick
->symtab
;
1684 /* Return the CU given its index. */
1686 static struct dwarf2_per_cu_data
*
1687 dw2_get_cu (int index
)
1689 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1691 index
-= dwarf2_per_objfile
->n_comp_units
;
1692 return dwarf2_per_objfile
->type_comp_units
[index
];
1694 return dwarf2_per_objfile
->all_comp_units
[index
];
1697 /* A helper function that knows how to read a 64-bit value in a way
1698 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1702 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1704 if (sizeof (ULONGEST
) < 8)
1708 /* Ignore the upper 4 bytes if they are all zero. */
1709 for (i
= 0; i
< 4; ++i
)
1710 if (bytes
[i
+ 4] != 0)
1713 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1716 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1720 /* Read the CU list from the mapped index, and use it to create all
1721 the CU objects for this objfile. Return 0 if something went wrong,
1722 1 if everything went ok. */
1725 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1726 offset_type cu_list_elements
)
1730 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1731 dwarf2_per_objfile
->all_comp_units
1732 = obstack_alloc (&objfile
->objfile_obstack
,
1733 dwarf2_per_objfile
->n_comp_units
1734 * sizeof (struct dwarf2_per_cu_data
*));
1736 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1738 struct dwarf2_per_cu_data
*the_cu
;
1739 ULONGEST offset
, length
;
1741 if (!extract_cu_value (cu_list
, &offset
)
1742 || !extract_cu_value (cu_list
+ 8, &length
))
1746 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1747 struct dwarf2_per_cu_data
);
1748 the_cu
->offset
= offset
;
1749 the_cu
->length
= length
;
1750 the_cu
->objfile
= objfile
;
1751 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1752 struct dwarf2_per_cu_quick_data
);
1753 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1759 /* Create the signatured type hash table from the index. */
1762 create_signatured_type_table_from_index (struct objfile
*objfile
,
1763 const gdb_byte
*bytes
,
1764 offset_type elements
)
1767 htab_t sig_types_hash
;
1769 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1770 dwarf2_per_objfile
->type_comp_units
1771 = obstack_alloc (&objfile
->objfile_obstack
,
1772 dwarf2_per_objfile
->n_type_comp_units
1773 * sizeof (struct dwarf2_per_cu_data
*));
1775 sig_types_hash
= allocate_signatured_type_table (objfile
);
1777 for (i
= 0; i
< elements
; i
+= 3)
1779 struct signatured_type
*type_sig
;
1780 ULONGEST offset
, type_offset
, signature
;
1783 if (!extract_cu_value (bytes
, &offset
)
1784 || !extract_cu_value (bytes
+ 8, &type_offset
))
1786 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1789 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1790 struct signatured_type
);
1791 type_sig
->signature
= signature
;
1792 type_sig
->offset
= offset
;
1793 type_sig
->type_offset
= type_offset
;
1794 type_sig
->per_cu
.from_debug_types
= 1;
1795 type_sig
->per_cu
.offset
= offset
;
1796 type_sig
->per_cu
.objfile
= objfile
;
1797 type_sig
->per_cu
.v
.quick
1798 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1799 struct dwarf2_per_cu_quick_data
);
1801 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1804 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1807 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1812 /* Read the address map data from the mapped index, and use it to
1813 populate the objfile's psymtabs_addrmap. */
1816 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1818 const gdb_byte
*iter
, *end
;
1819 struct obstack temp_obstack
;
1820 struct addrmap
*mutable_map
;
1821 struct cleanup
*cleanup
;
1824 obstack_init (&temp_obstack
);
1825 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1826 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1828 iter
= index
->address_table
;
1829 end
= iter
+ index
->address_table_size
;
1831 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1835 ULONGEST hi
, lo
, cu_index
;
1836 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1838 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1840 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1843 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1844 dw2_get_cu (cu_index
));
1847 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1848 &objfile
->objfile_obstack
);
1849 do_cleanups (cleanup
);
1852 /* The hash function for strings in the mapped index. This is the
1853 same as the hashtab.c hash function, but we keep a separate copy to
1854 maintain control over the implementation. This is necessary
1855 because the hash function is tied to the format of the mapped index
1859 mapped_index_string_hash (const void *p
)
1861 const unsigned char *str
= (const unsigned char *) p
;
1865 while ((c
= *str
++) != 0)
1866 r
= r
* 67 + c
- 113;
1871 /* Find a slot in the mapped index INDEX for the object named NAME.
1872 If NAME is found, set *VEC_OUT to point to the CU vector in the
1873 constant pool and return 1. If NAME cannot be found, return 0. */
1876 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1877 offset_type
**vec_out
)
1879 offset_type hash
= mapped_index_string_hash (name
);
1880 offset_type slot
, step
;
1882 slot
= hash
& (index
->symbol_table_slots
- 1);
1883 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
1887 /* Convert a slot number to an offset into the table. */
1888 offset_type i
= 2 * slot
;
1890 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
1893 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
1894 if (!strcmp (name
, str
))
1896 *vec_out
= (offset_type
*) (index
->constant_pool
1897 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
1901 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
1905 /* Read the index file. If everything went ok, initialize the "quick"
1906 elements of all the CUs and return 1. Otherwise, return 0. */
1909 dwarf2_read_index (struct objfile
*objfile
)
1912 struct mapped_index
*map
;
1913 offset_type
*metadata
;
1914 const gdb_byte
*cu_list
;
1915 const gdb_byte
*types_list
= NULL
;
1916 offset_type version
, cu_list_elements
;
1917 offset_type types_list_elements
= 0;
1920 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1921 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1924 /* Older elfutils strip versions could keep the section in the main
1925 executable while splitting it for the separate debug info file. */
1926 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
1927 & SEC_HAS_CONTENTS
) == 0)
1930 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1932 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1933 /* Version check. */
1934 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1935 /* Versions earlier than 3 emitted every copy of a psymbol. This
1936 causes the index to behave very poorly for certain requests. So,
1937 it seems better to just ignore such indices. */
1941 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1942 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1944 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1947 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1948 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1952 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1953 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1954 - MAYBE_SWAP (metadata
[i
]))
1958 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1959 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1960 - MAYBE_SWAP (metadata
[i
]));
1963 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1964 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1965 - MAYBE_SWAP (metadata
[i
]))
1966 / (2 * sizeof (offset_type
)));
1969 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1971 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1974 if (types_list_elements
1975 && !create_signatured_type_table_from_index (objfile
, types_list
,
1976 types_list_elements
))
1979 create_addrmap_from_index (objfile
, map
);
1981 dwarf2_per_objfile
->index_table
= map
;
1982 dwarf2_per_objfile
->using_index
= 1;
1987 /* A helper for the "quick" functions which sets the global
1988 dwarf2_per_objfile according to OBJFILE. */
1991 dw2_setup (struct objfile
*objfile
)
1993 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1994 gdb_assert (dwarf2_per_objfile
);
1997 /* A helper for the "quick" functions which attempts to read the line
1998 table for THIS_CU. */
2001 dw2_require_line_header (struct objfile
*objfile
,
2002 struct dwarf2_per_cu_data
*this_cu
)
2004 bfd
*abfd
= objfile
->obfd
;
2005 struct line_header
*lh
= NULL
;
2006 struct attribute
*attr
;
2007 struct cleanup
*cleanups
;
2008 struct die_info
*comp_unit_die
;
2009 struct dwarf2_section_info
* sec
;
2010 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2011 int has_children
, i
;
2012 struct dwarf2_cu cu
;
2013 unsigned int bytes_read
, buffer_size
;
2014 struct die_reader_specs reader_specs
;
2015 char *name
, *comp_dir
;
2017 if (this_cu
->v
.quick
->read_lines
)
2019 this_cu
->v
.quick
->read_lines
= 1;
2021 memset (&cu
, 0, sizeof (cu
));
2022 cu
.objfile
= objfile
;
2023 obstack_init (&cu
.comp_unit_obstack
);
2025 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2027 if (this_cu
->from_debug_types
)
2028 sec
= &dwarf2_per_objfile
->types
;
2030 sec
= &dwarf2_per_objfile
->info
;
2031 dwarf2_read_section (objfile
, sec
);
2032 buffer_size
= sec
->size
;
2033 buffer
= sec
->buffer
;
2034 info_ptr
= buffer
+ this_cu
->offset
;
2035 beg_of_comp_unit
= info_ptr
;
2037 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2038 buffer
, buffer_size
,
2041 /* Complete the cu_header. */
2042 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2043 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2046 cu
.per_cu
= this_cu
;
2048 dwarf2_read_abbrevs (abfd
, &cu
);
2049 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2051 if (this_cu
->from_debug_types
)
2052 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2053 init_cu_die_reader (&reader_specs
, &cu
);
2054 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2057 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2060 unsigned int line_offset
= DW_UNSND (attr
);
2061 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2065 do_cleanups (cleanups
);
2069 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2071 this_cu
->v
.quick
->lines
= lh
;
2073 this_cu
->v
.quick
->file_names
2074 = obstack_alloc (&objfile
->objfile_obstack
,
2075 lh
->num_file_names
* sizeof (char *));
2076 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2077 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2079 do_cleanups (cleanups
);
2082 /* A helper for the "quick" functions which computes and caches the
2083 real path for a given file name from the line table.
2084 dw2_require_line_header must have been called before this is
2088 dw2_require_full_path (struct objfile
*objfile
,
2089 struct dwarf2_per_cu_data
*per_cu
,
2092 if (!per_cu
->v
.quick
->full_names
)
2093 per_cu
->v
.quick
->full_names
2094 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2095 per_cu
->v
.quick
->lines
->num_file_names
,
2098 if (!per_cu
->v
.quick
->full_names
[index
])
2099 per_cu
->v
.quick
->full_names
[index
]
2100 = gdb_realpath (per_cu
->v
.quick
->file_names
[index
]);
2102 return per_cu
->v
.quick
->full_names
[index
];
2105 static struct symtab
*
2106 dw2_find_last_source_symtab (struct objfile
*objfile
)
2109 dw2_setup (objfile
);
2110 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2111 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2115 dw2_forget_cached_source_info (struct objfile
*objfile
)
2119 dw2_setup (objfile
);
2120 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2121 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2123 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2125 if (per_cu
->v
.quick
->full_names
)
2129 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2130 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
2136 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2137 const char *full_path
, const char *real_path
,
2138 struct symtab
**result
)
2141 int check_basename
= lbasename (name
) == name
;
2142 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2144 dw2_setup (objfile
);
2145 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2146 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2149 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2151 if (per_cu
->v
.quick
->symtab
)
2154 dw2_require_line_header (objfile
, per_cu
);
2155 if (!per_cu
->v
.quick
->lines
)
2158 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2160 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2162 if (FILENAME_CMP (name
, this_name
) == 0)
2164 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2168 if (check_basename
&& ! base_cu
2169 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2172 if (full_path
!= NULL
)
2174 const char *this_full_name
= dw2_require_full_path (objfile
,
2178 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2180 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2185 if (real_path
!= NULL
)
2187 const char *this_full_name
= dw2_require_full_path (objfile
,
2190 if (this_full_name
!= NULL
)
2192 char *rp
= gdb_realpath (this_full_name
);
2193 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2196 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2207 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2214 static struct symtab
*
2215 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2216 const char *name
, domain_enum domain
)
2218 /* We do all the work in the pre_expand_symtabs_matching hook
2223 /* A helper function that expands all symtabs that hold an object
2227 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2229 dw2_setup (objfile
);
2231 if (dwarf2_per_objfile
->index_table
)
2235 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2238 offset_type i
, len
= MAYBE_SWAP (*vec
);
2239 for (i
= 0; i
< len
; ++i
)
2241 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2242 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2244 dw2_instantiate_symtab (objfile
, per_cu
);
2251 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2252 int kind
, const char *name
,
2255 dw2_do_expand_symtabs_matching (objfile
, name
);
2259 dw2_print_stats (struct objfile
*objfile
)
2263 dw2_setup (objfile
);
2265 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2266 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2268 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2270 if (!per_cu
->v
.quick
->symtab
)
2273 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2277 dw2_dump (struct objfile
*objfile
)
2279 /* Nothing worth printing. */
2283 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2284 struct section_offsets
*delta
)
2286 /* There's nothing to relocate here. */
2290 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2291 const char *func_name
)
2293 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2297 dw2_expand_all_symtabs (struct objfile
*objfile
)
2301 dw2_setup (objfile
);
2303 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2304 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2306 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2308 dw2_instantiate_symtab (objfile
, per_cu
);
2313 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2314 const char *filename
)
2318 dw2_setup (objfile
);
2319 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2320 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2323 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2325 if (per_cu
->v
.quick
->symtab
)
2328 dw2_require_line_header (objfile
, per_cu
);
2329 if (!per_cu
->v
.quick
->lines
)
2332 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2334 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2335 if (strcmp (this_name
, filename
) == 0)
2337 dw2_instantiate_symtab (objfile
, per_cu
);
2345 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2347 struct dwarf2_per_cu_data
*per_cu
;
2350 dw2_setup (objfile
);
2352 if (!dwarf2_per_objfile
->index_table
)
2355 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2359 /* Note that this just looks at the very first one named NAME -- but
2360 actually we are looking for a function. find_main_filename
2361 should be rewritten so that it doesn't require a custom hook. It
2362 could just use the ordinary symbol tables. */
2363 /* vec[0] is the length, which must always be >0. */
2364 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2366 dw2_require_line_header (objfile
, per_cu
);
2367 if (!per_cu
->v
.quick
->lines
)
2370 return per_cu
->v
.quick
->file_names
[per_cu
->v
.quick
->lines
->num_file_names
- 1];
2374 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2375 struct objfile
*objfile
, int global
,
2376 int (*callback
) (struct block
*,
2377 struct symbol
*, void *),
2379 int (*match
) (const char *, const char *),
2380 int (*ordered_compare
) (const char *,
2383 /* Currently unimplemented; used for Ada. The function can be called if the
2384 current language is Ada for a non-Ada objfile using GNU index. As Ada
2385 does not look for non-Ada symbols this function should just return. */
2389 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2390 int (*file_matcher
) (const char *, void *),
2391 int (*name_matcher
) (const char *, void *),
2397 struct mapped_index
*index
;
2399 dw2_setup (objfile
);
2400 if (!dwarf2_per_objfile
->index_table
)
2402 index
= dwarf2_per_objfile
->index_table
;
2404 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2405 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2408 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2410 per_cu
->v
.quick
->mark
= 0;
2411 if (per_cu
->v
.quick
->symtab
)
2414 dw2_require_line_header (objfile
, per_cu
);
2415 if (!per_cu
->v
.quick
->lines
)
2418 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2420 if (file_matcher (per_cu
->v
.quick
->file_names
[j
], data
))
2422 per_cu
->v
.quick
->mark
= 1;
2428 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2430 offset_type idx
= 2 * iter
;
2432 offset_type
*vec
, vec_len
, vec_idx
;
2434 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2437 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2439 if (! (*name_matcher
) (name
, data
))
2442 /* The name was matched, now expand corresponding CUs that were
2444 vec
= (offset_type
*) (index
->constant_pool
2445 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2446 vec_len
= MAYBE_SWAP (vec
[0]);
2447 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2449 struct dwarf2_per_cu_data
*per_cu
;
2451 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2452 if (per_cu
->v
.quick
->mark
)
2453 dw2_instantiate_symtab (objfile
, per_cu
);
2458 static struct symtab
*
2459 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2460 struct minimal_symbol
*msymbol
,
2462 struct obj_section
*section
,
2465 struct dwarf2_per_cu_data
*data
;
2467 dw2_setup (objfile
);
2469 if (!objfile
->psymtabs_addrmap
)
2472 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2476 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2477 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2478 paddress (get_objfile_arch (objfile
), pc
));
2480 return dw2_instantiate_symtab (objfile
, data
);
2484 dw2_map_symbol_names (struct objfile
*objfile
,
2485 void (*fun
) (const char *, void *),
2489 struct mapped_index
*index
;
2491 dw2_setup (objfile
);
2493 if (!dwarf2_per_objfile
->index_table
)
2495 index
= dwarf2_per_objfile
->index_table
;
2497 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2499 offset_type idx
= 2 * iter
;
2501 offset_type
*vec
, vec_len
, vec_idx
;
2503 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2506 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2508 (*fun
) (name
, data
);
2513 dw2_map_symbol_filenames (struct objfile
*objfile
,
2514 void (*fun
) (const char *, const char *, void *),
2519 dw2_setup (objfile
);
2520 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2521 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2524 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2526 if (per_cu
->v
.quick
->symtab
)
2529 dw2_require_line_header (objfile
, per_cu
);
2530 if (!per_cu
->v
.quick
->lines
)
2533 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2535 const char *this_full_name
= dw2_require_full_path (objfile
, per_cu
,
2537 (*fun
) (per_cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2543 dw2_has_symbols (struct objfile
*objfile
)
2548 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2551 dw2_find_last_source_symtab
,
2552 dw2_forget_cached_source_info
,
2555 dw2_pre_expand_symtabs_matching
,
2559 dw2_expand_symtabs_for_function
,
2560 dw2_expand_all_symtabs
,
2561 dw2_expand_symtabs_with_filename
,
2562 dw2_find_symbol_file
,
2563 dw2_map_matching_symbols
,
2564 dw2_expand_symtabs_matching
,
2565 dw2_find_pc_sect_symtab
,
2566 dw2_map_symbol_names
,
2567 dw2_map_symbol_filenames
2570 /* Initialize for reading DWARF for this objfile. Return 0 if this
2571 file will use psymtabs, or 1 if using the GNU index. */
2574 dwarf2_initialize_objfile (struct objfile
*objfile
)
2576 /* If we're about to read full symbols, don't bother with the
2577 indices. In this case we also don't care if some other debug
2578 format is making psymtabs, because they are all about to be
2580 if ((objfile
->flags
& OBJF_READNOW
))
2584 dwarf2_per_objfile
->using_index
= 1;
2585 create_all_comp_units (objfile
);
2586 create_debug_types_hash_table (objfile
);
2588 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2589 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2591 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2593 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2594 struct dwarf2_per_cu_quick_data
);
2597 /* Return 1 so that gdb sees the "quick" functions. However,
2598 these functions will be no-ops because we will have expanded
2603 if (dwarf2_read_index (objfile
))
2606 dwarf2_build_psymtabs (objfile
);
2612 /* Build a partial symbol table. */
2615 dwarf2_build_psymtabs (struct objfile
*objfile
)
2617 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2619 init_psymbol_list (objfile
, 1024);
2622 dwarf2_build_psymtabs_hard (objfile
);
2625 /* Return TRUE if OFFSET is within CU_HEADER. */
2628 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2630 unsigned int bottom
= cu_header
->offset
;
2631 unsigned int top
= (cu_header
->offset
2633 + cu_header
->initial_length_size
);
2635 return (offset
>= bottom
&& offset
< top
);
2638 /* Read in the comp unit header information from the debug_info at info_ptr.
2639 NOTE: This leaves members offset, first_die_offset to be filled in
2643 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2644 gdb_byte
*info_ptr
, bfd
*abfd
)
2647 unsigned int bytes_read
;
2649 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2650 cu_header
->initial_length_size
= bytes_read
;
2651 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2652 info_ptr
+= bytes_read
;
2653 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2655 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2657 info_ptr
+= bytes_read
;
2658 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2660 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2661 if (signed_addr
< 0)
2662 internal_error (__FILE__
, __LINE__
,
2663 _("read_comp_unit_head: dwarf from non elf file"));
2664 cu_header
->signed_addr_p
= signed_addr
;
2670 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2671 gdb_byte
*buffer
, unsigned int buffer_size
,
2674 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2676 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2678 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2679 error (_("Dwarf Error: wrong version in compilation unit header "
2680 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2681 bfd_get_filename (abfd
));
2683 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2684 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2685 "(offset 0x%lx + 6) [in module %s]"),
2686 (long) header
->abbrev_offset
,
2687 (long) (beg_of_comp_unit
- buffer
),
2688 bfd_get_filename (abfd
));
2690 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2691 > buffer
+ buffer_size
)
2692 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2693 "(offset 0x%lx + 0) [in module %s]"),
2694 (long) header
->length
,
2695 (long) (beg_of_comp_unit
- buffer
),
2696 bfd_get_filename (abfd
));
2701 /* Read in the types comp unit header information from .debug_types entry at
2702 types_ptr. The result is a pointer to one past the end of the header. */
2705 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2706 ULONGEST
*signature
,
2707 gdb_byte
*types_ptr
, bfd
*abfd
)
2709 gdb_byte
*initial_types_ptr
= types_ptr
;
2711 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2712 &dwarf2_per_objfile
->types
);
2713 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2715 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2717 *signature
= read_8_bytes (abfd
, types_ptr
);
2719 types_ptr
+= cu_header
->offset_size
;
2720 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2725 /* Allocate a new partial symtab for file named NAME and mark this new
2726 partial symtab as being an include of PST. */
2729 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2730 struct objfile
*objfile
)
2732 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2734 subpst
->section_offsets
= pst
->section_offsets
;
2735 subpst
->textlow
= 0;
2736 subpst
->texthigh
= 0;
2738 subpst
->dependencies
= (struct partial_symtab
**)
2739 obstack_alloc (&objfile
->objfile_obstack
,
2740 sizeof (struct partial_symtab
*));
2741 subpst
->dependencies
[0] = pst
;
2742 subpst
->number_of_dependencies
= 1;
2744 subpst
->globals_offset
= 0;
2745 subpst
->n_global_syms
= 0;
2746 subpst
->statics_offset
= 0;
2747 subpst
->n_static_syms
= 0;
2748 subpst
->symtab
= NULL
;
2749 subpst
->read_symtab
= pst
->read_symtab
;
2752 /* No private part is necessary for include psymtabs. This property
2753 can be used to differentiate between such include psymtabs and
2754 the regular ones. */
2755 subpst
->read_symtab_private
= NULL
;
2758 /* Read the Line Number Program data and extract the list of files
2759 included by the source file represented by PST. Build an include
2760 partial symtab for each of these included files. */
2763 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2764 struct die_info
*die
,
2765 struct partial_symtab
*pst
)
2767 struct objfile
*objfile
= cu
->objfile
;
2768 bfd
*abfd
= objfile
->obfd
;
2769 struct line_header
*lh
= NULL
;
2770 struct attribute
*attr
;
2772 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2775 unsigned int line_offset
= DW_UNSND (attr
);
2777 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2780 return; /* No linetable, so no includes. */
2782 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2783 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2785 free_line_header (lh
);
2789 hash_type_signature (const void *item
)
2791 const struct signatured_type
*type_sig
= item
;
2793 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2794 return type_sig
->signature
;
2798 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2800 const struct signatured_type
*lhs
= item_lhs
;
2801 const struct signatured_type
*rhs
= item_rhs
;
2803 return lhs
->signature
== rhs
->signature
;
2806 /* Allocate a hash table for signatured types. */
2809 allocate_signatured_type_table (struct objfile
*objfile
)
2811 return htab_create_alloc_ex (41,
2812 hash_type_signature
,
2815 &objfile
->objfile_obstack
,
2816 hashtab_obstack_allocate
,
2817 dummy_obstack_deallocate
);
2820 /* A helper function to add a signatured type CU to a list. */
2823 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2825 struct signatured_type
*sigt
= *slot
;
2826 struct dwarf2_per_cu_data
***datap
= datum
;
2828 **datap
= &sigt
->per_cu
;
2834 /* Create the hash table of all entries in the .debug_types section.
2835 The result is zero if there is an error (e.g. missing .debug_types section),
2836 otherwise non-zero. */
2839 create_debug_types_hash_table (struct objfile
*objfile
)
2843 struct dwarf2_per_cu_data
**iter
;
2845 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2846 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2848 if (info_ptr
== NULL
)
2850 dwarf2_per_objfile
->signatured_types
= NULL
;
2854 types_htab
= allocate_signatured_type_table (objfile
);
2856 if (dwarf2_die_debug
)
2857 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2859 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2861 unsigned int offset
;
2862 unsigned int offset_size
;
2863 unsigned int type_offset
;
2864 unsigned int length
, initial_length_size
;
2865 unsigned short version
;
2867 struct signatured_type
*type_sig
;
2869 gdb_byte
*ptr
= info_ptr
;
2871 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2873 /* We need to read the type's signature in order to build the hash
2874 table, but we don't need to read anything else just yet. */
2876 /* Sanity check to ensure entire cu is present. */
2877 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2878 if (ptr
+ length
+ initial_length_size
2879 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2881 complaint (&symfile_complaints
,
2882 _("debug type entry runs off end of `.debug_types' section, ignored"));
2886 offset_size
= initial_length_size
== 4 ? 4 : 8;
2887 ptr
+= initial_length_size
;
2888 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2890 ptr
+= offset_size
; /* abbrev offset */
2891 ptr
+= 1; /* address size */
2892 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2894 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2896 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2897 memset (type_sig
, 0, sizeof (*type_sig
));
2898 type_sig
->signature
= signature
;
2899 type_sig
->offset
= offset
;
2900 type_sig
->type_offset
= type_offset
;
2901 type_sig
->per_cu
.objfile
= objfile
;
2902 type_sig
->per_cu
.from_debug_types
= 1;
2904 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2905 gdb_assert (slot
!= NULL
);
2908 if (dwarf2_die_debug
)
2909 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2910 offset
, phex (signature
, sizeof (signature
)));
2912 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2915 dwarf2_per_objfile
->signatured_types
= types_htab
;
2917 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2918 dwarf2_per_objfile
->type_comp_units
2919 = obstack_alloc (&objfile
->objfile_obstack
,
2920 dwarf2_per_objfile
->n_type_comp_units
2921 * sizeof (struct dwarf2_per_cu_data
*));
2922 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2923 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2924 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2925 == dwarf2_per_objfile
->n_type_comp_units
);
2930 /* Lookup a signature based type.
2931 Returns NULL if SIG is not present in the table. */
2933 static struct signatured_type
*
2934 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2936 struct signatured_type find_entry
, *entry
;
2938 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2940 complaint (&symfile_complaints
,
2941 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2945 find_entry
.signature
= sig
;
2946 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2950 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2953 init_cu_die_reader (struct die_reader_specs
*reader
,
2954 struct dwarf2_cu
*cu
)
2956 reader
->abfd
= cu
->objfile
->obfd
;
2958 if (cu
->per_cu
->from_debug_types
)
2960 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2961 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2965 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2966 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2970 /* Find the base address of the compilation unit for range lists and
2971 location lists. It will normally be specified by DW_AT_low_pc.
2972 In DWARF-3 draft 4, the base address could be overridden by
2973 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2974 compilation units with discontinuous ranges. */
2977 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2979 struct attribute
*attr
;
2982 cu
->base_address
= 0;
2984 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2987 cu
->base_address
= DW_ADDR (attr
);
2992 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2995 cu
->base_address
= DW_ADDR (attr
);
3001 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3002 to combine the common parts.
3003 Process a compilation unit for a psymtab.
3004 BUFFER is a pointer to the beginning of the dwarf section buffer,
3005 either .debug_info or debug_types.
3006 INFO_PTR is a pointer to the start of the CU.
3007 Returns a pointer to the next CU. */
3010 process_psymtab_comp_unit (struct objfile
*objfile
,
3011 struct dwarf2_per_cu_data
*this_cu
,
3012 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3013 unsigned int buffer_size
)
3015 bfd
*abfd
= objfile
->obfd
;
3016 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3017 struct die_info
*comp_unit_die
;
3018 struct partial_symtab
*pst
;
3020 struct cleanup
*back_to_inner
;
3021 struct dwarf2_cu cu
;
3022 int has_children
, has_pc_info
;
3023 struct attribute
*attr
;
3024 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3025 struct die_reader_specs reader_specs
;
3027 memset (&cu
, 0, sizeof (cu
));
3028 cu
.objfile
= objfile
;
3029 obstack_init (&cu
.comp_unit_obstack
);
3031 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3033 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3034 buffer
, buffer_size
,
3037 /* Complete the cu_header. */
3038 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3039 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3041 cu
.list_in_scope
= &file_symbols
;
3043 /* If this compilation unit was already read in, free the
3044 cached copy in order to read it in again. This is
3045 necessary because we skipped some symbols when we first
3046 read in the compilation unit (see load_partial_dies).
3047 This problem could be avoided, but the benefit is
3049 if (this_cu
->cu
!= NULL
)
3050 free_one_cached_comp_unit (this_cu
->cu
);
3052 /* Note that this is a pointer to our stack frame, being
3053 added to a global data structure. It will be cleaned up
3054 in free_stack_comp_unit when we finish with this
3055 compilation unit. */
3057 cu
.per_cu
= this_cu
;
3059 /* Read the abbrevs for this compilation unit into a table. */
3060 dwarf2_read_abbrevs (abfd
, &cu
);
3061 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3063 /* Read the compilation unit die. */
3064 if (this_cu
->from_debug_types
)
3065 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3066 init_cu_die_reader (&reader_specs
, &cu
);
3067 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3070 if (this_cu
->from_debug_types
)
3072 /* offset,length haven't been set yet for type units. */
3073 this_cu
->offset
= cu
.header
.offset
;
3074 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3076 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3078 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3079 + cu
.header
.initial_length_size
);
3080 do_cleanups (back_to_inner
);
3084 /* Set the language we're debugging. */
3085 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
3087 set_cu_language (DW_UNSND (attr
), &cu
);
3089 set_cu_language (language_minimal
, &cu
);
3091 /* Allocate a new partial symbol table structure. */
3092 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3093 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3094 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3095 /* TEXTLOW and TEXTHIGH are set below. */
3097 objfile
->global_psymbols
.next
,
3098 objfile
->static_psymbols
.next
);
3100 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3102 pst
->dirname
= DW_STRING (attr
);
3104 pst
->read_symtab_private
= this_cu
;
3106 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3108 /* Store the function that reads in the rest of the symbol table */
3109 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3111 this_cu
->v
.psymtab
= pst
;
3113 dwarf2_find_base_address (comp_unit_die
, &cu
);
3115 /* Possibly set the default values of LOWPC and HIGHPC from
3117 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3118 &best_highpc
, &cu
, pst
);
3119 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3120 /* Store the contiguous range if it is not empty; it can be empty for
3121 CUs with no code. */
3122 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3123 best_lowpc
+ baseaddr
,
3124 best_highpc
+ baseaddr
- 1, pst
);
3126 /* Check if comp unit has_children.
3127 If so, read the rest of the partial symbols from this comp unit.
3128 If not, there's no more debug_info for this comp unit. */
3131 struct partial_die_info
*first_die
;
3132 CORE_ADDR lowpc
, highpc
;
3134 lowpc
= ((CORE_ADDR
) -1);
3135 highpc
= ((CORE_ADDR
) 0);
3137 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3139 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3140 ! has_pc_info
, &cu
);
3142 /* If we didn't find a lowpc, set it to highpc to avoid
3143 complaints from `maint check'. */
3144 if (lowpc
== ((CORE_ADDR
) -1))
3147 /* If the compilation unit didn't have an explicit address range,
3148 then use the information extracted from its child dies. */
3152 best_highpc
= highpc
;
3155 pst
->textlow
= best_lowpc
+ baseaddr
;
3156 pst
->texthigh
= best_highpc
+ baseaddr
;
3158 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3159 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3160 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3161 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3162 sort_pst_symbols (pst
);
3164 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3165 + cu
.header
.initial_length_size
);
3167 if (this_cu
->from_debug_types
)
3169 /* It's not clear we want to do anything with stmt lists here.
3170 Waiting to see what gcc ultimately does. */
3174 /* Get the list of files included in the current compilation unit,
3175 and build a psymtab for each of them. */
3176 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3179 do_cleanups (back_to_inner
);
3184 /* Traversal function for htab_traverse_noresize.
3185 Process one .debug_types comp-unit. */
3188 process_type_comp_unit (void **slot
, void *info
)
3190 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3191 struct objfile
*objfile
= (struct objfile
*) info
;
3192 struct dwarf2_per_cu_data
*this_cu
;
3194 this_cu
= &entry
->per_cu
;
3196 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3197 process_psymtab_comp_unit (objfile
, this_cu
,
3198 dwarf2_per_objfile
->types
.buffer
,
3199 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3200 dwarf2_per_objfile
->types
.size
);
3205 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3206 Build partial symbol tables for the .debug_types comp-units. */
3209 build_type_psymtabs (struct objfile
*objfile
)
3211 if (! create_debug_types_hash_table (objfile
))
3214 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3215 process_type_comp_unit
, objfile
);
3218 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3221 psymtabs_addrmap_cleanup (void *o
)
3223 struct objfile
*objfile
= o
;
3225 objfile
->psymtabs_addrmap
= NULL
;
3228 /* Build the partial symbol table by doing a quick pass through the
3229 .debug_info and .debug_abbrev sections. */
3232 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3235 struct cleanup
*back_to
, *addrmap_cleanup
;
3236 struct obstack temp_obstack
;
3238 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3240 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3241 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3243 /* Any cached compilation units will be linked by the per-objfile
3244 read_in_chain. Make sure to free them when we're done. */
3245 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3247 build_type_psymtabs (objfile
);
3249 create_all_comp_units (objfile
);
3251 /* Create a temporary address map on a temporary obstack. We later
3252 copy this to the final obstack. */
3253 obstack_init (&temp_obstack
);
3254 make_cleanup_obstack_free (&temp_obstack
);
3255 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3256 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3258 /* Since the objects we're extracting from .debug_info vary in
3259 length, only the individual functions to extract them (like
3260 read_comp_unit_head and load_partial_die) can really know whether
3261 the buffer is large enough to hold another complete object.
3263 At the moment, they don't actually check that. If .debug_info
3264 holds just one extra byte after the last compilation unit's dies,
3265 then read_comp_unit_head will happily read off the end of the
3266 buffer. read_partial_die is similarly casual. Those functions
3269 For this loop condition, simply checking whether there's any data
3270 left at all should be sufficient. */
3272 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3273 + dwarf2_per_objfile
->info
.size
))
3275 struct dwarf2_per_cu_data
*this_cu
;
3277 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3280 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3281 dwarf2_per_objfile
->info
.buffer
,
3283 dwarf2_per_objfile
->info
.size
);
3286 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3287 &objfile
->objfile_obstack
);
3288 discard_cleanups (addrmap_cleanup
);
3290 do_cleanups (back_to
);
3293 /* Load the partial DIEs for a secondary CU into memory. */
3296 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3297 struct objfile
*objfile
)
3299 bfd
*abfd
= objfile
->obfd
;
3300 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3301 struct die_info
*comp_unit_die
;
3302 struct dwarf2_cu
*cu
;
3303 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3304 struct attribute
*attr
;
3306 struct die_reader_specs reader_specs
;
3309 gdb_assert (! this_cu
->from_debug_types
);
3311 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3312 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3313 beg_of_comp_unit
= info_ptr
;
3315 if (this_cu
->cu
== NULL
)
3317 cu
= alloc_one_comp_unit (objfile
);
3321 /* If an error occurs while loading, release our storage. */
3322 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3324 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3325 dwarf2_per_objfile
->info
.buffer
,
3326 dwarf2_per_objfile
->info
.size
,
3329 /* Complete the cu_header. */
3330 cu
->header
.offset
= this_cu
->offset
;
3331 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3333 /* Link this compilation unit into the compilation unit tree. */
3335 cu
->per_cu
= this_cu
;
3337 /* Link this CU into read_in_chain. */
3338 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3339 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3344 info_ptr
+= cu
->header
.first_die_offset
;
3347 /* Read the abbrevs for this compilation unit into a table. */
3348 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3349 dwarf2_read_abbrevs (abfd
, cu
);
3350 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3352 /* Read the compilation unit die. */
3353 init_cu_die_reader (&reader_specs
, cu
);
3354 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3357 /* Set the language we're debugging. */
3358 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3360 set_cu_language (DW_UNSND (attr
), cu
);
3362 set_cu_language (language_minimal
, cu
);
3364 /* Check if comp unit has_children.
3365 If so, read the rest of the partial symbols from this comp unit.
3366 If not, there's no more debug_info for this comp unit. */
3368 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3370 do_cleanups (free_abbrevs_cleanup
);
3374 /* We've successfully allocated this compilation unit. Let our
3375 caller clean it up when finished with it. */
3376 discard_cleanups (free_cu_cleanup
);
3380 /* Create a list of all compilation units in OBJFILE. We do this only
3381 if an inter-comp-unit reference is found; presumably if there is one,
3382 there will be many, and one will occur early in the .debug_info section.
3383 So there's no point in building this list incrementally. */
3386 create_all_comp_units (struct objfile
*objfile
)
3390 struct dwarf2_per_cu_data
**all_comp_units
;
3393 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3394 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3398 all_comp_units
= xmalloc (n_allocated
3399 * sizeof (struct dwarf2_per_cu_data
*));
3401 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3403 unsigned int length
, initial_length_size
;
3404 struct dwarf2_per_cu_data
*this_cu
;
3405 unsigned int offset
;
3407 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3409 /* Read just enough information to find out where the next
3410 compilation unit is. */
3411 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3412 &initial_length_size
);
3414 /* Save the compilation unit for later lookup. */
3415 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3416 sizeof (struct dwarf2_per_cu_data
));
3417 memset (this_cu
, 0, sizeof (*this_cu
));
3418 this_cu
->offset
= offset
;
3419 this_cu
->length
= length
+ initial_length_size
;
3420 this_cu
->objfile
= objfile
;
3422 if (n_comp_units
== n_allocated
)
3425 all_comp_units
= xrealloc (all_comp_units
,
3427 * sizeof (struct dwarf2_per_cu_data
*));
3429 all_comp_units
[n_comp_units
++] = this_cu
;
3431 info_ptr
= info_ptr
+ this_cu
->length
;
3434 dwarf2_per_objfile
->all_comp_units
3435 = obstack_alloc (&objfile
->objfile_obstack
,
3436 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3437 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3438 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3439 xfree (all_comp_units
);
3440 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3443 /* Process all loaded DIEs for compilation unit CU, starting at
3444 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3445 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3446 DW_AT_ranges). If NEED_PC is set, then this function will set
3447 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3448 and record the covered ranges in the addrmap. */
3451 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3452 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3454 struct partial_die_info
*pdi
;
3456 /* Now, march along the PDI's, descending into ones which have
3457 interesting children but skipping the children of the other ones,
3458 until we reach the end of the compilation unit. */
3464 fixup_partial_die (pdi
, cu
);
3466 /* Anonymous namespaces or modules have no name but have interesting
3467 children, so we need to look at them. Ditto for anonymous
3470 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3471 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3475 case DW_TAG_subprogram
:
3476 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3478 case DW_TAG_constant
:
3479 case DW_TAG_variable
:
3480 case DW_TAG_typedef
:
3481 case DW_TAG_union_type
:
3482 if (!pdi
->is_declaration
)
3484 add_partial_symbol (pdi
, cu
);
3487 case DW_TAG_class_type
:
3488 case DW_TAG_interface_type
:
3489 case DW_TAG_structure_type
:
3490 if (!pdi
->is_declaration
)
3492 add_partial_symbol (pdi
, cu
);
3495 case DW_TAG_enumeration_type
:
3496 if (!pdi
->is_declaration
)
3497 add_partial_enumeration (pdi
, cu
);
3499 case DW_TAG_base_type
:
3500 case DW_TAG_subrange_type
:
3501 /* File scope base type definitions are added to the partial
3503 add_partial_symbol (pdi
, cu
);
3505 case DW_TAG_namespace
:
3506 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3509 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3516 /* If the die has a sibling, skip to the sibling. */
3518 pdi
= pdi
->die_sibling
;
3522 /* Functions used to compute the fully scoped name of a partial DIE.
3524 Normally, this is simple. For C++, the parent DIE's fully scoped
3525 name is concatenated with "::" and the partial DIE's name. For
3526 Java, the same thing occurs except that "." is used instead of "::".
3527 Enumerators are an exception; they use the scope of their parent
3528 enumeration type, i.e. the name of the enumeration type is not
3529 prepended to the enumerator.
3531 There are two complexities. One is DW_AT_specification; in this
3532 case "parent" means the parent of the target of the specification,
3533 instead of the direct parent of the DIE. The other is compilers
3534 which do not emit DW_TAG_namespace; in this case we try to guess
3535 the fully qualified name of structure types from their members'
3536 linkage names. This must be done using the DIE's children rather
3537 than the children of any DW_AT_specification target. We only need
3538 to do this for structures at the top level, i.e. if the target of
3539 any DW_AT_specification (if any; otherwise the DIE itself) does not
3542 /* Compute the scope prefix associated with PDI's parent, in
3543 compilation unit CU. The result will be allocated on CU's
3544 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3545 field. NULL is returned if no prefix is necessary. */
3547 partial_die_parent_scope (struct partial_die_info
*pdi
,
3548 struct dwarf2_cu
*cu
)
3550 char *grandparent_scope
;
3551 struct partial_die_info
*parent
, *real_pdi
;
3553 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3554 then this means the parent of the specification DIE. */
3557 while (real_pdi
->has_specification
)
3558 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3560 parent
= real_pdi
->die_parent
;
3564 if (parent
->scope_set
)
3565 return parent
->scope
;
3567 fixup_partial_die (parent
, cu
);
3569 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3571 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3572 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3573 Work around this problem here. */
3574 if (cu
->language
== language_cplus
3575 && parent
->tag
== DW_TAG_namespace
3576 && strcmp (parent
->name
, "::") == 0
3577 && grandparent_scope
== NULL
)
3579 parent
->scope
= NULL
;
3580 parent
->scope_set
= 1;
3584 if (parent
->tag
== DW_TAG_namespace
3585 || parent
->tag
== DW_TAG_module
3586 || parent
->tag
== DW_TAG_structure_type
3587 || parent
->tag
== DW_TAG_class_type
3588 || parent
->tag
== DW_TAG_interface_type
3589 || parent
->tag
== DW_TAG_union_type
3590 || parent
->tag
== DW_TAG_enumeration_type
)
3592 if (grandparent_scope
== NULL
)
3593 parent
->scope
= parent
->name
;
3595 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3596 parent
->name
, 0, cu
);
3598 else if (parent
->tag
== DW_TAG_enumerator
)
3599 /* Enumerators should not get the name of the enumeration as a prefix. */
3600 parent
->scope
= grandparent_scope
;
3603 /* FIXME drow/2004-04-01: What should we be doing with
3604 function-local names? For partial symbols, we should probably be
3606 complaint (&symfile_complaints
,
3607 _("unhandled containing DIE tag %d for DIE at %d"),
3608 parent
->tag
, pdi
->offset
);
3609 parent
->scope
= grandparent_scope
;
3612 parent
->scope_set
= 1;
3613 return parent
->scope
;
3616 /* Return the fully scoped name associated with PDI, from compilation unit
3617 CU. The result will be allocated with malloc. */
3619 partial_die_full_name (struct partial_die_info
*pdi
,
3620 struct dwarf2_cu
*cu
)
3624 /* If this is a template instantiation, we can not work out the
3625 template arguments from partial DIEs. So, unfortunately, we have
3626 to go through the full DIEs. At least any work we do building
3627 types here will be reused if full symbols are loaded later. */
3628 if (pdi
->has_template_arguments
)
3630 fixup_partial_die (pdi
, cu
);
3632 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3634 struct die_info
*die
;
3635 struct attribute attr
;
3636 struct dwarf2_cu
*ref_cu
= cu
;
3639 attr
.form
= DW_FORM_ref_addr
;
3640 attr
.u
.addr
= pdi
->offset
;
3641 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3643 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3647 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3648 if (parent_scope
== NULL
)
3651 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3655 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3657 struct objfile
*objfile
= cu
->objfile
;
3659 char *actual_name
= NULL
;
3660 const struct partial_symbol
*psym
= NULL
;
3662 int built_actual_name
= 0;
3664 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3666 actual_name
= partial_die_full_name (pdi
, cu
);
3668 built_actual_name
= 1;
3670 if (actual_name
== NULL
)
3671 actual_name
= pdi
->name
;
3675 case DW_TAG_subprogram
:
3676 if (pdi
->is_external
|| cu
->language
== language_ada
)
3678 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3679 of the global scope. But in Ada, we want to be able to access
3680 nested procedures globally. So all Ada subprograms are stored
3681 in the global scope. */
3682 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3683 mst_text, objfile); */
3684 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3686 VAR_DOMAIN
, LOC_BLOCK
,
3687 &objfile
->global_psymbols
,
3688 0, pdi
->lowpc
+ baseaddr
,
3689 cu
->language
, objfile
);
3693 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3694 mst_file_text, objfile); */
3695 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3697 VAR_DOMAIN
, LOC_BLOCK
,
3698 &objfile
->static_psymbols
,
3699 0, pdi
->lowpc
+ baseaddr
,
3700 cu
->language
, objfile
);
3703 case DW_TAG_constant
:
3705 struct psymbol_allocation_list
*list
;
3707 if (pdi
->is_external
)
3708 list
= &objfile
->global_psymbols
;
3710 list
= &objfile
->static_psymbols
;
3711 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3712 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3713 list
, 0, 0, cu
->language
, objfile
);
3717 case DW_TAG_variable
:
3719 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3723 && !dwarf2_per_objfile
->has_section_at_zero
)
3725 /* A global or static variable may also have been stripped
3726 out by the linker if unused, in which case its address
3727 will be nullified; do not add such variables into partial
3728 symbol table then. */
3730 else if (pdi
->is_external
)
3733 Don't enter into the minimal symbol tables as there is
3734 a minimal symbol table entry from the ELF symbols already.
3735 Enter into partial symbol table if it has a location
3736 descriptor or a type.
3737 If the location descriptor is missing, new_symbol will create
3738 a LOC_UNRESOLVED symbol, the address of the variable will then
3739 be determined from the minimal symbol table whenever the variable
3741 The address for the partial symbol table entry is not
3742 used by GDB, but it comes in handy for debugging partial symbol
3745 if (pdi
->locdesc
|| pdi
->has_type
)
3746 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3748 VAR_DOMAIN
, LOC_STATIC
,
3749 &objfile
->global_psymbols
,
3751 cu
->language
, objfile
);
3755 /* Static Variable. Skip symbols without location descriptors. */
3756 if (pdi
->locdesc
== NULL
)
3758 if (built_actual_name
)
3759 xfree (actual_name
);
3762 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3763 mst_file_data, objfile); */
3764 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3766 VAR_DOMAIN
, LOC_STATIC
,
3767 &objfile
->static_psymbols
,
3769 cu
->language
, objfile
);
3772 case DW_TAG_typedef
:
3773 case DW_TAG_base_type
:
3774 case DW_TAG_subrange_type
:
3775 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3777 VAR_DOMAIN
, LOC_TYPEDEF
,
3778 &objfile
->static_psymbols
,
3779 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3781 case DW_TAG_namespace
:
3782 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3784 VAR_DOMAIN
, LOC_TYPEDEF
,
3785 &objfile
->global_psymbols
,
3786 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3788 case DW_TAG_class_type
:
3789 case DW_TAG_interface_type
:
3790 case DW_TAG_structure_type
:
3791 case DW_TAG_union_type
:
3792 case DW_TAG_enumeration_type
:
3793 /* Skip external references. The DWARF standard says in the section
3794 about "Structure, Union, and Class Type Entries": "An incomplete
3795 structure, union or class type is represented by a structure,
3796 union or class entry that does not have a byte size attribute
3797 and that has a DW_AT_declaration attribute." */
3798 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3800 if (built_actual_name
)
3801 xfree (actual_name
);
3805 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3806 static vs. global. */
3807 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3809 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3810 (cu
->language
== language_cplus
3811 || cu
->language
== language_java
)
3812 ? &objfile
->global_psymbols
3813 : &objfile
->static_psymbols
,
3814 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3817 case DW_TAG_enumerator
:
3818 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3820 VAR_DOMAIN
, LOC_CONST
,
3821 (cu
->language
== language_cplus
3822 || cu
->language
== language_java
)
3823 ? &objfile
->global_psymbols
3824 : &objfile
->static_psymbols
,
3825 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3831 if (built_actual_name
)
3832 xfree (actual_name
);
3835 /* Read a partial die corresponding to a namespace; also, add a symbol
3836 corresponding to that namespace to the symbol table. NAMESPACE is
3837 the name of the enclosing namespace. */
3840 add_partial_namespace (struct partial_die_info
*pdi
,
3841 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3842 int need_pc
, struct dwarf2_cu
*cu
)
3844 /* Add a symbol for the namespace. */
3846 add_partial_symbol (pdi
, cu
);
3848 /* Now scan partial symbols in that namespace. */
3850 if (pdi
->has_children
)
3851 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3854 /* Read a partial die corresponding to a Fortran module. */
3857 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3858 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3860 /* Now scan partial symbols in that module. */
3862 if (pdi
->has_children
)
3863 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3866 /* Read a partial die corresponding to a subprogram and create a partial
3867 symbol for that subprogram. When the CU language allows it, this
3868 routine also defines a partial symbol for each nested subprogram
3869 that this subprogram contains.
3871 DIE my also be a lexical block, in which case we simply search
3872 recursively for suprograms defined inside that lexical block.
3873 Again, this is only performed when the CU language allows this
3874 type of definitions. */
3877 add_partial_subprogram (struct partial_die_info
*pdi
,
3878 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3879 int need_pc
, struct dwarf2_cu
*cu
)
3881 if (pdi
->tag
== DW_TAG_subprogram
)
3883 if (pdi
->has_pc_info
)
3885 if (pdi
->lowpc
< *lowpc
)
3886 *lowpc
= pdi
->lowpc
;
3887 if (pdi
->highpc
> *highpc
)
3888 *highpc
= pdi
->highpc
;
3892 struct objfile
*objfile
= cu
->objfile
;
3894 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3895 SECT_OFF_TEXT (objfile
));
3896 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3897 pdi
->lowpc
+ baseaddr
,
3898 pdi
->highpc
- 1 + baseaddr
,
3899 cu
->per_cu
->v
.psymtab
);
3901 if (!pdi
->is_declaration
)
3902 /* Ignore subprogram DIEs that do not have a name, they are
3903 illegal. Do not emit a complaint at this point, we will
3904 do so when we convert this psymtab into a symtab. */
3906 add_partial_symbol (pdi
, cu
);
3910 if (! pdi
->has_children
)
3913 if (cu
->language
== language_ada
)
3915 pdi
= pdi
->die_child
;
3918 fixup_partial_die (pdi
, cu
);
3919 if (pdi
->tag
== DW_TAG_subprogram
3920 || pdi
->tag
== DW_TAG_lexical_block
)
3921 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3922 pdi
= pdi
->die_sibling
;
3927 /* Read a partial die corresponding to an enumeration type. */
3930 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3931 struct dwarf2_cu
*cu
)
3933 struct partial_die_info
*pdi
;
3935 if (enum_pdi
->name
!= NULL
)
3936 add_partial_symbol (enum_pdi
, cu
);
3938 pdi
= enum_pdi
->die_child
;
3941 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3942 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3944 add_partial_symbol (pdi
, cu
);
3945 pdi
= pdi
->die_sibling
;
3949 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3950 Return the corresponding abbrev, or NULL if the number is zero (indicating
3951 an empty DIE). In either case *BYTES_READ will be set to the length of
3952 the initial number. */
3954 static struct abbrev_info
*
3955 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3956 struct dwarf2_cu
*cu
)
3958 bfd
*abfd
= cu
->objfile
->obfd
;
3959 unsigned int abbrev_number
;
3960 struct abbrev_info
*abbrev
;
3962 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3964 if (abbrev_number
== 0)
3967 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3970 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3971 bfd_get_filename (abfd
));
3977 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3978 Returns a pointer to the end of a series of DIEs, terminated by an empty
3979 DIE. Any children of the skipped DIEs will also be skipped. */
3982 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3984 struct abbrev_info
*abbrev
;
3985 unsigned int bytes_read
;
3989 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3991 return info_ptr
+ bytes_read
;
3993 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3997 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3998 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3999 abbrev corresponding to that skipped uleb128 should be passed in
4000 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4004 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4005 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4007 unsigned int bytes_read
;
4008 struct attribute attr
;
4009 bfd
*abfd
= cu
->objfile
->obfd
;
4010 unsigned int form
, i
;
4012 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4014 /* The only abbrev we care about is DW_AT_sibling. */
4015 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4017 read_attribute (&attr
, &abbrev
->attrs
[i
],
4018 abfd
, info_ptr
, cu
);
4019 if (attr
.form
== DW_FORM_ref_addr
)
4020 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4022 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4025 /* If it isn't DW_AT_sibling, skip this attribute. */
4026 form
= abbrev
->attrs
[i
].form
;
4030 case DW_FORM_ref_addr
:
4031 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4032 and later it is offset sized. */
4033 if (cu
->header
.version
== 2)
4034 info_ptr
+= cu
->header
.addr_size
;
4036 info_ptr
+= cu
->header
.offset_size
;
4039 info_ptr
+= cu
->header
.addr_size
;
4046 case DW_FORM_flag_present
:
4061 case DW_FORM_string
:
4062 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4063 info_ptr
+= bytes_read
;
4065 case DW_FORM_sec_offset
:
4067 info_ptr
+= cu
->header
.offset_size
;
4069 case DW_FORM_exprloc
:
4071 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4072 info_ptr
+= bytes_read
;
4074 case DW_FORM_block1
:
4075 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4077 case DW_FORM_block2
:
4078 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4080 case DW_FORM_block4
:
4081 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4085 case DW_FORM_ref_udata
:
4086 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4088 case DW_FORM_indirect
:
4089 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4090 info_ptr
+= bytes_read
;
4091 /* We need to continue parsing from here, so just go back to
4093 goto skip_attribute
;
4096 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4097 dwarf_form_name (form
),
4098 bfd_get_filename (abfd
));
4102 if (abbrev
->has_children
)
4103 return skip_children (buffer
, info_ptr
, cu
);
4108 /* Locate ORIG_PDI's sibling.
4109 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4113 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4114 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4115 bfd
*abfd
, struct dwarf2_cu
*cu
)
4117 /* Do we know the sibling already? */
4119 if (orig_pdi
->sibling
)
4120 return orig_pdi
->sibling
;
4122 /* Are there any children to deal with? */
4124 if (!orig_pdi
->has_children
)
4127 /* Skip the children the long way. */
4129 return skip_children (buffer
, info_ptr
, cu
);
4132 /* Expand this partial symbol table into a full symbol table. */
4135 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4141 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4147 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4148 gdb_flush (gdb_stdout
);
4151 /* Restore our global data. */
4152 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4153 dwarf2_objfile_data_key
);
4155 /* If this psymtab is constructed from a debug-only objfile, the
4156 has_section_at_zero flag will not necessarily be correct. We
4157 can get the correct value for this flag by looking at the data
4158 associated with the (presumably stripped) associated objfile. */
4159 if (pst
->objfile
->separate_debug_objfile_backlink
)
4161 struct dwarf2_per_objfile
*dpo_backlink
4162 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4163 dwarf2_objfile_data_key
);
4165 dwarf2_per_objfile
->has_section_at_zero
4166 = dpo_backlink
->has_section_at_zero
;
4169 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4171 psymtab_to_symtab_1 (pst
);
4173 /* Finish up the debug error message. */
4175 printf_filtered (_("done.\n"));
4180 /* Add PER_CU to the queue. */
4183 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4185 struct dwarf2_queue_item
*item
;
4188 item
= xmalloc (sizeof (*item
));
4189 item
->per_cu
= per_cu
;
4192 if (dwarf2_queue
== NULL
)
4193 dwarf2_queue
= item
;
4195 dwarf2_queue_tail
->next
= item
;
4197 dwarf2_queue_tail
= item
;
4200 /* Process the queue. */
4203 process_queue (struct objfile
*objfile
)
4205 struct dwarf2_queue_item
*item
, *next_item
;
4207 /* The queue starts out with one item, but following a DIE reference
4208 may load a new CU, adding it to the end of the queue. */
4209 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4211 if (dwarf2_per_objfile
->using_index
4212 ? !item
->per_cu
->v
.quick
->symtab
4213 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4214 process_full_comp_unit (item
->per_cu
);
4216 item
->per_cu
->queued
= 0;
4217 next_item
= item
->next
;
4221 dwarf2_queue_tail
= NULL
;
4224 /* Free all allocated queue entries. This function only releases anything if
4225 an error was thrown; if the queue was processed then it would have been
4226 freed as we went along. */
4229 dwarf2_release_queue (void *dummy
)
4231 struct dwarf2_queue_item
*item
, *last
;
4233 item
= dwarf2_queue
;
4236 /* Anything still marked queued is likely to be in an
4237 inconsistent state, so discard it. */
4238 if (item
->per_cu
->queued
)
4240 if (item
->per_cu
->cu
!= NULL
)
4241 free_one_cached_comp_unit (item
->per_cu
->cu
);
4242 item
->per_cu
->queued
= 0;
4250 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4253 /* Read in full symbols for PST, and anything it depends on. */
4256 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4258 struct dwarf2_per_cu_data
*per_cu
;
4259 struct cleanup
*back_to
;
4262 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4263 if (!pst
->dependencies
[i
]->readin
)
4265 /* Inform about additional files that need to be read in. */
4268 /* FIXME: i18n: Need to make this a single string. */
4269 fputs_filtered (" ", gdb_stdout
);
4271 fputs_filtered ("and ", gdb_stdout
);
4273 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4274 wrap_here (""); /* Flush output */
4275 gdb_flush (gdb_stdout
);
4277 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4280 per_cu
= pst
->read_symtab_private
;
4284 /* It's an include file, no symbols to read for it.
4285 Everything is in the parent symtab. */
4290 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4293 /* Load the DIEs associated with PER_CU into memory. */
4296 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4298 bfd
*abfd
= objfile
->obfd
;
4299 struct dwarf2_cu
*cu
;
4300 unsigned int offset
;
4301 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4302 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4303 struct attribute
*attr
;
4306 gdb_assert (! per_cu
->from_debug_types
);
4308 /* Set local variables from the partial symbol table info. */
4309 offset
= per_cu
->offset
;
4311 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4312 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4313 beg_of_comp_unit
= info_ptr
;
4315 if (per_cu
->cu
== NULL
)
4317 cu
= alloc_one_comp_unit (objfile
);
4321 /* If an error occurs while loading, release our storage. */
4322 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4324 /* Read in the comp_unit header. */
4325 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4327 /* Complete the cu_header. */
4328 cu
->header
.offset
= offset
;
4329 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4331 /* Read the abbrevs for this compilation unit. */
4332 dwarf2_read_abbrevs (abfd
, cu
);
4333 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4335 /* Link this compilation unit into the compilation unit tree. */
4337 cu
->per_cu
= per_cu
;
4339 /* Link this CU into read_in_chain. */
4340 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4341 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4346 info_ptr
+= cu
->header
.first_die_offset
;
4349 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4351 /* We try not to read any attributes in this function, because not
4352 all objfiles needed for references have been loaded yet, and symbol
4353 table processing isn't initialized. But we have to set the CU language,
4354 or we won't be able to build types correctly. */
4355 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4357 set_cu_language (DW_UNSND (attr
), cu
);
4359 set_cu_language (language_minimal
, cu
);
4361 /* Similarly, if we do not read the producer, we can not apply
4362 producer-specific interpretation. */
4363 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4365 cu
->producer
= DW_STRING (attr
);
4369 do_cleanups (free_abbrevs_cleanup
);
4371 /* We've successfully allocated this compilation unit. Let our
4372 caller clean it up when finished with it. */
4373 discard_cleanups (free_cu_cleanup
);
4377 /* Add a DIE to the delayed physname list. */
4380 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4381 const char *name
, struct die_info
*die
,
4382 struct dwarf2_cu
*cu
)
4384 struct delayed_method_info mi
;
4386 mi
.fnfield_index
= fnfield_index
;
4390 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4393 /* A cleanup for freeing the delayed method list. */
4396 free_delayed_list (void *ptr
)
4398 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4399 if (cu
->method_list
!= NULL
)
4401 VEC_free (delayed_method_info
, cu
->method_list
);
4402 cu
->method_list
= NULL
;
4406 /* Compute the physnames of any methods on the CU's method list.
4408 The computation of method physnames is delayed in order to avoid the
4409 (bad) condition that one of the method's formal parameters is of an as yet
4413 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4416 struct delayed_method_info
*mi
;
4417 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4420 struct fn_fieldlist
*fn_flp
4421 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4422 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4423 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4427 /* Generate full symbol information for PST and CU, whose DIEs have
4428 already been loaded into memory. */
4431 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4433 struct dwarf2_cu
*cu
= per_cu
->cu
;
4434 struct objfile
*objfile
= per_cu
->objfile
;
4435 CORE_ADDR lowpc
, highpc
;
4436 struct symtab
*symtab
;
4437 struct cleanup
*back_to
, *delayed_list_cleanup
;
4440 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4443 back_to
= make_cleanup (really_free_pendings
, NULL
);
4444 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4446 cu
->list_in_scope
= &file_symbols
;
4448 dwarf2_find_base_address (cu
->dies
, cu
);
4450 /* Do line number decoding in read_file_scope () */
4451 process_die (cu
->dies
, cu
);
4453 /* Now that we have processed all the DIEs in the CU, all the types
4454 should be complete, and it should now be safe to compute all of the
4456 compute_delayed_physnames (cu
);
4457 do_cleanups (delayed_list_cleanup
);
4459 /* Some compilers don't define a DW_AT_high_pc attribute for the
4460 compilation unit. If the DW_AT_high_pc is missing, synthesize
4461 it, by scanning the DIE's below the compilation unit. */
4462 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4464 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4466 /* Set symtab language to language from DW_AT_language.
4467 If the compilation is from a C file generated by language preprocessors,
4468 do not set the language if it was already deduced by start_subfile. */
4470 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4472 symtab
->language
= cu
->language
;
4475 if (dwarf2_per_objfile
->using_index
)
4476 per_cu
->v
.quick
->symtab
= symtab
;
4479 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4480 pst
->symtab
= symtab
;
4484 do_cleanups (back_to
);
4487 /* Process a die and its children. */
4490 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4494 case DW_TAG_padding
:
4496 case DW_TAG_compile_unit
:
4497 read_file_scope (die
, cu
);
4499 case DW_TAG_type_unit
:
4500 read_type_unit_scope (die
, cu
);
4502 case DW_TAG_subprogram
:
4503 case DW_TAG_inlined_subroutine
:
4504 read_func_scope (die
, cu
);
4506 case DW_TAG_lexical_block
:
4507 case DW_TAG_try_block
:
4508 case DW_TAG_catch_block
:
4509 read_lexical_block_scope (die
, cu
);
4511 case DW_TAG_class_type
:
4512 case DW_TAG_interface_type
:
4513 case DW_TAG_structure_type
:
4514 case DW_TAG_union_type
:
4515 process_structure_scope (die
, cu
);
4517 case DW_TAG_enumeration_type
:
4518 process_enumeration_scope (die
, cu
);
4521 /* These dies have a type, but processing them does not create
4522 a symbol or recurse to process the children. Therefore we can
4523 read them on-demand through read_type_die. */
4524 case DW_TAG_subroutine_type
:
4525 case DW_TAG_set_type
:
4526 case DW_TAG_array_type
:
4527 case DW_TAG_pointer_type
:
4528 case DW_TAG_ptr_to_member_type
:
4529 case DW_TAG_reference_type
:
4530 case DW_TAG_string_type
:
4533 case DW_TAG_base_type
:
4534 case DW_TAG_subrange_type
:
4535 case DW_TAG_typedef
:
4536 /* Add a typedef symbol for the type definition, if it has a
4538 new_symbol (die
, read_type_die (die
, cu
), cu
);
4540 case DW_TAG_common_block
:
4541 read_common_block (die
, cu
);
4543 case DW_TAG_common_inclusion
:
4545 case DW_TAG_namespace
:
4546 processing_has_namespace_info
= 1;
4547 read_namespace (die
, cu
);
4550 processing_has_namespace_info
= 1;
4551 read_module (die
, cu
);
4553 case DW_TAG_imported_declaration
:
4554 case DW_TAG_imported_module
:
4555 processing_has_namespace_info
= 1;
4556 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4557 || cu
->language
!= language_fortran
))
4558 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4559 dwarf_tag_name (die
->tag
));
4560 read_import_statement (die
, cu
);
4563 new_symbol (die
, NULL
, cu
);
4568 /* A helper function for dwarf2_compute_name which determines whether DIE
4569 needs to have the name of the scope prepended to the name listed in the
4573 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4575 struct attribute
*attr
;
4579 case DW_TAG_namespace
:
4580 case DW_TAG_typedef
:
4581 case DW_TAG_class_type
:
4582 case DW_TAG_interface_type
:
4583 case DW_TAG_structure_type
:
4584 case DW_TAG_union_type
:
4585 case DW_TAG_enumeration_type
:
4586 case DW_TAG_enumerator
:
4587 case DW_TAG_subprogram
:
4591 case DW_TAG_variable
:
4592 case DW_TAG_constant
:
4593 /* We only need to prefix "globally" visible variables. These include
4594 any variable marked with DW_AT_external or any variable that
4595 lives in a namespace. [Variables in anonymous namespaces
4596 require prefixing, but they are not DW_AT_external.] */
4598 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4600 struct dwarf2_cu
*spec_cu
= cu
;
4602 return die_needs_namespace (die_specification (die
, &spec_cu
),
4606 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4607 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4608 && die
->parent
->tag
!= DW_TAG_module
)
4610 /* A variable in a lexical block of some kind does not need a
4611 namespace, even though in C++ such variables may be external
4612 and have a mangled name. */
4613 if (die
->parent
->tag
== DW_TAG_lexical_block
4614 || die
->parent
->tag
== DW_TAG_try_block
4615 || die
->parent
->tag
== DW_TAG_catch_block
4616 || die
->parent
->tag
== DW_TAG_subprogram
)
4625 /* Retrieve the last character from a mem_file. */
4628 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4630 char *last_char_p
= (char *) object
;
4633 *last_char_p
= buffer
[length
- 1];
4636 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4637 compute the physname for the object, which include a method's
4638 formal parameters (C++/Java) and return type (Java).
4640 For Ada, return the DIE's linkage name rather than the fully qualified
4641 name. PHYSNAME is ignored..
4643 The result is allocated on the objfile_obstack and canonicalized. */
4646 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4650 name
= dwarf2_name (die
, cu
);
4652 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4653 compute it by typename_concat inside GDB. */
4654 if (cu
->language
== language_ada
4655 || (cu
->language
== language_fortran
&& physname
))
4657 /* For Ada unit, we prefer the linkage name over the name, as
4658 the former contains the exported name, which the user expects
4659 to be able to reference. Ideally, we want the user to be able
4660 to reference this entity using either natural or linkage name,
4661 but we haven't started looking at this enhancement yet. */
4662 struct attribute
*attr
;
4664 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4666 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4667 if (attr
&& DW_STRING (attr
))
4668 return DW_STRING (attr
);
4671 /* These are the only languages we know how to qualify names in. */
4673 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4674 || cu
->language
== language_fortran
))
4676 if (die_needs_namespace (die
, cu
))
4680 struct ui_file
*buf
;
4682 prefix
= determine_prefix (die
, cu
);
4683 buf
= mem_fileopen ();
4684 if (*prefix
!= '\0')
4686 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4689 fputs_unfiltered (prefixed_name
, buf
);
4690 xfree (prefixed_name
);
4693 fputs_unfiltered (name
? name
: "", buf
);
4695 /* Template parameters may be specified in the DIE's DW_AT_name, or
4696 as children with DW_TAG_template_type_param or
4697 DW_TAG_value_type_param. If the latter, add them to the name
4698 here. If the name already has template parameters, then
4699 skip this step; some versions of GCC emit both, and
4700 it is more efficient to use the pre-computed name.
4702 Something to keep in mind about this process: it is very
4703 unlikely, or in some cases downright impossible, to produce
4704 something that will match the mangled name of a function.
4705 If the definition of the function has the same debug info,
4706 we should be able to match up with it anyway. But fallbacks
4707 using the minimal symbol, for instance to find a method
4708 implemented in a stripped copy of libstdc++, will not work.
4709 If we do not have debug info for the definition, we will have to
4710 match them up some other way.
4712 When we do name matching there is a related problem with function
4713 templates; two instantiated function templates are allowed to
4714 differ only by their return types, which we do not add here. */
4716 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4718 struct attribute
*attr
;
4719 struct die_info
*child
;
4722 die
->building_fullname
= 1;
4724 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4729 struct dwarf2_locexpr_baton
*baton
;
4732 if (child
->tag
!= DW_TAG_template_type_param
4733 && child
->tag
!= DW_TAG_template_value_param
)
4738 fputs_unfiltered ("<", buf
);
4742 fputs_unfiltered (", ", buf
);
4744 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4747 complaint (&symfile_complaints
,
4748 _("template parameter missing DW_AT_type"));
4749 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4752 type
= die_type (child
, cu
);
4754 if (child
->tag
== DW_TAG_template_type_param
)
4756 c_print_type (type
, "", buf
, -1, 0);
4760 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4763 complaint (&symfile_complaints
,
4764 _("template parameter missing DW_AT_const_value"));
4765 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4769 dwarf2_const_value_attr (attr
, type
, name
,
4770 &cu
->comp_unit_obstack
, cu
,
4771 &value
, &bytes
, &baton
);
4773 if (TYPE_NOSIGN (type
))
4774 /* GDB prints characters as NUMBER 'CHAR'. If that's
4775 changed, this can use value_print instead. */
4776 c_printchar (value
, type
, buf
);
4779 struct value_print_options opts
;
4782 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4786 else if (bytes
!= NULL
)
4788 v
= allocate_value (type
);
4789 memcpy (value_contents_writeable (v
), bytes
,
4790 TYPE_LENGTH (type
));
4793 v
= value_from_longest (type
, value
);
4795 /* Specify decimal so that we do not depend on the radix. */
4796 get_formatted_print_options (&opts
, 'd');
4798 value_print (v
, buf
, &opts
);
4804 die
->building_fullname
= 0;
4808 /* Close the argument list, with a space if necessary
4809 (nested templates). */
4810 char last_char
= '\0';
4811 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4812 if (last_char
== '>')
4813 fputs_unfiltered (" >", buf
);
4815 fputs_unfiltered (">", buf
);
4819 /* For Java and C++ methods, append formal parameter type
4820 information, if PHYSNAME. */
4822 if (physname
&& die
->tag
== DW_TAG_subprogram
4823 && (cu
->language
== language_cplus
4824 || cu
->language
== language_java
))
4826 struct type
*type
= read_type_die (die
, cu
);
4828 c_type_print_args (type
, buf
, 0, cu
->language
);
4830 if (cu
->language
== language_java
)
4832 /* For java, we must append the return type to method
4834 if (die
->tag
== DW_TAG_subprogram
)
4835 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4838 else if (cu
->language
== language_cplus
)
4840 /* Assume that an artificial first parameter is
4841 "this", but do not crash if it is not. RealView
4842 marks unnamed (and thus unused) parameters as
4843 artificial; there is no way to differentiate
4845 if (TYPE_NFIELDS (type
) > 0
4846 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4847 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4848 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4849 fputs_unfiltered (" const", buf
);
4853 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4855 ui_file_delete (buf
);
4857 if (cu
->language
== language_cplus
)
4860 = dwarf2_canonicalize_name (name
, cu
,
4861 &cu
->objfile
->objfile_obstack
);
4872 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4873 If scope qualifiers are appropriate they will be added. The result
4874 will be allocated on the objfile_obstack, or NULL if the DIE does
4875 not have a name. NAME may either be from a previous call to
4876 dwarf2_name or NULL.
4878 The output string will be canonicalized (if C++/Java). */
4881 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4883 return dwarf2_compute_name (name
, die
, cu
, 0);
4886 /* Construct a physname for the given DIE in CU. NAME may either be
4887 from a previous call to dwarf2_name or NULL. The result will be
4888 allocated on the objfile_objstack or NULL if the DIE does not have a
4891 The output string will be canonicalized (if C++/Java). */
4894 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4896 return dwarf2_compute_name (name
, die
, cu
, 1);
4899 /* Read the import statement specified by the given die and record it. */
4902 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4904 struct attribute
*import_attr
;
4905 struct die_info
*imported_die
;
4906 struct dwarf2_cu
*imported_cu
;
4907 const char *imported_name
;
4908 const char *imported_name_prefix
;
4909 const char *canonical_name
;
4910 const char *import_alias
;
4911 const char *imported_declaration
= NULL
;
4912 const char *import_prefix
;
4916 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4917 if (import_attr
== NULL
)
4919 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4920 dwarf_tag_name (die
->tag
));
4925 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4926 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4927 if (imported_name
== NULL
)
4929 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4931 The import in the following code:
4945 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4946 <52> DW_AT_decl_file : 1
4947 <53> DW_AT_decl_line : 6
4948 <54> DW_AT_import : <0x75>
4949 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4951 <5b> DW_AT_decl_file : 1
4952 <5c> DW_AT_decl_line : 2
4953 <5d> DW_AT_type : <0x6e>
4955 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4956 <76> DW_AT_byte_size : 4
4957 <77> DW_AT_encoding : 5 (signed)
4959 imports the wrong die ( 0x75 instead of 0x58 ).
4960 This case will be ignored until the gcc bug is fixed. */
4964 /* Figure out the local name after import. */
4965 import_alias
= dwarf2_name (die
, cu
);
4967 /* Figure out where the statement is being imported to. */
4968 import_prefix
= determine_prefix (die
, cu
);
4970 /* Figure out what the scope of the imported die is and prepend it
4971 to the name of the imported die. */
4972 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4974 if (imported_die
->tag
!= DW_TAG_namespace
4975 && imported_die
->tag
!= DW_TAG_module
)
4977 imported_declaration
= imported_name
;
4978 canonical_name
= imported_name_prefix
;
4980 else if (strlen (imported_name_prefix
) > 0)
4982 temp
= alloca (strlen (imported_name_prefix
)
4983 + 2 + strlen (imported_name
) + 1);
4984 strcpy (temp
, imported_name_prefix
);
4985 strcat (temp
, "::");
4986 strcat (temp
, imported_name
);
4987 canonical_name
= temp
;
4990 canonical_name
= imported_name
;
4992 cp_add_using_directive (import_prefix
,
4995 imported_declaration
,
4996 &cu
->objfile
->objfile_obstack
);
5000 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5002 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5006 free_cu_line_header (void *arg
)
5008 struct dwarf2_cu
*cu
= arg
;
5010 free_line_header (cu
->line_header
);
5011 cu
->line_header
= NULL
;
5015 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5016 char **name
, char **comp_dir
)
5018 struct attribute
*attr
;
5023 /* Find the filename. Do not use dwarf2_name here, since the filename
5024 is not a source language identifier. */
5025 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5028 *name
= DW_STRING (attr
);
5031 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5033 *comp_dir
= DW_STRING (attr
);
5034 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5036 *comp_dir
= ldirname (*name
);
5037 if (*comp_dir
!= NULL
)
5038 make_cleanup (xfree
, *comp_dir
);
5040 if (*comp_dir
!= NULL
)
5042 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5043 directory, get rid of it. */
5044 char *cp
= strchr (*comp_dir
, ':');
5046 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5051 *name
= "<unknown>";
5055 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5057 struct objfile
*objfile
= cu
->objfile
;
5058 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5059 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5060 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5061 struct attribute
*attr
;
5063 char *comp_dir
= NULL
;
5064 struct die_info
*child_die
;
5065 bfd
*abfd
= objfile
->obfd
;
5066 struct line_header
*line_header
= 0;
5069 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5071 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5073 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5074 from finish_block. */
5075 if (lowpc
== ((CORE_ADDR
) -1))
5080 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5082 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5085 set_cu_language (DW_UNSND (attr
), cu
);
5088 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5090 cu
->producer
= DW_STRING (attr
);
5092 /* We assume that we're processing GCC output. */
5093 processing_gcc_compilation
= 2;
5095 processing_has_namespace_info
= 0;
5097 start_symtab (name
, comp_dir
, lowpc
);
5098 record_debugformat ("DWARF 2");
5099 record_producer (cu
->producer
);
5101 initialize_cu_func_list (cu
);
5103 /* Decode line number information if present. We do this before
5104 processing child DIEs, so that the line header table is available
5105 for DW_AT_decl_file. */
5106 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5109 unsigned int line_offset
= DW_UNSND (attr
);
5110 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5113 cu
->line_header
= line_header
;
5114 make_cleanup (free_cu_line_header
, cu
);
5115 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5119 /* Process all dies in compilation unit. */
5120 if (die
->child
!= NULL
)
5122 child_die
= die
->child
;
5123 while (child_die
&& child_die
->tag
)
5125 process_die (child_die
, cu
);
5126 child_die
= sibling_die (child_die
);
5130 /* Decode macro information, if present. Dwarf 2 macro information
5131 refers to information in the line number info statement program
5132 header, so we can only read it if we've read the header
5134 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5135 if (attr
&& line_header
)
5137 unsigned int macro_offset
= DW_UNSND (attr
);
5139 dwarf_decode_macros (line_header
, macro_offset
,
5140 comp_dir
, abfd
, cu
);
5142 do_cleanups (back_to
);
5145 /* For TUs we want to skip the first top level sibling if it's not the
5146 actual type being defined by this TU. In this case the first top
5147 level sibling is there to provide context only. */
5150 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5152 struct objfile
*objfile
= cu
->objfile
;
5153 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5155 struct attribute
*attr
;
5157 char *comp_dir
= NULL
;
5158 struct die_info
*child_die
;
5159 bfd
*abfd
= objfile
->obfd
;
5161 /* start_symtab needs a low pc, but we don't really have one.
5162 Do what read_file_scope would do in the absence of such info. */
5163 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5165 /* Find the filename. Do not use dwarf2_name here, since the filename
5166 is not a source language identifier. */
5167 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5169 name
= DW_STRING (attr
);
5171 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5173 comp_dir
= DW_STRING (attr
);
5174 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5176 comp_dir
= ldirname (name
);
5177 if (comp_dir
!= NULL
)
5178 make_cleanup (xfree
, comp_dir
);
5184 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5186 set_cu_language (DW_UNSND (attr
), cu
);
5188 /* This isn't technically needed today. It is done for symmetry
5189 with read_file_scope. */
5190 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5192 cu
->producer
= DW_STRING (attr
);
5194 /* We assume that we're processing GCC output. */
5195 processing_gcc_compilation
= 2;
5197 processing_has_namespace_info
= 0;
5199 start_symtab (name
, comp_dir
, lowpc
);
5200 record_debugformat ("DWARF 2");
5201 record_producer (cu
->producer
);
5203 /* Process the dies in the type unit. */
5204 if (die
->child
== NULL
)
5206 dump_die_for_error (die
);
5207 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5208 bfd_get_filename (abfd
));
5211 child_die
= die
->child
;
5213 while (child_die
&& child_die
->tag
)
5215 process_die (child_die
, cu
);
5217 child_die
= sibling_die (child_die
);
5220 do_cleanups (back_to
);
5224 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5225 struct dwarf2_cu
*cu
)
5227 struct function_range
*thisfn
;
5229 thisfn
= (struct function_range
*)
5230 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5231 thisfn
->name
= name
;
5232 thisfn
->lowpc
= lowpc
;
5233 thisfn
->highpc
= highpc
;
5234 thisfn
->seen_line
= 0;
5235 thisfn
->next
= NULL
;
5237 if (cu
->last_fn
== NULL
)
5238 cu
->first_fn
= thisfn
;
5240 cu
->last_fn
->next
= thisfn
;
5242 cu
->last_fn
= thisfn
;
5245 /* qsort helper for inherit_abstract_dies. */
5248 unsigned_int_compar (const void *ap
, const void *bp
)
5250 unsigned int a
= *(unsigned int *) ap
;
5251 unsigned int b
= *(unsigned int *) bp
;
5253 return (a
> b
) - (b
> a
);
5256 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5257 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5258 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5261 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5263 struct die_info
*child_die
;
5264 unsigned die_children_count
;
5265 /* CU offsets which were referenced by children of the current DIE. */
5267 unsigned *offsets_end
, *offsetp
;
5268 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5269 struct die_info
*origin_die
;
5270 /* Iterator of the ORIGIN_DIE children. */
5271 struct die_info
*origin_child_die
;
5272 struct cleanup
*cleanups
;
5273 struct attribute
*attr
;
5274 struct dwarf2_cu
*origin_cu
;
5275 struct pending
**origin_previous_list_in_scope
;
5277 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5281 /* Note that following die references may follow to a die in a
5285 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5287 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5289 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5290 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5292 if (die
->tag
!= origin_die
->tag
5293 && !(die
->tag
== DW_TAG_inlined_subroutine
5294 && origin_die
->tag
== DW_TAG_subprogram
))
5295 complaint (&symfile_complaints
,
5296 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5297 die
->offset
, origin_die
->offset
);
5299 child_die
= die
->child
;
5300 die_children_count
= 0;
5301 while (child_die
&& child_die
->tag
)
5303 child_die
= sibling_die (child_die
);
5304 die_children_count
++;
5306 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5307 cleanups
= make_cleanup (xfree
, offsets
);
5309 offsets_end
= offsets
;
5310 child_die
= die
->child
;
5311 while (child_die
&& child_die
->tag
)
5313 /* For each CHILD_DIE, find the corresponding child of
5314 ORIGIN_DIE. If there is more than one layer of
5315 DW_AT_abstract_origin, follow them all; there shouldn't be,
5316 but GCC versions at least through 4.4 generate this (GCC PR
5318 struct die_info
*child_origin_die
= child_die
;
5319 struct dwarf2_cu
*child_origin_cu
= cu
;
5323 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5327 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5331 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5332 counterpart may exist. */
5333 if (child_origin_die
!= child_die
)
5335 if (child_die
->tag
!= child_origin_die
->tag
5336 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5337 && child_origin_die
->tag
== DW_TAG_subprogram
))
5338 complaint (&symfile_complaints
,
5339 _("Child DIE 0x%x and its abstract origin 0x%x have "
5340 "different tags"), child_die
->offset
,
5341 child_origin_die
->offset
);
5342 if (child_origin_die
->parent
!= origin_die
)
5343 complaint (&symfile_complaints
,
5344 _("Child DIE 0x%x and its abstract origin 0x%x have "
5345 "different parents"), child_die
->offset
,
5346 child_origin_die
->offset
);
5348 *offsets_end
++ = child_origin_die
->offset
;
5350 child_die
= sibling_die (child_die
);
5352 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5353 unsigned_int_compar
);
5354 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5355 if (offsetp
[-1] == *offsetp
)
5356 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5357 "to DIE 0x%x as their abstract origin"),
5358 die
->offset
, *offsetp
);
5361 origin_child_die
= origin_die
->child
;
5362 while (origin_child_die
&& origin_child_die
->tag
)
5364 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5365 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5367 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5369 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5370 process_die (origin_child_die
, origin_cu
);
5372 origin_child_die
= sibling_die (origin_child_die
);
5374 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5376 do_cleanups (cleanups
);
5380 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5382 struct objfile
*objfile
= cu
->objfile
;
5383 struct context_stack
*new;
5386 struct die_info
*child_die
;
5387 struct attribute
*attr
, *call_line
, *call_file
;
5390 struct block
*block
;
5391 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5392 VEC (symbolp
) *template_args
= NULL
;
5393 struct template_symbol
*templ_func
= NULL
;
5397 /* If we do not have call site information, we can't show the
5398 caller of this inlined function. That's too confusing, so
5399 only use the scope for local variables. */
5400 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5401 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5402 if (call_line
== NULL
|| call_file
== NULL
)
5404 read_lexical_block_scope (die
, cu
);
5409 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5411 name
= dwarf2_name (die
, cu
);
5413 /* Ignore functions with missing or empty names. These are actually
5414 illegal according to the DWARF standard. */
5417 complaint (&symfile_complaints
,
5418 _("missing name for subprogram DIE at %d"), die
->offset
);
5422 /* Ignore functions with missing or invalid low and high pc attributes. */
5423 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5425 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5426 if (!attr
|| !DW_UNSND (attr
))
5427 complaint (&symfile_complaints
,
5428 _("cannot get low and high bounds for subprogram DIE at %d"),
5436 /* Record the function range for dwarf_decode_lines. */
5437 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5439 /* If we have any template arguments, then we must allocate a
5440 different sort of symbol. */
5441 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5443 if (child_die
->tag
== DW_TAG_template_type_param
5444 || child_die
->tag
== DW_TAG_template_value_param
)
5446 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5447 struct template_symbol
);
5448 templ_func
->base
.is_cplus_template_function
= 1;
5453 new = push_context (0, lowpc
);
5454 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5455 (struct symbol
*) templ_func
);
5457 /* If there is a location expression for DW_AT_frame_base, record
5459 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5461 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5462 expression is being recorded directly in the function's symbol
5463 and not in a separate frame-base object. I guess this hack is
5464 to avoid adding some sort of frame-base adjunct/annex to the
5465 function's symbol :-(. The problem with doing this is that it
5466 results in a function symbol with a location expression that
5467 has nothing to do with the location of the function, ouch! The
5468 relationship should be: a function's symbol has-a frame base; a
5469 frame-base has-a location expression. */
5470 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5472 cu
->list_in_scope
= &local_symbols
;
5474 if (die
->child
!= NULL
)
5476 child_die
= die
->child
;
5477 while (child_die
&& child_die
->tag
)
5479 if (child_die
->tag
== DW_TAG_template_type_param
5480 || child_die
->tag
== DW_TAG_template_value_param
)
5482 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5485 VEC_safe_push (symbolp
, template_args
, arg
);
5488 process_die (child_die
, cu
);
5489 child_die
= sibling_die (child_die
);
5493 inherit_abstract_dies (die
, cu
);
5495 /* If we have a DW_AT_specification, we might need to import using
5496 directives from the context of the specification DIE. See the
5497 comment in determine_prefix. */
5498 if (cu
->language
== language_cplus
5499 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5501 struct dwarf2_cu
*spec_cu
= cu
;
5502 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5506 child_die
= spec_die
->child
;
5507 while (child_die
&& child_die
->tag
)
5509 if (child_die
->tag
== DW_TAG_imported_module
)
5510 process_die (child_die
, spec_cu
);
5511 child_die
= sibling_die (child_die
);
5514 /* In some cases, GCC generates specification DIEs that
5515 themselves contain DW_AT_specification attributes. */
5516 spec_die
= die_specification (spec_die
, &spec_cu
);
5520 new = pop_context ();
5521 /* Make a block for the local symbols within. */
5522 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5523 lowpc
, highpc
, objfile
);
5525 /* For C++, set the block's scope. */
5526 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5527 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5528 determine_prefix (die
, cu
),
5529 processing_has_namespace_info
);
5531 /* If we have address ranges, record them. */
5532 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5534 /* Attach template arguments to function. */
5535 if (! VEC_empty (symbolp
, template_args
))
5537 gdb_assert (templ_func
!= NULL
);
5539 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5540 templ_func
->template_arguments
5541 = obstack_alloc (&objfile
->objfile_obstack
,
5542 (templ_func
->n_template_arguments
5543 * sizeof (struct symbol
*)));
5544 memcpy (templ_func
->template_arguments
,
5545 VEC_address (symbolp
, template_args
),
5546 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5547 VEC_free (symbolp
, template_args
);
5550 /* In C++, we can have functions nested inside functions (e.g., when
5551 a function declares a class that has methods). This means that
5552 when we finish processing a function scope, we may need to go
5553 back to building a containing block's symbol lists. */
5554 local_symbols
= new->locals
;
5555 param_symbols
= new->params
;
5556 using_directives
= new->using_directives
;
5558 /* If we've finished processing a top-level function, subsequent
5559 symbols go in the file symbol list. */
5560 if (outermost_context_p ())
5561 cu
->list_in_scope
= &file_symbols
;
5564 /* Process all the DIES contained within a lexical block scope. Start
5565 a new scope, process the dies, and then close the scope. */
5568 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5570 struct objfile
*objfile
= cu
->objfile
;
5571 struct context_stack
*new;
5572 CORE_ADDR lowpc
, highpc
;
5573 struct die_info
*child_die
;
5576 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5578 /* Ignore blocks with missing or invalid low and high pc attributes. */
5579 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5580 as multiple lexical blocks? Handling children in a sane way would
5581 be nasty. Might be easier to properly extend generic blocks to
5583 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5588 push_context (0, lowpc
);
5589 if (die
->child
!= NULL
)
5591 child_die
= die
->child
;
5592 while (child_die
&& child_die
->tag
)
5594 process_die (child_die
, cu
);
5595 child_die
= sibling_die (child_die
);
5598 new = pop_context ();
5600 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5603 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5606 /* Note that recording ranges after traversing children, as we
5607 do here, means that recording a parent's ranges entails
5608 walking across all its children's ranges as they appear in
5609 the address map, which is quadratic behavior.
5611 It would be nicer to record the parent's ranges before
5612 traversing its children, simply overriding whatever you find
5613 there. But since we don't even decide whether to create a
5614 block until after we've traversed its children, that's hard
5616 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5618 local_symbols
= new->locals
;
5619 using_directives
= new->using_directives
;
5622 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5623 Return 1 if the attributes are present and valid, otherwise, return 0.
5624 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5627 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5628 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5629 struct partial_symtab
*ranges_pst
)
5631 struct objfile
*objfile
= cu
->objfile
;
5632 struct comp_unit_head
*cu_header
= &cu
->header
;
5633 bfd
*obfd
= objfile
->obfd
;
5634 unsigned int addr_size
= cu_header
->addr_size
;
5635 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5636 /* Base address selection entry. */
5647 found_base
= cu
->base_known
;
5648 base
= cu
->base_address
;
5650 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5651 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5653 complaint (&symfile_complaints
,
5654 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5658 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5660 /* Read in the largest possible address. */
5661 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5662 if ((marker
& mask
) == mask
)
5664 /* If we found the largest possible address, then
5665 read the base address. */
5666 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5667 buffer
+= 2 * addr_size
;
5668 offset
+= 2 * addr_size
;
5674 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5678 CORE_ADDR range_beginning
, range_end
;
5680 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5681 buffer
+= addr_size
;
5682 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5683 buffer
+= addr_size
;
5684 offset
+= 2 * addr_size
;
5686 /* An end of list marker is a pair of zero addresses. */
5687 if (range_beginning
== 0 && range_end
== 0)
5688 /* Found the end of list entry. */
5691 /* Each base address selection entry is a pair of 2 values.
5692 The first is the largest possible address, the second is
5693 the base address. Check for a base address here. */
5694 if ((range_beginning
& mask
) == mask
)
5696 /* If we found the largest possible address, then
5697 read the base address. */
5698 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5705 /* We have no valid base address for the ranges
5707 complaint (&symfile_complaints
,
5708 _("Invalid .debug_ranges data (no base address)"));
5712 range_beginning
+= base
;
5715 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5716 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5717 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5720 /* FIXME: This is recording everything as a low-high
5721 segment of consecutive addresses. We should have a
5722 data structure for discontiguous block ranges
5726 low
= range_beginning
;
5732 if (range_beginning
< low
)
5733 low
= range_beginning
;
5734 if (range_end
> high
)
5740 /* If the first entry is an end-of-list marker, the range
5741 describes an empty scope, i.e. no instructions. */
5747 *high_return
= high
;
5751 /* Get low and high pc attributes from a die. Return 1 if the attributes
5752 are present and valid, otherwise, return 0. Return -1 if the range is
5753 discontinuous, i.e. derived from DW_AT_ranges information. */
5755 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5756 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5757 struct partial_symtab
*pst
)
5759 struct attribute
*attr
;
5764 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5767 high
= DW_ADDR (attr
);
5768 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5770 low
= DW_ADDR (attr
);
5772 /* Found high w/o low attribute. */
5775 /* Found consecutive range of addresses. */
5780 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5783 /* Value of the DW_AT_ranges attribute is the offset in the
5784 .debug_ranges section. */
5785 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5787 /* Found discontinuous range of addresses. */
5795 /* When using the GNU linker, .gnu.linkonce. sections are used to
5796 eliminate duplicate copies of functions and vtables and such.
5797 The linker will arbitrarily choose one and discard the others.
5798 The AT_*_pc values for such functions refer to local labels in
5799 these sections. If the section from that file was discarded, the
5800 labels are not in the output, so the relocs get a value of 0.
5801 If this is a discarded function, mark the pc bounds as invalid,
5802 so that GDB will ignore it. */
5803 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5811 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5812 its low and high PC addresses. Do nothing if these addresses could not
5813 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5814 and HIGHPC to the high address if greater than HIGHPC. */
5817 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5818 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5819 struct dwarf2_cu
*cu
)
5821 CORE_ADDR low
, high
;
5822 struct die_info
*child
= die
->child
;
5824 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5826 *lowpc
= min (*lowpc
, low
);
5827 *highpc
= max (*highpc
, high
);
5830 /* If the language does not allow nested subprograms (either inside
5831 subprograms or lexical blocks), we're done. */
5832 if (cu
->language
!= language_ada
)
5835 /* Check all the children of the given DIE. If it contains nested
5836 subprograms, then check their pc bounds. Likewise, we need to
5837 check lexical blocks as well, as they may also contain subprogram
5839 while (child
&& child
->tag
)
5841 if (child
->tag
== DW_TAG_subprogram
5842 || child
->tag
== DW_TAG_lexical_block
)
5843 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5844 child
= sibling_die (child
);
5848 /* Get the low and high pc's represented by the scope DIE, and store
5849 them in *LOWPC and *HIGHPC. If the correct values can't be
5850 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5853 get_scope_pc_bounds (struct die_info
*die
,
5854 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5855 struct dwarf2_cu
*cu
)
5857 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5858 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5859 CORE_ADDR current_low
, current_high
;
5861 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5863 best_low
= current_low
;
5864 best_high
= current_high
;
5868 struct die_info
*child
= die
->child
;
5870 while (child
&& child
->tag
)
5872 switch (child
->tag
) {
5873 case DW_TAG_subprogram
:
5874 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5876 case DW_TAG_namespace
:
5878 /* FIXME: carlton/2004-01-16: Should we do this for
5879 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5880 that current GCC's always emit the DIEs corresponding
5881 to definitions of methods of classes as children of a
5882 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5883 the DIEs giving the declarations, which could be
5884 anywhere). But I don't see any reason why the
5885 standards says that they have to be there. */
5886 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5888 if (current_low
!= ((CORE_ADDR
) -1))
5890 best_low
= min (best_low
, current_low
);
5891 best_high
= max (best_high
, current_high
);
5899 child
= sibling_die (child
);
5904 *highpc
= best_high
;
5907 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5910 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5911 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5913 struct attribute
*attr
;
5915 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5918 CORE_ADDR high
= DW_ADDR (attr
);
5920 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5923 CORE_ADDR low
= DW_ADDR (attr
);
5925 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5929 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5932 bfd
*obfd
= cu
->objfile
->obfd
;
5934 /* The value of the DW_AT_ranges attribute is the offset of the
5935 address range list in the .debug_ranges section. */
5936 unsigned long offset
= DW_UNSND (attr
);
5937 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5939 /* For some target architectures, but not others, the
5940 read_address function sign-extends the addresses it returns.
5941 To recognize base address selection entries, we need a
5943 unsigned int addr_size
= cu
->header
.addr_size
;
5944 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5946 /* The base address, to which the next pair is relative. Note
5947 that this 'base' is a DWARF concept: most entries in a range
5948 list are relative, to reduce the number of relocs against the
5949 debugging information. This is separate from this function's
5950 'baseaddr' argument, which GDB uses to relocate debugging
5951 information from a shared library based on the address at
5952 which the library was loaded. */
5953 CORE_ADDR base
= cu
->base_address
;
5954 int base_known
= cu
->base_known
;
5956 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5957 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5959 complaint (&symfile_complaints
,
5960 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5967 unsigned int bytes_read
;
5968 CORE_ADDR start
, end
;
5970 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5971 buffer
+= bytes_read
;
5972 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5973 buffer
+= bytes_read
;
5975 /* Did we find the end of the range list? */
5976 if (start
== 0 && end
== 0)
5979 /* Did we find a base address selection entry? */
5980 else if ((start
& base_select_mask
) == base_select_mask
)
5986 /* We found an ordinary address range. */
5991 complaint (&symfile_complaints
,
5992 _("Invalid .debug_ranges data (no base address)"));
5996 record_block_range (block
,
5997 baseaddr
+ base
+ start
,
5998 baseaddr
+ base
+ end
- 1);
6004 /* Add an aggregate field to the field list. */
6007 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6008 struct dwarf2_cu
*cu
)
6010 struct objfile
*objfile
= cu
->objfile
;
6011 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6012 struct nextfield
*new_field
;
6013 struct attribute
*attr
;
6015 char *fieldname
= "";
6017 /* Allocate a new field list entry and link it in. */
6018 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6019 make_cleanup (xfree
, new_field
);
6020 memset (new_field
, 0, sizeof (struct nextfield
));
6022 if (die
->tag
== DW_TAG_inheritance
)
6024 new_field
->next
= fip
->baseclasses
;
6025 fip
->baseclasses
= new_field
;
6029 new_field
->next
= fip
->fields
;
6030 fip
->fields
= new_field
;
6034 /* Handle accessibility and virtuality of field.
6035 The default accessibility for members is public, the default
6036 accessibility for inheritance is private. */
6037 if (die
->tag
!= DW_TAG_inheritance
)
6038 new_field
->accessibility
= DW_ACCESS_public
;
6040 new_field
->accessibility
= DW_ACCESS_private
;
6041 new_field
->virtuality
= DW_VIRTUALITY_none
;
6043 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6045 new_field
->accessibility
= DW_UNSND (attr
);
6046 if (new_field
->accessibility
!= DW_ACCESS_public
)
6047 fip
->non_public_fields
= 1;
6048 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6050 new_field
->virtuality
= DW_UNSND (attr
);
6052 fp
= &new_field
->field
;
6054 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6056 /* Data member other than a C++ static data member. */
6058 /* Get type of field. */
6059 fp
->type
= die_type (die
, cu
);
6061 SET_FIELD_BITPOS (*fp
, 0);
6063 /* Get bit size of field (zero if none). */
6064 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6067 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6071 FIELD_BITSIZE (*fp
) = 0;
6074 /* Get bit offset of field. */
6075 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6078 int byte_offset
= 0;
6080 if (attr_form_is_section_offset (attr
))
6081 dwarf2_complex_location_expr_complaint ();
6082 else if (attr_form_is_constant (attr
))
6083 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6084 else if (attr_form_is_block (attr
))
6085 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6087 dwarf2_complex_location_expr_complaint ();
6089 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6091 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6094 if (gdbarch_bits_big_endian (gdbarch
))
6096 /* For big endian bits, the DW_AT_bit_offset gives the
6097 additional bit offset from the MSB of the containing
6098 anonymous object to the MSB of the field. We don't
6099 have to do anything special since we don't need to
6100 know the size of the anonymous object. */
6101 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6105 /* For little endian bits, compute the bit offset to the
6106 MSB of the anonymous object, subtract off the number of
6107 bits from the MSB of the field to the MSB of the
6108 object, and then subtract off the number of bits of
6109 the field itself. The result is the bit offset of
6110 the LSB of the field. */
6112 int bit_offset
= DW_UNSND (attr
);
6114 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6117 /* The size of the anonymous object containing
6118 the bit field is explicit, so use the
6119 indicated size (in bytes). */
6120 anonymous_size
= DW_UNSND (attr
);
6124 /* The size of the anonymous object containing
6125 the bit field must be inferred from the type
6126 attribute of the data member containing the
6128 anonymous_size
= TYPE_LENGTH (fp
->type
);
6130 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6131 - bit_offset
- FIELD_BITSIZE (*fp
);
6135 /* Get name of field. */
6136 fieldname
= dwarf2_name (die
, cu
);
6137 if (fieldname
== NULL
)
6140 /* The name is already allocated along with this objfile, so we don't
6141 need to duplicate it for the type. */
6142 fp
->name
= fieldname
;
6144 /* Change accessibility for artificial fields (e.g. virtual table
6145 pointer or virtual base class pointer) to private. */
6146 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6148 FIELD_ARTIFICIAL (*fp
) = 1;
6149 new_field
->accessibility
= DW_ACCESS_private
;
6150 fip
->non_public_fields
= 1;
6153 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6155 /* C++ static member. */
6157 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6158 is a declaration, but all versions of G++ as of this writing
6159 (so through at least 3.2.1) incorrectly generate
6160 DW_TAG_variable tags. */
6164 /* Get name of field. */
6165 fieldname
= dwarf2_name (die
, cu
);
6166 if (fieldname
== NULL
)
6169 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6171 /* Only create a symbol if this is an external value.
6172 new_symbol checks this and puts the value in the global symbol
6173 table, which we want. If it is not external, new_symbol
6174 will try to put the value in cu->list_in_scope which is wrong. */
6175 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6177 /* A static const member, not much different than an enum as far as
6178 we're concerned, except that we can support more types. */
6179 new_symbol (die
, NULL
, cu
);
6182 /* Get physical name. */
6183 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6185 /* The name is already allocated along with this objfile, so we don't
6186 need to duplicate it for the type. */
6187 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6188 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6189 FIELD_NAME (*fp
) = fieldname
;
6191 else if (die
->tag
== DW_TAG_inheritance
)
6193 /* C++ base class field. */
6194 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6197 int byte_offset
= 0;
6199 if (attr_form_is_section_offset (attr
))
6200 dwarf2_complex_location_expr_complaint ();
6201 else if (attr_form_is_constant (attr
))
6202 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6203 else if (attr_form_is_block (attr
))
6204 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6206 dwarf2_complex_location_expr_complaint ();
6208 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6210 FIELD_BITSIZE (*fp
) = 0;
6211 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6212 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6213 fip
->nbaseclasses
++;
6217 /* Add a typedef defined in the scope of the FIP's class. */
6220 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6221 struct dwarf2_cu
*cu
)
6223 struct objfile
*objfile
= cu
->objfile
;
6224 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6225 struct typedef_field_list
*new_field
;
6226 struct attribute
*attr
;
6227 struct typedef_field
*fp
;
6228 char *fieldname
= "";
6230 /* Allocate a new field list entry and link it in. */
6231 new_field
= xzalloc (sizeof (*new_field
));
6232 make_cleanup (xfree
, new_field
);
6234 gdb_assert (die
->tag
== DW_TAG_typedef
);
6236 fp
= &new_field
->field
;
6238 /* Get name of field. */
6239 fp
->name
= dwarf2_name (die
, cu
);
6240 if (fp
->name
== NULL
)
6243 fp
->type
= read_type_die (die
, cu
);
6245 new_field
->next
= fip
->typedef_field_list
;
6246 fip
->typedef_field_list
= new_field
;
6247 fip
->typedef_field_list_count
++;
6250 /* Create the vector of fields, and attach it to the type. */
6253 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6254 struct dwarf2_cu
*cu
)
6256 int nfields
= fip
->nfields
;
6258 /* Record the field count, allocate space for the array of fields,
6259 and create blank accessibility bitfields if necessary. */
6260 TYPE_NFIELDS (type
) = nfields
;
6261 TYPE_FIELDS (type
) = (struct field
*)
6262 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6263 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6265 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6267 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6269 TYPE_FIELD_PRIVATE_BITS (type
) =
6270 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6271 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6273 TYPE_FIELD_PROTECTED_BITS (type
) =
6274 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6275 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6277 TYPE_FIELD_IGNORE_BITS (type
) =
6278 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6279 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6282 /* If the type has baseclasses, allocate and clear a bit vector for
6283 TYPE_FIELD_VIRTUAL_BITS. */
6284 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6286 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6287 unsigned char *pointer
;
6289 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6290 pointer
= TYPE_ALLOC (type
, num_bytes
);
6291 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6292 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6293 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6296 /* Copy the saved-up fields into the field vector. Start from the head
6297 of the list, adding to the tail of the field array, so that they end
6298 up in the same order in the array in which they were added to the list. */
6299 while (nfields
-- > 0)
6301 struct nextfield
*fieldp
;
6305 fieldp
= fip
->fields
;
6306 fip
->fields
= fieldp
->next
;
6310 fieldp
= fip
->baseclasses
;
6311 fip
->baseclasses
= fieldp
->next
;
6314 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6315 switch (fieldp
->accessibility
)
6317 case DW_ACCESS_private
:
6318 if (cu
->language
!= language_ada
)
6319 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6322 case DW_ACCESS_protected
:
6323 if (cu
->language
!= language_ada
)
6324 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6327 case DW_ACCESS_public
:
6331 /* Unknown accessibility. Complain and treat it as public. */
6333 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6334 fieldp
->accessibility
);
6338 if (nfields
< fip
->nbaseclasses
)
6340 switch (fieldp
->virtuality
)
6342 case DW_VIRTUALITY_virtual
:
6343 case DW_VIRTUALITY_pure_virtual
:
6344 if (cu
->language
== language_ada
)
6345 error ("unexpected virtuality in component of Ada type");
6346 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6353 /* Add a member function to the proper fieldlist. */
6356 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6357 struct type
*type
, struct dwarf2_cu
*cu
)
6359 struct objfile
*objfile
= cu
->objfile
;
6360 struct attribute
*attr
;
6361 struct fnfieldlist
*flp
;
6363 struct fn_field
*fnp
;
6365 struct nextfnfield
*new_fnfield
;
6366 struct type
*this_type
;
6368 if (cu
->language
== language_ada
)
6369 error ("unexpected member function in Ada type");
6371 /* Get name of member function. */
6372 fieldname
= dwarf2_name (die
, cu
);
6373 if (fieldname
== NULL
)
6376 /* Look up member function name in fieldlist. */
6377 for (i
= 0; i
< fip
->nfnfields
; i
++)
6379 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6383 /* Create new list element if necessary. */
6384 if (i
< fip
->nfnfields
)
6385 flp
= &fip
->fnfieldlists
[i
];
6388 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6390 fip
->fnfieldlists
= (struct fnfieldlist
*)
6391 xrealloc (fip
->fnfieldlists
,
6392 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6393 * sizeof (struct fnfieldlist
));
6394 if (fip
->nfnfields
== 0)
6395 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6397 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6398 flp
->name
= fieldname
;
6401 i
= fip
->nfnfields
++;
6404 /* Create a new member function field and chain it to the field list
6406 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6407 make_cleanup (xfree
, new_fnfield
);
6408 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6409 new_fnfield
->next
= flp
->head
;
6410 flp
->head
= new_fnfield
;
6413 /* Fill in the member function field info. */
6414 fnp
= &new_fnfield
->fnfield
;
6416 /* Delay processing of the physname until later. */
6417 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6419 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6424 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6425 fnp
->physname
= physname
? physname
: "";
6428 fnp
->type
= alloc_type (objfile
);
6429 this_type
= read_type_die (die
, cu
);
6430 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6432 int nparams
= TYPE_NFIELDS (this_type
);
6434 /* TYPE is the domain of this method, and THIS_TYPE is the type
6435 of the method itself (TYPE_CODE_METHOD). */
6436 smash_to_method_type (fnp
->type
, type
,
6437 TYPE_TARGET_TYPE (this_type
),
6438 TYPE_FIELDS (this_type
),
6439 TYPE_NFIELDS (this_type
),
6440 TYPE_VARARGS (this_type
));
6442 /* Handle static member functions.
6443 Dwarf2 has no clean way to discern C++ static and non-static
6444 member functions. G++ helps GDB by marking the first
6445 parameter for non-static member functions (which is the
6446 this pointer) as artificial. We obtain this information
6447 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6448 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6449 fnp
->voffset
= VOFFSET_STATIC
;
6452 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6453 dwarf2_full_name (fieldname
, die
, cu
));
6455 /* Get fcontext from DW_AT_containing_type if present. */
6456 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6457 fnp
->fcontext
= die_containing_type (die
, cu
);
6459 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6460 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6462 /* Get accessibility. */
6463 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6466 switch (DW_UNSND (attr
))
6468 case DW_ACCESS_private
:
6469 fnp
->is_private
= 1;
6471 case DW_ACCESS_protected
:
6472 fnp
->is_protected
= 1;
6477 /* Check for artificial methods. */
6478 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6479 if (attr
&& DW_UNSND (attr
) != 0)
6480 fnp
->is_artificial
= 1;
6482 /* Get index in virtual function table if it is a virtual member
6483 function. For older versions of GCC, this is an offset in the
6484 appropriate virtual table, as specified by DW_AT_containing_type.
6485 For everyone else, it is an expression to be evaluated relative
6486 to the object address. */
6488 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6491 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6493 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6495 /* Old-style GCC. */
6496 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6498 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6499 || (DW_BLOCK (attr
)->size
> 1
6500 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6501 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6503 struct dwarf_block blk
;
6506 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6508 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6509 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6510 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6511 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6512 dwarf2_complex_location_expr_complaint ();
6514 fnp
->voffset
/= cu
->header
.addr_size
;
6518 dwarf2_complex_location_expr_complaint ();
6521 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6523 else if (attr_form_is_section_offset (attr
))
6525 dwarf2_complex_location_expr_complaint ();
6529 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6535 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6536 if (attr
&& DW_UNSND (attr
))
6538 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6539 complaint (&symfile_complaints
,
6540 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6541 fieldname
, die
->offset
);
6542 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6543 TYPE_CPLUS_DYNAMIC (type
) = 1;
6548 /* Create the vector of member function fields, and attach it to the type. */
6551 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6552 struct dwarf2_cu
*cu
)
6554 struct fnfieldlist
*flp
;
6555 int total_length
= 0;
6558 if (cu
->language
== language_ada
)
6559 error ("unexpected member functions in Ada type");
6561 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6562 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6563 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6565 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6567 struct nextfnfield
*nfp
= flp
->head
;
6568 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6571 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6572 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6573 fn_flp
->fn_fields
= (struct fn_field
*)
6574 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6575 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6576 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6578 total_length
+= flp
->length
;
6581 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6582 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6585 /* Returns non-zero if NAME is the name of a vtable member in CU's
6586 language, zero otherwise. */
6588 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6590 static const char vptr
[] = "_vptr";
6591 static const char vtable
[] = "vtable";
6593 /* Look for the C++ and Java forms of the vtable. */
6594 if ((cu
->language
== language_java
6595 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6596 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6597 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6603 /* GCC outputs unnamed structures that are really pointers to member
6604 functions, with the ABI-specified layout. If TYPE describes
6605 such a structure, smash it into a member function type.
6607 GCC shouldn't do this; it should just output pointer to member DIEs.
6608 This is GCC PR debug/28767. */
6611 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6613 struct type
*pfn_type
, *domain_type
, *new_type
;
6615 /* Check for a structure with no name and two children. */
6616 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6619 /* Check for __pfn and __delta members. */
6620 if (TYPE_FIELD_NAME (type
, 0) == NULL
6621 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6622 || TYPE_FIELD_NAME (type
, 1) == NULL
6623 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6626 /* Find the type of the method. */
6627 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6628 if (pfn_type
== NULL
6629 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6630 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6633 /* Look for the "this" argument. */
6634 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6635 if (TYPE_NFIELDS (pfn_type
) == 0
6636 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6637 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6640 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6641 new_type
= alloc_type (objfile
);
6642 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6643 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6644 TYPE_VARARGS (pfn_type
));
6645 smash_to_methodptr_type (type
, new_type
);
6648 /* Called when we find the DIE that starts a structure or union scope
6649 (definition) to create a type for the structure or union. Fill in
6650 the type's name and general properties; the members will not be
6651 processed until process_structure_type.
6653 NOTE: we need to call these functions regardless of whether or not the
6654 DIE has a DW_AT_name attribute, since it might be an anonymous
6655 structure or union. This gets the type entered into our set of
6658 However, if the structure is incomplete (an opaque struct/union)
6659 then suppress creating a symbol table entry for it since gdb only
6660 wants to find the one with the complete definition. Note that if
6661 it is complete, we just call new_symbol, which does it's own
6662 checking about whether the struct/union is anonymous or not (and
6663 suppresses creating a symbol table entry itself). */
6665 static struct type
*
6666 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6668 struct objfile
*objfile
= cu
->objfile
;
6670 struct attribute
*attr
;
6673 /* If the definition of this type lives in .debug_types, read that type.
6674 Don't follow DW_AT_specification though, that will take us back up
6675 the chain and we want to go down. */
6676 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6679 struct dwarf2_cu
*type_cu
= cu
;
6680 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6682 /* We could just recurse on read_structure_type, but we need to call
6683 get_die_type to ensure only one type for this DIE is created.
6684 This is important, for example, because for c++ classes we need
6685 TYPE_NAME set which is only done by new_symbol. Blech. */
6686 type
= read_type_die (type_die
, type_cu
);
6688 /* TYPE_CU may not be the same as CU.
6689 Ensure TYPE is recorded in CU's type_hash table. */
6690 return set_die_type (die
, type
, cu
);
6693 type
= alloc_type (objfile
);
6694 INIT_CPLUS_SPECIFIC (type
);
6696 name
= dwarf2_name (die
, cu
);
6699 if (cu
->language
== language_cplus
6700 || cu
->language
== language_java
)
6702 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6704 /* dwarf2_full_name might have already finished building the DIE's
6705 type. If so, there is no need to continue. */
6706 if (get_die_type (die
, cu
) != NULL
)
6707 return get_die_type (die
, cu
);
6709 TYPE_TAG_NAME (type
) = full_name
;
6710 if (die
->tag
== DW_TAG_structure_type
6711 || die
->tag
== DW_TAG_class_type
)
6712 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6716 /* The name is already allocated along with this objfile, so
6717 we don't need to duplicate it for the type. */
6718 TYPE_TAG_NAME (type
) = (char *) name
;
6719 if (die
->tag
== DW_TAG_class_type
)
6720 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6724 if (die
->tag
== DW_TAG_structure_type
)
6726 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6728 else if (die
->tag
== DW_TAG_union_type
)
6730 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6734 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6737 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6738 TYPE_DECLARED_CLASS (type
) = 1;
6740 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6743 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6747 TYPE_LENGTH (type
) = 0;
6750 TYPE_STUB_SUPPORTED (type
) = 1;
6751 if (die_is_declaration (die
, cu
))
6752 TYPE_STUB (type
) = 1;
6753 else if (attr
== NULL
&& die
->child
== NULL
6754 && producer_is_realview (cu
->producer
))
6755 /* RealView does not output the required DW_AT_declaration
6756 on incomplete types. */
6757 TYPE_STUB (type
) = 1;
6759 /* We need to add the type field to the die immediately so we don't
6760 infinitely recurse when dealing with pointers to the structure
6761 type within the structure itself. */
6762 set_die_type (die
, type
, cu
);
6764 /* set_die_type should be already done. */
6765 set_descriptive_type (type
, die
, cu
);
6770 /* Finish creating a structure or union type, including filling in
6771 its members and creating a symbol for it. */
6774 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6776 struct objfile
*objfile
= cu
->objfile
;
6777 struct die_info
*child_die
= die
->child
;
6780 type
= get_die_type (die
, cu
);
6782 type
= read_structure_type (die
, cu
);
6784 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6786 struct field_info fi
;
6787 struct die_info
*child_die
;
6788 VEC (symbolp
) *template_args
= NULL
;
6789 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6791 memset (&fi
, 0, sizeof (struct field_info
));
6793 child_die
= die
->child
;
6795 while (child_die
&& child_die
->tag
)
6797 if (child_die
->tag
== DW_TAG_member
6798 || child_die
->tag
== DW_TAG_variable
)
6800 /* NOTE: carlton/2002-11-05: A C++ static data member
6801 should be a DW_TAG_member that is a declaration, but
6802 all versions of G++ as of this writing (so through at
6803 least 3.2.1) incorrectly generate DW_TAG_variable
6804 tags for them instead. */
6805 dwarf2_add_field (&fi
, child_die
, cu
);
6807 else if (child_die
->tag
== DW_TAG_subprogram
)
6809 /* C++ member function. */
6810 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6812 else if (child_die
->tag
== DW_TAG_inheritance
)
6814 /* C++ base class field. */
6815 dwarf2_add_field (&fi
, child_die
, cu
);
6817 else if (child_die
->tag
== DW_TAG_typedef
)
6818 dwarf2_add_typedef (&fi
, child_die
, cu
);
6819 else if (child_die
->tag
== DW_TAG_template_type_param
6820 || child_die
->tag
== DW_TAG_template_value_param
)
6822 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6825 VEC_safe_push (symbolp
, template_args
, arg
);
6828 child_die
= sibling_die (child_die
);
6831 /* Attach template arguments to type. */
6832 if (! VEC_empty (symbolp
, template_args
))
6834 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6835 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6836 = VEC_length (symbolp
, template_args
);
6837 TYPE_TEMPLATE_ARGUMENTS (type
)
6838 = obstack_alloc (&objfile
->objfile_obstack
,
6839 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6840 * sizeof (struct symbol
*)));
6841 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6842 VEC_address (symbolp
, template_args
),
6843 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6844 * sizeof (struct symbol
*)));
6845 VEC_free (symbolp
, template_args
);
6848 /* Attach fields and member functions to the type. */
6850 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6853 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6855 /* Get the type which refers to the base class (possibly this
6856 class itself) which contains the vtable pointer for the current
6857 class from the DW_AT_containing_type attribute. This use of
6858 DW_AT_containing_type is a GNU extension. */
6860 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6862 struct type
*t
= die_containing_type (die
, cu
);
6864 TYPE_VPTR_BASETYPE (type
) = t
;
6869 /* Our own class provides vtbl ptr. */
6870 for (i
= TYPE_NFIELDS (t
) - 1;
6871 i
>= TYPE_N_BASECLASSES (t
);
6874 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6876 if (is_vtable_name (fieldname
, cu
))
6878 TYPE_VPTR_FIELDNO (type
) = i
;
6883 /* Complain if virtual function table field not found. */
6884 if (i
< TYPE_N_BASECLASSES (t
))
6885 complaint (&symfile_complaints
,
6886 _("virtual function table pointer not found when defining class '%s'"),
6887 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6892 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6895 else if (cu
->producer
6896 && strncmp (cu
->producer
,
6897 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6899 /* The IBM XLC compiler does not provide direct indication
6900 of the containing type, but the vtable pointer is
6901 always named __vfp. */
6905 for (i
= TYPE_NFIELDS (type
) - 1;
6906 i
>= TYPE_N_BASECLASSES (type
);
6909 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6911 TYPE_VPTR_FIELDNO (type
) = i
;
6912 TYPE_VPTR_BASETYPE (type
) = type
;
6919 /* Copy fi.typedef_field_list linked list elements content into the
6920 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6921 if (fi
.typedef_field_list
)
6923 int i
= fi
.typedef_field_list_count
;
6925 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6926 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6927 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6928 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6930 /* Reverse the list order to keep the debug info elements order. */
6933 struct typedef_field
*dest
, *src
;
6935 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6936 src
= &fi
.typedef_field_list
->field
;
6937 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6942 do_cleanups (back_to
);
6945 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6947 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6948 snapshots) has been known to create a die giving a declaration
6949 for a class that has, as a child, a die giving a definition for a
6950 nested class. So we have to process our children even if the
6951 current die is a declaration. Normally, of course, a declaration
6952 won't have any children at all. */
6954 while (child_die
!= NULL
&& child_die
->tag
)
6956 if (child_die
->tag
== DW_TAG_member
6957 || child_die
->tag
== DW_TAG_variable
6958 || child_die
->tag
== DW_TAG_inheritance
6959 || child_die
->tag
== DW_TAG_template_value_param
6960 || child_die
->tag
== DW_TAG_template_type_param
)
6965 process_die (child_die
, cu
);
6967 child_die
= sibling_die (child_die
);
6970 /* Do not consider external references. According to the DWARF standard,
6971 these DIEs are identified by the fact that they have no byte_size
6972 attribute, and a declaration attribute. */
6973 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6974 || !die_is_declaration (die
, cu
))
6975 new_symbol (die
, type
, cu
);
6978 /* Given a DW_AT_enumeration_type die, set its type. We do not
6979 complete the type's fields yet, or create any symbols. */
6981 static struct type
*
6982 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6984 struct objfile
*objfile
= cu
->objfile
;
6986 struct attribute
*attr
;
6989 /* If the definition of this type lives in .debug_types, read that type.
6990 Don't follow DW_AT_specification though, that will take us back up
6991 the chain and we want to go down. */
6992 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6995 struct dwarf2_cu
*type_cu
= cu
;
6996 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6998 type
= read_type_die (type_die
, type_cu
);
7000 /* TYPE_CU may not be the same as CU.
7001 Ensure TYPE is recorded in CU's type_hash table. */
7002 return set_die_type (die
, type
, cu
);
7005 type
= alloc_type (objfile
);
7007 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7008 name
= dwarf2_full_name (NULL
, die
, cu
);
7010 TYPE_TAG_NAME (type
) = (char *) name
;
7012 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7015 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7019 TYPE_LENGTH (type
) = 0;
7022 /* The enumeration DIE can be incomplete. In Ada, any type can be
7023 declared as private in the package spec, and then defined only
7024 inside the package body. Such types are known as Taft Amendment
7025 Types. When another package uses such a type, an incomplete DIE
7026 may be generated by the compiler. */
7027 if (die_is_declaration (die
, cu
))
7028 TYPE_STUB (type
) = 1;
7030 return set_die_type (die
, type
, cu
);
7033 /* Given a pointer to a die which begins an enumeration, process all
7034 the dies that define the members of the enumeration, and create the
7035 symbol for the enumeration type.
7037 NOTE: We reverse the order of the element list. */
7040 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7042 struct type
*this_type
;
7044 this_type
= get_die_type (die
, cu
);
7045 if (this_type
== NULL
)
7046 this_type
= read_enumeration_type (die
, cu
);
7048 if (die
->child
!= NULL
)
7050 struct die_info
*child_die
;
7052 struct field
*fields
= NULL
;
7054 int unsigned_enum
= 1;
7057 child_die
= die
->child
;
7058 while (child_die
&& child_die
->tag
)
7060 if (child_die
->tag
!= DW_TAG_enumerator
)
7062 process_die (child_die
, cu
);
7066 name
= dwarf2_name (child_die
, cu
);
7069 sym
= new_symbol (child_die
, this_type
, cu
);
7070 if (SYMBOL_VALUE (sym
) < 0)
7073 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7075 fields
= (struct field
*)
7077 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7078 * sizeof (struct field
));
7081 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7082 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7083 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7084 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7090 child_die
= sibling_die (child_die
);
7095 TYPE_NFIELDS (this_type
) = num_fields
;
7096 TYPE_FIELDS (this_type
) = (struct field
*)
7097 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7098 memcpy (TYPE_FIELDS (this_type
), fields
,
7099 sizeof (struct field
) * num_fields
);
7103 TYPE_UNSIGNED (this_type
) = 1;
7106 new_symbol (die
, this_type
, cu
);
7109 /* Extract all information from a DW_TAG_array_type DIE and put it in
7110 the DIE's type field. For now, this only handles one dimensional
7113 static struct type
*
7114 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7116 struct objfile
*objfile
= cu
->objfile
;
7117 struct die_info
*child_die
;
7119 struct type
*element_type
, *range_type
, *index_type
;
7120 struct type
**range_types
= NULL
;
7121 struct attribute
*attr
;
7123 struct cleanup
*back_to
;
7126 element_type
= die_type (die
, cu
);
7128 /* The die_type call above may have already set the type for this DIE. */
7129 type
= get_die_type (die
, cu
);
7133 /* Irix 6.2 native cc creates array types without children for
7134 arrays with unspecified length. */
7135 if (die
->child
== NULL
)
7137 index_type
= objfile_type (objfile
)->builtin_int
;
7138 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7139 type
= create_array_type (NULL
, element_type
, range_type
);
7140 return set_die_type (die
, type
, cu
);
7143 back_to
= make_cleanup (null_cleanup
, NULL
);
7144 child_die
= die
->child
;
7145 while (child_die
&& child_die
->tag
)
7147 if (child_die
->tag
== DW_TAG_subrange_type
)
7149 struct type
*child_type
= read_type_die (child_die
, cu
);
7151 if (child_type
!= NULL
)
7153 /* The range type was succesfully read. Save it for
7154 the array type creation. */
7155 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7157 range_types
= (struct type
**)
7158 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7159 * sizeof (struct type
*));
7161 make_cleanup (free_current_contents
, &range_types
);
7163 range_types
[ndim
++] = child_type
;
7166 child_die
= sibling_die (child_die
);
7169 /* Dwarf2 dimensions are output from left to right, create the
7170 necessary array types in backwards order. */
7172 type
= element_type
;
7174 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7179 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7184 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7187 /* Understand Dwarf2 support for vector types (like they occur on
7188 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7189 array type. This is not part of the Dwarf2/3 standard yet, but a
7190 custom vendor extension. The main difference between a regular
7191 array and the vector variant is that vectors are passed by value
7193 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7195 make_vector_type (type
);
7197 name
= dwarf2_name (die
, cu
);
7199 TYPE_NAME (type
) = name
;
7201 /* Install the type in the die. */
7202 set_die_type (die
, type
, cu
);
7204 /* set_die_type should be already done. */
7205 set_descriptive_type (type
, die
, cu
);
7207 do_cleanups (back_to
);
7212 static enum dwarf_array_dim_ordering
7213 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7215 struct attribute
*attr
;
7217 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7219 if (attr
) return DW_SND (attr
);
7222 GNU F77 is a special case, as at 08/2004 array type info is the
7223 opposite order to the dwarf2 specification, but data is still
7224 laid out as per normal fortran.
7226 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7230 if (cu
->language
== language_fortran
7231 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7233 return DW_ORD_row_major
;
7236 switch (cu
->language_defn
->la_array_ordering
)
7238 case array_column_major
:
7239 return DW_ORD_col_major
;
7240 case array_row_major
:
7242 return DW_ORD_row_major
;
7246 /* Extract all information from a DW_TAG_set_type DIE and put it in
7247 the DIE's type field. */
7249 static struct type
*
7250 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7252 struct type
*domain_type
, *set_type
;
7253 struct attribute
*attr
;
7255 domain_type
= die_type (die
, cu
);
7257 /* The die_type call above may have already set the type for this DIE. */
7258 set_type
= get_die_type (die
, cu
);
7262 set_type
= create_set_type (NULL
, domain_type
);
7264 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7266 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7268 return set_die_type (die
, set_type
, cu
);
7271 /* First cut: install each common block member as a global variable. */
7274 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7276 struct die_info
*child_die
;
7277 struct attribute
*attr
;
7279 CORE_ADDR base
= (CORE_ADDR
) 0;
7281 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7284 /* Support the .debug_loc offsets */
7285 if (attr_form_is_block (attr
))
7287 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7289 else if (attr_form_is_section_offset (attr
))
7291 dwarf2_complex_location_expr_complaint ();
7295 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7296 "common block member");
7299 if (die
->child
!= NULL
)
7301 child_die
= die
->child
;
7302 while (child_die
&& child_die
->tag
)
7304 sym
= new_symbol (child_die
, NULL
, cu
);
7305 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7306 if (sym
!= NULL
&& attr
!= NULL
)
7308 CORE_ADDR byte_offset
= 0;
7310 if (attr_form_is_section_offset (attr
))
7311 dwarf2_complex_location_expr_complaint ();
7312 else if (attr_form_is_constant (attr
))
7313 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7314 else if (attr_form_is_block (attr
))
7315 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7317 dwarf2_complex_location_expr_complaint ();
7319 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7320 add_symbol_to_list (sym
, &global_symbols
);
7322 child_die
= sibling_die (child_die
);
7327 /* Create a type for a C++ namespace. */
7329 static struct type
*
7330 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7332 struct objfile
*objfile
= cu
->objfile
;
7333 const char *previous_prefix
, *name
;
7337 /* For extensions, reuse the type of the original namespace. */
7338 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7340 struct die_info
*ext_die
;
7341 struct dwarf2_cu
*ext_cu
= cu
;
7343 ext_die
= dwarf2_extension (die
, &ext_cu
);
7344 type
= read_type_die (ext_die
, ext_cu
);
7346 /* EXT_CU may not be the same as CU.
7347 Ensure TYPE is recorded in CU's type_hash table. */
7348 return set_die_type (die
, type
, cu
);
7351 name
= namespace_name (die
, &is_anonymous
, cu
);
7353 /* Now build the name of the current namespace. */
7355 previous_prefix
= determine_prefix (die
, cu
);
7356 if (previous_prefix
[0] != '\0')
7357 name
= typename_concat (&objfile
->objfile_obstack
,
7358 previous_prefix
, name
, 0, cu
);
7360 /* Create the type. */
7361 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7363 TYPE_NAME (type
) = (char *) name
;
7364 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7366 return set_die_type (die
, type
, cu
);
7369 /* Read a C++ namespace. */
7372 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7374 struct objfile
*objfile
= cu
->objfile
;
7378 /* Add a symbol associated to this if we haven't seen the namespace
7379 before. Also, add a using directive if it's an anonymous
7382 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7386 type
= read_type_die (die
, cu
);
7387 new_symbol (die
, type
, cu
);
7389 name
= namespace_name (die
, &is_anonymous
, cu
);
7392 const char *previous_prefix
= determine_prefix (die
, cu
);
7394 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7395 NULL
, &objfile
->objfile_obstack
);
7399 if (die
->child
!= NULL
)
7401 struct die_info
*child_die
= die
->child
;
7403 while (child_die
&& child_die
->tag
)
7405 process_die (child_die
, cu
);
7406 child_die
= sibling_die (child_die
);
7411 /* Read a Fortran module as type. This DIE can be only a declaration used for
7412 imported module. Still we need that type as local Fortran "use ... only"
7413 declaration imports depend on the created type in determine_prefix. */
7415 static struct type
*
7416 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7418 struct objfile
*objfile
= cu
->objfile
;
7422 module_name
= dwarf2_name (die
, cu
);
7424 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7426 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7428 /* determine_prefix uses TYPE_TAG_NAME. */
7429 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7431 return set_die_type (die
, type
, cu
);
7434 /* Read a Fortran module. */
7437 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7439 struct die_info
*child_die
= die
->child
;
7441 while (child_die
&& child_die
->tag
)
7443 process_die (child_die
, cu
);
7444 child_die
= sibling_die (child_die
);
7448 /* Return the name of the namespace represented by DIE. Set
7449 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7453 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7455 struct die_info
*current_die
;
7456 const char *name
= NULL
;
7458 /* Loop through the extensions until we find a name. */
7460 for (current_die
= die
;
7461 current_die
!= NULL
;
7462 current_die
= dwarf2_extension (die
, &cu
))
7464 name
= dwarf2_name (current_die
, cu
);
7469 /* Is it an anonymous namespace? */
7471 *is_anonymous
= (name
== NULL
);
7473 name
= "(anonymous namespace)";
7478 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7479 the user defined type vector. */
7481 static struct type
*
7482 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7484 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7485 struct comp_unit_head
*cu_header
= &cu
->header
;
7487 struct attribute
*attr_byte_size
;
7488 struct attribute
*attr_address_class
;
7489 int byte_size
, addr_class
;
7490 struct type
*target_type
;
7492 target_type
= die_type (die
, cu
);
7494 /* The die_type call above may have already set the type for this DIE. */
7495 type
= get_die_type (die
, cu
);
7499 type
= lookup_pointer_type (target_type
);
7501 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7503 byte_size
= DW_UNSND (attr_byte_size
);
7505 byte_size
= cu_header
->addr_size
;
7507 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7508 if (attr_address_class
)
7509 addr_class
= DW_UNSND (attr_address_class
);
7511 addr_class
= DW_ADDR_none
;
7513 /* If the pointer size or address class is different than the
7514 default, create a type variant marked as such and set the
7515 length accordingly. */
7516 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7518 if (gdbarch_address_class_type_flags_p (gdbarch
))
7522 type_flags
= gdbarch_address_class_type_flags
7523 (gdbarch
, byte_size
, addr_class
);
7524 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7526 type
= make_type_with_address_space (type
, type_flags
);
7528 else if (TYPE_LENGTH (type
) != byte_size
)
7530 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7534 /* Should we also complain about unhandled address classes? */
7538 TYPE_LENGTH (type
) = byte_size
;
7539 return set_die_type (die
, type
, cu
);
7542 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7543 the user defined type vector. */
7545 static struct type
*
7546 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7549 struct type
*to_type
;
7550 struct type
*domain
;
7552 to_type
= die_type (die
, cu
);
7553 domain
= die_containing_type (die
, cu
);
7555 /* The calls above may have already set the type for this DIE. */
7556 type
= get_die_type (die
, cu
);
7560 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7561 type
= lookup_methodptr_type (to_type
);
7563 type
= lookup_memberptr_type (to_type
, domain
);
7565 return set_die_type (die
, type
, cu
);
7568 /* Extract all information from a DW_TAG_reference_type DIE and add to
7569 the user defined type vector. */
7571 static struct type
*
7572 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7574 struct comp_unit_head
*cu_header
= &cu
->header
;
7575 struct type
*type
, *target_type
;
7576 struct attribute
*attr
;
7578 target_type
= die_type (die
, cu
);
7580 /* The die_type call above may have already set the type for this DIE. */
7581 type
= get_die_type (die
, cu
);
7585 type
= lookup_reference_type (target_type
);
7586 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7589 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7593 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7595 return set_die_type (die
, type
, cu
);
7598 static struct type
*
7599 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7601 struct type
*base_type
, *cv_type
;
7603 base_type
= die_type (die
, cu
);
7605 /* The die_type call above may have already set the type for this DIE. */
7606 cv_type
= get_die_type (die
, cu
);
7610 /* In case the const qualifier is applied to an array type, the element type
7611 is so qualified, not the array type (section 6.7.3 of C99). */
7612 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7614 struct type
*el_type
, *inner_array
;
7616 base_type
= copy_type (base_type
);
7617 inner_array
= base_type
;
7619 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7621 TYPE_TARGET_TYPE (inner_array
) =
7622 copy_type (TYPE_TARGET_TYPE (inner_array
));
7623 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7626 el_type
= TYPE_TARGET_TYPE (inner_array
);
7627 TYPE_TARGET_TYPE (inner_array
) =
7628 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7630 return set_die_type (die
, base_type
, cu
);
7633 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7634 return set_die_type (die
, cv_type
, cu
);
7637 static struct type
*
7638 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7640 struct type
*base_type
, *cv_type
;
7642 base_type
= die_type (die
, cu
);
7644 /* The die_type call above may have already set the type for this DIE. */
7645 cv_type
= get_die_type (die
, cu
);
7649 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7650 return set_die_type (die
, cv_type
, cu
);
7653 /* Extract all information from a DW_TAG_string_type DIE and add to
7654 the user defined type vector. It isn't really a user defined type,
7655 but it behaves like one, with other DIE's using an AT_user_def_type
7656 attribute to reference it. */
7658 static struct type
*
7659 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7661 struct objfile
*objfile
= cu
->objfile
;
7662 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7663 struct type
*type
, *range_type
, *index_type
, *char_type
;
7664 struct attribute
*attr
;
7665 unsigned int length
;
7667 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7670 length
= DW_UNSND (attr
);
7674 /* check for the DW_AT_byte_size attribute */
7675 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7678 length
= DW_UNSND (attr
);
7686 index_type
= objfile_type (objfile
)->builtin_int
;
7687 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7688 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7689 type
= create_string_type (NULL
, char_type
, range_type
);
7691 return set_die_type (die
, type
, cu
);
7694 /* Handle DIES due to C code like:
7698 int (*funcp)(int a, long l);
7702 ('funcp' generates a DW_TAG_subroutine_type DIE)
7705 static struct type
*
7706 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7708 struct type
*type
; /* Type that this function returns */
7709 struct type
*ftype
; /* Function that returns above type */
7710 struct attribute
*attr
;
7712 type
= die_type (die
, cu
);
7714 /* The die_type call above may have already set the type for this DIE. */
7715 ftype
= get_die_type (die
, cu
);
7719 ftype
= lookup_function_type (type
);
7721 /* All functions in C++, Pascal and Java have prototypes. */
7722 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7723 if ((attr
&& (DW_UNSND (attr
) != 0))
7724 || cu
->language
== language_cplus
7725 || cu
->language
== language_java
7726 || cu
->language
== language_pascal
)
7727 TYPE_PROTOTYPED (ftype
) = 1;
7728 else if (producer_is_realview (cu
->producer
))
7729 /* RealView does not emit DW_AT_prototyped. We can not
7730 distinguish prototyped and unprototyped functions; default to
7731 prototyped, since that is more common in modern code (and
7732 RealView warns about unprototyped functions). */
7733 TYPE_PROTOTYPED (ftype
) = 1;
7735 /* Store the calling convention in the type if it's available in
7736 the subroutine die. Otherwise set the calling convention to
7737 the default value DW_CC_normal. */
7738 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7739 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7741 /* We need to add the subroutine type to the die immediately so
7742 we don't infinitely recurse when dealing with parameters
7743 declared as the same subroutine type. */
7744 set_die_type (die
, ftype
, cu
);
7746 if (die
->child
!= NULL
)
7748 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7749 struct die_info
*child_die
;
7750 int nparams
, iparams
;
7752 /* Count the number of parameters.
7753 FIXME: GDB currently ignores vararg functions, but knows about
7754 vararg member functions. */
7756 child_die
= die
->child
;
7757 while (child_die
&& child_die
->tag
)
7759 if (child_die
->tag
== DW_TAG_formal_parameter
)
7761 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7762 TYPE_VARARGS (ftype
) = 1;
7763 child_die
= sibling_die (child_die
);
7766 /* Allocate storage for parameters and fill them in. */
7767 TYPE_NFIELDS (ftype
) = nparams
;
7768 TYPE_FIELDS (ftype
) = (struct field
*)
7769 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7771 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7772 even if we error out during the parameters reading below. */
7773 for (iparams
= 0; iparams
< nparams
; iparams
++)
7774 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7777 child_die
= die
->child
;
7778 while (child_die
&& child_die
->tag
)
7780 if (child_die
->tag
== DW_TAG_formal_parameter
)
7782 struct type
*arg_type
;
7784 /* DWARF version 2 has no clean way to discern C++
7785 static and non-static member functions. G++ helps
7786 GDB by marking the first parameter for non-static
7787 member functions (which is the this pointer) as
7788 artificial. We pass this information to
7789 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7791 DWARF version 3 added DW_AT_object_pointer, which GCC
7792 4.5 does not yet generate. */
7793 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7795 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7798 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7800 /* GCC/43521: In java, the formal parameter
7801 "this" is sometimes not marked with DW_AT_artificial. */
7802 if (cu
->language
== language_java
)
7804 const char *name
= dwarf2_name (child_die
, cu
);
7806 if (name
&& !strcmp (name
, "this"))
7807 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7810 arg_type
= die_type (child_die
, cu
);
7812 /* RealView does not mark THIS as const, which the testsuite
7813 expects. GCC marks THIS as const in method definitions,
7814 but not in the class specifications (GCC PR 43053). */
7815 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7816 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7819 struct dwarf2_cu
*arg_cu
= cu
;
7820 const char *name
= dwarf2_name (child_die
, cu
);
7822 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7825 /* If the compiler emits this, use it. */
7826 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7829 else if (name
&& strcmp (name
, "this") == 0)
7830 /* Function definitions will have the argument names. */
7832 else if (name
== NULL
&& iparams
== 0)
7833 /* Declarations may not have the names, so like
7834 elsewhere in GDB, assume an artificial first
7835 argument is "this". */
7839 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7843 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7846 child_die
= sibling_die (child_die
);
7853 static struct type
*
7854 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7856 struct objfile
*objfile
= cu
->objfile
;
7857 const char *name
= NULL
;
7858 struct type
*this_type
;
7860 name
= dwarf2_full_name (NULL
, die
, cu
);
7861 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7862 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7863 TYPE_NAME (this_type
) = (char *) name
;
7864 set_die_type (die
, this_type
, cu
);
7865 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7869 /* Find a representation of a given base type and install
7870 it in the TYPE field of the die. */
7872 static struct type
*
7873 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7875 struct objfile
*objfile
= cu
->objfile
;
7877 struct attribute
*attr
;
7878 int encoding
= 0, size
= 0;
7880 enum type_code code
= TYPE_CODE_INT
;
7882 struct type
*target_type
= NULL
;
7884 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7887 encoding
= DW_UNSND (attr
);
7889 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7892 size
= DW_UNSND (attr
);
7894 name
= dwarf2_name (die
, cu
);
7897 complaint (&symfile_complaints
,
7898 _("DW_AT_name missing from DW_TAG_base_type"));
7903 case DW_ATE_address
:
7904 /* Turn DW_ATE_address into a void * pointer. */
7905 code
= TYPE_CODE_PTR
;
7906 type_flags
|= TYPE_FLAG_UNSIGNED
;
7907 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7909 case DW_ATE_boolean
:
7910 code
= TYPE_CODE_BOOL
;
7911 type_flags
|= TYPE_FLAG_UNSIGNED
;
7913 case DW_ATE_complex_float
:
7914 code
= TYPE_CODE_COMPLEX
;
7915 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7917 case DW_ATE_decimal_float
:
7918 code
= TYPE_CODE_DECFLOAT
;
7921 code
= TYPE_CODE_FLT
;
7925 case DW_ATE_unsigned
:
7926 type_flags
|= TYPE_FLAG_UNSIGNED
;
7928 case DW_ATE_signed_char
:
7929 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7930 || cu
->language
== language_pascal
)
7931 code
= TYPE_CODE_CHAR
;
7933 case DW_ATE_unsigned_char
:
7934 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7935 || cu
->language
== language_pascal
)
7936 code
= TYPE_CODE_CHAR
;
7937 type_flags
|= TYPE_FLAG_UNSIGNED
;
7940 /* We just treat this as an integer and then recognize the
7941 type by name elsewhere. */
7945 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7946 dwarf_type_encoding_name (encoding
));
7950 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7951 TYPE_NAME (type
) = name
;
7952 TYPE_TARGET_TYPE (type
) = target_type
;
7954 if (name
&& strcmp (name
, "char") == 0)
7955 TYPE_NOSIGN (type
) = 1;
7957 return set_die_type (die
, type
, cu
);
7960 /* Read the given DW_AT_subrange DIE. */
7962 static struct type
*
7963 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7965 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7966 struct type
*base_type
;
7967 struct type
*range_type
;
7968 struct attribute
*attr
;
7972 LONGEST negative_mask
;
7974 base_type
= die_type (die
, cu
);
7975 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7976 check_typedef (base_type
);
7978 /* The die_type call above may have already set the type for this DIE. */
7979 range_type
= get_die_type (die
, cu
);
7983 if (cu
->language
== language_fortran
)
7985 /* FORTRAN implies a lower bound of 1, if not given. */
7989 /* FIXME: For variable sized arrays either of these could be
7990 a variable rather than a constant value. We'll allow it,
7991 but we don't know how to handle it. */
7992 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7994 low
= dwarf2_get_attr_constant_value (attr
, 0);
7996 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7999 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8001 /* GCC encodes arrays with unspecified or dynamic length
8002 with a DW_FORM_block1 attribute or a reference attribute.
8003 FIXME: GDB does not yet know how to handle dynamic
8004 arrays properly, treat them as arrays with unspecified
8007 FIXME: jimb/2003-09-22: GDB does not really know
8008 how to handle arrays of unspecified length
8009 either; we just represent them as zero-length
8010 arrays. Choose an appropriate upper bound given
8011 the lower bound we've computed above. */
8015 high
= dwarf2_get_attr_constant_value (attr
, 1);
8019 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8022 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8023 high
= low
+ count
- 1;
8027 /* Dwarf-2 specifications explicitly allows to create subrange types
8028 without specifying a base type.
8029 In that case, the base type must be set to the type of
8030 the lower bound, upper bound or count, in that order, if any of these
8031 three attributes references an object that has a type.
8032 If no base type is found, the Dwarf-2 specifications say that
8033 a signed integer type of size equal to the size of an address should
8035 For the following C code: `extern char gdb_int [];'
8036 GCC produces an empty range DIE.
8037 FIXME: muller/2010-05-28: Possible references to object for low bound,
8038 high bound or count are not yet handled by this code.
8040 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8042 struct objfile
*objfile
= cu
->objfile
;
8043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8044 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8045 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8047 /* Test "int", "long int", and "long long int" objfile types,
8048 and select the first one having a size above or equal to the
8049 architecture address size. */
8050 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8051 base_type
= int_type
;
8054 int_type
= objfile_type (objfile
)->builtin_long
;
8055 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8056 base_type
= int_type
;
8059 int_type
= objfile_type (objfile
)->builtin_long_long
;
8060 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8061 base_type
= int_type
;
8067 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8068 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8069 low
|= negative_mask
;
8070 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8071 high
|= negative_mask
;
8073 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8075 /* Mark arrays with dynamic length at least as an array of unspecified
8076 length. GDB could check the boundary but before it gets implemented at
8077 least allow accessing the array elements. */
8078 if (attr
&& attr
->form
== DW_FORM_block1
)
8079 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8081 name
= dwarf2_name (die
, cu
);
8083 TYPE_NAME (range_type
) = name
;
8085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8087 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8089 set_die_type (die
, range_type
, cu
);
8091 /* set_die_type should be already done. */
8092 set_descriptive_type (range_type
, die
, cu
);
8097 static struct type
*
8098 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8102 /* For now, we only support the C meaning of an unspecified type: void. */
8104 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8105 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8107 return set_die_type (die
, type
, cu
);
8110 /* Trivial hash function for die_info: the hash value of a DIE
8111 is its offset in .debug_info for this objfile. */
8114 die_hash (const void *item
)
8116 const struct die_info
*die
= item
;
8121 /* Trivial comparison function for die_info structures: two DIEs
8122 are equal if they have the same offset. */
8125 die_eq (const void *item_lhs
, const void *item_rhs
)
8127 const struct die_info
*die_lhs
= item_lhs
;
8128 const struct die_info
*die_rhs
= item_rhs
;
8130 return die_lhs
->offset
== die_rhs
->offset
;
8133 /* Read a whole compilation unit into a linked list of dies. */
8135 static struct die_info
*
8136 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8138 struct die_reader_specs reader_specs
;
8139 int read_abbrevs
= 0;
8140 struct cleanup
*back_to
= NULL
;
8141 struct die_info
*die
;
8143 if (cu
->dwarf2_abbrevs
== NULL
)
8145 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8146 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8150 gdb_assert (cu
->die_hash
== NULL
);
8152 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8156 &cu
->comp_unit_obstack
,
8157 hashtab_obstack_allocate
,
8158 dummy_obstack_deallocate
);
8160 init_cu_die_reader (&reader_specs
, cu
);
8162 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8165 do_cleanups (back_to
);
8170 /* Main entry point for reading a DIE and all children.
8171 Read the DIE and dump it if requested. */
8173 static struct die_info
*
8174 read_die_and_children (const struct die_reader_specs
*reader
,
8176 gdb_byte
**new_info_ptr
,
8177 struct die_info
*parent
)
8179 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8180 new_info_ptr
, parent
);
8182 if (dwarf2_die_debug
)
8184 fprintf_unfiltered (gdb_stdlog
,
8185 "\nRead die from %s of %s:\n",
8186 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8188 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8190 : "unknown section",
8191 reader
->abfd
->filename
);
8192 dump_die (result
, dwarf2_die_debug
);
8198 /* Read a single die and all its descendents. Set the die's sibling
8199 field to NULL; set other fields in the die correctly, and set all
8200 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8201 location of the info_ptr after reading all of those dies. PARENT
8202 is the parent of the die in question. */
8204 static struct die_info
*
8205 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8207 gdb_byte
**new_info_ptr
,
8208 struct die_info
*parent
)
8210 struct die_info
*die
;
8214 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8217 *new_info_ptr
= cur_ptr
;
8220 store_in_ref_table (die
, reader
->cu
);
8223 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8227 *new_info_ptr
= cur_ptr
;
8230 die
->sibling
= NULL
;
8231 die
->parent
= parent
;
8235 /* Read a die, all of its descendents, and all of its siblings; set
8236 all of the fields of all of the dies correctly. Arguments are as
8237 in read_die_and_children. */
8239 static struct die_info
*
8240 read_die_and_siblings (const struct die_reader_specs
*reader
,
8242 gdb_byte
**new_info_ptr
,
8243 struct die_info
*parent
)
8245 struct die_info
*first_die
, *last_sibling
;
8249 first_die
= last_sibling
= NULL
;
8253 struct die_info
*die
8254 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8258 *new_info_ptr
= cur_ptr
;
8265 last_sibling
->sibling
= die
;
8271 /* Read the die from the .debug_info section buffer. Set DIEP to
8272 point to a newly allocated die with its information, except for its
8273 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8274 whether the die has children or not. */
8277 read_full_die (const struct die_reader_specs
*reader
,
8278 struct die_info
**diep
, gdb_byte
*info_ptr
,
8281 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8282 struct abbrev_info
*abbrev
;
8283 struct die_info
*die
;
8284 struct dwarf2_cu
*cu
= reader
->cu
;
8285 bfd
*abfd
= reader
->abfd
;
8287 offset
= info_ptr
- reader
->buffer
;
8288 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8289 info_ptr
+= bytes_read
;
8297 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8299 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8301 bfd_get_filename (abfd
));
8303 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8304 die
->offset
= offset
;
8305 die
->tag
= abbrev
->tag
;
8306 die
->abbrev
= abbrev_number
;
8308 die
->num_attrs
= abbrev
->num_attrs
;
8310 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8311 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8312 abfd
, info_ptr
, cu
);
8315 *has_children
= abbrev
->has_children
;
8319 /* In DWARF version 2, the description of the debugging information is
8320 stored in a separate .debug_abbrev section. Before we read any
8321 dies from a section we read in all abbreviations and install them
8322 in a hash table. This function also sets flags in CU describing
8323 the data found in the abbrev table. */
8326 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8328 struct comp_unit_head
*cu_header
= &cu
->header
;
8329 gdb_byte
*abbrev_ptr
;
8330 struct abbrev_info
*cur_abbrev
;
8331 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8332 unsigned int abbrev_form
, hash_number
;
8333 struct attr_abbrev
*cur_attrs
;
8334 unsigned int allocated_attrs
;
8336 /* Initialize dwarf2 abbrevs */
8337 obstack_init (&cu
->abbrev_obstack
);
8338 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8340 * sizeof (struct abbrev_info
*)));
8341 memset (cu
->dwarf2_abbrevs
, 0,
8342 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8344 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8345 &dwarf2_per_objfile
->abbrev
);
8346 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8347 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8348 abbrev_ptr
+= bytes_read
;
8350 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8351 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8353 /* loop until we reach an abbrev number of 0 */
8354 while (abbrev_number
)
8356 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8358 /* read in abbrev header */
8359 cur_abbrev
->number
= abbrev_number
;
8360 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8361 abbrev_ptr
+= bytes_read
;
8362 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8365 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8366 cu
->has_namespace_info
= 1;
8368 /* now read in declarations */
8369 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8370 abbrev_ptr
+= bytes_read
;
8371 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8372 abbrev_ptr
+= bytes_read
;
8375 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8377 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8379 = xrealloc (cur_attrs
, (allocated_attrs
8380 * sizeof (struct attr_abbrev
)));
8383 /* Record whether this compilation unit might have
8384 inter-compilation-unit references. If we don't know what form
8385 this attribute will have, then it might potentially be a
8386 DW_FORM_ref_addr, so we conservatively expect inter-CU
8389 if (abbrev_form
== DW_FORM_ref_addr
8390 || abbrev_form
== DW_FORM_indirect
)
8391 cu
->has_form_ref_addr
= 1;
8393 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8394 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8395 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8396 abbrev_ptr
+= bytes_read
;
8397 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8398 abbrev_ptr
+= bytes_read
;
8401 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8402 (cur_abbrev
->num_attrs
8403 * sizeof (struct attr_abbrev
)));
8404 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8405 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8407 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8408 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8409 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8411 /* Get next abbreviation.
8412 Under Irix6 the abbreviations for a compilation unit are not
8413 always properly terminated with an abbrev number of 0.
8414 Exit loop if we encounter an abbreviation which we have
8415 already read (which means we are about to read the abbreviations
8416 for the next compile unit) or if the end of the abbreviation
8417 table is reached. */
8418 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8419 >= dwarf2_per_objfile
->abbrev
.size
)
8421 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8422 abbrev_ptr
+= bytes_read
;
8423 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8430 /* Release the memory used by the abbrev table for a compilation unit. */
8433 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8435 struct dwarf2_cu
*cu
= ptr_to_cu
;
8437 obstack_free (&cu
->abbrev_obstack
, NULL
);
8438 cu
->dwarf2_abbrevs
= NULL
;
8441 /* Lookup an abbrev_info structure in the abbrev hash table. */
8443 static struct abbrev_info
*
8444 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8446 unsigned int hash_number
;
8447 struct abbrev_info
*abbrev
;
8449 hash_number
= number
% ABBREV_HASH_SIZE
;
8450 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8454 if (abbrev
->number
== number
)
8457 abbrev
= abbrev
->next
;
8462 /* Returns nonzero if TAG represents a type that we might generate a partial
8466 is_type_tag_for_partial (int tag
)
8471 /* Some types that would be reasonable to generate partial symbols for,
8472 that we don't at present. */
8473 case DW_TAG_array_type
:
8474 case DW_TAG_file_type
:
8475 case DW_TAG_ptr_to_member_type
:
8476 case DW_TAG_set_type
:
8477 case DW_TAG_string_type
:
8478 case DW_TAG_subroutine_type
:
8480 case DW_TAG_base_type
:
8481 case DW_TAG_class_type
:
8482 case DW_TAG_interface_type
:
8483 case DW_TAG_enumeration_type
:
8484 case DW_TAG_structure_type
:
8485 case DW_TAG_subrange_type
:
8486 case DW_TAG_typedef
:
8487 case DW_TAG_union_type
:
8494 /* Load all DIEs that are interesting for partial symbols into memory. */
8496 static struct partial_die_info
*
8497 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8498 int building_psymtab
, struct dwarf2_cu
*cu
)
8500 struct partial_die_info
*part_die
;
8501 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8502 struct abbrev_info
*abbrev
;
8503 unsigned int bytes_read
;
8504 unsigned int load_all
= 0;
8506 int nesting_level
= 1;
8511 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8515 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8519 &cu
->comp_unit_obstack
,
8520 hashtab_obstack_allocate
,
8521 dummy_obstack_deallocate
);
8523 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8524 sizeof (struct partial_die_info
));
8528 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8530 /* A NULL abbrev means the end of a series of children. */
8533 if (--nesting_level
== 0)
8535 /* PART_DIE was probably the last thing allocated on the
8536 comp_unit_obstack, so we could call obstack_free
8537 here. We don't do that because the waste is small,
8538 and will be cleaned up when we're done with this
8539 compilation unit. This way, we're also more robust
8540 against other users of the comp_unit_obstack. */
8543 info_ptr
+= bytes_read
;
8544 last_die
= parent_die
;
8545 parent_die
= parent_die
->die_parent
;
8549 /* Check for template arguments. We never save these; if
8550 they're seen, we just mark the parent, and go on our way. */
8551 if (parent_die
!= NULL
8552 && cu
->language
== language_cplus
8553 && (abbrev
->tag
== DW_TAG_template_type_param
8554 || abbrev
->tag
== DW_TAG_template_value_param
))
8556 parent_die
->has_template_arguments
= 1;
8560 /* We don't need a partial DIE for the template argument. */
8561 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8567 /* We only recurse into subprograms looking for template arguments.
8568 Skip their other children. */
8570 && cu
->language
== language_cplus
8571 && parent_die
!= NULL
8572 && parent_die
->tag
== DW_TAG_subprogram
)
8574 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8578 /* Check whether this DIE is interesting enough to save. Normally
8579 we would not be interested in members here, but there may be
8580 later variables referencing them via DW_AT_specification (for
8583 && !is_type_tag_for_partial (abbrev
->tag
)
8584 && abbrev
->tag
!= DW_TAG_constant
8585 && abbrev
->tag
!= DW_TAG_enumerator
8586 && abbrev
->tag
!= DW_TAG_subprogram
8587 && abbrev
->tag
!= DW_TAG_lexical_block
8588 && abbrev
->tag
!= DW_TAG_variable
8589 && abbrev
->tag
!= DW_TAG_namespace
8590 && abbrev
->tag
!= DW_TAG_module
8591 && abbrev
->tag
!= DW_TAG_member
)
8593 /* Otherwise we skip to the next sibling, if any. */
8594 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8598 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8599 buffer
, info_ptr
, cu
);
8601 /* This two-pass algorithm for processing partial symbols has a
8602 high cost in cache pressure. Thus, handle some simple cases
8603 here which cover the majority of C partial symbols. DIEs
8604 which neither have specification tags in them, nor could have
8605 specification tags elsewhere pointing at them, can simply be
8606 processed and discarded.
8608 This segment is also optional; scan_partial_symbols and
8609 add_partial_symbol will handle these DIEs if we chain
8610 them in normally. When compilers which do not emit large
8611 quantities of duplicate debug information are more common,
8612 this code can probably be removed. */
8614 /* Any complete simple types at the top level (pretty much all
8615 of them, for a language without namespaces), can be processed
8617 if (parent_die
== NULL
8618 && part_die
->has_specification
== 0
8619 && part_die
->is_declaration
== 0
8620 && (part_die
->tag
== DW_TAG_typedef
8621 || part_die
->tag
== DW_TAG_base_type
8622 || part_die
->tag
== DW_TAG_subrange_type
))
8624 if (building_psymtab
&& part_die
->name
!= NULL
)
8625 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8626 VAR_DOMAIN
, LOC_TYPEDEF
,
8627 &cu
->objfile
->static_psymbols
,
8628 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8629 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8633 /* If we're at the second level, and we're an enumerator, and
8634 our parent has no specification (meaning possibly lives in a
8635 namespace elsewhere), then we can add the partial symbol now
8636 instead of queueing it. */
8637 if (part_die
->tag
== DW_TAG_enumerator
8638 && parent_die
!= NULL
8639 && parent_die
->die_parent
== NULL
8640 && parent_die
->tag
== DW_TAG_enumeration_type
8641 && parent_die
->has_specification
== 0)
8643 if (part_die
->name
== NULL
)
8644 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8645 else if (building_psymtab
)
8646 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8647 VAR_DOMAIN
, LOC_CONST
,
8648 (cu
->language
== language_cplus
8649 || cu
->language
== language_java
)
8650 ? &cu
->objfile
->global_psymbols
8651 : &cu
->objfile
->static_psymbols
,
8652 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8654 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8658 /* We'll save this DIE so link it in. */
8659 part_die
->die_parent
= parent_die
;
8660 part_die
->die_sibling
= NULL
;
8661 part_die
->die_child
= NULL
;
8663 if (last_die
&& last_die
== parent_die
)
8664 last_die
->die_child
= part_die
;
8666 last_die
->die_sibling
= part_die
;
8668 last_die
= part_die
;
8670 if (first_die
== NULL
)
8671 first_die
= part_die
;
8673 /* Maybe add the DIE to the hash table. Not all DIEs that we
8674 find interesting need to be in the hash table, because we
8675 also have the parent/sibling/child chains; only those that we
8676 might refer to by offset later during partial symbol reading.
8678 For now this means things that might have be the target of a
8679 DW_AT_specification, DW_AT_abstract_origin, or
8680 DW_AT_extension. DW_AT_extension will refer only to
8681 namespaces; DW_AT_abstract_origin refers to functions (and
8682 many things under the function DIE, but we do not recurse
8683 into function DIEs during partial symbol reading) and
8684 possibly variables as well; DW_AT_specification refers to
8685 declarations. Declarations ought to have the DW_AT_declaration
8686 flag. It happens that GCC forgets to put it in sometimes, but
8687 only for functions, not for types.
8689 Adding more things than necessary to the hash table is harmless
8690 except for the performance cost. Adding too few will result in
8691 wasted time in find_partial_die, when we reread the compilation
8692 unit with load_all_dies set. */
8695 || abbrev
->tag
== DW_TAG_constant
8696 || abbrev
->tag
== DW_TAG_subprogram
8697 || abbrev
->tag
== DW_TAG_variable
8698 || abbrev
->tag
== DW_TAG_namespace
8699 || part_die
->is_declaration
)
8703 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8704 part_die
->offset
, INSERT
);
8708 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8709 sizeof (struct partial_die_info
));
8711 /* For some DIEs we want to follow their children (if any). For C
8712 we have no reason to follow the children of structures; for other
8713 languages we have to, so that we can get at method physnames
8714 to infer fully qualified class names, for DW_AT_specification,
8715 and for C++ template arguments. For C++, we also look one level
8716 inside functions to find template arguments (if the name of the
8717 function does not already contain the template arguments).
8719 For Ada, we need to scan the children of subprograms and lexical
8720 blocks as well because Ada allows the definition of nested
8721 entities that could be interesting for the debugger, such as
8722 nested subprograms for instance. */
8723 if (last_die
->has_children
8725 || last_die
->tag
== DW_TAG_namespace
8726 || last_die
->tag
== DW_TAG_module
8727 || last_die
->tag
== DW_TAG_enumeration_type
8728 || (cu
->language
== language_cplus
8729 && last_die
->tag
== DW_TAG_subprogram
8730 && (last_die
->name
== NULL
8731 || strchr (last_die
->name
, '<') == NULL
))
8732 || (cu
->language
!= language_c
8733 && (last_die
->tag
== DW_TAG_class_type
8734 || last_die
->tag
== DW_TAG_interface_type
8735 || last_die
->tag
== DW_TAG_structure_type
8736 || last_die
->tag
== DW_TAG_union_type
))
8737 || (cu
->language
== language_ada
8738 && (last_die
->tag
== DW_TAG_subprogram
8739 || last_die
->tag
== DW_TAG_lexical_block
))))
8742 parent_die
= last_die
;
8746 /* Otherwise we skip to the next sibling, if any. */
8747 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8749 /* Back to the top, do it again. */
8753 /* Read a minimal amount of information into the minimal die structure. */
8756 read_partial_die (struct partial_die_info
*part_die
,
8757 struct abbrev_info
*abbrev
,
8758 unsigned int abbrev_len
, bfd
*abfd
,
8759 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8760 struct dwarf2_cu
*cu
)
8763 struct attribute attr
;
8764 int has_low_pc_attr
= 0;
8765 int has_high_pc_attr
= 0;
8767 memset (part_die
, 0, sizeof (struct partial_die_info
));
8769 part_die
->offset
= info_ptr
- buffer
;
8771 info_ptr
+= abbrev_len
;
8776 part_die
->tag
= abbrev
->tag
;
8777 part_die
->has_children
= abbrev
->has_children
;
8779 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8781 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8783 /* Store the data if it is of an attribute we want to keep in a
8784 partial symbol table. */
8788 switch (part_die
->tag
)
8790 case DW_TAG_compile_unit
:
8791 case DW_TAG_type_unit
:
8792 /* Compilation units have a DW_AT_name that is a filename, not
8793 a source language identifier. */
8794 case DW_TAG_enumeration_type
:
8795 case DW_TAG_enumerator
:
8796 /* These tags always have simple identifiers already; no need
8797 to canonicalize them. */
8798 part_die
->name
= DW_STRING (&attr
);
8802 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8803 &cu
->objfile
->objfile_obstack
);
8807 case DW_AT_linkage_name
:
8808 case DW_AT_MIPS_linkage_name
:
8809 /* Note that both forms of linkage name might appear. We
8810 assume they will be the same, and we only store the last
8812 if (cu
->language
== language_ada
)
8813 part_die
->name
= DW_STRING (&attr
);
8814 part_die
->linkage_name
= DW_STRING (&attr
);
8817 has_low_pc_attr
= 1;
8818 part_die
->lowpc
= DW_ADDR (&attr
);
8821 has_high_pc_attr
= 1;
8822 part_die
->highpc
= DW_ADDR (&attr
);
8824 case DW_AT_location
:
8825 /* Support the .debug_loc offsets */
8826 if (attr_form_is_block (&attr
))
8828 part_die
->locdesc
= DW_BLOCK (&attr
);
8830 else if (attr_form_is_section_offset (&attr
))
8832 dwarf2_complex_location_expr_complaint ();
8836 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8837 "partial symbol information");
8840 case DW_AT_external
:
8841 part_die
->is_external
= DW_UNSND (&attr
);
8843 case DW_AT_declaration
:
8844 part_die
->is_declaration
= DW_UNSND (&attr
);
8847 part_die
->has_type
= 1;
8849 case DW_AT_abstract_origin
:
8850 case DW_AT_specification
:
8851 case DW_AT_extension
:
8852 part_die
->has_specification
= 1;
8853 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8856 /* Ignore absolute siblings, they might point outside of
8857 the current compile unit. */
8858 if (attr
.form
== DW_FORM_ref_addr
)
8859 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8861 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8863 case DW_AT_byte_size
:
8864 part_die
->has_byte_size
= 1;
8866 case DW_AT_calling_convention
:
8867 /* DWARF doesn't provide a way to identify a program's source-level
8868 entry point. DW_AT_calling_convention attributes are only meant
8869 to describe functions' calling conventions.
8871 However, because it's a necessary piece of information in
8872 Fortran, and because DW_CC_program is the only piece of debugging
8873 information whose definition refers to a 'main program' at all,
8874 several compilers have begun marking Fortran main programs with
8875 DW_CC_program --- even when those functions use the standard
8876 calling conventions.
8878 So until DWARF specifies a way to provide this information and
8879 compilers pick up the new representation, we'll support this
8881 if (DW_UNSND (&attr
) == DW_CC_program
8882 && cu
->language
== language_fortran
)
8884 set_main_name (part_die
->name
);
8886 /* As this DIE has a static linkage the name would be difficult
8887 to look up later. */
8888 language_of_main
= language_fortran
;
8896 /* When using the GNU linker, .gnu.linkonce. sections are used to
8897 eliminate duplicate copies of functions and vtables and such.
8898 The linker will arbitrarily choose one and discard the others.
8899 The AT_*_pc values for such functions refer to local labels in
8900 these sections. If the section from that file was discarded, the
8901 labels are not in the output, so the relocs get a value of 0.
8902 If this is a discarded function, mark the pc bounds as invalid,
8903 so that GDB will ignore it. */
8904 if (has_low_pc_attr
&& has_high_pc_attr
8905 && part_die
->lowpc
< part_die
->highpc
8906 && (part_die
->lowpc
!= 0
8907 || dwarf2_per_objfile
->has_section_at_zero
))
8908 part_die
->has_pc_info
= 1;
8913 /* Find a cached partial DIE at OFFSET in CU. */
8915 static struct partial_die_info
*
8916 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8918 struct partial_die_info
*lookup_die
= NULL
;
8919 struct partial_die_info part_die
;
8921 part_die
.offset
= offset
;
8922 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8927 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8928 except in the case of .debug_types DIEs which do not reference
8929 outside their CU (they do however referencing other types via
8932 static struct partial_die_info
*
8933 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8935 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8936 struct partial_die_info
*pd
= NULL
;
8938 if (cu
->per_cu
->from_debug_types
)
8940 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8946 if (offset_in_cu_p (&cu
->header
, offset
))
8948 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8953 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8955 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8956 load_partial_comp_unit (per_cu
, cu
->objfile
);
8958 per_cu
->cu
->last_used
= 0;
8959 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8961 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8963 struct cleanup
*back_to
;
8964 struct partial_die_info comp_unit_die
;
8965 struct abbrev_info
*abbrev
;
8966 unsigned int bytes_read
;
8969 per_cu
->load_all_dies
= 1;
8971 /* Re-read the DIEs. */
8972 back_to
= make_cleanup (null_cleanup
, 0);
8973 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8975 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8976 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8978 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8979 + per_cu
->cu
->header
.offset
8980 + per_cu
->cu
->header
.first_die_offset
);
8981 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8982 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8983 per_cu
->cu
->objfile
->obfd
,
8984 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8986 if (comp_unit_die
.has_children
)
8987 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8988 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8990 do_cleanups (back_to
);
8992 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8998 internal_error (__FILE__
, __LINE__
,
8999 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
9000 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9004 /* See if we can figure out if the class lives in a namespace. We do
9005 this by looking for a member function; its demangled name will
9006 contain namespace info, if there is any. */
9009 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9010 struct dwarf2_cu
*cu
)
9012 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9013 what template types look like, because the demangler
9014 frequently doesn't give the same name as the debug info. We
9015 could fix this by only using the demangled name to get the
9016 prefix (but see comment in read_structure_type). */
9018 struct partial_die_info
*real_pdi
;
9019 struct partial_die_info
*child_pdi
;
9021 /* If this DIE (this DIE's specification, if any) has a parent, then
9022 we should not do this. We'll prepend the parent's fully qualified
9023 name when we create the partial symbol. */
9025 real_pdi
= struct_pdi
;
9026 while (real_pdi
->has_specification
)
9027 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9029 if (real_pdi
->die_parent
!= NULL
)
9032 for (child_pdi
= struct_pdi
->die_child
;
9034 child_pdi
= child_pdi
->die_sibling
)
9036 if (child_pdi
->tag
== DW_TAG_subprogram
9037 && child_pdi
->linkage_name
!= NULL
)
9039 char *actual_class_name
9040 = language_class_name_from_physname (cu
->language_defn
,
9041 child_pdi
->linkage_name
);
9042 if (actual_class_name
!= NULL
)
9045 = obsavestring (actual_class_name
,
9046 strlen (actual_class_name
),
9047 &cu
->objfile
->objfile_obstack
);
9048 xfree (actual_class_name
);
9055 /* Adjust PART_DIE before generating a symbol for it. This function
9056 may set the is_external flag or change the DIE's name. */
9059 fixup_partial_die (struct partial_die_info
*part_die
,
9060 struct dwarf2_cu
*cu
)
9062 /* Once we've fixed up a die, there's no point in doing so again.
9063 This also avoids a memory leak if we were to call
9064 guess_partial_die_structure_name multiple times. */
9065 if (part_die
->fixup_called
)
9068 /* If we found a reference attribute and the DIE has no name, try
9069 to find a name in the referred to DIE. */
9071 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9073 struct partial_die_info
*spec_die
;
9075 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9077 fixup_partial_die (spec_die
, cu
);
9081 part_die
->name
= spec_die
->name
;
9083 /* Copy DW_AT_external attribute if it is set. */
9084 if (spec_die
->is_external
)
9085 part_die
->is_external
= spec_die
->is_external
;
9089 /* Set default names for some unnamed DIEs. */
9091 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9092 part_die
->name
= "(anonymous namespace)";
9094 /* If there is no parent die to provide a namespace, and there are
9095 children, see if we can determine the namespace from their linkage
9097 NOTE: We need to do this even if cu->has_namespace_info != 0.
9098 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9099 if (cu
->language
== language_cplus
9100 && dwarf2_per_objfile
->types
.asection
!= NULL
9101 && part_die
->die_parent
== NULL
9102 && part_die
->has_children
9103 && (part_die
->tag
== DW_TAG_class_type
9104 || part_die
->tag
== DW_TAG_structure_type
9105 || part_die
->tag
== DW_TAG_union_type
))
9106 guess_partial_die_structure_name (part_die
, cu
);
9108 part_die
->fixup_called
= 1;
9111 /* Read an attribute value described by an attribute form. */
9114 read_attribute_value (struct attribute
*attr
, unsigned form
,
9115 bfd
*abfd
, gdb_byte
*info_ptr
,
9116 struct dwarf2_cu
*cu
)
9118 struct comp_unit_head
*cu_header
= &cu
->header
;
9119 unsigned int bytes_read
;
9120 struct dwarf_block
*blk
;
9125 case DW_FORM_ref_addr
:
9126 if (cu
->header
.version
== 2)
9127 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9129 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9130 info_ptr
+= bytes_read
;
9133 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9134 info_ptr
+= bytes_read
;
9136 case DW_FORM_block2
:
9137 blk
= dwarf_alloc_block (cu
);
9138 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9140 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9141 info_ptr
+= blk
->size
;
9142 DW_BLOCK (attr
) = blk
;
9144 case DW_FORM_block4
:
9145 blk
= dwarf_alloc_block (cu
);
9146 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9148 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9149 info_ptr
+= blk
->size
;
9150 DW_BLOCK (attr
) = blk
;
9153 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9157 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9161 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9164 case DW_FORM_sec_offset
:
9165 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9166 info_ptr
+= bytes_read
;
9168 case DW_FORM_string
:
9169 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9170 DW_STRING_IS_CANONICAL (attr
) = 0;
9171 info_ptr
+= bytes_read
;
9174 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9176 DW_STRING_IS_CANONICAL (attr
) = 0;
9177 info_ptr
+= bytes_read
;
9179 case DW_FORM_exprloc
:
9181 blk
= dwarf_alloc_block (cu
);
9182 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9183 info_ptr
+= bytes_read
;
9184 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9185 info_ptr
+= blk
->size
;
9186 DW_BLOCK (attr
) = blk
;
9188 case DW_FORM_block1
:
9189 blk
= dwarf_alloc_block (cu
);
9190 blk
->size
= read_1_byte (abfd
, info_ptr
);
9192 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9193 info_ptr
+= blk
->size
;
9194 DW_BLOCK (attr
) = blk
;
9197 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9201 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9204 case DW_FORM_flag_present
:
9205 DW_UNSND (attr
) = 1;
9208 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9209 info_ptr
+= bytes_read
;
9212 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9213 info_ptr
+= bytes_read
;
9216 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9220 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9224 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9228 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9232 /* Convert the signature to something we can record in DW_UNSND
9234 NOTE: This is NULL if the type wasn't found. */
9235 DW_SIGNATURED_TYPE (attr
) =
9236 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9239 case DW_FORM_ref_udata
:
9240 DW_ADDR (attr
) = (cu
->header
.offset
9241 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9242 info_ptr
+= bytes_read
;
9244 case DW_FORM_indirect
:
9245 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9246 info_ptr
+= bytes_read
;
9247 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9250 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9251 dwarf_form_name (form
),
9252 bfd_get_filename (abfd
));
9255 /* We have seen instances where the compiler tried to emit a byte
9256 size attribute of -1 which ended up being encoded as an unsigned
9257 0xffffffff. Although 0xffffffff is technically a valid size value,
9258 an object of this size seems pretty unlikely so we can relatively
9259 safely treat these cases as if the size attribute was invalid and
9260 treat them as zero by default. */
9261 if (attr
->name
== DW_AT_byte_size
9262 && form
== DW_FORM_data4
9263 && DW_UNSND (attr
) >= 0xffffffff)
9266 (&symfile_complaints
,
9267 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9268 hex_string (DW_UNSND (attr
)));
9269 DW_UNSND (attr
) = 0;
9275 /* Read an attribute described by an abbreviated attribute. */
9278 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9279 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9281 attr
->name
= abbrev
->name
;
9282 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9285 /* read dwarf information from a buffer */
9288 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9290 return bfd_get_8 (abfd
, buf
);
9294 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9296 return bfd_get_signed_8 (abfd
, buf
);
9300 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9302 return bfd_get_16 (abfd
, buf
);
9306 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9308 return bfd_get_signed_16 (abfd
, buf
);
9312 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9314 return bfd_get_32 (abfd
, buf
);
9318 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9320 return bfd_get_signed_32 (abfd
, buf
);
9324 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9326 return bfd_get_64 (abfd
, buf
);
9330 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9331 unsigned int *bytes_read
)
9333 struct comp_unit_head
*cu_header
= &cu
->header
;
9334 CORE_ADDR retval
= 0;
9336 if (cu_header
->signed_addr_p
)
9338 switch (cu_header
->addr_size
)
9341 retval
= bfd_get_signed_16 (abfd
, buf
);
9344 retval
= bfd_get_signed_32 (abfd
, buf
);
9347 retval
= bfd_get_signed_64 (abfd
, buf
);
9350 internal_error (__FILE__
, __LINE__
,
9351 _("read_address: bad switch, signed [in module %s]"),
9352 bfd_get_filename (abfd
));
9357 switch (cu_header
->addr_size
)
9360 retval
= bfd_get_16 (abfd
, buf
);
9363 retval
= bfd_get_32 (abfd
, buf
);
9366 retval
= bfd_get_64 (abfd
, buf
);
9369 internal_error (__FILE__
, __LINE__
,
9370 _("read_address: bad switch, unsigned [in module %s]"),
9371 bfd_get_filename (abfd
));
9375 *bytes_read
= cu_header
->addr_size
;
9379 /* Read the initial length from a section. The (draft) DWARF 3
9380 specification allows the initial length to take up either 4 bytes
9381 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9382 bytes describe the length and all offsets will be 8 bytes in length
9385 An older, non-standard 64-bit format is also handled by this
9386 function. The older format in question stores the initial length
9387 as an 8-byte quantity without an escape value. Lengths greater
9388 than 2^32 aren't very common which means that the initial 4 bytes
9389 is almost always zero. Since a length value of zero doesn't make
9390 sense for the 32-bit format, this initial zero can be considered to
9391 be an escape value which indicates the presence of the older 64-bit
9392 format. As written, the code can't detect (old format) lengths
9393 greater than 4GB. If it becomes necessary to handle lengths
9394 somewhat larger than 4GB, we could allow other small values (such
9395 as the non-sensical values of 1, 2, and 3) to also be used as
9396 escape values indicating the presence of the old format.
9398 The value returned via bytes_read should be used to increment the
9399 relevant pointer after calling read_initial_length().
9401 [ Note: read_initial_length() and read_offset() are based on the
9402 document entitled "DWARF Debugging Information Format", revision
9403 3, draft 8, dated November 19, 2001. This document was obtained
9406 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9408 This document is only a draft and is subject to change. (So beware.)
9410 Details regarding the older, non-standard 64-bit format were
9411 determined empirically by examining 64-bit ELF files produced by
9412 the SGI toolchain on an IRIX 6.5 machine.
9414 - Kevin, July 16, 2002
9418 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9420 LONGEST length
= bfd_get_32 (abfd
, buf
);
9422 if (length
== 0xffffffff)
9424 length
= bfd_get_64 (abfd
, buf
+ 4);
9427 else if (length
== 0)
9429 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9430 length
= bfd_get_64 (abfd
, buf
);
9441 /* Cover function for read_initial_length.
9442 Returns the length of the object at BUF, and stores the size of the
9443 initial length in *BYTES_READ and stores the size that offsets will be in
9445 If the initial length size is not equivalent to that specified in
9446 CU_HEADER then issue a complaint.
9447 This is useful when reading non-comp-unit headers. */
9450 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9451 const struct comp_unit_head
*cu_header
,
9452 unsigned int *bytes_read
,
9453 unsigned int *offset_size
)
9455 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9457 gdb_assert (cu_header
->initial_length_size
== 4
9458 || cu_header
->initial_length_size
== 8
9459 || cu_header
->initial_length_size
== 12);
9461 if (cu_header
->initial_length_size
!= *bytes_read
)
9462 complaint (&symfile_complaints
,
9463 _("intermixed 32-bit and 64-bit DWARF sections"));
9465 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9469 /* Read an offset from the data stream. The size of the offset is
9470 given by cu_header->offset_size. */
9473 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9474 unsigned int *bytes_read
)
9476 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9478 *bytes_read
= cu_header
->offset_size
;
9482 /* Read an offset from the data stream. */
9485 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9489 switch (offset_size
)
9492 retval
= bfd_get_32 (abfd
, buf
);
9495 retval
= bfd_get_64 (abfd
, buf
);
9498 internal_error (__FILE__
, __LINE__
,
9499 _("read_offset_1: bad switch [in module %s]"),
9500 bfd_get_filename (abfd
));
9507 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9509 /* If the size of a host char is 8 bits, we can return a pointer
9510 to the buffer, otherwise we have to copy the data to a buffer
9511 allocated on the temporary obstack. */
9512 gdb_assert (HOST_CHAR_BIT
== 8);
9517 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9519 /* If the size of a host char is 8 bits, we can return a pointer
9520 to the string, otherwise we have to copy the string to a buffer
9521 allocated on the temporary obstack. */
9522 gdb_assert (HOST_CHAR_BIT
== 8);
9525 *bytes_read_ptr
= 1;
9528 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9529 return (char *) buf
;
9533 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9534 const struct comp_unit_head
*cu_header
,
9535 unsigned int *bytes_read_ptr
)
9537 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9539 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9540 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9542 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9543 bfd_get_filename (abfd
));
9546 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9548 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9549 bfd_get_filename (abfd
));
9552 gdb_assert (HOST_CHAR_BIT
== 8);
9553 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9555 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9558 static unsigned long
9559 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9561 unsigned long result
;
9562 unsigned int num_read
;
9572 byte
= bfd_get_8 (abfd
, buf
);
9575 result
|= ((unsigned long)(byte
& 127) << shift
);
9576 if ((byte
& 128) == 0)
9582 *bytes_read_ptr
= num_read
;
9587 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9590 int i
, shift
, num_read
;
9599 byte
= bfd_get_8 (abfd
, buf
);
9602 result
|= ((long)(byte
& 127) << shift
);
9604 if ((byte
& 128) == 0)
9609 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9610 result
|= -(((long)1) << shift
);
9611 *bytes_read_ptr
= num_read
;
9615 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9618 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9624 byte
= bfd_get_8 (abfd
, buf
);
9626 if ((byte
& 128) == 0)
9632 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9639 cu
->language
= language_c
;
9641 case DW_LANG_C_plus_plus
:
9642 cu
->language
= language_cplus
;
9645 cu
->language
= language_d
;
9647 case DW_LANG_Fortran77
:
9648 case DW_LANG_Fortran90
:
9649 case DW_LANG_Fortran95
:
9650 cu
->language
= language_fortran
;
9652 case DW_LANG_Mips_Assembler
:
9653 cu
->language
= language_asm
;
9656 cu
->language
= language_java
;
9660 cu
->language
= language_ada
;
9662 case DW_LANG_Modula2
:
9663 cu
->language
= language_m2
;
9665 case DW_LANG_Pascal83
:
9666 cu
->language
= language_pascal
;
9669 cu
->language
= language_objc
;
9671 case DW_LANG_Cobol74
:
9672 case DW_LANG_Cobol85
:
9674 cu
->language
= language_minimal
;
9677 cu
->language_defn
= language_def (cu
->language
);
9680 /* Return the named attribute or NULL if not there. */
9682 static struct attribute
*
9683 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9686 struct attribute
*spec
= NULL
;
9688 for (i
= 0; i
< die
->num_attrs
; ++i
)
9690 if (die
->attrs
[i
].name
== name
)
9691 return &die
->attrs
[i
];
9692 if (die
->attrs
[i
].name
== DW_AT_specification
9693 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9694 spec
= &die
->attrs
[i
];
9699 die
= follow_die_ref (die
, spec
, &cu
);
9700 return dwarf2_attr (die
, name
, cu
);
9706 /* Return the named attribute or NULL if not there,
9707 but do not follow DW_AT_specification, etc.
9708 This is for use in contexts where we're reading .debug_types dies.
9709 Following DW_AT_specification, DW_AT_abstract_origin will take us
9710 back up the chain, and we want to go down. */
9712 static struct attribute
*
9713 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9714 struct dwarf2_cu
*cu
)
9718 for (i
= 0; i
< die
->num_attrs
; ++i
)
9719 if (die
->attrs
[i
].name
== name
)
9720 return &die
->attrs
[i
];
9725 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9726 and holds a non-zero value. This function should only be used for
9727 DW_FORM_flag or DW_FORM_flag_present attributes. */
9730 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9732 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9734 return (attr
&& DW_UNSND (attr
));
9738 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9740 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9741 which value is non-zero. However, we have to be careful with
9742 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9743 (via dwarf2_flag_true_p) follows this attribute. So we may
9744 end up accidently finding a declaration attribute that belongs
9745 to a different DIE referenced by the specification attribute,
9746 even though the given DIE does not have a declaration attribute. */
9747 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9748 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9751 /* Return the die giving the specification for DIE, if there is
9752 one. *SPEC_CU is the CU containing DIE on input, and the CU
9753 containing the return value on output. If there is no
9754 specification, but there is an abstract origin, that is
9757 static struct die_info
*
9758 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9760 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9763 if (spec_attr
== NULL
)
9764 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9766 if (spec_attr
== NULL
)
9769 return follow_die_ref (die
, spec_attr
, spec_cu
);
9772 /* Free the line_header structure *LH, and any arrays and strings it
9775 free_line_header (struct line_header
*lh
)
9777 if (lh
->standard_opcode_lengths
)
9778 xfree (lh
->standard_opcode_lengths
);
9780 /* Remember that all the lh->file_names[i].name pointers are
9781 pointers into debug_line_buffer, and don't need to be freed. */
9783 xfree (lh
->file_names
);
9785 /* Similarly for the include directory names. */
9786 if (lh
->include_dirs
)
9787 xfree (lh
->include_dirs
);
9793 /* Add an entry to LH's include directory table. */
9795 add_include_dir (struct line_header
*lh
, char *include_dir
)
9797 /* Grow the array if necessary. */
9798 if (lh
->include_dirs_size
== 0)
9800 lh
->include_dirs_size
= 1; /* for testing */
9801 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9802 * sizeof (*lh
->include_dirs
));
9804 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9806 lh
->include_dirs_size
*= 2;
9807 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9808 (lh
->include_dirs_size
9809 * sizeof (*lh
->include_dirs
)));
9812 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9816 /* Add an entry to LH's file name table. */
9818 add_file_name (struct line_header
*lh
,
9820 unsigned int dir_index
,
9821 unsigned int mod_time
,
9822 unsigned int length
)
9824 struct file_entry
*fe
;
9826 /* Grow the array if necessary. */
9827 if (lh
->file_names_size
== 0)
9829 lh
->file_names_size
= 1; /* for testing */
9830 lh
->file_names
= xmalloc (lh
->file_names_size
9831 * sizeof (*lh
->file_names
));
9833 else if (lh
->num_file_names
>= lh
->file_names_size
)
9835 lh
->file_names_size
*= 2;
9836 lh
->file_names
= xrealloc (lh
->file_names
,
9837 (lh
->file_names_size
9838 * sizeof (*lh
->file_names
)));
9841 fe
= &lh
->file_names
[lh
->num_file_names
++];
9843 fe
->dir_index
= dir_index
;
9844 fe
->mod_time
= mod_time
;
9845 fe
->length
= length
;
9851 /* Read the statement program header starting at OFFSET in
9852 .debug_line, according to the endianness of ABFD. Return a pointer
9853 to a struct line_header, allocated using xmalloc.
9855 NOTE: the strings in the include directory and file name tables of
9856 the returned object point into debug_line_buffer, and must not be
9858 static struct line_header
*
9859 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9860 struct dwarf2_cu
*cu
)
9862 struct cleanup
*back_to
;
9863 struct line_header
*lh
;
9865 unsigned int bytes_read
, offset_size
;
9867 char *cur_dir
, *cur_file
;
9869 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9870 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9872 complaint (&symfile_complaints
, _("missing .debug_line section"));
9876 /* Make sure that at least there's room for the total_length field.
9877 That could be 12 bytes long, but we're just going to fudge that. */
9878 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9880 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9884 lh
= xmalloc (sizeof (*lh
));
9885 memset (lh
, 0, sizeof (*lh
));
9886 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9889 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9891 /* Read in the header. */
9893 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9894 &bytes_read
, &offset_size
);
9895 line_ptr
+= bytes_read
;
9896 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9897 + dwarf2_per_objfile
->line
.size
))
9899 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9902 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9903 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9905 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9906 line_ptr
+= offset_size
;
9907 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9909 if (lh
->version
>= 4)
9911 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9915 lh
->maximum_ops_per_instruction
= 1;
9917 if (lh
->maximum_ops_per_instruction
== 0)
9919 lh
->maximum_ops_per_instruction
= 1;
9920 complaint (&symfile_complaints
,
9921 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9924 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9926 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9928 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9930 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9932 lh
->standard_opcode_lengths
9933 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9935 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9936 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9938 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9942 /* Read directory table. */
9943 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9945 line_ptr
+= bytes_read
;
9946 add_include_dir (lh
, cur_dir
);
9948 line_ptr
+= bytes_read
;
9950 /* Read file name table. */
9951 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9953 unsigned int dir_index
, mod_time
, length
;
9955 line_ptr
+= bytes_read
;
9956 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9957 line_ptr
+= bytes_read
;
9958 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9959 line_ptr
+= bytes_read
;
9960 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9961 line_ptr
+= bytes_read
;
9963 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9965 line_ptr
+= bytes_read
;
9966 lh
->statement_program_start
= line_ptr
;
9968 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9969 + dwarf2_per_objfile
->line
.size
))
9970 complaint (&symfile_complaints
,
9971 _("line number info header doesn't fit in `.debug_line' section"));
9973 discard_cleanups (back_to
);
9977 /* This function exists to work around a bug in certain compilers
9978 (particularly GCC 2.95), in which the first line number marker of a
9979 function does not show up until after the prologue, right before
9980 the second line number marker. This function shifts ADDRESS down
9981 to the beginning of the function if necessary, and is called on
9982 addresses passed to record_line. */
9985 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9987 struct function_range
*fn
;
9989 /* Find the function_range containing address. */
9994 cu
->cached_fn
= cu
->first_fn
;
9998 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10004 while (fn
&& fn
!= cu
->cached_fn
)
10005 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10015 if (address
!= fn
->lowpc
)
10016 complaint (&symfile_complaints
,
10017 _("misplaced first line number at 0x%lx for '%s'"),
10018 (unsigned long) address
, fn
->name
);
10023 /* Subroutine of dwarf_decode_lines to simplify it.
10024 Return the file name of the psymtab for included file FILE_INDEX
10025 in line header LH of PST.
10026 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10027 If space for the result is malloc'd, it will be freed by a cleanup.
10028 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10031 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10032 const struct partial_symtab
*pst
,
10033 const char *comp_dir
)
10035 const struct file_entry fe
= lh
->file_names
[file_index
];
10036 char *include_name
= fe
.name
;
10037 char *include_name_to_compare
= include_name
;
10038 char *dir_name
= NULL
;
10039 const char *pst_filename
;
10040 char *copied_name
= NULL
;
10044 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10046 if (!IS_ABSOLUTE_PATH (include_name
)
10047 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10049 /* Avoid creating a duplicate psymtab for PST.
10050 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10051 Before we do the comparison, however, we need to account
10052 for DIR_NAME and COMP_DIR.
10053 First prepend dir_name (if non-NULL). If we still don't
10054 have an absolute path prepend comp_dir (if non-NULL).
10055 However, the directory we record in the include-file's
10056 psymtab does not contain COMP_DIR (to match the
10057 corresponding symtab(s)).
10062 bash$ gcc -g ./hello.c
10063 include_name = "hello.c"
10065 DW_AT_comp_dir = comp_dir = "/tmp"
10066 DW_AT_name = "./hello.c" */
10068 if (dir_name
!= NULL
)
10070 include_name
= concat (dir_name
, SLASH_STRING
,
10071 include_name
, (char *)NULL
);
10072 include_name_to_compare
= include_name
;
10073 make_cleanup (xfree
, include_name
);
10075 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10077 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10078 include_name
, (char *)NULL
);
10082 pst_filename
= pst
->filename
;
10083 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10085 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10086 pst_filename
, (char *)NULL
);
10087 pst_filename
= copied_name
;
10090 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10092 if (include_name_to_compare
!= include_name
)
10093 xfree (include_name_to_compare
);
10094 if (copied_name
!= NULL
)
10095 xfree (copied_name
);
10099 return include_name
;
10102 /* Decode the Line Number Program (LNP) for the given line_header
10103 structure and CU. The actual information extracted and the type
10104 of structures created from the LNP depends on the value of PST.
10106 1. If PST is NULL, then this procedure uses the data from the program
10107 to create all necessary symbol tables, and their linetables.
10109 2. If PST is not NULL, this procedure reads the program to determine
10110 the list of files included by the unit represented by PST, and
10111 builds all the associated partial symbol tables.
10113 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10114 It is used for relative paths in the line table.
10115 NOTE: When processing partial symtabs (pst != NULL),
10116 comp_dir == pst->dirname.
10118 NOTE: It is important that psymtabs have the same file name (via strcmp)
10119 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10120 symtab we don't use it in the name of the psymtabs we create.
10121 E.g. expand_line_sal requires this when finding psymtabs to expand.
10122 A good testcase for this is mb-inline.exp. */
10125 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10126 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10128 gdb_byte
*line_ptr
, *extended_end
;
10129 gdb_byte
*line_end
;
10130 unsigned int bytes_read
, extended_len
;
10131 unsigned char op_code
, extended_op
, adj_opcode
;
10132 CORE_ADDR baseaddr
;
10133 struct objfile
*objfile
= cu
->objfile
;
10134 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10135 const int decode_for_pst_p
= (pst
!= NULL
);
10136 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10138 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10140 line_ptr
= lh
->statement_program_start
;
10141 line_end
= lh
->statement_program_end
;
10143 /* Read the statement sequences until there's nothing left. */
10144 while (line_ptr
< line_end
)
10146 /* state machine registers */
10147 CORE_ADDR address
= 0;
10148 unsigned int file
= 1;
10149 unsigned int line
= 1;
10150 unsigned int column
= 0;
10151 int is_stmt
= lh
->default_is_stmt
;
10152 int basic_block
= 0;
10153 int end_sequence
= 0;
10155 unsigned char op_index
= 0;
10157 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10159 /* Start a subfile for the current file of the state machine. */
10160 /* lh->include_dirs and lh->file_names are 0-based, but the
10161 directory and file name numbers in the statement program
10163 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10167 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10169 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10172 /* Decode the table. */
10173 while (!end_sequence
)
10175 op_code
= read_1_byte (abfd
, line_ptr
);
10177 if (line_ptr
> line_end
)
10179 dwarf2_debug_line_missing_end_sequence_complaint ();
10183 if (op_code
>= lh
->opcode_base
)
10185 /* Special operand. */
10186 adj_opcode
= op_code
- lh
->opcode_base
;
10187 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10188 / lh
->maximum_ops_per_instruction
)
10189 * lh
->minimum_instruction_length
);
10190 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10191 % lh
->maximum_ops_per_instruction
);
10192 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10193 if (lh
->num_file_names
< file
|| file
== 0)
10194 dwarf2_debug_line_missing_file_complaint ();
10195 /* For now we ignore lines not starting on an
10196 instruction boundary. */
10197 else if (op_index
== 0)
10199 lh
->file_names
[file
- 1].included_p
= 1;
10200 if (!decode_for_pst_p
&& is_stmt
)
10202 if (last_subfile
!= current_subfile
)
10204 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10206 record_line (last_subfile
, 0, addr
);
10207 last_subfile
= current_subfile
;
10209 /* Append row to matrix using current values. */
10210 addr
= check_cu_functions (address
, cu
);
10211 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10212 record_line (current_subfile
, line
, addr
);
10217 else switch (op_code
)
10219 case DW_LNS_extended_op
:
10220 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10221 line_ptr
+= bytes_read
;
10222 extended_end
= line_ptr
+ extended_len
;
10223 extended_op
= read_1_byte (abfd
, line_ptr
);
10225 switch (extended_op
)
10227 case DW_LNE_end_sequence
:
10230 case DW_LNE_set_address
:
10231 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10233 line_ptr
+= bytes_read
;
10234 address
+= baseaddr
;
10236 case DW_LNE_define_file
:
10239 unsigned int dir_index
, mod_time
, length
;
10241 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10242 line_ptr
+= bytes_read
;
10244 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10245 line_ptr
+= bytes_read
;
10247 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10248 line_ptr
+= bytes_read
;
10250 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10251 line_ptr
+= bytes_read
;
10252 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10255 case DW_LNE_set_discriminator
:
10256 /* The discriminator is not interesting to the debugger;
10258 line_ptr
= extended_end
;
10261 complaint (&symfile_complaints
,
10262 _("mangled .debug_line section"));
10265 /* Make sure that we parsed the extended op correctly. If e.g.
10266 we expected a different address size than the producer used,
10267 we may have read the wrong number of bytes. */
10268 if (line_ptr
!= extended_end
)
10270 complaint (&symfile_complaints
,
10271 _("mangled .debug_line section"));
10276 if (lh
->num_file_names
< file
|| file
== 0)
10277 dwarf2_debug_line_missing_file_complaint ();
10280 lh
->file_names
[file
- 1].included_p
= 1;
10281 if (!decode_for_pst_p
&& is_stmt
)
10283 if (last_subfile
!= current_subfile
)
10285 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10287 record_line (last_subfile
, 0, addr
);
10288 last_subfile
= current_subfile
;
10290 addr
= check_cu_functions (address
, cu
);
10291 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10292 record_line (current_subfile
, line
, addr
);
10297 case DW_LNS_advance_pc
:
10300 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10302 address
+= (((op_index
+ adjust
)
10303 / lh
->maximum_ops_per_instruction
)
10304 * lh
->minimum_instruction_length
);
10305 op_index
= ((op_index
+ adjust
)
10306 % lh
->maximum_ops_per_instruction
);
10307 line_ptr
+= bytes_read
;
10310 case DW_LNS_advance_line
:
10311 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10312 line_ptr
+= bytes_read
;
10314 case DW_LNS_set_file
:
10316 /* The arrays lh->include_dirs and lh->file_names are
10317 0-based, but the directory and file name numbers in
10318 the statement program are 1-based. */
10319 struct file_entry
*fe
;
10322 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10323 line_ptr
+= bytes_read
;
10324 if (lh
->num_file_names
< file
|| file
== 0)
10325 dwarf2_debug_line_missing_file_complaint ();
10328 fe
= &lh
->file_names
[file
- 1];
10330 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10331 if (!decode_for_pst_p
)
10333 last_subfile
= current_subfile
;
10334 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10339 case DW_LNS_set_column
:
10340 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10341 line_ptr
+= bytes_read
;
10343 case DW_LNS_negate_stmt
:
10344 is_stmt
= (!is_stmt
);
10346 case DW_LNS_set_basic_block
:
10349 /* Add to the address register of the state machine the
10350 address increment value corresponding to special opcode
10351 255. I.e., this value is scaled by the minimum
10352 instruction length since special opcode 255 would have
10353 scaled the the increment. */
10354 case DW_LNS_const_add_pc
:
10356 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10358 address
+= (((op_index
+ adjust
)
10359 / lh
->maximum_ops_per_instruction
)
10360 * lh
->minimum_instruction_length
);
10361 op_index
= ((op_index
+ adjust
)
10362 % lh
->maximum_ops_per_instruction
);
10365 case DW_LNS_fixed_advance_pc
:
10366 address
+= read_2_bytes (abfd
, line_ptr
);
10372 /* Unknown standard opcode, ignore it. */
10375 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10377 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10378 line_ptr
+= bytes_read
;
10383 if (lh
->num_file_names
< file
|| file
== 0)
10384 dwarf2_debug_line_missing_file_complaint ();
10387 lh
->file_names
[file
- 1].included_p
= 1;
10388 if (!decode_for_pst_p
)
10390 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10391 record_line (current_subfile
, 0, addr
);
10396 if (decode_for_pst_p
)
10400 /* Now that we're done scanning the Line Header Program, we can
10401 create the psymtab of each included file. */
10402 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10403 if (lh
->file_names
[file_index
].included_p
== 1)
10405 char *include_name
=
10406 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10407 if (include_name
!= NULL
)
10408 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10413 /* Make sure a symtab is created for every file, even files
10414 which contain only variables (i.e. no code with associated
10418 struct file_entry
*fe
;
10420 for (i
= 0; i
< lh
->num_file_names
; i
++)
10424 fe
= &lh
->file_names
[i
];
10426 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10427 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10429 /* Skip the main file; we don't need it, and it must be
10430 allocated last, so that it will show up before the
10431 non-primary symtabs in the objfile's symtab list. */
10432 if (current_subfile
== first_subfile
)
10435 if (current_subfile
->symtab
== NULL
)
10436 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10438 fe
->symtab
= current_subfile
->symtab
;
10443 /* Start a subfile for DWARF. FILENAME is the name of the file and
10444 DIRNAME the name of the source directory which contains FILENAME
10445 or NULL if not known. COMP_DIR is the compilation directory for the
10446 linetable's compilation unit or NULL if not known.
10447 This routine tries to keep line numbers from identical absolute and
10448 relative file names in a common subfile.
10450 Using the `list' example from the GDB testsuite, which resides in
10451 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10452 of /srcdir/list0.c yields the following debugging information for list0.c:
10454 DW_AT_name: /srcdir/list0.c
10455 DW_AT_comp_dir: /compdir
10456 files.files[0].name: list0.h
10457 files.files[0].dir: /srcdir
10458 files.files[1].name: list0.c
10459 files.files[1].dir: /srcdir
10461 The line number information for list0.c has to end up in a single
10462 subfile, so that `break /srcdir/list0.c:1' works as expected.
10463 start_subfile will ensure that this happens provided that we pass the
10464 concatenation of files.files[1].dir and files.files[1].name as the
10468 dwarf2_start_subfile (char *filename
, const char *dirname
, const char *comp_dir
)
10472 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10473 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10474 second argument to start_subfile. To be consistent, we do the
10475 same here. In order not to lose the line information directory,
10476 we concatenate it to the filename when it makes sense.
10477 Note that the Dwarf3 standard says (speaking of filenames in line
10478 information): ``The directory index is ignored for file names
10479 that represent full path names''. Thus ignoring dirname in the
10480 `else' branch below isn't an issue. */
10482 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10483 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10485 fullname
= filename
;
10487 start_subfile (fullname
, comp_dir
);
10489 if (fullname
!= filename
)
10494 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10495 struct dwarf2_cu
*cu
)
10497 struct objfile
*objfile
= cu
->objfile
;
10498 struct comp_unit_head
*cu_header
= &cu
->header
;
10500 /* NOTE drow/2003-01-30: There used to be a comment and some special
10501 code here to turn a symbol with DW_AT_external and a
10502 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10503 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10504 with some versions of binutils) where shared libraries could have
10505 relocations against symbols in their debug information - the
10506 minimal symbol would have the right address, but the debug info
10507 would not. It's no longer necessary, because we will explicitly
10508 apply relocations when we read in the debug information now. */
10510 /* A DW_AT_location attribute with no contents indicates that a
10511 variable has been optimized away. */
10512 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10514 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10518 /* Handle one degenerate form of location expression specially, to
10519 preserve GDB's previous behavior when section offsets are
10520 specified. If this is just a DW_OP_addr then mark this symbol
10523 if (attr_form_is_block (attr
)
10524 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10525 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10527 unsigned int dummy
;
10529 SYMBOL_VALUE_ADDRESS (sym
) =
10530 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10531 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10532 fixup_symbol_section (sym
, objfile
);
10533 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10534 SYMBOL_SECTION (sym
));
10538 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10539 expression evaluator, and use LOC_COMPUTED only when necessary
10540 (i.e. when the value of a register or memory location is
10541 referenced, or a thread-local block, etc.). Then again, it might
10542 not be worthwhile. I'm assuming that it isn't unless performance
10543 or memory numbers show me otherwise. */
10545 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10546 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10549 /* Given a pointer to a DWARF information entry, figure out if we need
10550 to make a symbol table entry for it, and if so, create a new entry
10551 and return a pointer to it.
10552 If TYPE is NULL, determine symbol type from the die, otherwise
10553 used the passed type.
10554 If SPACE is not NULL, use it to hold the new symbol. If it is
10555 NULL, allocate a new symbol on the objfile's obstack. */
10557 static struct symbol
*
10558 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10559 struct symbol
*space
)
10561 struct objfile
*objfile
= cu
->objfile
;
10562 struct symbol
*sym
= NULL
;
10564 struct attribute
*attr
= NULL
;
10565 struct attribute
*attr2
= NULL
;
10566 CORE_ADDR baseaddr
;
10567 struct pending
**list_to_add
= NULL
;
10569 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10571 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10573 name
= dwarf2_name (die
, cu
);
10576 const char *linkagename
;
10577 int suppress_add
= 0;
10582 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10583 OBJSTAT (objfile
, n_syms
++);
10585 /* Cache this symbol's name and the name's demangled form (if any). */
10586 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10587 linkagename
= dwarf2_physname (name
, die
, cu
);
10588 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10590 /* Fortran does not have mangling standard and the mangling does differ
10591 between gfortran, iFort etc. */
10592 if (cu
->language
== language_fortran
10593 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10594 symbol_set_demangled_name (&(sym
->ginfo
),
10595 (char *) dwarf2_full_name (name
, die
, cu
),
10598 /* Default assumptions.
10599 Use the passed type or decode it from the die. */
10600 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10601 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10603 SYMBOL_TYPE (sym
) = type
;
10605 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10606 attr
= dwarf2_attr (die
,
10607 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10611 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10614 attr
= dwarf2_attr (die
,
10615 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10619 int file_index
= DW_UNSND (attr
);
10621 if (cu
->line_header
== NULL
10622 || file_index
> cu
->line_header
->num_file_names
)
10623 complaint (&symfile_complaints
,
10624 _("file index out of range"));
10625 else if (file_index
> 0)
10627 struct file_entry
*fe
;
10629 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10630 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10637 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10640 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10642 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10643 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10644 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10645 add_symbol_to_list (sym
, cu
->list_in_scope
);
10647 case DW_TAG_subprogram
:
10648 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10650 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10651 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10652 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10653 || cu
->language
== language_ada
)
10655 /* Subprograms marked external are stored as a global symbol.
10656 Ada subprograms, whether marked external or not, are always
10657 stored as a global symbol, because we want to be able to
10658 access them globally. For instance, we want to be able
10659 to break on a nested subprogram without having to
10660 specify the context. */
10661 list_to_add
= &global_symbols
;
10665 list_to_add
= cu
->list_in_scope
;
10668 case DW_TAG_inlined_subroutine
:
10669 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10671 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10672 SYMBOL_INLINED (sym
) = 1;
10673 /* Do not add the symbol to any lists. It will be found via
10674 BLOCK_FUNCTION from the blockvector. */
10676 case DW_TAG_template_value_param
:
10678 /* Fall through. */
10679 case DW_TAG_constant
:
10680 case DW_TAG_variable
:
10681 case DW_TAG_member
:
10682 /* Compilation with minimal debug info may result in variables
10683 with missing type entries. Change the misleading `void' type
10684 to something sensible. */
10685 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10687 = objfile_type (objfile
)->nodebug_data_symbol
;
10689 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10690 /* In the case of DW_TAG_member, we should only be called for
10691 static const members. */
10692 if (die
->tag
== DW_TAG_member
)
10694 /* dwarf2_add_field uses die_is_declaration,
10695 so we do the same. */
10696 gdb_assert (die_is_declaration (die
, cu
));
10701 dwarf2_const_value (attr
, sym
, cu
);
10702 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10705 if (attr2
&& (DW_UNSND (attr2
) != 0))
10706 list_to_add
= &global_symbols
;
10708 list_to_add
= cu
->list_in_scope
;
10712 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10715 var_decode_location (attr
, sym
, cu
);
10716 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10717 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10718 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10719 && !dwarf2_per_objfile
->has_section_at_zero
)
10721 /* When a static variable is eliminated by the linker,
10722 the corresponding debug information is not stripped
10723 out, but the variable address is set to null;
10724 do not add such variables into symbol table. */
10726 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10728 /* Workaround gfortran PR debug/40040 - it uses
10729 DW_AT_location for variables in -fPIC libraries which may
10730 get overriden by other libraries/executable and get
10731 a different address. Resolve it by the minimal symbol
10732 which may come from inferior's executable using copy
10733 relocation. Make this workaround only for gfortran as for
10734 other compilers GDB cannot guess the minimal symbol
10735 Fortran mangling kind. */
10736 if (cu
->language
== language_fortran
&& die
->parent
10737 && die
->parent
->tag
== DW_TAG_module
10739 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10740 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10742 /* A variable with DW_AT_external is never static,
10743 but it may be block-scoped. */
10744 list_to_add
= (cu
->list_in_scope
== &file_symbols
10745 ? &global_symbols
: cu
->list_in_scope
);
10748 list_to_add
= cu
->list_in_scope
;
10752 /* We do not know the address of this symbol.
10753 If it is an external symbol and we have type information
10754 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10755 The address of the variable will then be determined from
10756 the minimal symbol table whenever the variable is
10758 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10759 if (attr2
&& (DW_UNSND (attr2
) != 0)
10760 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10762 /* A variable with DW_AT_external is never static, but it
10763 may be block-scoped. */
10764 list_to_add
= (cu
->list_in_scope
== &file_symbols
10765 ? &global_symbols
: cu
->list_in_scope
);
10767 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10769 else if (!die_is_declaration (die
, cu
))
10771 /* Use the default LOC_OPTIMIZED_OUT class. */
10772 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10774 list_to_add
= cu
->list_in_scope
;
10778 case DW_TAG_formal_parameter
:
10779 /* If we are inside a function, mark this as an argument. If
10780 not, we might be looking at an argument to an inlined function
10781 when we do not have enough information to show inlined frames;
10782 pretend it's a local variable in that case so that the user can
10784 if (context_stack_depth
> 0
10785 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10786 SYMBOL_IS_ARGUMENT (sym
) = 1;
10787 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10790 var_decode_location (attr
, sym
, cu
);
10792 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10795 dwarf2_const_value (attr
, sym
, cu
);
10797 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10798 if (attr
&& DW_UNSND (attr
))
10800 struct type
*ref_type
;
10802 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10803 SYMBOL_TYPE (sym
) = ref_type
;
10806 list_to_add
= cu
->list_in_scope
;
10808 case DW_TAG_unspecified_parameters
:
10809 /* From varargs functions; gdb doesn't seem to have any
10810 interest in this information, so just ignore it for now.
10813 case DW_TAG_template_type_param
:
10815 /* Fall through. */
10816 case DW_TAG_class_type
:
10817 case DW_TAG_interface_type
:
10818 case DW_TAG_structure_type
:
10819 case DW_TAG_union_type
:
10820 case DW_TAG_set_type
:
10821 case DW_TAG_enumeration_type
:
10822 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10823 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10826 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10827 really ever be static objects: otherwise, if you try
10828 to, say, break of a class's method and you're in a file
10829 which doesn't mention that class, it won't work unless
10830 the check for all static symbols in lookup_symbol_aux
10831 saves you. See the OtherFileClass tests in
10832 gdb.c++/namespace.exp. */
10836 list_to_add
= (cu
->list_in_scope
== &file_symbols
10837 && (cu
->language
== language_cplus
10838 || cu
->language
== language_java
)
10839 ? &global_symbols
: cu
->list_in_scope
);
10841 /* The semantics of C++ state that "struct foo {
10842 ... }" also defines a typedef for "foo". A Java
10843 class declaration also defines a typedef for the
10845 if (cu
->language
== language_cplus
10846 || cu
->language
== language_java
10847 || cu
->language
== language_ada
)
10849 /* The symbol's name is already allocated along
10850 with this objfile, so we don't need to
10851 duplicate it for the type. */
10852 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10853 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10858 case DW_TAG_typedef
:
10859 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10860 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10861 list_to_add
= cu
->list_in_scope
;
10863 case DW_TAG_base_type
:
10864 case DW_TAG_subrange_type
:
10865 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10866 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10867 list_to_add
= cu
->list_in_scope
;
10869 case DW_TAG_enumerator
:
10870 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10873 dwarf2_const_value (attr
, sym
, cu
);
10876 /* NOTE: carlton/2003-11-10: See comment above in the
10877 DW_TAG_class_type, etc. block. */
10879 list_to_add
= (cu
->list_in_scope
== &file_symbols
10880 && (cu
->language
== language_cplus
10881 || cu
->language
== language_java
)
10882 ? &global_symbols
: cu
->list_in_scope
);
10885 case DW_TAG_namespace
:
10886 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10887 list_to_add
= &global_symbols
;
10890 /* Not a tag we recognize. Hopefully we aren't processing
10891 trash data, but since we must specifically ignore things
10892 we don't recognize, there is nothing else we should do at
10894 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10895 dwarf_tag_name (die
->tag
));
10901 sym
->hash_next
= objfile
->template_symbols
;
10902 objfile
->template_symbols
= sym
;
10903 list_to_add
= NULL
;
10906 if (list_to_add
!= NULL
)
10907 add_symbol_to_list (sym
, list_to_add
);
10909 /* For the benefit of old versions of GCC, check for anonymous
10910 namespaces based on the demangled name. */
10911 if (!processing_has_namespace_info
10912 && cu
->language
== language_cplus
)
10913 cp_scan_for_anonymous_namespaces (sym
);
10918 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10920 static struct symbol
*
10921 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10923 return new_symbol_full (die
, type
, cu
, NULL
);
10926 /* Given an attr with a DW_FORM_dataN value in host byte order,
10927 zero-extend it as appropriate for the symbol's type. The DWARF
10928 standard (v4) is not entirely clear about the meaning of using
10929 DW_FORM_dataN for a constant with a signed type, where the type is
10930 wider than the data. The conclusion of a discussion on the DWARF
10931 list was that this is unspecified. We choose to always zero-extend
10932 because that is the interpretation long in use by GCC. */
10935 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10936 const char *name
, struct obstack
*obstack
,
10937 struct dwarf2_cu
*cu
, long *value
, int bits
)
10939 struct objfile
*objfile
= cu
->objfile
;
10940 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10941 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10942 LONGEST l
= DW_UNSND (attr
);
10944 if (bits
< sizeof (*value
) * 8)
10946 l
&= ((LONGEST
) 1 << bits
) - 1;
10949 else if (bits
== sizeof (*value
) * 8)
10953 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10954 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10961 /* Read a constant value from an attribute. Either set *VALUE, or if
10962 the value does not fit in *VALUE, set *BYTES - either already
10963 allocated on the objfile obstack, or newly allocated on OBSTACK,
10964 or, set *BATON, if we translated the constant to a location
10968 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10969 const char *name
, struct obstack
*obstack
,
10970 struct dwarf2_cu
*cu
,
10971 long *value
, gdb_byte
**bytes
,
10972 struct dwarf2_locexpr_baton
**baton
)
10974 struct objfile
*objfile
= cu
->objfile
;
10975 struct comp_unit_head
*cu_header
= &cu
->header
;
10976 struct dwarf_block
*blk
;
10977 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10978 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10984 switch (attr
->form
)
10990 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10991 dwarf2_const_value_length_mismatch_complaint (name
,
10992 cu_header
->addr_size
,
10993 TYPE_LENGTH (type
));
10994 /* Symbols of this form are reasonably rare, so we just
10995 piggyback on the existing location code rather than writing
10996 a new implementation of symbol_computed_ops. */
10997 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
10998 sizeof (struct dwarf2_locexpr_baton
));
10999 (*baton
)->per_cu
= cu
->per_cu
;
11000 gdb_assert ((*baton
)->per_cu
);
11002 (*baton
)->size
= 2 + cu_header
->addr_size
;
11003 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11004 (*baton
)->data
= data
;
11006 data
[0] = DW_OP_addr
;
11007 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11008 byte_order
, DW_ADDR (attr
));
11009 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11012 case DW_FORM_string
:
11014 /* DW_STRING is already allocated on the objfile obstack, point
11016 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11018 case DW_FORM_block1
:
11019 case DW_FORM_block2
:
11020 case DW_FORM_block4
:
11021 case DW_FORM_block
:
11022 case DW_FORM_exprloc
:
11023 blk
= DW_BLOCK (attr
);
11024 if (TYPE_LENGTH (type
) != blk
->size
)
11025 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11026 TYPE_LENGTH (type
));
11027 *bytes
= blk
->data
;
11030 /* The DW_AT_const_value attributes are supposed to carry the
11031 symbol's value "represented as it would be on the target
11032 architecture." By the time we get here, it's already been
11033 converted to host endianness, so we just need to sign- or
11034 zero-extend it as appropriate. */
11035 case DW_FORM_data1
:
11036 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
11038 case DW_FORM_data2
:
11039 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
11041 case DW_FORM_data4
:
11042 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
11044 case DW_FORM_data8
:
11045 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
11048 case DW_FORM_sdata
:
11049 *value
= DW_SND (attr
);
11052 case DW_FORM_udata
:
11053 *value
= DW_UNSND (attr
);
11057 complaint (&symfile_complaints
,
11058 _("unsupported const value attribute form: '%s'"),
11059 dwarf_form_name (attr
->form
));
11066 /* Copy constant value from an attribute to a symbol. */
11069 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11070 struct dwarf2_cu
*cu
)
11072 struct objfile
*objfile
= cu
->objfile
;
11073 struct comp_unit_head
*cu_header
= &cu
->header
;
11076 struct dwarf2_locexpr_baton
*baton
;
11078 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11079 SYMBOL_PRINT_NAME (sym
),
11080 &objfile
->objfile_obstack
, cu
,
11081 &value
, &bytes
, &baton
);
11085 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11086 SYMBOL_LOCATION_BATON (sym
) = baton
;
11087 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11089 else if (bytes
!= NULL
)
11091 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11092 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11096 SYMBOL_VALUE (sym
) = value
;
11097 SYMBOL_CLASS (sym
) = LOC_CONST
;
11101 /* Return the type of the die in question using its DW_AT_type attribute. */
11103 static struct type
*
11104 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11106 struct attribute
*type_attr
;
11108 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11111 /* A missing DW_AT_type represents a void type. */
11112 return objfile_type (cu
->objfile
)->builtin_void
;
11115 return lookup_die_type (die
, type_attr
, cu
);
11118 /* True iff CU's producer generates GNAT Ada auxiliary information
11119 that allows to find parallel types through that information instead
11120 of having to do expensive parallel lookups by type name. */
11123 need_gnat_info (struct dwarf2_cu
*cu
)
11125 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11126 of GNAT produces this auxiliary information, without any indication
11127 that it is produced. Part of enhancing the FSF version of GNAT
11128 to produce that information will be to put in place an indicator
11129 that we can use in order to determine whether the descriptive type
11130 info is available or not. One suggestion that has been made is
11131 to use a new attribute, attached to the CU die. For now, assume
11132 that the descriptive type info is not available. */
11136 /* Return the auxiliary type of the die in question using its
11137 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11138 attribute is not present. */
11140 static struct type
*
11141 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11143 struct attribute
*type_attr
;
11145 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11149 return lookup_die_type (die
, type_attr
, cu
);
11152 /* If DIE has a descriptive_type attribute, then set the TYPE's
11153 descriptive type accordingly. */
11156 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11157 struct dwarf2_cu
*cu
)
11159 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11161 if (descriptive_type
)
11163 ALLOCATE_GNAT_AUX_TYPE (type
);
11164 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11168 /* Return the containing type of the die in question using its
11169 DW_AT_containing_type attribute. */
11171 static struct type
*
11172 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11174 struct attribute
*type_attr
;
11176 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11178 error (_("Dwarf Error: Problem turning containing type into gdb type "
11179 "[in module %s]"), cu
->objfile
->name
);
11181 return lookup_die_type (die
, type_attr
, cu
);
11184 /* Look up the type of DIE in CU using its type attribute ATTR.
11185 If there is no type substitute an error marker. */
11187 static struct type
*
11188 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11189 struct dwarf2_cu
*cu
)
11191 struct type
*this_type
;
11193 /* First see if we have it cached. */
11195 if (is_ref_attr (attr
))
11197 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11199 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11201 else if (attr
->form
== DW_FORM_sig8
)
11203 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11204 struct dwarf2_cu
*sig_cu
;
11205 unsigned int offset
;
11207 /* sig_type will be NULL if the signatured type is missing from
11209 if (sig_type
== NULL
)
11210 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11211 "at 0x%x [in module %s]"),
11212 die
->offset
, cu
->objfile
->name
);
11214 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11215 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11216 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11220 dump_die_for_error (die
);
11221 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11222 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11225 /* If not cached we need to read it in. */
11227 if (this_type
== NULL
)
11229 struct die_info
*type_die
;
11230 struct dwarf2_cu
*type_cu
= cu
;
11232 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11233 /* If the type is cached, we should have found it above. */
11234 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11235 this_type
= read_type_die_1 (type_die
, type_cu
);
11238 /* If we still don't have a type use an error marker. */
11240 if (this_type
== NULL
)
11242 char *message
, *saved
;
11244 /* read_type_die already issued a complaint. */
11245 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11249 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11250 message
, strlen (message
));
11253 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11259 /* Return the type in DIE, CU.
11260 Returns NULL for invalid types.
11262 This first does a lookup in the appropriate type_hash table,
11263 and only reads the die in if necessary.
11265 NOTE: This can be called when reading in partial or full symbols. */
11267 static struct type
*
11268 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11270 struct type
*this_type
;
11272 this_type
= get_die_type (die
, cu
);
11276 return read_type_die_1 (die
, cu
);
11279 /* Read the type in DIE, CU.
11280 Returns NULL for invalid types. */
11282 static struct type
*
11283 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11285 struct type
*this_type
= NULL
;
11289 case DW_TAG_class_type
:
11290 case DW_TAG_interface_type
:
11291 case DW_TAG_structure_type
:
11292 case DW_TAG_union_type
:
11293 this_type
= read_structure_type (die
, cu
);
11295 case DW_TAG_enumeration_type
:
11296 this_type
= read_enumeration_type (die
, cu
);
11298 case DW_TAG_subprogram
:
11299 case DW_TAG_subroutine_type
:
11300 case DW_TAG_inlined_subroutine
:
11301 this_type
= read_subroutine_type (die
, cu
);
11303 case DW_TAG_array_type
:
11304 this_type
= read_array_type (die
, cu
);
11306 case DW_TAG_set_type
:
11307 this_type
= read_set_type (die
, cu
);
11309 case DW_TAG_pointer_type
:
11310 this_type
= read_tag_pointer_type (die
, cu
);
11312 case DW_TAG_ptr_to_member_type
:
11313 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11315 case DW_TAG_reference_type
:
11316 this_type
= read_tag_reference_type (die
, cu
);
11318 case DW_TAG_const_type
:
11319 this_type
= read_tag_const_type (die
, cu
);
11321 case DW_TAG_volatile_type
:
11322 this_type
= read_tag_volatile_type (die
, cu
);
11324 case DW_TAG_string_type
:
11325 this_type
= read_tag_string_type (die
, cu
);
11327 case DW_TAG_typedef
:
11328 this_type
= read_typedef (die
, cu
);
11330 case DW_TAG_subrange_type
:
11331 this_type
= read_subrange_type (die
, cu
);
11333 case DW_TAG_base_type
:
11334 this_type
= read_base_type (die
, cu
);
11336 case DW_TAG_unspecified_type
:
11337 this_type
= read_unspecified_type (die
, cu
);
11339 case DW_TAG_namespace
:
11340 this_type
= read_namespace_type (die
, cu
);
11342 case DW_TAG_module
:
11343 this_type
= read_module_type (die
, cu
);
11346 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11347 dwarf_tag_name (die
->tag
));
11354 /* See if we can figure out if the class lives in a namespace. We do
11355 this by looking for a member function; its demangled name will
11356 contain namespace info, if there is any.
11357 Return the computed name or NULL.
11358 Space for the result is allocated on the objfile's obstack.
11359 This is the full-die version of guess_partial_die_structure_name.
11360 In this case we know DIE has no useful parent. */
11363 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11365 struct die_info
*spec_die
;
11366 struct dwarf2_cu
*spec_cu
;
11367 struct die_info
*child
;
11370 spec_die
= die_specification (die
, &spec_cu
);
11371 if (spec_die
!= NULL
)
11377 for (child
= die
->child
;
11379 child
= child
->sibling
)
11381 if (child
->tag
== DW_TAG_subprogram
)
11383 struct attribute
*attr
;
11385 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11387 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11391 = language_class_name_from_physname (cu
->language_defn
,
11395 if (actual_name
!= NULL
)
11397 char *die_name
= dwarf2_name (die
, cu
);
11399 if (die_name
!= NULL
11400 && strcmp (die_name
, actual_name
) != 0)
11402 /* Strip off the class name from the full name.
11403 We want the prefix. */
11404 int die_name_len
= strlen (die_name
);
11405 int actual_name_len
= strlen (actual_name
);
11407 /* Test for '::' as a sanity check. */
11408 if (actual_name_len
> die_name_len
+ 2
11409 && actual_name
[actual_name_len
- die_name_len
- 1] == ':')
11411 obsavestring (actual_name
,
11412 actual_name_len
- die_name_len
- 2,
11413 &cu
->objfile
->objfile_obstack
);
11416 xfree (actual_name
);
11425 /* Return the name of the namespace/class that DIE is defined within,
11426 or "" if we can't tell. The caller should not xfree the result.
11428 For example, if we're within the method foo() in the following
11438 then determine_prefix on foo's die will return "N::C". */
11441 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11443 struct die_info
*parent
, *spec_die
;
11444 struct dwarf2_cu
*spec_cu
;
11445 struct type
*parent_type
;
11447 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11448 && cu
->language
!= language_fortran
)
11451 /* We have to be careful in the presence of DW_AT_specification.
11452 For example, with GCC 3.4, given the code
11456 // Definition of N::foo.
11460 then we'll have a tree of DIEs like this:
11462 1: DW_TAG_compile_unit
11463 2: DW_TAG_namespace // N
11464 3: DW_TAG_subprogram // declaration of N::foo
11465 4: DW_TAG_subprogram // definition of N::foo
11466 DW_AT_specification // refers to die #3
11468 Thus, when processing die #4, we have to pretend that we're in
11469 the context of its DW_AT_specification, namely the contex of die
11472 spec_die
= die_specification (die
, &spec_cu
);
11473 if (spec_die
== NULL
)
11474 parent
= die
->parent
;
11477 parent
= spec_die
->parent
;
11481 if (parent
== NULL
)
11483 else if (parent
->building_fullname
)
11486 const char *parent_name
;
11488 /* It has been seen on RealView 2.2 built binaries,
11489 DW_TAG_template_type_param types actually _defined_ as
11490 children of the parent class:
11493 template class <class Enum> Class{};
11494 Class<enum E> class_e;
11496 1: DW_TAG_class_type (Class)
11497 2: DW_TAG_enumeration_type (E)
11498 3: DW_TAG_enumerator (enum1:0)
11499 3: DW_TAG_enumerator (enum2:1)
11501 2: DW_TAG_template_type_param
11502 DW_AT_type DW_FORM_ref_udata (E)
11504 Besides being broken debug info, it can put GDB into an
11505 infinite loop. Consider:
11507 When we're building the full name for Class<E>, we'll start
11508 at Class, and go look over its template type parameters,
11509 finding E. We'll then try to build the full name of E, and
11510 reach here. We're now trying to build the full name of E,
11511 and look over the parent DIE for containing scope. In the
11512 broken case, if we followed the parent DIE of E, we'd again
11513 find Class, and once again go look at its template type
11514 arguments, etc., etc. Simply don't consider such parent die
11515 as source-level parent of this die (it can't be, the language
11516 doesn't allow it), and break the loop here. */
11517 name
= dwarf2_name (die
, cu
);
11518 parent_name
= dwarf2_name (parent
, cu
);
11519 complaint (&symfile_complaints
,
11520 _("template param type '%s' defined within parent '%s'"),
11521 name
? name
: "<unknown>",
11522 parent_name
? parent_name
: "<unknown>");
11526 switch (parent
->tag
)
11528 case DW_TAG_namespace
:
11529 parent_type
= read_type_die (parent
, cu
);
11530 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11531 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11532 Work around this problem here. */
11533 if (cu
->language
== language_cplus
11534 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11536 /* We give a name to even anonymous namespaces. */
11537 return TYPE_TAG_NAME (parent_type
);
11538 case DW_TAG_class_type
:
11539 case DW_TAG_interface_type
:
11540 case DW_TAG_structure_type
:
11541 case DW_TAG_union_type
:
11542 case DW_TAG_module
:
11543 parent_type
= read_type_die (parent
, cu
);
11544 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11545 return TYPE_TAG_NAME (parent_type
);
11547 /* An anonymous structure is only allowed non-static data
11548 members; no typedefs, no member functions, et cetera.
11549 So it does not need a prefix. */
11551 case DW_TAG_compile_unit
:
11552 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11553 if (cu
->language
== language_cplus
11554 && dwarf2_per_objfile
->types
.asection
!= NULL
11555 && die
->child
!= NULL
11556 && (die
->tag
== DW_TAG_class_type
11557 || die
->tag
== DW_TAG_structure_type
11558 || die
->tag
== DW_TAG_union_type
))
11560 char *name
= guess_full_die_structure_name (die
, cu
);
11566 return determine_prefix (parent
, cu
);
11570 /* Return a newly-allocated string formed by concatenating PREFIX and
11571 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11572 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11573 perform an obconcat, otherwise allocate storage for the result. The CU argument
11574 is used to determine the language and hence, the appropriate separator. */
11576 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11579 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11580 int physname
, struct dwarf2_cu
*cu
)
11582 const char *lead
= "";
11585 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11587 else if (cu
->language
== language_java
)
11589 else if (cu
->language
== language_fortran
&& physname
)
11591 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11592 DW_AT_MIPS_linkage_name is preferred and used instead. */
11600 if (prefix
== NULL
)
11602 if (suffix
== NULL
)
11607 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11609 strcpy (retval
, lead
);
11610 strcat (retval
, prefix
);
11611 strcat (retval
, sep
);
11612 strcat (retval
, suffix
);
11617 /* We have an obstack. */
11618 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11622 /* Return sibling of die, NULL if no sibling. */
11624 static struct die_info
*
11625 sibling_die (struct die_info
*die
)
11627 return die
->sibling
;
11630 /* Get name of a die, return NULL if not found. */
11633 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11634 struct obstack
*obstack
)
11636 if (name
&& cu
->language
== language_cplus
)
11638 char *canon_name
= cp_canonicalize_string (name
);
11640 if (canon_name
!= NULL
)
11642 if (strcmp (canon_name
, name
) != 0)
11643 name
= obsavestring (canon_name
, strlen (canon_name
),
11645 xfree (canon_name
);
11652 /* Get name of a die, return NULL if not found. */
11655 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11657 struct attribute
*attr
;
11659 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11660 if (!attr
|| !DW_STRING (attr
))
11665 case DW_TAG_compile_unit
:
11666 /* Compilation units have a DW_AT_name that is a filename, not
11667 a source language identifier. */
11668 case DW_TAG_enumeration_type
:
11669 case DW_TAG_enumerator
:
11670 /* These tags always have simple identifiers already; no need
11671 to canonicalize them. */
11672 return DW_STRING (attr
);
11674 case DW_TAG_subprogram
:
11675 /* Java constructors will all be named "<init>", so return
11676 the class name when we see this special case. */
11677 if (cu
->language
== language_java
11678 && DW_STRING (attr
) != NULL
11679 && strcmp (DW_STRING (attr
), "<init>") == 0)
11681 struct dwarf2_cu
*spec_cu
= cu
;
11682 struct die_info
*spec_die
;
11684 /* GCJ will output '<init>' for Java constructor names.
11685 For this special case, return the name of the parent class. */
11687 /* GCJ may output suprogram DIEs with AT_specification set.
11688 If so, use the name of the specified DIE. */
11689 spec_die
= die_specification (die
, &spec_cu
);
11690 if (spec_die
!= NULL
)
11691 return dwarf2_name (spec_die
, spec_cu
);
11696 if (die
->tag
== DW_TAG_class_type
)
11697 return dwarf2_name (die
, cu
);
11699 while (die
->tag
!= DW_TAG_compile_unit
);
11703 case DW_TAG_class_type
:
11704 case DW_TAG_interface_type
:
11705 case DW_TAG_structure_type
:
11706 case DW_TAG_union_type
:
11707 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11708 structures or unions. These were of the form "._%d" in GCC 4.1,
11709 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11710 and GCC 4.4. We work around this problem by ignoring these. */
11711 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11712 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11720 if (!DW_STRING_IS_CANONICAL (attr
))
11723 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11724 &cu
->objfile
->objfile_obstack
);
11725 DW_STRING_IS_CANONICAL (attr
) = 1;
11727 return DW_STRING (attr
);
11730 /* Return the die that this die in an extension of, or NULL if there
11731 is none. *EXT_CU is the CU containing DIE on input, and the CU
11732 containing the return value on output. */
11734 static struct die_info
*
11735 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11737 struct attribute
*attr
;
11739 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11743 return follow_die_ref (die
, attr
, ext_cu
);
11746 /* Convert a DIE tag into its string name. */
11749 dwarf_tag_name (unsigned tag
)
11753 case DW_TAG_padding
:
11754 return "DW_TAG_padding";
11755 case DW_TAG_array_type
:
11756 return "DW_TAG_array_type";
11757 case DW_TAG_class_type
:
11758 return "DW_TAG_class_type";
11759 case DW_TAG_entry_point
:
11760 return "DW_TAG_entry_point";
11761 case DW_TAG_enumeration_type
:
11762 return "DW_TAG_enumeration_type";
11763 case DW_TAG_formal_parameter
:
11764 return "DW_TAG_formal_parameter";
11765 case DW_TAG_imported_declaration
:
11766 return "DW_TAG_imported_declaration";
11768 return "DW_TAG_label";
11769 case DW_TAG_lexical_block
:
11770 return "DW_TAG_lexical_block";
11771 case DW_TAG_member
:
11772 return "DW_TAG_member";
11773 case DW_TAG_pointer_type
:
11774 return "DW_TAG_pointer_type";
11775 case DW_TAG_reference_type
:
11776 return "DW_TAG_reference_type";
11777 case DW_TAG_compile_unit
:
11778 return "DW_TAG_compile_unit";
11779 case DW_TAG_string_type
:
11780 return "DW_TAG_string_type";
11781 case DW_TAG_structure_type
:
11782 return "DW_TAG_structure_type";
11783 case DW_TAG_subroutine_type
:
11784 return "DW_TAG_subroutine_type";
11785 case DW_TAG_typedef
:
11786 return "DW_TAG_typedef";
11787 case DW_TAG_union_type
:
11788 return "DW_TAG_union_type";
11789 case DW_TAG_unspecified_parameters
:
11790 return "DW_TAG_unspecified_parameters";
11791 case DW_TAG_variant
:
11792 return "DW_TAG_variant";
11793 case DW_TAG_common_block
:
11794 return "DW_TAG_common_block";
11795 case DW_TAG_common_inclusion
:
11796 return "DW_TAG_common_inclusion";
11797 case DW_TAG_inheritance
:
11798 return "DW_TAG_inheritance";
11799 case DW_TAG_inlined_subroutine
:
11800 return "DW_TAG_inlined_subroutine";
11801 case DW_TAG_module
:
11802 return "DW_TAG_module";
11803 case DW_TAG_ptr_to_member_type
:
11804 return "DW_TAG_ptr_to_member_type";
11805 case DW_TAG_set_type
:
11806 return "DW_TAG_set_type";
11807 case DW_TAG_subrange_type
:
11808 return "DW_TAG_subrange_type";
11809 case DW_TAG_with_stmt
:
11810 return "DW_TAG_with_stmt";
11811 case DW_TAG_access_declaration
:
11812 return "DW_TAG_access_declaration";
11813 case DW_TAG_base_type
:
11814 return "DW_TAG_base_type";
11815 case DW_TAG_catch_block
:
11816 return "DW_TAG_catch_block";
11817 case DW_TAG_const_type
:
11818 return "DW_TAG_const_type";
11819 case DW_TAG_constant
:
11820 return "DW_TAG_constant";
11821 case DW_TAG_enumerator
:
11822 return "DW_TAG_enumerator";
11823 case DW_TAG_file_type
:
11824 return "DW_TAG_file_type";
11825 case DW_TAG_friend
:
11826 return "DW_TAG_friend";
11827 case DW_TAG_namelist
:
11828 return "DW_TAG_namelist";
11829 case DW_TAG_namelist_item
:
11830 return "DW_TAG_namelist_item";
11831 case DW_TAG_packed_type
:
11832 return "DW_TAG_packed_type";
11833 case DW_TAG_subprogram
:
11834 return "DW_TAG_subprogram";
11835 case DW_TAG_template_type_param
:
11836 return "DW_TAG_template_type_param";
11837 case DW_TAG_template_value_param
:
11838 return "DW_TAG_template_value_param";
11839 case DW_TAG_thrown_type
:
11840 return "DW_TAG_thrown_type";
11841 case DW_TAG_try_block
:
11842 return "DW_TAG_try_block";
11843 case DW_TAG_variant_part
:
11844 return "DW_TAG_variant_part";
11845 case DW_TAG_variable
:
11846 return "DW_TAG_variable";
11847 case DW_TAG_volatile_type
:
11848 return "DW_TAG_volatile_type";
11849 case DW_TAG_dwarf_procedure
:
11850 return "DW_TAG_dwarf_procedure";
11851 case DW_TAG_restrict_type
:
11852 return "DW_TAG_restrict_type";
11853 case DW_TAG_interface_type
:
11854 return "DW_TAG_interface_type";
11855 case DW_TAG_namespace
:
11856 return "DW_TAG_namespace";
11857 case DW_TAG_imported_module
:
11858 return "DW_TAG_imported_module";
11859 case DW_TAG_unspecified_type
:
11860 return "DW_TAG_unspecified_type";
11861 case DW_TAG_partial_unit
:
11862 return "DW_TAG_partial_unit";
11863 case DW_TAG_imported_unit
:
11864 return "DW_TAG_imported_unit";
11865 case DW_TAG_condition
:
11866 return "DW_TAG_condition";
11867 case DW_TAG_shared_type
:
11868 return "DW_TAG_shared_type";
11869 case DW_TAG_type_unit
:
11870 return "DW_TAG_type_unit";
11871 case DW_TAG_MIPS_loop
:
11872 return "DW_TAG_MIPS_loop";
11873 case DW_TAG_HP_array_descriptor
:
11874 return "DW_TAG_HP_array_descriptor";
11875 case DW_TAG_format_label
:
11876 return "DW_TAG_format_label";
11877 case DW_TAG_function_template
:
11878 return "DW_TAG_function_template";
11879 case DW_TAG_class_template
:
11880 return "DW_TAG_class_template";
11881 case DW_TAG_GNU_BINCL
:
11882 return "DW_TAG_GNU_BINCL";
11883 case DW_TAG_GNU_EINCL
:
11884 return "DW_TAG_GNU_EINCL";
11885 case DW_TAG_upc_shared_type
:
11886 return "DW_TAG_upc_shared_type";
11887 case DW_TAG_upc_strict_type
:
11888 return "DW_TAG_upc_strict_type";
11889 case DW_TAG_upc_relaxed_type
:
11890 return "DW_TAG_upc_relaxed_type";
11891 case DW_TAG_PGI_kanji_type
:
11892 return "DW_TAG_PGI_kanji_type";
11893 case DW_TAG_PGI_interface_block
:
11894 return "DW_TAG_PGI_interface_block";
11896 return "DW_TAG_<unknown>";
11900 /* Convert a DWARF attribute code into its string name. */
11903 dwarf_attr_name (unsigned attr
)
11907 case DW_AT_sibling
:
11908 return "DW_AT_sibling";
11909 case DW_AT_location
:
11910 return "DW_AT_location";
11912 return "DW_AT_name";
11913 case DW_AT_ordering
:
11914 return "DW_AT_ordering";
11915 case DW_AT_subscr_data
:
11916 return "DW_AT_subscr_data";
11917 case DW_AT_byte_size
:
11918 return "DW_AT_byte_size";
11919 case DW_AT_bit_offset
:
11920 return "DW_AT_bit_offset";
11921 case DW_AT_bit_size
:
11922 return "DW_AT_bit_size";
11923 case DW_AT_element_list
:
11924 return "DW_AT_element_list";
11925 case DW_AT_stmt_list
:
11926 return "DW_AT_stmt_list";
11928 return "DW_AT_low_pc";
11929 case DW_AT_high_pc
:
11930 return "DW_AT_high_pc";
11931 case DW_AT_language
:
11932 return "DW_AT_language";
11934 return "DW_AT_member";
11936 return "DW_AT_discr";
11937 case DW_AT_discr_value
:
11938 return "DW_AT_discr_value";
11939 case DW_AT_visibility
:
11940 return "DW_AT_visibility";
11942 return "DW_AT_import";
11943 case DW_AT_string_length
:
11944 return "DW_AT_string_length";
11945 case DW_AT_common_reference
:
11946 return "DW_AT_common_reference";
11947 case DW_AT_comp_dir
:
11948 return "DW_AT_comp_dir";
11949 case DW_AT_const_value
:
11950 return "DW_AT_const_value";
11951 case DW_AT_containing_type
:
11952 return "DW_AT_containing_type";
11953 case DW_AT_default_value
:
11954 return "DW_AT_default_value";
11956 return "DW_AT_inline";
11957 case DW_AT_is_optional
:
11958 return "DW_AT_is_optional";
11959 case DW_AT_lower_bound
:
11960 return "DW_AT_lower_bound";
11961 case DW_AT_producer
:
11962 return "DW_AT_producer";
11963 case DW_AT_prototyped
:
11964 return "DW_AT_prototyped";
11965 case DW_AT_return_addr
:
11966 return "DW_AT_return_addr";
11967 case DW_AT_start_scope
:
11968 return "DW_AT_start_scope";
11969 case DW_AT_bit_stride
:
11970 return "DW_AT_bit_stride";
11971 case DW_AT_upper_bound
:
11972 return "DW_AT_upper_bound";
11973 case DW_AT_abstract_origin
:
11974 return "DW_AT_abstract_origin";
11975 case DW_AT_accessibility
:
11976 return "DW_AT_accessibility";
11977 case DW_AT_address_class
:
11978 return "DW_AT_address_class";
11979 case DW_AT_artificial
:
11980 return "DW_AT_artificial";
11981 case DW_AT_base_types
:
11982 return "DW_AT_base_types";
11983 case DW_AT_calling_convention
:
11984 return "DW_AT_calling_convention";
11986 return "DW_AT_count";
11987 case DW_AT_data_member_location
:
11988 return "DW_AT_data_member_location";
11989 case DW_AT_decl_column
:
11990 return "DW_AT_decl_column";
11991 case DW_AT_decl_file
:
11992 return "DW_AT_decl_file";
11993 case DW_AT_decl_line
:
11994 return "DW_AT_decl_line";
11995 case DW_AT_declaration
:
11996 return "DW_AT_declaration";
11997 case DW_AT_discr_list
:
11998 return "DW_AT_discr_list";
11999 case DW_AT_encoding
:
12000 return "DW_AT_encoding";
12001 case DW_AT_external
:
12002 return "DW_AT_external";
12003 case DW_AT_frame_base
:
12004 return "DW_AT_frame_base";
12006 return "DW_AT_friend";
12007 case DW_AT_identifier_case
:
12008 return "DW_AT_identifier_case";
12009 case DW_AT_macro_info
:
12010 return "DW_AT_macro_info";
12011 case DW_AT_namelist_items
:
12012 return "DW_AT_namelist_items";
12013 case DW_AT_priority
:
12014 return "DW_AT_priority";
12015 case DW_AT_segment
:
12016 return "DW_AT_segment";
12017 case DW_AT_specification
:
12018 return "DW_AT_specification";
12019 case DW_AT_static_link
:
12020 return "DW_AT_static_link";
12022 return "DW_AT_type";
12023 case DW_AT_use_location
:
12024 return "DW_AT_use_location";
12025 case DW_AT_variable_parameter
:
12026 return "DW_AT_variable_parameter";
12027 case DW_AT_virtuality
:
12028 return "DW_AT_virtuality";
12029 case DW_AT_vtable_elem_location
:
12030 return "DW_AT_vtable_elem_location";
12031 /* DWARF 3 values. */
12032 case DW_AT_allocated
:
12033 return "DW_AT_allocated";
12034 case DW_AT_associated
:
12035 return "DW_AT_associated";
12036 case DW_AT_data_location
:
12037 return "DW_AT_data_location";
12038 case DW_AT_byte_stride
:
12039 return "DW_AT_byte_stride";
12040 case DW_AT_entry_pc
:
12041 return "DW_AT_entry_pc";
12042 case DW_AT_use_UTF8
:
12043 return "DW_AT_use_UTF8";
12044 case DW_AT_extension
:
12045 return "DW_AT_extension";
12047 return "DW_AT_ranges";
12048 case DW_AT_trampoline
:
12049 return "DW_AT_trampoline";
12050 case DW_AT_call_column
:
12051 return "DW_AT_call_column";
12052 case DW_AT_call_file
:
12053 return "DW_AT_call_file";
12054 case DW_AT_call_line
:
12055 return "DW_AT_call_line";
12056 case DW_AT_description
:
12057 return "DW_AT_description";
12058 case DW_AT_binary_scale
:
12059 return "DW_AT_binary_scale";
12060 case DW_AT_decimal_scale
:
12061 return "DW_AT_decimal_scale";
12063 return "DW_AT_small";
12064 case DW_AT_decimal_sign
:
12065 return "DW_AT_decimal_sign";
12066 case DW_AT_digit_count
:
12067 return "DW_AT_digit_count";
12068 case DW_AT_picture_string
:
12069 return "DW_AT_picture_string";
12070 case DW_AT_mutable
:
12071 return "DW_AT_mutable";
12072 case DW_AT_threads_scaled
:
12073 return "DW_AT_threads_scaled";
12074 case DW_AT_explicit
:
12075 return "DW_AT_explicit";
12076 case DW_AT_object_pointer
:
12077 return "DW_AT_object_pointer";
12078 case DW_AT_endianity
:
12079 return "DW_AT_endianity";
12080 case DW_AT_elemental
:
12081 return "DW_AT_elemental";
12083 return "DW_AT_pure";
12084 case DW_AT_recursive
:
12085 return "DW_AT_recursive";
12086 /* DWARF 4 values. */
12087 case DW_AT_signature
:
12088 return "DW_AT_signature";
12089 case DW_AT_linkage_name
:
12090 return "DW_AT_linkage_name";
12091 /* SGI/MIPS extensions. */
12092 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12093 case DW_AT_MIPS_fde
:
12094 return "DW_AT_MIPS_fde";
12096 case DW_AT_MIPS_loop_begin
:
12097 return "DW_AT_MIPS_loop_begin";
12098 case DW_AT_MIPS_tail_loop_begin
:
12099 return "DW_AT_MIPS_tail_loop_begin";
12100 case DW_AT_MIPS_epilog_begin
:
12101 return "DW_AT_MIPS_epilog_begin";
12102 case DW_AT_MIPS_loop_unroll_factor
:
12103 return "DW_AT_MIPS_loop_unroll_factor";
12104 case DW_AT_MIPS_software_pipeline_depth
:
12105 return "DW_AT_MIPS_software_pipeline_depth";
12106 case DW_AT_MIPS_linkage_name
:
12107 return "DW_AT_MIPS_linkage_name";
12108 case DW_AT_MIPS_stride
:
12109 return "DW_AT_MIPS_stride";
12110 case DW_AT_MIPS_abstract_name
:
12111 return "DW_AT_MIPS_abstract_name";
12112 case DW_AT_MIPS_clone_origin
:
12113 return "DW_AT_MIPS_clone_origin";
12114 case DW_AT_MIPS_has_inlines
:
12115 return "DW_AT_MIPS_has_inlines";
12116 /* HP extensions. */
12117 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12118 case DW_AT_HP_block_index
:
12119 return "DW_AT_HP_block_index";
12121 case DW_AT_HP_unmodifiable
:
12122 return "DW_AT_HP_unmodifiable";
12123 case DW_AT_HP_actuals_stmt_list
:
12124 return "DW_AT_HP_actuals_stmt_list";
12125 case DW_AT_HP_proc_per_section
:
12126 return "DW_AT_HP_proc_per_section";
12127 case DW_AT_HP_raw_data_ptr
:
12128 return "DW_AT_HP_raw_data_ptr";
12129 case DW_AT_HP_pass_by_reference
:
12130 return "DW_AT_HP_pass_by_reference";
12131 case DW_AT_HP_opt_level
:
12132 return "DW_AT_HP_opt_level";
12133 case DW_AT_HP_prof_version_id
:
12134 return "DW_AT_HP_prof_version_id";
12135 case DW_AT_HP_opt_flags
:
12136 return "DW_AT_HP_opt_flags";
12137 case DW_AT_HP_cold_region_low_pc
:
12138 return "DW_AT_HP_cold_region_low_pc";
12139 case DW_AT_HP_cold_region_high_pc
:
12140 return "DW_AT_HP_cold_region_high_pc";
12141 case DW_AT_HP_all_variables_modifiable
:
12142 return "DW_AT_HP_all_variables_modifiable";
12143 case DW_AT_HP_linkage_name
:
12144 return "DW_AT_HP_linkage_name";
12145 case DW_AT_HP_prof_flags
:
12146 return "DW_AT_HP_prof_flags";
12147 /* GNU extensions. */
12148 case DW_AT_sf_names
:
12149 return "DW_AT_sf_names";
12150 case DW_AT_src_info
:
12151 return "DW_AT_src_info";
12152 case DW_AT_mac_info
:
12153 return "DW_AT_mac_info";
12154 case DW_AT_src_coords
:
12155 return "DW_AT_src_coords";
12156 case DW_AT_body_begin
:
12157 return "DW_AT_body_begin";
12158 case DW_AT_body_end
:
12159 return "DW_AT_body_end";
12160 case DW_AT_GNU_vector
:
12161 return "DW_AT_GNU_vector";
12162 case DW_AT_GNU_odr_signature
:
12163 return "DW_AT_GNU_odr_signature";
12164 /* VMS extensions. */
12165 case DW_AT_VMS_rtnbeg_pd_address
:
12166 return "DW_AT_VMS_rtnbeg_pd_address";
12167 /* UPC extension. */
12168 case DW_AT_upc_threads_scaled
:
12169 return "DW_AT_upc_threads_scaled";
12170 /* PGI (STMicroelectronics) extensions. */
12171 case DW_AT_PGI_lbase
:
12172 return "DW_AT_PGI_lbase";
12173 case DW_AT_PGI_soffset
:
12174 return "DW_AT_PGI_soffset";
12175 case DW_AT_PGI_lstride
:
12176 return "DW_AT_PGI_lstride";
12178 return "DW_AT_<unknown>";
12182 /* Convert a DWARF value form code into its string name. */
12185 dwarf_form_name (unsigned form
)
12190 return "DW_FORM_addr";
12191 case DW_FORM_block2
:
12192 return "DW_FORM_block2";
12193 case DW_FORM_block4
:
12194 return "DW_FORM_block4";
12195 case DW_FORM_data2
:
12196 return "DW_FORM_data2";
12197 case DW_FORM_data4
:
12198 return "DW_FORM_data4";
12199 case DW_FORM_data8
:
12200 return "DW_FORM_data8";
12201 case DW_FORM_string
:
12202 return "DW_FORM_string";
12203 case DW_FORM_block
:
12204 return "DW_FORM_block";
12205 case DW_FORM_block1
:
12206 return "DW_FORM_block1";
12207 case DW_FORM_data1
:
12208 return "DW_FORM_data1";
12210 return "DW_FORM_flag";
12211 case DW_FORM_sdata
:
12212 return "DW_FORM_sdata";
12214 return "DW_FORM_strp";
12215 case DW_FORM_udata
:
12216 return "DW_FORM_udata";
12217 case DW_FORM_ref_addr
:
12218 return "DW_FORM_ref_addr";
12220 return "DW_FORM_ref1";
12222 return "DW_FORM_ref2";
12224 return "DW_FORM_ref4";
12226 return "DW_FORM_ref8";
12227 case DW_FORM_ref_udata
:
12228 return "DW_FORM_ref_udata";
12229 case DW_FORM_indirect
:
12230 return "DW_FORM_indirect";
12231 case DW_FORM_sec_offset
:
12232 return "DW_FORM_sec_offset";
12233 case DW_FORM_exprloc
:
12234 return "DW_FORM_exprloc";
12235 case DW_FORM_flag_present
:
12236 return "DW_FORM_flag_present";
12238 return "DW_FORM_sig8";
12240 return "DW_FORM_<unknown>";
12244 /* Convert a DWARF stack opcode into its string name. */
12247 dwarf_stack_op_name (unsigned op
, int def
)
12252 return "DW_OP_addr";
12254 return "DW_OP_deref";
12255 case DW_OP_const1u
:
12256 return "DW_OP_const1u";
12257 case DW_OP_const1s
:
12258 return "DW_OP_const1s";
12259 case DW_OP_const2u
:
12260 return "DW_OP_const2u";
12261 case DW_OP_const2s
:
12262 return "DW_OP_const2s";
12263 case DW_OP_const4u
:
12264 return "DW_OP_const4u";
12265 case DW_OP_const4s
:
12266 return "DW_OP_const4s";
12267 case DW_OP_const8u
:
12268 return "DW_OP_const8u";
12269 case DW_OP_const8s
:
12270 return "DW_OP_const8s";
12272 return "DW_OP_constu";
12274 return "DW_OP_consts";
12276 return "DW_OP_dup";
12278 return "DW_OP_drop";
12280 return "DW_OP_over";
12282 return "DW_OP_pick";
12284 return "DW_OP_swap";
12286 return "DW_OP_rot";
12288 return "DW_OP_xderef";
12290 return "DW_OP_abs";
12292 return "DW_OP_and";
12294 return "DW_OP_div";
12296 return "DW_OP_minus";
12298 return "DW_OP_mod";
12300 return "DW_OP_mul";
12302 return "DW_OP_neg";
12304 return "DW_OP_not";
12308 return "DW_OP_plus";
12309 case DW_OP_plus_uconst
:
12310 return "DW_OP_plus_uconst";
12312 return "DW_OP_shl";
12314 return "DW_OP_shr";
12316 return "DW_OP_shra";
12318 return "DW_OP_xor";
12320 return "DW_OP_bra";
12334 return "DW_OP_skip";
12336 return "DW_OP_lit0";
12338 return "DW_OP_lit1";
12340 return "DW_OP_lit2";
12342 return "DW_OP_lit3";
12344 return "DW_OP_lit4";
12346 return "DW_OP_lit5";
12348 return "DW_OP_lit6";
12350 return "DW_OP_lit7";
12352 return "DW_OP_lit8";
12354 return "DW_OP_lit9";
12356 return "DW_OP_lit10";
12358 return "DW_OP_lit11";
12360 return "DW_OP_lit12";
12362 return "DW_OP_lit13";
12364 return "DW_OP_lit14";
12366 return "DW_OP_lit15";
12368 return "DW_OP_lit16";
12370 return "DW_OP_lit17";
12372 return "DW_OP_lit18";
12374 return "DW_OP_lit19";
12376 return "DW_OP_lit20";
12378 return "DW_OP_lit21";
12380 return "DW_OP_lit22";
12382 return "DW_OP_lit23";
12384 return "DW_OP_lit24";
12386 return "DW_OP_lit25";
12388 return "DW_OP_lit26";
12390 return "DW_OP_lit27";
12392 return "DW_OP_lit28";
12394 return "DW_OP_lit29";
12396 return "DW_OP_lit30";
12398 return "DW_OP_lit31";
12400 return "DW_OP_reg0";
12402 return "DW_OP_reg1";
12404 return "DW_OP_reg2";
12406 return "DW_OP_reg3";
12408 return "DW_OP_reg4";
12410 return "DW_OP_reg5";
12412 return "DW_OP_reg6";
12414 return "DW_OP_reg7";
12416 return "DW_OP_reg8";
12418 return "DW_OP_reg9";
12420 return "DW_OP_reg10";
12422 return "DW_OP_reg11";
12424 return "DW_OP_reg12";
12426 return "DW_OP_reg13";
12428 return "DW_OP_reg14";
12430 return "DW_OP_reg15";
12432 return "DW_OP_reg16";
12434 return "DW_OP_reg17";
12436 return "DW_OP_reg18";
12438 return "DW_OP_reg19";
12440 return "DW_OP_reg20";
12442 return "DW_OP_reg21";
12444 return "DW_OP_reg22";
12446 return "DW_OP_reg23";
12448 return "DW_OP_reg24";
12450 return "DW_OP_reg25";
12452 return "DW_OP_reg26";
12454 return "DW_OP_reg27";
12456 return "DW_OP_reg28";
12458 return "DW_OP_reg29";
12460 return "DW_OP_reg30";
12462 return "DW_OP_reg31";
12464 return "DW_OP_breg0";
12466 return "DW_OP_breg1";
12468 return "DW_OP_breg2";
12470 return "DW_OP_breg3";
12472 return "DW_OP_breg4";
12474 return "DW_OP_breg5";
12476 return "DW_OP_breg6";
12478 return "DW_OP_breg7";
12480 return "DW_OP_breg8";
12482 return "DW_OP_breg9";
12484 return "DW_OP_breg10";
12486 return "DW_OP_breg11";
12488 return "DW_OP_breg12";
12490 return "DW_OP_breg13";
12492 return "DW_OP_breg14";
12494 return "DW_OP_breg15";
12496 return "DW_OP_breg16";
12498 return "DW_OP_breg17";
12500 return "DW_OP_breg18";
12502 return "DW_OP_breg19";
12504 return "DW_OP_breg20";
12506 return "DW_OP_breg21";
12508 return "DW_OP_breg22";
12510 return "DW_OP_breg23";
12512 return "DW_OP_breg24";
12514 return "DW_OP_breg25";
12516 return "DW_OP_breg26";
12518 return "DW_OP_breg27";
12520 return "DW_OP_breg28";
12522 return "DW_OP_breg29";
12524 return "DW_OP_breg30";
12526 return "DW_OP_breg31";
12528 return "DW_OP_regx";
12530 return "DW_OP_fbreg";
12532 return "DW_OP_bregx";
12534 return "DW_OP_piece";
12535 case DW_OP_deref_size
:
12536 return "DW_OP_deref_size";
12537 case DW_OP_xderef_size
:
12538 return "DW_OP_xderef_size";
12540 return "DW_OP_nop";
12541 /* DWARF 3 extensions. */
12542 case DW_OP_push_object_address
:
12543 return "DW_OP_push_object_address";
12545 return "DW_OP_call2";
12547 return "DW_OP_call4";
12548 case DW_OP_call_ref
:
12549 return "DW_OP_call_ref";
12550 case DW_OP_form_tls_address
:
12551 return "DW_OP_form_tls_address";
12552 case DW_OP_call_frame_cfa
:
12553 return "DW_OP_call_frame_cfa";
12554 case DW_OP_bit_piece
:
12555 return "DW_OP_bit_piece";
12556 /* DWARF 4 extensions. */
12557 case DW_OP_implicit_value
:
12558 return "DW_OP_implicit_value";
12559 case DW_OP_stack_value
:
12560 return "DW_OP_stack_value";
12561 /* GNU extensions. */
12562 case DW_OP_GNU_push_tls_address
:
12563 return "DW_OP_GNU_push_tls_address";
12564 case DW_OP_GNU_uninit
:
12565 return "DW_OP_GNU_uninit";
12567 return def
? "OP_<unknown>" : NULL
;
12572 dwarf_bool_name (unsigned mybool
)
12580 /* Convert a DWARF type code into its string name. */
12583 dwarf_type_encoding_name (unsigned enc
)
12588 return "DW_ATE_void";
12589 case DW_ATE_address
:
12590 return "DW_ATE_address";
12591 case DW_ATE_boolean
:
12592 return "DW_ATE_boolean";
12593 case DW_ATE_complex_float
:
12594 return "DW_ATE_complex_float";
12596 return "DW_ATE_float";
12597 case DW_ATE_signed
:
12598 return "DW_ATE_signed";
12599 case DW_ATE_signed_char
:
12600 return "DW_ATE_signed_char";
12601 case DW_ATE_unsigned
:
12602 return "DW_ATE_unsigned";
12603 case DW_ATE_unsigned_char
:
12604 return "DW_ATE_unsigned_char";
12606 case DW_ATE_imaginary_float
:
12607 return "DW_ATE_imaginary_float";
12608 case DW_ATE_packed_decimal
:
12609 return "DW_ATE_packed_decimal";
12610 case DW_ATE_numeric_string
:
12611 return "DW_ATE_numeric_string";
12612 case DW_ATE_edited
:
12613 return "DW_ATE_edited";
12614 case DW_ATE_signed_fixed
:
12615 return "DW_ATE_signed_fixed";
12616 case DW_ATE_unsigned_fixed
:
12617 return "DW_ATE_unsigned_fixed";
12618 case DW_ATE_decimal_float
:
12619 return "DW_ATE_decimal_float";
12622 return "DW_ATE_UTF";
12623 /* HP extensions. */
12624 case DW_ATE_HP_float80
:
12625 return "DW_ATE_HP_float80";
12626 case DW_ATE_HP_complex_float80
:
12627 return "DW_ATE_HP_complex_float80";
12628 case DW_ATE_HP_float128
:
12629 return "DW_ATE_HP_float128";
12630 case DW_ATE_HP_complex_float128
:
12631 return "DW_ATE_HP_complex_float128";
12632 case DW_ATE_HP_floathpintel
:
12633 return "DW_ATE_HP_floathpintel";
12634 case DW_ATE_HP_imaginary_float80
:
12635 return "DW_ATE_HP_imaginary_float80";
12636 case DW_ATE_HP_imaginary_float128
:
12637 return "DW_ATE_HP_imaginary_float128";
12639 return "DW_ATE_<unknown>";
12643 /* Convert a DWARF call frame info operation to its string name. */
12647 dwarf_cfi_name (unsigned cfi_opc
)
12651 case DW_CFA_advance_loc
:
12652 return "DW_CFA_advance_loc";
12653 case DW_CFA_offset
:
12654 return "DW_CFA_offset";
12655 case DW_CFA_restore
:
12656 return "DW_CFA_restore";
12658 return "DW_CFA_nop";
12659 case DW_CFA_set_loc
:
12660 return "DW_CFA_set_loc";
12661 case DW_CFA_advance_loc1
:
12662 return "DW_CFA_advance_loc1";
12663 case DW_CFA_advance_loc2
:
12664 return "DW_CFA_advance_loc2";
12665 case DW_CFA_advance_loc4
:
12666 return "DW_CFA_advance_loc4";
12667 case DW_CFA_offset_extended
:
12668 return "DW_CFA_offset_extended";
12669 case DW_CFA_restore_extended
:
12670 return "DW_CFA_restore_extended";
12671 case DW_CFA_undefined
:
12672 return "DW_CFA_undefined";
12673 case DW_CFA_same_value
:
12674 return "DW_CFA_same_value";
12675 case DW_CFA_register
:
12676 return "DW_CFA_register";
12677 case DW_CFA_remember_state
:
12678 return "DW_CFA_remember_state";
12679 case DW_CFA_restore_state
:
12680 return "DW_CFA_restore_state";
12681 case DW_CFA_def_cfa
:
12682 return "DW_CFA_def_cfa";
12683 case DW_CFA_def_cfa_register
:
12684 return "DW_CFA_def_cfa_register";
12685 case DW_CFA_def_cfa_offset
:
12686 return "DW_CFA_def_cfa_offset";
12688 case DW_CFA_def_cfa_expression
:
12689 return "DW_CFA_def_cfa_expression";
12690 case DW_CFA_expression
:
12691 return "DW_CFA_expression";
12692 case DW_CFA_offset_extended_sf
:
12693 return "DW_CFA_offset_extended_sf";
12694 case DW_CFA_def_cfa_sf
:
12695 return "DW_CFA_def_cfa_sf";
12696 case DW_CFA_def_cfa_offset_sf
:
12697 return "DW_CFA_def_cfa_offset_sf";
12698 case DW_CFA_val_offset
:
12699 return "DW_CFA_val_offset";
12700 case DW_CFA_val_offset_sf
:
12701 return "DW_CFA_val_offset_sf";
12702 case DW_CFA_val_expression
:
12703 return "DW_CFA_val_expression";
12704 /* SGI/MIPS specific. */
12705 case DW_CFA_MIPS_advance_loc8
:
12706 return "DW_CFA_MIPS_advance_loc8";
12707 /* GNU extensions. */
12708 case DW_CFA_GNU_window_save
:
12709 return "DW_CFA_GNU_window_save";
12710 case DW_CFA_GNU_args_size
:
12711 return "DW_CFA_GNU_args_size";
12712 case DW_CFA_GNU_negative_offset_extended
:
12713 return "DW_CFA_GNU_negative_offset_extended";
12715 return "DW_CFA_<unknown>";
12721 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12725 print_spaces (indent
, f
);
12726 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12727 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12729 if (die
->parent
!= NULL
)
12731 print_spaces (indent
, f
);
12732 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12733 die
->parent
->offset
);
12736 print_spaces (indent
, f
);
12737 fprintf_unfiltered (f
, " has children: %s\n",
12738 dwarf_bool_name (die
->child
!= NULL
));
12740 print_spaces (indent
, f
);
12741 fprintf_unfiltered (f
, " attributes:\n");
12743 for (i
= 0; i
< die
->num_attrs
; ++i
)
12745 print_spaces (indent
, f
);
12746 fprintf_unfiltered (f
, " %s (%s) ",
12747 dwarf_attr_name (die
->attrs
[i
].name
),
12748 dwarf_form_name (die
->attrs
[i
].form
));
12750 switch (die
->attrs
[i
].form
)
12752 case DW_FORM_ref_addr
:
12754 fprintf_unfiltered (f
, "address: ");
12755 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12757 case DW_FORM_block2
:
12758 case DW_FORM_block4
:
12759 case DW_FORM_block
:
12760 case DW_FORM_block1
:
12761 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12763 case DW_FORM_exprloc
:
12764 fprintf_unfiltered (f
, "expression: size %u",
12765 DW_BLOCK (&die
->attrs
[i
])->size
);
12770 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12771 (long) (DW_ADDR (&die
->attrs
[i
])));
12773 case DW_FORM_data1
:
12774 case DW_FORM_data2
:
12775 case DW_FORM_data4
:
12776 case DW_FORM_data8
:
12777 case DW_FORM_udata
:
12778 case DW_FORM_sdata
:
12779 fprintf_unfiltered (f
, "constant: %s",
12780 pulongest (DW_UNSND (&die
->attrs
[i
])));
12782 case DW_FORM_sec_offset
:
12783 fprintf_unfiltered (f
, "section offset: %s",
12784 pulongest (DW_UNSND (&die
->attrs
[i
])));
12787 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12788 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12789 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12791 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12793 case DW_FORM_string
:
12795 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12796 DW_STRING (&die
->attrs
[i
])
12797 ? DW_STRING (&die
->attrs
[i
]) : "",
12798 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12801 if (DW_UNSND (&die
->attrs
[i
]))
12802 fprintf_unfiltered (f
, "flag: TRUE");
12804 fprintf_unfiltered (f
, "flag: FALSE");
12806 case DW_FORM_flag_present
:
12807 fprintf_unfiltered (f
, "flag: TRUE");
12809 case DW_FORM_indirect
:
12810 /* the reader will have reduced the indirect form to
12811 the "base form" so this form should not occur */
12812 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12815 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12816 die
->attrs
[i
].form
);
12819 fprintf_unfiltered (f
, "\n");
12824 dump_die_for_error (struct die_info
*die
)
12826 dump_die_shallow (gdb_stderr
, 0, die
);
12830 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12832 int indent
= level
* 4;
12834 gdb_assert (die
!= NULL
);
12836 if (level
>= max_level
)
12839 dump_die_shallow (f
, indent
, die
);
12841 if (die
->child
!= NULL
)
12843 print_spaces (indent
, f
);
12844 fprintf_unfiltered (f
, " Children:");
12845 if (level
+ 1 < max_level
)
12847 fprintf_unfiltered (f
, "\n");
12848 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12852 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12856 if (die
->sibling
!= NULL
&& level
> 0)
12858 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12862 /* This is called from the pdie macro in gdbinit.in.
12863 It's not static so gcc will keep a copy callable from gdb. */
12866 dump_die (struct die_info
*die
, int max_level
)
12868 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12872 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12876 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12882 is_ref_attr (struct attribute
*attr
)
12884 switch (attr
->form
)
12886 case DW_FORM_ref_addr
:
12891 case DW_FORM_ref_udata
:
12898 static unsigned int
12899 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12901 if (is_ref_attr (attr
))
12902 return DW_ADDR (attr
);
12904 complaint (&symfile_complaints
,
12905 _("unsupported die ref attribute form: '%s'"),
12906 dwarf_form_name (attr
->form
));
12910 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12911 * the value held by the attribute is not constant. */
12914 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12916 if (attr
->form
== DW_FORM_sdata
)
12917 return DW_SND (attr
);
12918 else if (attr
->form
== DW_FORM_udata
12919 || attr
->form
== DW_FORM_data1
12920 || attr
->form
== DW_FORM_data2
12921 || attr
->form
== DW_FORM_data4
12922 || attr
->form
== DW_FORM_data8
)
12923 return DW_UNSND (attr
);
12926 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12927 dwarf_form_name (attr
->form
));
12928 return default_value
;
12932 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12933 unit and add it to our queue.
12934 The result is non-zero if PER_CU was queued, otherwise the result is zero
12935 meaning either PER_CU is already queued or it is already loaded. */
12938 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12939 struct dwarf2_per_cu_data
*per_cu
)
12941 /* We may arrive here during partial symbol reading, if we need full
12942 DIEs to process an unusual case (e.g. template arguments). Do
12943 not queue PER_CU, just tell our caller to load its DIEs. */
12944 if (dwarf2_per_objfile
->reading_partial_symbols
)
12946 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12951 /* Mark the dependence relation so that we don't flush PER_CU
12953 dwarf2_add_dependence (this_cu
, per_cu
);
12955 /* If it's already on the queue, we have nothing to do. */
12956 if (per_cu
->queued
)
12959 /* If the compilation unit is already loaded, just mark it as
12961 if (per_cu
->cu
!= NULL
)
12963 per_cu
->cu
->last_used
= 0;
12967 /* Add it to the queue. */
12968 queue_comp_unit (per_cu
, this_cu
->objfile
);
12973 /* Follow reference or signature attribute ATTR of SRC_DIE.
12974 On entry *REF_CU is the CU of SRC_DIE.
12975 On exit *REF_CU is the CU of the result. */
12977 static struct die_info
*
12978 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12979 struct dwarf2_cu
**ref_cu
)
12981 struct die_info
*die
;
12983 if (is_ref_attr (attr
))
12984 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12985 else if (attr
->form
== DW_FORM_sig8
)
12986 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12989 dump_die_for_error (src_die
);
12990 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12991 (*ref_cu
)->objfile
->name
);
12997 /* Follow reference OFFSET.
12998 On entry *REF_CU is the CU of the source die referencing OFFSET.
12999 On exit *REF_CU is the CU of the result.
13000 Returns NULL if OFFSET is invalid. */
13002 static struct die_info
*
13003 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13005 struct die_info temp_die
;
13006 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13008 gdb_assert (cu
->per_cu
!= NULL
);
13012 if (cu
->per_cu
->from_debug_types
)
13014 /* .debug_types CUs cannot reference anything outside their CU.
13015 If they need to, they have to reference a signatured type via
13017 if (! offset_in_cu_p (&cu
->header
, offset
))
13020 else if (! offset_in_cu_p (&cu
->header
, offset
))
13022 struct dwarf2_per_cu_data
*per_cu
;
13024 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13026 /* If necessary, add it to the queue and load its DIEs. */
13027 if (maybe_queue_comp_unit (cu
, per_cu
))
13028 load_full_comp_unit (per_cu
, cu
->objfile
);
13030 target_cu
= per_cu
->cu
;
13032 else if (cu
->dies
== NULL
)
13034 /* We're loading full DIEs during partial symbol reading. */
13035 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13036 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13039 *ref_cu
= target_cu
;
13040 temp_die
.offset
= offset
;
13041 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13044 /* Follow reference attribute ATTR of SRC_DIE.
13045 On entry *REF_CU is the CU of SRC_DIE.
13046 On exit *REF_CU is the CU of the result. */
13048 static struct die_info
*
13049 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13050 struct dwarf2_cu
**ref_cu
)
13052 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13053 struct dwarf2_cu
*cu
= *ref_cu
;
13054 struct die_info
*die
;
13056 die
= follow_die_offset (offset
, ref_cu
);
13058 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13059 "at 0x%x [in module %s]"),
13060 offset
, src_die
->offset
, cu
->objfile
->name
);
13065 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13066 value is intended for DW_OP_call*. */
13068 struct dwarf2_locexpr_baton
13069 dwarf2_fetch_die_location_block (unsigned int offset
,
13070 struct dwarf2_per_cu_data
*per_cu
)
13072 struct dwarf2_cu
*cu
= per_cu
->cu
;
13073 struct die_info
*die
;
13074 struct attribute
*attr
;
13075 struct dwarf2_locexpr_baton retval
;
13077 die
= follow_die_offset (offset
, &cu
);
13079 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13080 offset
, per_cu
->cu
->objfile
->name
);
13082 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13085 /* DWARF: "If there is no such attribute, then there is no effect.". */
13087 retval
.data
= NULL
;
13092 if (!attr_form_is_block (attr
))
13093 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13094 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13095 offset
, per_cu
->cu
->objfile
->name
);
13097 retval
.data
= DW_BLOCK (attr
)->data
;
13098 retval
.size
= DW_BLOCK (attr
)->size
;
13100 retval
.per_cu
= cu
->per_cu
;
13104 /* Follow the signature attribute ATTR in SRC_DIE.
13105 On entry *REF_CU is the CU of SRC_DIE.
13106 On exit *REF_CU is the CU of the result. */
13108 static struct die_info
*
13109 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13110 struct dwarf2_cu
**ref_cu
)
13112 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13113 struct die_info temp_die
;
13114 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13115 struct dwarf2_cu
*sig_cu
;
13116 struct die_info
*die
;
13118 /* sig_type will be NULL if the signatured type is missing from
13120 if (sig_type
== NULL
)
13121 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13122 "at 0x%x [in module %s]"),
13123 src_die
->offset
, objfile
->name
);
13125 /* If necessary, add it to the queue and load its DIEs. */
13127 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13128 read_signatured_type (objfile
, sig_type
);
13130 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13132 sig_cu
= sig_type
->per_cu
.cu
;
13133 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13134 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13141 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
13142 "at 0x%x [in module %s]"),
13143 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13146 /* Given an offset of a signatured type, return its signatured_type. */
13148 static struct signatured_type
*
13149 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13151 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13152 unsigned int length
, initial_length_size
;
13153 unsigned int sig_offset
;
13154 struct signatured_type find_entry
, *type_sig
;
13156 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13157 sig_offset
= (initial_length_size
13159 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13160 + 1 /*address_size*/);
13161 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13162 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13164 /* This is only used to lookup previously recorded types.
13165 If we didn't find it, it's our bug. */
13166 gdb_assert (type_sig
!= NULL
);
13167 gdb_assert (offset
== type_sig
->offset
);
13172 /* Read in signatured type at OFFSET and build its CU and die(s). */
13175 read_signatured_type_at_offset (struct objfile
*objfile
,
13176 unsigned int offset
)
13178 struct signatured_type
*type_sig
;
13180 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13182 /* We have the section offset, but we need the signature to do the
13183 hash table lookup. */
13184 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13186 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13188 read_signatured_type (objfile
, type_sig
);
13190 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13193 /* Read in a signatured type and build its CU and DIEs. */
13196 read_signatured_type (struct objfile
*objfile
,
13197 struct signatured_type
*type_sig
)
13199 gdb_byte
*types_ptr
;
13200 struct die_reader_specs reader_specs
;
13201 struct dwarf2_cu
*cu
;
13202 ULONGEST signature
;
13203 struct cleanup
*back_to
, *free_cu_cleanup
;
13204 struct attribute
*attr
;
13206 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13207 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13209 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13211 cu
= xmalloc (sizeof (struct dwarf2_cu
));
13212 memset (cu
, 0, sizeof (struct dwarf2_cu
));
13213 obstack_init (&cu
->comp_unit_obstack
);
13214 cu
->objfile
= objfile
;
13215 type_sig
->per_cu
.cu
= cu
;
13216 cu
->per_cu
= &type_sig
->per_cu
;
13218 /* If an error occurs while loading, release our storage. */
13219 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13221 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13222 types_ptr
, objfile
->obfd
);
13223 gdb_assert (signature
== type_sig
->signature
);
13226 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13230 &cu
->comp_unit_obstack
,
13231 hashtab_obstack_allocate
,
13232 dummy_obstack_deallocate
);
13234 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13235 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13237 init_cu_die_reader (&reader_specs
, cu
);
13239 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13242 /* We try not to read any attributes in this function, because not
13243 all objfiles needed for references have been loaded yet, and symbol
13244 table processing isn't initialized. But we have to set the CU language,
13245 or we won't be able to build types correctly. */
13246 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
13248 set_cu_language (DW_UNSND (attr
), cu
);
13250 set_cu_language (language_minimal
, cu
);
13252 do_cleanups (back_to
);
13254 /* We've successfully allocated this compilation unit. Let our caller
13255 clean it up when finished with it. */
13256 discard_cleanups (free_cu_cleanup
);
13258 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13259 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13262 /* Decode simple location descriptions.
13263 Given a pointer to a dwarf block that defines a location, compute
13264 the location and return the value.
13266 NOTE drow/2003-11-18: This function is called in two situations
13267 now: for the address of static or global variables (partial symbols
13268 only) and for offsets into structures which are expected to be
13269 (more or less) constant. The partial symbol case should go away,
13270 and only the constant case should remain. That will let this
13271 function complain more accurately. A few special modes are allowed
13272 without complaint for global variables (for instance, global
13273 register values and thread-local values).
13275 A location description containing no operations indicates that the
13276 object is optimized out. The return value is 0 for that case.
13277 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13278 callers will only want a very basic result and this can become a
13281 Note that stack[0] is unused except as a default error return.
13282 Note that stack overflow is not yet handled. */
13285 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13287 struct objfile
*objfile
= cu
->objfile
;
13289 int size
= blk
->size
;
13290 gdb_byte
*data
= blk
->data
;
13291 CORE_ADDR stack
[64];
13293 unsigned int bytes_read
, unsnd
;
13337 stack
[++stacki
] = op
- DW_OP_lit0
;
13372 stack
[++stacki
] = op
- DW_OP_reg0
;
13374 dwarf2_complex_location_expr_complaint ();
13378 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13380 stack
[++stacki
] = unsnd
;
13382 dwarf2_complex_location_expr_complaint ();
13386 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13391 case DW_OP_const1u
:
13392 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13396 case DW_OP_const1s
:
13397 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13401 case DW_OP_const2u
:
13402 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13406 case DW_OP_const2s
:
13407 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13411 case DW_OP_const4u
:
13412 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13416 case DW_OP_const4s
:
13417 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13422 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13428 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13433 stack
[stacki
+ 1] = stack
[stacki
];
13438 stack
[stacki
- 1] += stack
[stacki
];
13442 case DW_OP_plus_uconst
:
13443 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13448 stack
[stacki
- 1] -= stack
[stacki
];
13453 /* If we're not the last op, then we definitely can't encode
13454 this using GDB's address_class enum. This is valid for partial
13455 global symbols, although the variable's address will be bogus
13458 dwarf2_complex_location_expr_complaint ();
13461 case DW_OP_GNU_push_tls_address
:
13462 /* The top of the stack has the offset from the beginning
13463 of the thread control block at which the variable is located. */
13464 /* Nothing should follow this operator, so the top of stack would
13466 /* This is valid for partial global symbols, but the variable's
13467 address will be bogus in the psymtab. */
13469 dwarf2_complex_location_expr_complaint ();
13472 case DW_OP_GNU_uninit
:
13476 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13477 dwarf_stack_op_name (op
, 1));
13478 return (stack
[stacki
]);
13481 return (stack
[stacki
]);
13484 /* memory allocation interface */
13486 static struct dwarf_block
*
13487 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13489 struct dwarf_block
*blk
;
13491 blk
= (struct dwarf_block
*)
13492 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13496 static struct abbrev_info
*
13497 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13499 struct abbrev_info
*abbrev
;
13501 abbrev
= (struct abbrev_info
*)
13502 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13503 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13507 static struct die_info
*
13508 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13510 struct die_info
*die
;
13511 size_t size
= sizeof (struct die_info
);
13514 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13516 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13517 memset (die
, 0, sizeof (struct die_info
));
13522 /* Macro support. */
13525 /* Return the full name of file number I in *LH's file name table.
13526 Use COMP_DIR as the name of the current directory of the
13527 compilation. The result is allocated using xmalloc; the caller is
13528 responsible for freeing it. */
13530 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13532 /* Is the file number a valid index into the line header's file name
13533 table? Remember that file numbers start with one, not zero. */
13534 if (1 <= file
&& file
<= lh
->num_file_names
)
13536 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13538 if (IS_ABSOLUTE_PATH (fe
->name
))
13539 return xstrdup (fe
->name
);
13547 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13553 dir_len
= strlen (dir
);
13554 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13555 strcpy (full_name
, dir
);
13556 full_name
[dir_len
] = '/';
13557 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13561 return xstrdup (fe
->name
);
13566 /* The compiler produced a bogus file number. We can at least
13567 record the macro definitions made in the file, even if we
13568 won't be able to find the file by name. */
13569 char fake_name
[80];
13571 sprintf (fake_name
, "<bad macro file number %d>", file
);
13573 complaint (&symfile_complaints
,
13574 _("bad file number in macro information (%d)"),
13577 return xstrdup (fake_name
);
13582 static struct macro_source_file
*
13583 macro_start_file (int file
, int line
,
13584 struct macro_source_file
*current_file
,
13585 const char *comp_dir
,
13586 struct line_header
*lh
, struct objfile
*objfile
)
13588 /* The full name of this source file. */
13589 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13591 /* We don't create a macro table for this compilation unit
13592 at all until we actually get a filename. */
13593 if (! pending_macros
)
13594 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13595 objfile
->macro_cache
);
13597 if (! current_file
)
13598 /* If we have no current file, then this must be the start_file
13599 directive for the compilation unit's main source file. */
13600 current_file
= macro_set_main (pending_macros
, full_name
);
13602 current_file
= macro_include (current_file
, line
, full_name
);
13606 return current_file
;
13610 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13611 followed by a null byte. */
13613 copy_string (const char *buf
, int len
)
13615 char *s
= xmalloc (len
+ 1);
13617 memcpy (s
, buf
, len
);
13623 static const char *
13624 consume_improper_spaces (const char *p
, const char *body
)
13628 complaint (&symfile_complaints
,
13629 _("macro definition contains spaces in formal argument list:\n`%s'"),
13641 parse_macro_definition (struct macro_source_file
*file
, int line
,
13646 /* The body string takes one of two forms. For object-like macro
13647 definitions, it should be:
13649 <macro name> " " <definition>
13651 For function-like macro definitions, it should be:
13653 <macro name> "() " <definition>
13655 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13657 Spaces may appear only where explicitly indicated, and in the
13660 The Dwarf 2 spec says that an object-like macro's name is always
13661 followed by a space, but versions of GCC around March 2002 omit
13662 the space when the macro's definition is the empty string.
13664 The Dwarf 2 spec says that there should be no spaces between the
13665 formal arguments in a function-like macro's formal argument list,
13666 but versions of GCC around March 2002 include spaces after the
13670 /* Find the extent of the macro name. The macro name is terminated
13671 by either a space or null character (for an object-like macro) or
13672 an opening paren (for a function-like macro). */
13673 for (p
= body
; *p
; p
++)
13674 if (*p
== ' ' || *p
== '(')
13677 if (*p
== ' ' || *p
== '\0')
13679 /* It's an object-like macro. */
13680 int name_len
= p
- body
;
13681 char *name
= copy_string (body
, name_len
);
13682 const char *replacement
;
13685 replacement
= body
+ name_len
+ 1;
13688 dwarf2_macro_malformed_definition_complaint (body
);
13689 replacement
= body
+ name_len
;
13692 macro_define_object (file
, line
, name
, replacement
);
13696 else if (*p
== '(')
13698 /* It's a function-like macro. */
13699 char *name
= copy_string (body
, p
- body
);
13702 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13706 p
= consume_improper_spaces (p
, body
);
13708 /* Parse the formal argument list. */
13709 while (*p
&& *p
!= ')')
13711 /* Find the extent of the current argument name. */
13712 const char *arg_start
= p
;
13714 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13717 if (! *p
|| p
== arg_start
)
13718 dwarf2_macro_malformed_definition_complaint (body
);
13721 /* Make sure argv has room for the new argument. */
13722 if (argc
>= argv_size
)
13725 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13728 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13731 p
= consume_improper_spaces (p
, body
);
13733 /* Consume the comma, if present. */
13738 p
= consume_improper_spaces (p
, body
);
13747 /* Perfectly formed definition, no complaints. */
13748 macro_define_function (file
, line
, name
,
13749 argc
, (const char **) argv
,
13751 else if (*p
== '\0')
13753 /* Complain, but do define it. */
13754 dwarf2_macro_malformed_definition_complaint (body
);
13755 macro_define_function (file
, line
, name
,
13756 argc
, (const char **) argv
,
13760 /* Just complain. */
13761 dwarf2_macro_malformed_definition_complaint (body
);
13764 /* Just complain. */
13765 dwarf2_macro_malformed_definition_complaint (body
);
13771 for (i
= 0; i
< argc
; i
++)
13777 dwarf2_macro_malformed_definition_complaint (body
);
13782 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13783 char *comp_dir
, bfd
*abfd
,
13784 struct dwarf2_cu
*cu
)
13786 gdb_byte
*mac_ptr
, *mac_end
;
13787 struct macro_source_file
*current_file
= 0;
13788 enum dwarf_macinfo_record_type macinfo_type
;
13789 int at_commandline
;
13791 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13792 &dwarf2_per_objfile
->macinfo
);
13793 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13795 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13799 /* First pass: Find the name of the base filename.
13800 This filename is needed in order to process all macros whose definition
13801 (or undefinition) comes from the command line. These macros are defined
13802 before the first DW_MACINFO_start_file entry, and yet still need to be
13803 associated to the base file.
13805 To determine the base file name, we scan the macro definitions until we
13806 reach the first DW_MACINFO_start_file entry. We then initialize
13807 CURRENT_FILE accordingly so that any macro definition found before the
13808 first DW_MACINFO_start_file can still be associated to the base file. */
13810 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13811 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13812 + dwarf2_per_objfile
->macinfo
.size
;
13816 /* Do we at least have room for a macinfo type byte? */
13817 if (mac_ptr
>= mac_end
)
13819 /* Complaint is printed during the second pass as GDB will probably
13820 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13824 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13827 switch (macinfo_type
)
13829 /* A zero macinfo type indicates the end of the macro
13834 case DW_MACINFO_define
:
13835 case DW_MACINFO_undef
:
13836 /* Only skip the data by MAC_PTR. */
13838 unsigned int bytes_read
;
13840 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13841 mac_ptr
+= bytes_read
;
13842 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13843 mac_ptr
+= bytes_read
;
13847 case DW_MACINFO_start_file
:
13849 unsigned int bytes_read
;
13852 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13853 mac_ptr
+= bytes_read
;
13854 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13855 mac_ptr
+= bytes_read
;
13857 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13862 case DW_MACINFO_end_file
:
13863 /* No data to skip by MAC_PTR. */
13866 case DW_MACINFO_vendor_ext
:
13867 /* Only skip the data by MAC_PTR. */
13869 unsigned int bytes_read
;
13871 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13872 mac_ptr
+= bytes_read
;
13873 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13874 mac_ptr
+= bytes_read
;
13881 } while (macinfo_type
!= 0 && current_file
== NULL
);
13883 /* Second pass: Process all entries.
13885 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13886 command-line macro definitions/undefinitions. This flag is unset when we
13887 reach the first DW_MACINFO_start_file entry. */
13889 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13891 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13892 GDB is still reading the definitions from command line. First
13893 DW_MACINFO_start_file will need to be ignored as it was already executed
13894 to create CURRENT_FILE for the main source holding also the command line
13895 definitions. On first met DW_MACINFO_start_file this flag is reset to
13896 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13898 at_commandline
= 1;
13902 /* Do we at least have room for a macinfo type byte? */
13903 if (mac_ptr
>= mac_end
)
13905 dwarf2_macros_too_long_complaint ();
13909 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13912 switch (macinfo_type
)
13914 /* A zero macinfo type indicates the end of the macro
13919 case DW_MACINFO_define
:
13920 case DW_MACINFO_undef
:
13922 unsigned int bytes_read
;
13926 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13927 mac_ptr
+= bytes_read
;
13928 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13929 mac_ptr
+= bytes_read
;
13931 if (! current_file
)
13933 /* DWARF violation as no main source is present. */
13934 complaint (&symfile_complaints
,
13935 _("debug info with no main source gives macro %s "
13937 macinfo_type
== DW_MACINFO_define
?
13939 macinfo_type
== DW_MACINFO_undef
?
13940 _("undefinition") :
13941 _("something-or-other"), line
, body
);
13944 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13945 complaint (&symfile_complaints
,
13946 _("debug info gives %s macro %s with %s line %d: %s"),
13947 at_commandline
? _("command-line") : _("in-file"),
13948 macinfo_type
== DW_MACINFO_define
?
13950 macinfo_type
== DW_MACINFO_undef
?
13951 _("undefinition") :
13952 _("something-or-other"),
13953 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13955 if (macinfo_type
== DW_MACINFO_define
)
13956 parse_macro_definition (current_file
, line
, body
);
13957 else if (macinfo_type
== DW_MACINFO_undef
)
13958 macro_undef (current_file
, line
, body
);
13962 case DW_MACINFO_start_file
:
13964 unsigned int bytes_read
;
13967 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13968 mac_ptr
+= bytes_read
;
13969 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13970 mac_ptr
+= bytes_read
;
13972 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13973 complaint (&symfile_complaints
,
13974 _("debug info gives source %d included "
13975 "from %s at %s line %d"),
13976 file
, at_commandline
? _("command-line") : _("file"),
13977 line
== 0 ? _("zero") : _("non-zero"), line
);
13979 if (at_commandline
)
13981 /* This DW_MACINFO_start_file was executed in the pass one. */
13982 at_commandline
= 0;
13985 current_file
= macro_start_file (file
, line
,
13986 current_file
, comp_dir
,
13991 case DW_MACINFO_end_file
:
13992 if (! current_file
)
13993 complaint (&symfile_complaints
,
13994 _("macro debug info has an unmatched `close_file' directive"));
13997 current_file
= current_file
->included_by
;
13998 if (! current_file
)
14000 enum dwarf_macinfo_record_type next_type
;
14002 /* GCC circa March 2002 doesn't produce the zero
14003 type byte marking the end of the compilation
14004 unit. Complain if it's not there, but exit no
14007 /* Do we at least have room for a macinfo type byte? */
14008 if (mac_ptr
>= mac_end
)
14010 dwarf2_macros_too_long_complaint ();
14014 /* We don't increment mac_ptr here, so this is just
14016 next_type
= read_1_byte (abfd
, mac_ptr
);
14017 if (next_type
!= 0)
14018 complaint (&symfile_complaints
,
14019 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
14026 case DW_MACINFO_vendor_ext
:
14028 unsigned int bytes_read
;
14032 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14033 mac_ptr
+= bytes_read
;
14034 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14035 mac_ptr
+= bytes_read
;
14037 /* We don't recognize any vendor extensions. */
14041 } while (macinfo_type
!= 0);
14044 /* Check if the attribute's form is a DW_FORM_block*
14045 if so return true else false. */
14047 attr_form_is_block (struct attribute
*attr
)
14049 return (attr
== NULL
? 0 :
14050 attr
->form
== DW_FORM_block1
14051 || attr
->form
== DW_FORM_block2
14052 || attr
->form
== DW_FORM_block4
14053 || attr
->form
== DW_FORM_block
14054 || attr
->form
== DW_FORM_exprloc
);
14057 /* Return non-zero if ATTR's value is a section offset --- classes
14058 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14059 You may use DW_UNSND (attr) to retrieve such offsets.
14061 Section 7.5.4, "Attribute Encodings", explains that no attribute
14062 may have a value that belongs to more than one of these classes; it
14063 would be ambiguous if we did, because we use the same forms for all
14066 attr_form_is_section_offset (struct attribute
*attr
)
14068 return (attr
->form
== DW_FORM_data4
14069 || attr
->form
== DW_FORM_data8
14070 || attr
->form
== DW_FORM_sec_offset
);
14074 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14075 zero otherwise. When this function returns true, you can apply
14076 dwarf2_get_attr_constant_value to it.
14078 However, note that for some attributes you must check
14079 attr_form_is_section_offset before using this test. DW_FORM_data4
14080 and DW_FORM_data8 are members of both the constant class, and of
14081 the classes that contain offsets into other debug sections
14082 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14083 that, if an attribute's can be either a constant or one of the
14084 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14085 taken as section offsets, not constants. */
14087 attr_form_is_constant (struct attribute
*attr
)
14089 switch (attr
->form
)
14091 case DW_FORM_sdata
:
14092 case DW_FORM_udata
:
14093 case DW_FORM_data1
:
14094 case DW_FORM_data2
:
14095 case DW_FORM_data4
:
14096 case DW_FORM_data8
:
14104 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14105 struct dwarf2_cu
*cu
)
14107 if (attr_form_is_section_offset (attr
)
14108 /* ".debug_loc" may not exist at all, or the offset may be outside
14109 the section. If so, fall through to the complaint in the
14111 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
14113 struct dwarf2_loclist_baton
*baton
;
14115 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14116 sizeof (struct dwarf2_loclist_baton
));
14117 baton
->per_cu
= cu
->per_cu
;
14118 gdb_assert (baton
->per_cu
);
14120 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14121 &dwarf2_per_objfile
->loc
);
14123 /* We don't know how long the location list is, but make sure we
14124 don't run off the edge of the section. */
14125 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14126 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14127 baton
->base_address
= cu
->base_address
;
14128 if (cu
->base_known
== 0)
14129 complaint (&symfile_complaints
,
14130 _("Location list used without specifying the CU base address."));
14132 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14133 SYMBOL_LOCATION_BATON (sym
) = baton
;
14137 struct dwarf2_locexpr_baton
*baton
;
14139 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14140 sizeof (struct dwarf2_locexpr_baton
));
14141 baton
->per_cu
= cu
->per_cu
;
14142 gdb_assert (baton
->per_cu
);
14144 if (attr_form_is_block (attr
))
14146 /* Note that we're just copying the block's data pointer
14147 here, not the actual data. We're still pointing into the
14148 info_buffer for SYM's objfile; right now we never release
14149 that buffer, but when we do clean up properly this may
14151 baton
->size
= DW_BLOCK (attr
)->size
;
14152 baton
->data
= DW_BLOCK (attr
)->data
;
14156 dwarf2_invalid_attrib_class_complaint ("location description",
14157 SYMBOL_NATURAL_NAME (sym
));
14159 baton
->data
= NULL
;
14162 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14163 SYMBOL_LOCATION_BATON (sym
) = baton
;
14167 /* Return the OBJFILE associated with the compilation unit CU. If CU
14168 came from a separate debuginfo file, then the master objfile is
14172 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14174 struct objfile
*objfile
= per_cu
->objfile
;
14176 /* Return the master objfile, so that we can report and look up the
14177 correct file containing this variable. */
14178 if (objfile
->separate_debug_objfile_backlink
)
14179 objfile
= objfile
->separate_debug_objfile_backlink
;
14184 /* Return the address size given in the compilation unit header for CU. */
14187 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14190 return per_cu
->cu
->header
.addr_size
;
14193 /* If the CU is not currently read in, we re-read its header. */
14194 struct objfile
*objfile
= per_cu
->objfile
;
14195 struct dwarf2_per_objfile
*per_objfile
14196 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14197 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14198 struct comp_unit_head cu_header
;
14200 memset (&cu_header
, 0, sizeof cu_header
);
14201 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14202 return cu_header
.addr_size
;
14206 /* Return the offset size given in the compilation unit header for CU. */
14209 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14212 return per_cu
->cu
->header
.offset_size
;
14215 /* If the CU is not currently read in, we re-read its header. */
14216 struct objfile
*objfile
= per_cu
->objfile
;
14217 struct dwarf2_per_objfile
*per_objfile
14218 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14219 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14220 struct comp_unit_head cu_header
;
14222 memset (&cu_header
, 0, sizeof cu_header
);
14223 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14224 return cu_header
.offset_size
;
14228 /* Return the text offset of the CU. The returned offset comes from
14229 this CU's objfile. If this objfile came from a separate debuginfo
14230 file, then the offset may be different from the corresponding
14231 offset in the parent objfile. */
14234 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14236 struct objfile
*objfile
= per_cu
->objfile
;
14238 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14241 /* Locate the .debug_info compilation unit from CU's objfile which contains
14242 the DIE at OFFSET. Raises an error on failure. */
14244 static struct dwarf2_per_cu_data
*
14245 dwarf2_find_containing_comp_unit (unsigned int offset
,
14246 struct objfile
*objfile
)
14248 struct dwarf2_per_cu_data
*this_cu
;
14252 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14255 int mid
= low
+ (high
- low
) / 2;
14257 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14262 gdb_assert (low
== high
);
14263 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14266 error (_("Dwarf Error: could not find partial DIE containing "
14267 "offset 0x%lx [in module %s]"),
14268 (long) offset
, bfd_get_filename (objfile
->obfd
));
14270 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14271 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14275 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14276 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14277 && offset
>= this_cu
->offset
+ this_cu
->length
)
14278 error (_("invalid dwarf2 offset %u"), offset
);
14279 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14284 /* Locate the compilation unit from OBJFILE which is located at exactly
14285 OFFSET. Raises an error on failure. */
14287 static struct dwarf2_per_cu_data
*
14288 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14290 struct dwarf2_per_cu_data
*this_cu
;
14292 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14293 if (this_cu
->offset
!= offset
)
14294 error (_("no compilation unit with offset %u."), offset
);
14298 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
14300 static struct dwarf2_cu
*
14301 alloc_one_comp_unit (struct objfile
*objfile
)
14303 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
14304 cu
->objfile
= objfile
;
14305 obstack_init (&cu
->comp_unit_obstack
);
14309 /* Release one cached compilation unit, CU. We unlink it from the tree
14310 of compilation units, but we don't remove it from the read_in_chain;
14311 the caller is responsible for that.
14312 NOTE: DATA is a void * because this function is also used as a
14313 cleanup routine. */
14316 free_one_comp_unit (void *data
)
14318 struct dwarf2_cu
*cu
= data
;
14320 if (cu
->per_cu
!= NULL
)
14321 cu
->per_cu
->cu
= NULL
;
14324 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14329 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14330 when we're finished with it. We can't free the pointer itself, but be
14331 sure to unlink it from the cache. Also release any associated storage
14332 and perform cache maintenance.
14334 Only used during partial symbol parsing. */
14337 free_stack_comp_unit (void *data
)
14339 struct dwarf2_cu
*cu
= data
;
14341 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14342 cu
->partial_dies
= NULL
;
14344 if (cu
->per_cu
!= NULL
)
14346 /* This compilation unit is on the stack in our caller, so we
14347 should not xfree it. Just unlink it. */
14348 cu
->per_cu
->cu
= NULL
;
14351 /* If we had a per-cu pointer, then we may have other compilation
14352 units loaded, so age them now. */
14353 age_cached_comp_units ();
14357 /* Free all cached compilation units. */
14360 free_cached_comp_units (void *data
)
14362 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14364 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14365 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14366 while (per_cu
!= NULL
)
14368 struct dwarf2_per_cu_data
*next_cu
;
14370 next_cu
= per_cu
->cu
->read_in_chain
;
14372 free_one_comp_unit (per_cu
->cu
);
14373 *last_chain
= next_cu
;
14379 /* Increase the age counter on each cached compilation unit, and free
14380 any that are too old. */
14383 age_cached_comp_units (void)
14385 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14387 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14388 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14389 while (per_cu
!= NULL
)
14391 per_cu
->cu
->last_used
++;
14392 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14393 dwarf2_mark (per_cu
->cu
);
14394 per_cu
= per_cu
->cu
->read_in_chain
;
14397 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14398 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14399 while (per_cu
!= NULL
)
14401 struct dwarf2_per_cu_data
*next_cu
;
14403 next_cu
= per_cu
->cu
->read_in_chain
;
14405 if (!per_cu
->cu
->mark
)
14407 free_one_comp_unit (per_cu
->cu
);
14408 *last_chain
= next_cu
;
14411 last_chain
= &per_cu
->cu
->read_in_chain
;
14417 /* Remove a single compilation unit from the cache. */
14420 free_one_cached_comp_unit (void *target_cu
)
14422 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14424 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14425 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14426 while (per_cu
!= NULL
)
14428 struct dwarf2_per_cu_data
*next_cu
;
14430 next_cu
= per_cu
->cu
->read_in_chain
;
14432 if (per_cu
->cu
== target_cu
)
14434 free_one_comp_unit (per_cu
->cu
);
14435 *last_chain
= next_cu
;
14439 last_chain
= &per_cu
->cu
->read_in_chain
;
14445 /* Release all extra memory associated with OBJFILE. */
14448 dwarf2_free_objfile (struct objfile
*objfile
)
14450 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14452 if (dwarf2_per_objfile
== NULL
)
14455 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14456 free_cached_comp_units (NULL
);
14458 if (dwarf2_per_objfile
->using_index
)
14462 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14465 struct dwarf2_per_cu_data
*per_cu
=
14466 dwarf2_per_objfile
->all_comp_units
[i
];
14468 if (!per_cu
->v
.quick
->lines
)
14471 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
14473 if (per_cu
->v
.quick
->file_names
)
14474 xfree ((void *) per_cu
->v
.quick
->file_names
[j
]);
14475 if (per_cu
->v
.quick
->full_names
)
14476 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
14479 free_line_header (per_cu
->v
.quick
->lines
);
14483 /* Everything else should be on the objfile obstack. */
14486 /* A pair of DIE offset and GDB type pointer. We store these
14487 in a hash table separate from the DIEs, and preserve them
14488 when the DIEs are flushed out of cache. */
14490 struct dwarf2_offset_and_type
14492 unsigned int offset
;
14496 /* Hash function for a dwarf2_offset_and_type. */
14499 offset_and_type_hash (const void *item
)
14501 const struct dwarf2_offset_and_type
*ofs
= item
;
14503 return ofs
->offset
;
14506 /* Equality function for a dwarf2_offset_and_type. */
14509 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14511 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14512 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14514 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14517 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14518 table if necessary. For convenience, return TYPE.
14520 The DIEs reading must have careful ordering to:
14521 * Not cause infite loops trying to read in DIEs as a prerequisite for
14522 reading current DIE.
14523 * Not trying to dereference contents of still incompletely read in types
14524 while reading in other DIEs.
14525 * Enable referencing still incompletely read in types just by a pointer to
14526 the type without accessing its fields.
14528 Therefore caller should follow these rules:
14529 * Try to fetch any prerequisite types we may need to build this DIE type
14530 before building the type and calling set_die_type.
14531 * After building type call set_die_type for current DIE as soon as
14532 possible before fetching more types to complete the current type.
14533 * Make the type as complete as possible before fetching more types. */
14535 static struct type
*
14536 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14538 struct dwarf2_offset_and_type
**slot
, ofs
;
14539 struct objfile
*objfile
= cu
->objfile
;
14540 htab_t
*type_hash_ptr
;
14542 /* For Ada types, make sure that the gnat-specific data is always
14543 initialized (if not already set). There are a few types where
14544 we should not be doing so, because the type-specific area is
14545 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14546 where the type-specific area is used to store the floatformat).
14547 But this is not a problem, because the gnat-specific information
14548 is actually not needed for these types. */
14549 if (need_gnat_info (cu
)
14550 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14551 && TYPE_CODE (type
) != TYPE_CODE_FLT
14552 && !HAVE_GNAT_AUX_INFO (type
))
14553 INIT_GNAT_SPECIFIC (type
);
14555 if (cu
->per_cu
->from_debug_types
)
14556 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14558 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14560 if (*type_hash_ptr
== NULL
)
14563 = htab_create_alloc_ex (127,
14564 offset_and_type_hash
,
14565 offset_and_type_eq
,
14567 &objfile
->objfile_obstack
,
14568 hashtab_obstack_allocate
,
14569 dummy_obstack_deallocate
);
14572 ofs
.offset
= die
->offset
;
14574 slot
= (struct dwarf2_offset_and_type
**)
14575 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14577 complaint (&symfile_complaints
,
14578 _("A problem internal to GDB: DIE 0x%x has type already set"),
14580 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14585 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14586 table, or return NULL if the die does not have a saved type. */
14588 static struct type
*
14589 get_die_type_at_offset (unsigned int offset
,
14590 struct dwarf2_per_cu_data
*per_cu
)
14592 struct dwarf2_offset_and_type
*slot
, ofs
;
14595 if (per_cu
->from_debug_types
)
14596 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14598 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14599 if (type_hash
== NULL
)
14602 ofs
.offset
= offset
;
14603 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14610 /* Look up the type for DIE in the appropriate type_hash table,
14611 or return NULL if DIE does not have a saved type. */
14613 static struct type
*
14614 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14616 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14619 /* Add a dependence relationship from CU to REF_PER_CU. */
14622 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14623 struct dwarf2_per_cu_data
*ref_per_cu
)
14627 if (cu
->dependencies
== NULL
)
14629 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14630 NULL
, &cu
->comp_unit_obstack
,
14631 hashtab_obstack_allocate
,
14632 dummy_obstack_deallocate
);
14634 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14636 *slot
= ref_per_cu
;
14639 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14640 Set the mark field in every compilation unit in the
14641 cache that we must keep because we are keeping CU. */
14644 dwarf2_mark_helper (void **slot
, void *data
)
14646 struct dwarf2_per_cu_data
*per_cu
;
14648 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14649 if (per_cu
->cu
->mark
)
14651 per_cu
->cu
->mark
= 1;
14653 if (per_cu
->cu
->dependencies
!= NULL
)
14654 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14659 /* Set the mark field in CU and in every other compilation unit in the
14660 cache that we must keep because we are keeping CU. */
14663 dwarf2_mark (struct dwarf2_cu
*cu
)
14668 if (cu
->dependencies
!= NULL
)
14669 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14673 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14677 per_cu
->cu
->mark
= 0;
14678 per_cu
= per_cu
->cu
->read_in_chain
;
14682 /* Trivial hash function for partial_die_info: the hash value of a DIE
14683 is its offset in .debug_info for this objfile. */
14686 partial_die_hash (const void *item
)
14688 const struct partial_die_info
*part_die
= item
;
14690 return part_die
->offset
;
14693 /* Trivial comparison function for partial_die_info structures: two DIEs
14694 are equal if they have the same offset. */
14697 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14699 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14700 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14702 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14705 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14706 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14709 set_dwarf2_cmd (char *args
, int from_tty
)
14711 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14715 show_dwarf2_cmd (char *args
, int from_tty
)
14717 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14720 /* If section described by INFO was mmapped, munmap it now. */
14723 munmap_section_buffer (struct dwarf2_section_info
*info
)
14725 if (info
->was_mmapped
)
14728 intptr_t begin
= (intptr_t) info
->buffer
;
14729 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14730 size_t map_length
= info
->size
+ begin
- map_begin
;
14732 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14734 /* Without HAVE_MMAP, we should never be here to begin with. */
14735 gdb_assert_not_reached ("no mmap support");
14740 /* munmap debug sections for OBJFILE, if necessary. */
14743 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14745 struct dwarf2_per_objfile
*data
= d
;
14747 /* This is sorted according to the order they're defined in to make it easier
14748 to keep in sync. */
14749 munmap_section_buffer (&data
->info
);
14750 munmap_section_buffer (&data
->abbrev
);
14751 munmap_section_buffer (&data
->line
);
14752 munmap_section_buffer (&data
->loc
);
14753 munmap_section_buffer (&data
->macinfo
);
14754 munmap_section_buffer (&data
->str
);
14755 munmap_section_buffer (&data
->ranges
);
14756 munmap_section_buffer (&data
->types
);
14757 munmap_section_buffer (&data
->frame
);
14758 munmap_section_buffer (&data
->eh_frame
);
14759 munmap_section_buffer (&data
->gdb_index
);
14764 /* The contents of the hash table we create when building the string
14766 struct strtab_entry
14768 offset_type offset
;
14772 /* Hash function for a strtab_entry. */
14775 hash_strtab_entry (const void *e
)
14777 const struct strtab_entry
*entry
= e
;
14778 return mapped_index_string_hash (entry
->str
);
14781 /* Equality function for a strtab_entry. */
14784 eq_strtab_entry (const void *a
, const void *b
)
14786 const struct strtab_entry
*ea
= a
;
14787 const struct strtab_entry
*eb
= b
;
14788 return !strcmp (ea
->str
, eb
->str
);
14791 /* Create a strtab_entry hash table. */
14794 create_strtab (void)
14796 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14797 xfree
, xcalloc
, xfree
);
14800 /* Add a string to the constant pool. Return the string's offset in
14804 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14807 struct strtab_entry entry
;
14808 struct strtab_entry
*result
;
14811 slot
= htab_find_slot (table
, &entry
, INSERT
);
14816 result
= XNEW (struct strtab_entry
);
14817 result
->offset
= obstack_object_size (cpool
);
14819 obstack_grow_str0 (cpool
, str
);
14822 return result
->offset
;
14825 /* An entry in the symbol table. */
14826 struct symtab_index_entry
14828 /* The name of the symbol. */
14830 /* The offset of the name in the constant pool. */
14831 offset_type index_offset
;
14832 /* A sorted vector of the indices of all the CUs that hold an object
14834 VEC (offset_type
) *cu_indices
;
14837 /* The symbol table. This is a power-of-2-sized hash table. */
14838 struct mapped_symtab
14840 offset_type n_elements
;
14842 struct symtab_index_entry
**data
;
14845 /* Hash function for a symtab_index_entry. */
14848 hash_symtab_entry (const void *e
)
14850 const struct symtab_index_entry
*entry
= e
;
14851 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14852 sizeof (offset_type
) * VEC_length (offset_type
,
14853 entry
->cu_indices
),
14857 /* Equality function for a symtab_index_entry. */
14860 eq_symtab_entry (const void *a
, const void *b
)
14862 const struct symtab_index_entry
*ea
= a
;
14863 const struct symtab_index_entry
*eb
= b
;
14864 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14865 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14867 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14868 VEC_address (offset_type
, eb
->cu_indices
),
14869 sizeof (offset_type
) * len
);
14872 /* Destroy a symtab_index_entry. */
14875 delete_symtab_entry (void *p
)
14877 struct symtab_index_entry
*entry
= p
;
14878 VEC_free (offset_type
, entry
->cu_indices
);
14882 /* Create a hash table holding symtab_index_entry objects. */
14885 create_symbol_hash_table (void)
14887 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14888 delete_symtab_entry
, xcalloc
, xfree
);
14891 /* Create a new mapped symtab object. */
14893 static struct mapped_symtab
*
14894 create_mapped_symtab (void)
14896 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14897 symtab
->n_elements
= 0;
14898 symtab
->size
= 1024;
14899 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14903 /* Destroy a mapped_symtab. */
14906 cleanup_mapped_symtab (void *p
)
14908 struct mapped_symtab
*symtab
= p
;
14909 /* The contents of the array are freed when the other hash table is
14911 xfree (symtab
->data
);
14915 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14918 static struct symtab_index_entry
**
14919 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14921 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14923 index
= hash
& (symtab
->size
- 1);
14924 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14928 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14929 return &symtab
->data
[index
];
14930 index
= (index
+ step
) & (symtab
->size
- 1);
14934 /* Expand SYMTAB's hash table. */
14937 hash_expand (struct mapped_symtab
*symtab
)
14939 offset_type old_size
= symtab
->size
;
14941 struct symtab_index_entry
**old_entries
= symtab
->data
;
14944 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14946 for (i
= 0; i
< old_size
; ++i
)
14948 if (old_entries
[i
])
14950 struct symtab_index_entry
**slot
= find_slot (symtab
,
14951 old_entries
[i
]->name
);
14952 *slot
= old_entries
[i
];
14956 xfree (old_entries
);
14959 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14960 is the index of the CU in which the symbol appears. */
14963 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
14964 offset_type cu_index
)
14966 struct symtab_index_entry
**slot
;
14968 ++symtab
->n_elements
;
14969 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
14970 hash_expand (symtab
);
14972 slot
= find_slot (symtab
, name
);
14975 *slot
= XNEW (struct symtab_index_entry
);
14976 (*slot
)->name
= name
;
14977 (*slot
)->cu_indices
= NULL
;
14979 /* Don't push an index twice. Due to how we add entries we only
14980 have to check the last one. */
14981 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
14982 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
14983 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
14986 /* Add a vector of indices to the constant pool. */
14989 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
14990 struct symtab_index_entry
*entry
)
14994 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
14997 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
14998 offset_type val
= MAYBE_SWAP (len
);
15003 entry
->index_offset
= obstack_object_size (cpool
);
15005 obstack_grow (cpool
, &val
, sizeof (val
));
15007 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15010 val
= MAYBE_SWAP (iter
);
15011 obstack_grow (cpool
, &val
, sizeof (val
));
15016 struct symtab_index_entry
*old_entry
= *slot
;
15017 entry
->index_offset
= old_entry
->index_offset
;
15020 return entry
->index_offset
;
15023 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15024 constant pool entries going into the obstack CPOOL. */
15027 write_hash_table (struct mapped_symtab
*symtab
,
15028 struct obstack
*output
, struct obstack
*cpool
)
15031 htab_t symbol_hash_table
;
15034 symbol_hash_table
= create_symbol_hash_table ();
15035 str_table
= create_strtab ();
15037 /* We add all the index vectors to the constant pool first, to
15038 ensure alignment is ok. */
15039 for (i
= 0; i
< symtab
->size
; ++i
)
15041 if (symtab
->data
[i
])
15042 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15045 /* Now write out the hash table. */
15046 for (i
= 0; i
< symtab
->size
; ++i
)
15048 offset_type str_off
, vec_off
;
15050 if (symtab
->data
[i
])
15052 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15053 vec_off
= symtab
->data
[i
]->index_offset
;
15057 /* While 0 is a valid constant pool index, it is not valid
15058 to have 0 for both offsets. */
15063 str_off
= MAYBE_SWAP (str_off
);
15064 vec_off
= MAYBE_SWAP (vec_off
);
15066 obstack_grow (output
, &str_off
, sizeof (str_off
));
15067 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15070 htab_delete (str_table
);
15071 htab_delete (symbol_hash_table
);
15074 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
15075 from PST; CU_INDEX is the index of the CU in the vector of all
15079 add_address_entry (struct objfile
*objfile
,
15080 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
15081 unsigned int cu_index
)
15083 offset_type offset
;
15085 CORE_ADDR baseaddr
;
15087 /* Don't bother recording empty ranges. */
15088 if (pst
->textlow
== pst
->texthigh
)
15091 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15093 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
15094 obstack_grow (addr_obstack
, addr
, 8);
15095 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
15096 obstack_grow (addr_obstack
, addr
, 8);
15097 offset
= MAYBE_SWAP (cu_index
);
15098 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
15101 /* Add a list of partial symbols to SYMTAB. */
15104 write_psymbols (struct mapped_symtab
*symtab
,
15106 struct partial_symbol
**psymp
,
15108 offset_type cu_index
,
15111 for (; count
-- > 0; ++psymp
)
15113 void **slot
, *lookup
;
15115 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15116 error (_("Ada is not currently supported by the index"));
15118 /* We only want to add a given psymbol once. However, we also
15119 want to account for whether it is global or static. So, we
15120 may add it twice, using slightly different values. */
15123 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15125 lookup
= (void *) val
;
15130 /* Only add a given psymbol once. */
15131 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15135 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15140 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15141 exception if there is an error. */
15144 write_obstack (FILE *file
, struct obstack
*obstack
)
15146 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15148 != obstack_object_size (obstack
))
15149 error (_("couldn't data write to file"));
15152 /* Unlink a file if the argument is not NULL. */
15155 unlink_if_set (void *p
)
15157 char **filename
= p
;
15159 unlink (*filename
);
15162 /* A helper struct used when iterating over debug_types. */
15163 struct signatured_type_index_data
15165 struct objfile
*objfile
;
15166 struct mapped_symtab
*symtab
;
15167 struct obstack
*types_list
;
15172 /* A helper function that writes a single signatured_type to an
15176 write_one_signatured_type (void **slot
, void *d
)
15178 struct signatured_type_index_data
*info
= d
;
15179 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15180 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15181 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15184 write_psymbols (info
->symtab
,
15186 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15187 psymtab
->n_global_syms
, info
->cu_index
,
15189 write_psymbols (info
->symtab
,
15191 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15192 psymtab
->n_static_syms
, info
->cu_index
,
15195 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15196 obstack_grow (info
->types_list
, val
, 8);
15197 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15198 obstack_grow (info
->types_list
, val
, 8);
15199 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15200 obstack_grow (info
->types_list
, val
, 8);
15207 /* A cleanup function for an htab_t. */
15210 cleanup_htab (void *arg
)
15215 /* Create an index file for OBJFILE in the directory DIR. */
15218 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15220 struct cleanup
*cleanup
;
15221 char *filename
, *cleanup_filename
;
15222 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15223 struct obstack cu_list
, types_cu_list
;
15226 struct mapped_symtab
*symtab
;
15227 offset_type val
, size_of_contents
, total_len
;
15232 if (!objfile
->psymtabs
)
15234 if (dwarf2_per_objfile
->using_index
)
15235 error (_("Cannot use an index to create the index"));
15237 if (stat (objfile
->name
, &st
) < 0)
15238 perror_with_name (_("Could not stat"));
15240 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15241 INDEX_SUFFIX
, (char *) NULL
);
15242 cleanup
= make_cleanup (xfree
, filename
);
15244 out_file
= fopen (filename
, "wb");
15246 error (_("Can't open `%s' for writing"), filename
);
15248 cleanup_filename
= filename
;
15249 make_cleanup (unlink_if_set
, &cleanup_filename
);
15251 symtab
= create_mapped_symtab ();
15252 make_cleanup (cleanup_mapped_symtab
, symtab
);
15254 obstack_init (&addr_obstack
);
15255 make_cleanup_obstack_free (&addr_obstack
);
15257 obstack_init (&cu_list
);
15258 make_cleanup_obstack_free (&cu_list
);
15260 obstack_init (&types_cu_list
);
15261 make_cleanup_obstack_free (&types_cu_list
);
15263 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15264 NULL
, xcalloc
, xfree
);
15265 make_cleanup (cleanup_htab
, psyms_seen
);
15267 /* The list is already sorted, so we don't need to do additional
15268 work here. Also, the debug_types entries do not appear in
15269 all_comp_units, but only in their own hash table. */
15270 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15272 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15273 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15276 write_psymbols (symtab
,
15278 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15279 psymtab
->n_global_syms
, i
,
15281 write_psymbols (symtab
,
15283 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15284 psymtab
->n_static_syms
, i
,
15287 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
15289 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15290 obstack_grow (&cu_list
, val
, 8);
15291 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15292 obstack_grow (&cu_list
, val
, 8);
15295 /* Write out the .debug_type entries, if any. */
15296 if (dwarf2_per_objfile
->signatured_types
)
15298 struct signatured_type_index_data sig_data
;
15300 sig_data
.objfile
= objfile
;
15301 sig_data
.symtab
= symtab
;
15302 sig_data
.types_list
= &types_cu_list
;
15303 sig_data
.psyms_seen
= psyms_seen
;
15304 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15305 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15306 write_one_signatured_type
, &sig_data
);
15309 obstack_init (&constant_pool
);
15310 make_cleanup_obstack_free (&constant_pool
);
15311 obstack_init (&symtab_obstack
);
15312 make_cleanup_obstack_free (&symtab_obstack
);
15313 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15315 obstack_init (&contents
);
15316 make_cleanup_obstack_free (&contents
);
15317 size_of_contents
= 6 * sizeof (offset_type
);
15318 total_len
= size_of_contents
;
15320 /* The version number. */
15321 val
= MAYBE_SWAP (3);
15322 obstack_grow (&contents
, &val
, sizeof (val
));
15324 /* The offset of the CU list from the start of the file. */
15325 val
= MAYBE_SWAP (total_len
);
15326 obstack_grow (&contents
, &val
, sizeof (val
));
15327 total_len
+= obstack_object_size (&cu_list
);
15329 /* The offset of the types CU list from the start of the file. */
15330 val
= MAYBE_SWAP (total_len
);
15331 obstack_grow (&contents
, &val
, sizeof (val
));
15332 total_len
+= obstack_object_size (&types_cu_list
);
15334 /* The offset of the address table from the start of the file. */
15335 val
= MAYBE_SWAP (total_len
);
15336 obstack_grow (&contents
, &val
, sizeof (val
));
15337 total_len
+= obstack_object_size (&addr_obstack
);
15339 /* The offset of the symbol table from the start of the file. */
15340 val
= MAYBE_SWAP (total_len
);
15341 obstack_grow (&contents
, &val
, sizeof (val
));
15342 total_len
+= obstack_object_size (&symtab_obstack
);
15344 /* The offset of the constant pool from the start of the file. */
15345 val
= MAYBE_SWAP (total_len
);
15346 obstack_grow (&contents
, &val
, sizeof (val
));
15347 total_len
+= obstack_object_size (&constant_pool
);
15349 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15351 write_obstack (out_file
, &contents
);
15352 write_obstack (out_file
, &cu_list
);
15353 write_obstack (out_file
, &types_cu_list
);
15354 write_obstack (out_file
, &addr_obstack
);
15355 write_obstack (out_file
, &symtab_obstack
);
15356 write_obstack (out_file
, &constant_pool
);
15360 /* We want to keep the file, so we set cleanup_filename to NULL
15361 here. See unlink_if_set. */
15362 cleanup_filename
= NULL
;
15364 do_cleanups (cleanup
);
15367 /* The mapped index file format is designed to be directly mmap()able
15368 on any architecture. In most cases, a datum is represented using a
15369 little-endian 32-bit integer value, called an offset_type. Big
15370 endian machines must byte-swap the values before using them.
15371 Exceptions to this rule are noted. The data is laid out such that
15372 alignment is always respected.
15374 A mapped index consists of several sections.
15376 1. The file header. This is a sequence of values, of offset_type
15377 unless otherwise noted:
15379 [0] The version number, currently 3. Versions 1 and 2 are
15381 [1] The offset, from the start of the file, of the CU list.
15382 [2] The offset, from the start of the file, of the types CU list.
15383 Note that this section can be empty, in which case this offset will
15384 be equal to the next offset.
15385 [3] The offset, from the start of the file, of the address section.
15386 [4] The offset, from the start of the file, of the symbol table.
15387 [5] The offset, from the start of the file, of the constant pool.
15389 2. The CU list. This is a sequence of pairs of 64-bit
15390 little-endian values, sorted by the CU offset. The first element
15391 in each pair is the offset of a CU in the .debug_info section. The
15392 second element in each pair is the length of that CU. References
15393 to a CU elsewhere in the map are done using a CU index, which is
15394 just the 0-based index into this table. Note that if there are
15395 type CUs, then conceptually CUs and type CUs form a single list for
15396 the purposes of CU indices.
15398 3. The types CU list. This is a sequence of triplets of 64-bit
15399 little-endian values. In a triplet, the first value is the CU
15400 offset, the second value is the type offset in the CU, and the
15401 third value is the type signature. The types CU list is not
15404 4. The address section. The address section consists of a sequence
15405 of address entries. Each address entry has three elements.
15406 [0] The low address. This is a 64-bit little-endian value.
15407 [1] The high address. This is a 64-bit little-endian value.
15408 [2] The CU index. This is an offset_type value.
15410 5. The symbol table. This is a hash table. The size of the hash
15411 table is always a power of 2. The initial hash and the step are
15412 currently defined by the `find_slot' function.
15414 Each slot in the hash table consists of a pair of offset_type
15415 values. The first value is the offset of the symbol's name in the
15416 constant pool. The second value is the offset of the CU vector in
15419 If both values are 0, then this slot in the hash table is empty.
15420 This is ok because while 0 is a valid constant pool index, it
15421 cannot be a valid index for both a string and a CU vector.
15423 A string in the constant pool is stored as a \0-terminated string,
15426 A CU vector in the constant pool is a sequence of offset_type
15427 values. The first value is the number of CU indices in the vector.
15428 Each subsequent value is the index of a CU in the CU list. This
15429 element in the hash table is used to indicate which CUs define the
15432 6. The constant pool. This is simply a bunch of bytes. It is
15433 organized so that alignment is correct: CU vectors are stored
15434 first, followed by strings. */
15437 save_gdb_index_command (char *arg
, int from_tty
)
15439 struct objfile
*objfile
;
15442 error (_("usage: save gdb-index DIRECTORY"));
15444 ALL_OBJFILES (objfile
)
15448 /* If the objfile does not correspond to an actual file, skip it. */
15449 if (stat (objfile
->name
, &st
) < 0)
15452 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15453 if (dwarf2_per_objfile
)
15455 volatile struct gdb_exception except
;
15457 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15459 write_psymtabs_to_index (objfile
, arg
);
15461 if (except
.reason
< 0)
15462 exception_fprintf (gdb_stderr
, except
,
15463 _("Error while writing index for `%s': "),
15471 int dwarf2_always_disassemble
;
15474 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15475 struct cmd_list_element
*c
, const char *value
)
15477 fprintf_filtered (file
, _("\
15478 Whether to always disassemble DWARF expressions is %s.\n"),
15482 void _initialize_dwarf2_read (void);
15485 _initialize_dwarf2_read (void)
15487 struct cmd_list_element
*c
;
15489 dwarf2_objfile_data_key
15490 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15492 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15493 Set DWARF 2 specific variables.\n\
15494 Configure DWARF 2 variables such as the cache size"),
15495 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15496 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15498 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15499 Show DWARF 2 specific variables\n\
15500 Show DWARF 2 variables such as the cache size"),
15501 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15502 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15504 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15505 &dwarf2_max_cache_age
, _("\
15506 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15507 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15508 A higher limit means that cached compilation units will be stored\n\
15509 in memory longer, and more total memory will be used. Zero disables\n\
15510 caching, which can slow down startup."),
15512 show_dwarf2_max_cache_age
,
15513 &set_dwarf2_cmdlist
,
15514 &show_dwarf2_cmdlist
);
15516 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15517 &dwarf2_always_disassemble
, _("\
15518 Set whether `info address' always disassembles DWARF expressions."), _("\
15519 Show whether `info address' always disassembles DWARF expressions."), _("\
15520 When enabled, DWARF expressions are always printed in an assembly-like\n\
15521 syntax. When disabled, expressions will be printed in a more\n\
15522 conversational style, when possible."),
15524 show_dwarf2_always_disassemble
,
15525 &set_dwarf2_cmdlist
,
15526 &show_dwarf2_cmdlist
);
15528 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15529 Set debugging of the dwarf2 DIE reader."), _("\
15530 Show debugging of the dwarf2 DIE reader."), _("\
15531 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15532 The value is the maximum depth to print."),
15535 &setdebuglist
, &showdebuglist
);
15537 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15539 Save a .gdb-index file.\n\
15540 Usage: save gdb-index DIRECTORY"),
15542 set_cmd_completer (c
, filename_completer
);