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 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1225 struct dwarf2_loclist_baton
*baton
,
1226 struct attribute
*attr
);
1228 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1230 struct dwarf2_cu
*cu
);
1232 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1233 struct abbrev_info
*abbrev
,
1234 struct dwarf2_cu
*cu
);
1236 static void free_stack_comp_unit (void *);
1238 static hashval_t
partial_die_hash (const void *item
);
1240 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1242 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1243 (unsigned int offset
, struct objfile
*objfile
);
1245 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1246 (unsigned int offset
, struct objfile
*objfile
);
1248 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1249 struct objfile
*objfile
);
1251 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1252 struct die_info
*comp_unit_die
);
1254 static void free_one_comp_unit (void *);
1256 static void free_cached_comp_units (void *);
1258 static void age_cached_comp_units (void);
1260 static void free_one_cached_comp_unit (void *);
1262 static struct type
*set_die_type (struct die_info
*, struct type
*,
1263 struct dwarf2_cu
*);
1265 static void create_all_comp_units (struct objfile
*);
1267 static int create_debug_types_hash_table (struct objfile
*objfile
);
1269 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1272 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1274 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1275 struct dwarf2_per_cu_data
*);
1277 static void dwarf2_mark (struct dwarf2_cu
*);
1279 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1281 static struct type
*get_die_type_at_offset (unsigned int,
1282 struct dwarf2_per_cu_data
*per_cu
);
1284 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1286 static void dwarf2_release_queue (void *dummy
);
1288 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1289 struct objfile
*objfile
);
1291 static void process_queue (struct objfile
*objfile
);
1293 static void find_file_and_directory (struct die_info
*die
,
1294 struct dwarf2_cu
*cu
,
1295 char **name
, char **comp_dir
);
1297 static char *file_full_name (int file
, struct line_header
*lh
,
1298 const char *comp_dir
);
1300 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1303 unsigned int buffer_size
,
1306 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1307 struct dwarf2_cu
*cu
);
1309 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1313 /* Convert VALUE between big- and little-endian. */
1315 byte_swap (offset_type value
)
1319 result
= (value
& 0xff) << 24;
1320 result
|= (value
& 0xff00) << 8;
1321 result
|= (value
& 0xff0000) >> 8;
1322 result
|= (value
& 0xff000000) >> 24;
1326 #define MAYBE_SWAP(V) byte_swap (V)
1329 #define MAYBE_SWAP(V) (V)
1330 #endif /* WORDS_BIGENDIAN */
1332 /* The suffix for an index file. */
1333 #define INDEX_SUFFIX ".gdb-index"
1335 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1336 struct dwarf2_cu
*cu
);
1338 /* Try to locate the sections we need for DWARF 2 debugging
1339 information and return true if we have enough to do something. */
1342 dwarf2_has_info (struct objfile
*objfile
)
1344 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1345 if (!dwarf2_per_objfile
)
1347 /* Initialize per-objfile state. */
1348 struct dwarf2_per_objfile
*data
1349 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1351 memset (data
, 0, sizeof (*data
));
1352 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1353 dwarf2_per_objfile
= data
;
1355 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1356 dwarf2_per_objfile
->objfile
= objfile
;
1358 return (dwarf2_per_objfile
->info
.asection
!= NULL
1359 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1362 /* When loading sections, we can either look for ".<name>", or for
1363 * ".z<name>", which indicates a compressed section. */
1366 section_is_p (const char *section_name
, const char *name
)
1368 return (section_name
[0] == '.'
1369 && (strcmp (section_name
+ 1, name
) == 0
1370 || (section_name
[1] == 'z'
1371 && strcmp (section_name
+ 2, name
) == 0)));
1374 /* This function is mapped across the sections and remembers the
1375 offset and size of each of the debugging sections we are interested
1379 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1381 if (section_is_p (sectp
->name
, INFO_SECTION
))
1383 dwarf2_per_objfile
->info
.asection
= sectp
;
1384 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1386 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1388 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1389 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1391 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1393 dwarf2_per_objfile
->line
.asection
= sectp
;
1394 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1396 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1398 dwarf2_per_objfile
->loc
.asection
= sectp
;
1399 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1401 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1403 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1404 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1406 else if (section_is_p (sectp
->name
, STR_SECTION
))
1408 dwarf2_per_objfile
->str
.asection
= sectp
;
1409 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1411 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1413 dwarf2_per_objfile
->frame
.asection
= sectp
;
1414 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1416 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1418 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1420 if (aflag
& SEC_HAS_CONTENTS
)
1422 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1423 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1426 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1428 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1429 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1431 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1433 dwarf2_per_objfile
->types
.asection
= sectp
;
1434 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1436 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1438 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1439 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1442 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1443 && bfd_section_vma (abfd
, sectp
) == 0)
1444 dwarf2_per_objfile
->has_section_at_zero
= 1;
1447 /* Decompress a section that was compressed using zlib. Store the
1448 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1451 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1452 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1454 bfd
*abfd
= objfile
->obfd
;
1456 error (_("Support for zlib-compressed DWARF data (from '%s') "
1457 "is disabled in this copy of GDB"),
1458 bfd_get_filename (abfd
));
1460 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1461 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1462 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1463 bfd_size_type uncompressed_size
;
1464 gdb_byte
*uncompressed_buffer
;
1467 int header_size
= 12;
1469 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1470 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1471 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1472 bfd_get_filename (abfd
));
1474 /* Read the zlib header. In this case, it should be "ZLIB" followed
1475 by the uncompressed section size, 8 bytes in big-endian order. */
1476 if (compressed_size
< header_size
1477 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1478 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1479 bfd_get_filename (abfd
));
1480 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1481 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1482 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1483 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1484 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1485 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1486 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1487 uncompressed_size
+= compressed_buffer
[11];
1489 /* It is possible the section consists of several compressed
1490 buffers concatenated together, so we uncompress in a loop. */
1494 strm
.avail_in
= compressed_size
- header_size
;
1495 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1496 strm
.avail_out
= uncompressed_size
;
1497 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1499 rc
= inflateInit (&strm
);
1500 while (strm
.avail_in
> 0)
1503 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1504 bfd_get_filename (abfd
), rc
);
1505 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1506 + (uncompressed_size
- strm
.avail_out
));
1507 rc
= inflate (&strm
, Z_FINISH
);
1508 if (rc
!= Z_STREAM_END
)
1509 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1510 bfd_get_filename (abfd
), rc
);
1511 rc
= inflateReset (&strm
);
1513 rc
= inflateEnd (&strm
);
1515 || strm
.avail_out
!= 0)
1516 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1517 bfd_get_filename (abfd
), rc
);
1519 do_cleanups (cleanup
);
1520 *outbuf
= uncompressed_buffer
;
1521 *outsize
= uncompressed_size
;
1525 /* Read the contents of the section SECTP from object file specified by
1526 OBJFILE, store info about the section into INFO.
1527 If the section is compressed, uncompress it before returning. */
1530 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1532 bfd
*abfd
= objfile
->obfd
;
1533 asection
*sectp
= info
->asection
;
1534 gdb_byte
*buf
, *retbuf
;
1535 unsigned char header
[4];
1539 info
->buffer
= NULL
;
1540 info
->was_mmapped
= 0;
1543 if (info
->asection
== NULL
|| info
->size
== 0)
1546 /* Check if the file has a 4-byte header indicating compression. */
1547 if (info
->size
> sizeof (header
)
1548 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1549 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1551 /* Upon decompression, update the buffer and its size. */
1552 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1554 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1562 pagesize
= getpagesize ();
1564 /* Only try to mmap sections which are large enough: we don't want to
1565 waste space due to fragmentation. Also, only try mmap for sections
1566 without relocations. */
1568 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1570 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1571 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1572 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1573 MAP_PRIVATE
, pg_offset
);
1575 if (retbuf
!= MAP_FAILED
)
1577 info
->was_mmapped
= 1;
1578 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1579 #if HAVE_POSIX_MADVISE
1580 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1587 /* If we get here, we are a normal, not-compressed section. */
1589 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1591 /* When debugging .o files, we may need to apply relocations; see
1592 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1593 We never compress sections in .o files, so we only need to
1594 try this when the section is not compressed. */
1595 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1598 info
->buffer
= retbuf
;
1602 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1603 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1604 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1605 bfd_get_filename (abfd
));
1608 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1612 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1613 asection
**sectp
, gdb_byte
**bufp
,
1614 bfd_size_type
*sizep
)
1616 struct dwarf2_per_objfile
*data
1617 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1618 struct dwarf2_section_info
*info
;
1620 /* We may see an objfile without any DWARF, in which case we just
1629 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1630 info
= &data
->eh_frame
;
1631 else if (section_is_p (section_name
, FRAME_SECTION
))
1632 info
= &data
->frame
;
1634 gdb_assert_not_reached ("unexpected section");
1636 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1637 /* We haven't read this section in yet. Do it now. */
1638 dwarf2_read_section (objfile
, info
);
1640 *sectp
= info
->asection
;
1641 *bufp
= info
->buffer
;
1642 *sizep
= info
->size
;
1647 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1651 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1652 struct dwarf2_per_cu_data
*per_cu
)
1654 struct cleanup
*back_to
;
1656 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1658 queue_comp_unit (per_cu
, objfile
);
1660 if (per_cu
->from_debug_types
)
1661 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1663 load_full_comp_unit (per_cu
, objfile
);
1665 process_queue (objfile
);
1667 /* Age the cache, releasing compilation units that have not
1668 been used recently. */
1669 age_cached_comp_units ();
1671 do_cleanups (back_to
);
1674 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1675 the objfile from which this CU came. Returns the resulting symbol
1678 static struct symtab
*
1679 dw2_instantiate_symtab (struct objfile
*objfile
,
1680 struct dwarf2_per_cu_data
*per_cu
)
1682 if (!per_cu
->v
.quick
->symtab
)
1684 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1685 increment_reading_symtab ();
1686 dw2_do_instantiate_symtab (objfile
, per_cu
);
1687 do_cleanups (back_to
);
1689 return per_cu
->v
.quick
->symtab
;
1692 /* Return the CU given its index. */
1694 static struct dwarf2_per_cu_data
*
1695 dw2_get_cu (int index
)
1697 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1699 index
-= dwarf2_per_objfile
->n_comp_units
;
1700 return dwarf2_per_objfile
->type_comp_units
[index
];
1702 return dwarf2_per_objfile
->all_comp_units
[index
];
1705 /* A helper function that knows how to read a 64-bit value in a way
1706 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1710 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1712 if (sizeof (ULONGEST
) < 8)
1716 /* Ignore the upper 4 bytes if they are all zero. */
1717 for (i
= 0; i
< 4; ++i
)
1718 if (bytes
[i
+ 4] != 0)
1721 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1724 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1728 /* Read the CU list from the mapped index, and use it to create all
1729 the CU objects for this objfile. Return 0 if something went wrong,
1730 1 if everything went ok. */
1733 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1734 offset_type cu_list_elements
)
1738 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1739 dwarf2_per_objfile
->all_comp_units
1740 = obstack_alloc (&objfile
->objfile_obstack
,
1741 dwarf2_per_objfile
->n_comp_units
1742 * sizeof (struct dwarf2_per_cu_data
*));
1744 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1746 struct dwarf2_per_cu_data
*the_cu
;
1747 ULONGEST offset
, length
;
1749 if (!extract_cu_value (cu_list
, &offset
)
1750 || !extract_cu_value (cu_list
+ 8, &length
))
1754 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1755 struct dwarf2_per_cu_data
);
1756 the_cu
->offset
= offset
;
1757 the_cu
->length
= length
;
1758 the_cu
->objfile
= objfile
;
1759 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1760 struct dwarf2_per_cu_quick_data
);
1761 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1767 /* Create the signatured type hash table from the index. */
1770 create_signatured_type_table_from_index (struct objfile
*objfile
,
1771 const gdb_byte
*bytes
,
1772 offset_type elements
)
1775 htab_t sig_types_hash
;
1777 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1778 dwarf2_per_objfile
->type_comp_units
1779 = obstack_alloc (&objfile
->objfile_obstack
,
1780 dwarf2_per_objfile
->n_type_comp_units
1781 * sizeof (struct dwarf2_per_cu_data
*));
1783 sig_types_hash
= allocate_signatured_type_table (objfile
);
1785 for (i
= 0; i
< elements
; i
+= 3)
1787 struct signatured_type
*type_sig
;
1788 ULONGEST offset
, type_offset
, signature
;
1791 if (!extract_cu_value (bytes
, &offset
)
1792 || !extract_cu_value (bytes
+ 8, &type_offset
))
1794 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1797 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1798 struct signatured_type
);
1799 type_sig
->signature
= signature
;
1800 type_sig
->offset
= offset
;
1801 type_sig
->type_offset
= type_offset
;
1802 type_sig
->per_cu
.from_debug_types
= 1;
1803 type_sig
->per_cu
.offset
= offset
;
1804 type_sig
->per_cu
.objfile
= objfile
;
1805 type_sig
->per_cu
.v
.quick
1806 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1807 struct dwarf2_per_cu_quick_data
);
1809 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1812 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1815 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1820 /* Read the address map data from the mapped index, and use it to
1821 populate the objfile's psymtabs_addrmap. */
1824 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1826 const gdb_byte
*iter
, *end
;
1827 struct obstack temp_obstack
;
1828 struct addrmap
*mutable_map
;
1829 struct cleanup
*cleanup
;
1832 obstack_init (&temp_obstack
);
1833 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1834 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1836 iter
= index
->address_table
;
1837 end
= iter
+ index
->address_table_size
;
1839 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1843 ULONGEST hi
, lo
, cu_index
;
1844 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1846 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1848 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1851 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1852 dw2_get_cu (cu_index
));
1855 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1856 &objfile
->objfile_obstack
);
1857 do_cleanups (cleanup
);
1860 /* The hash function for strings in the mapped index. This is the
1861 same as the hashtab.c hash function, but we keep a separate copy to
1862 maintain control over the implementation. This is necessary
1863 because the hash function is tied to the format of the mapped index
1867 mapped_index_string_hash (const void *p
)
1869 const unsigned char *str
= (const unsigned char *) p
;
1873 while ((c
= *str
++) != 0)
1874 r
= r
* 67 + c
- 113;
1879 /* Find a slot in the mapped index INDEX for the object named NAME.
1880 If NAME is found, set *VEC_OUT to point to the CU vector in the
1881 constant pool and return 1. If NAME cannot be found, return 0. */
1884 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1885 offset_type
**vec_out
)
1887 offset_type hash
= mapped_index_string_hash (name
);
1888 offset_type slot
, step
;
1890 slot
= hash
& (index
->symbol_table_slots
- 1);
1891 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
1895 /* Convert a slot number to an offset into the table. */
1896 offset_type i
= 2 * slot
;
1898 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
1901 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
1902 if (!strcmp (name
, str
))
1904 *vec_out
= (offset_type
*) (index
->constant_pool
1905 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
1909 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
1913 /* Read the index file. If everything went ok, initialize the "quick"
1914 elements of all the CUs and return 1. Otherwise, return 0. */
1917 dwarf2_read_index (struct objfile
*objfile
)
1920 struct mapped_index
*map
;
1921 offset_type
*metadata
;
1922 const gdb_byte
*cu_list
;
1923 const gdb_byte
*types_list
= NULL
;
1924 offset_type version
, cu_list_elements
;
1925 offset_type types_list_elements
= 0;
1928 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1929 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1932 /* Older elfutils strip versions could keep the section in the main
1933 executable while splitting it for the separate debug info file. */
1934 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
1935 & SEC_HAS_CONTENTS
) == 0)
1938 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1940 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1941 /* Version check. */
1942 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1943 /* Versions earlier than 3 emitted every copy of a psymbol. This
1944 causes the index to behave very poorly for certain requests. So,
1945 it seems better to just ignore such indices. */
1948 /* Indexes with higher version than the one supported by GDB may be no
1949 longer backward compatible. */
1953 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1954 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1956 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1959 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1960 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1964 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1965 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1966 - MAYBE_SWAP (metadata
[i
]))
1970 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1971 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1972 - MAYBE_SWAP (metadata
[i
]));
1975 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1976 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1977 - MAYBE_SWAP (metadata
[i
]))
1978 / (2 * sizeof (offset_type
)));
1981 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1983 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1986 if (types_list_elements
1987 && !create_signatured_type_table_from_index (objfile
, types_list
,
1988 types_list_elements
))
1991 create_addrmap_from_index (objfile
, map
);
1993 dwarf2_per_objfile
->index_table
= map
;
1994 dwarf2_per_objfile
->using_index
= 1;
1999 /* A helper for the "quick" functions which sets the global
2000 dwarf2_per_objfile according to OBJFILE. */
2003 dw2_setup (struct objfile
*objfile
)
2005 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2006 gdb_assert (dwarf2_per_objfile
);
2009 /* A helper for the "quick" functions which attempts to read the line
2010 table for THIS_CU. */
2013 dw2_require_line_header (struct objfile
*objfile
,
2014 struct dwarf2_per_cu_data
*this_cu
)
2016 bfd
*abfd
= objfile
->obfd
;
2017 struct line_header
*lh
= NULL
;
2018 struct attribute
*attr
;
2019 struct cleanup
*cleanups
;
2020 struct die_info
*comp_unit_die
;
2021 struct dwarf2_section_info
* sec
;
2022 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2023 int has_children
, i
;
2024 struct dwarf2_cu cu
;
2025 unsigned int bytes_read
, buffer_size
;
2026 struct die_reader_specs reader_specs
;
2027 char *name
, *comp_dir
;
2029 if (this_cu
->v
.quick
->read_lines
)
2031 this_cu
->v
.quick
->read_lines
= 1;
2033 init_one_comp_unit (&cu
, objfile
);
2034 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2036 if (this_cu
->from_debug_types
)
2037 sec
= &dwarf2_per_objfile
->types
;
2039 sec
= &dwarf2_per_objfile
->info
;
2040 dwarf2_read_section (objfile
, sec
);
2041 buffer_size
= sec
->size
;
2042 buffer
= sec
->buffer
;
2043 info_ptr
= buffer
+ this_cu
->offset
;
2044 beg_of_comp_unit
= info_ptr
;
2046 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2047 buffer
, buffer_size
,
2050 /* Complete the cu_header. */
2051 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2052 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2055 cu
.per_cu
= this_cu
;
2057 dwarf2_read_abbrevs (abfd
, &cu
);
2058 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2060 if (this_cu
->from_debug_types
)
2061 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2062 init_cu_die_reader (&reader_specs
, &cu
);
2063 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2066 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2069 unsigned int line_offset
= DW_UNSND (attr
);
2070 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2074 do_cleanups (cleanups
);
2078 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2080 this_cu
->v
.quick
->lines
= lh
;
2082 this_cu
->v
.quick
->file_names
2083 = obstack_alloc (&objfile
->objfile_obstack
,
2084 lh
->num_file_names
* sizeof (char *));
2085 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2086 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2088 do_cleanups (cleanups
);
2091 /* A helper for the "quick" functions which computes and caches the
2092 real path for a given file name from the line table.
2093 dw2_require_line_header must have been called before this is
2097 dw2_require_full_path (struct objfile
*objfile
,
2098 struct dwarf2_per_cu_data
*per_cu
,
2101 if (!per_cu
->v
.quick
->full_names
)
2102 per_cu
->v
.quick
->full_names
2103 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2104 per_cu
->v
.quick
->lines
->num_file_names
,
2107 if (!per_cu
->v
.quick
->full_names
[index
])
2108 per_cu
->v
.quick
->full_names
[index
]
2109 = gdb_realpath (per_cu
->v
.quick
->file_names
[index
]);
2111 return per_cu
->v
.quick
->full_names
[index
];
2114 static struct symtab
*
2115 dw2_find_last_source_symtab (struct objfile
*objfile
)
2118 dw2_setup (objfile
);
2119 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2120 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2124 dw2_forget_cached_source_info (struct objfile
*objfile
)
2128 dw2_setup (objfile
);
2129 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2130 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2132 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2134 if (per_cu
->v
.quick
->full_names
)
2138 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2140 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
2141 per_cu
->v
.quick
->full_names
[j
] = NULL
;
2148 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2149 const char *full_path
, const char *real_path
,
2150 struct symtab
**result
)
2153 int check_basename
= lbasename (name
) == name
;
2154 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2156 dw2_setup (objfile
);
2157 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2158 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2161 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2163 if (per_cu
->v
.quick
->symtab
)
2166 dw2_require_line_header (objfile
, per_cu
);
2167 if (!per_cu
->v
.quick
->lines
)
2170 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2172 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2174 if (FILENAME_CMP (name
, this_name
) == 0)
2176 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2180 if (check_basename
&& ! base_cu
2181 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2184 if (full_path
!= NULL
)
2186 const char *this_full_name
= dw2_require_full_path (objfile
,
2190 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2192 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2197 if (real_path
!= NULL
)
2199 const char *this_full_name
= dw2_require_full_path (objfile
,
2202 if (this_full_name
!= NULL
2203 && FILENAME_CMP (real_path
, this_full_name
) == 0)
2205 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2214 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2221 static struct symtab
*
2222 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2223 const char *name
, domain_enum domain
)
2225 /* We do all the work in the pre_expand_symtabs_matching hook
2230 /* A helper function that expands all symtabs that hold an object
2234 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2236 dw2_setup (objfile
);
2238 if (dwarf2_per_objfile
->index_table
)
2242 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2245 offset_type i
, len
= MAYBE_SWAP (*vec
);
2246 for (i
= 0; i
< len
; ++i
)
2248 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2249 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2251 dw2_instantiate_symtab (objfile
, per_cu
);
2258 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2259 int kind
, const char *name
,
2262 dw2_do_expand_symtabs_matching (objfile
, name
);
2266 dw2_print_stats (struct objfile
*objfile
)
2270 dw2_setup (objfile
);
2272 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2273 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2275 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2277 if (!per_cu
->v
.quick
->symtab
)
2280 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2284 dw2_dump (struct objfile
*objfile
)
2286 /* Nothing worth printing. */
2290 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2291 struct section_offsets
*delta
)
2293 /* There's nothing to relocate here. */
2297 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2298 const char *func_name
)
2300 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2304 dw2_expand_all_symtabs (struct objfile
*objfile
)
2308 dw2_setup (objfile
);
2310 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2311 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2313 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2315 dw2_instantiate_symtab (objfile
, per_cu
);
2320 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2321 const char *filename
)
2325 dw2_setup (objfile
);
2326 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2327 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2330 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2332 if (per_cu
->v
.quick
->symtab
)
2335 dw2_require_line_header (objfile
, per_cu
);
2336 if (!per_cu
->v
.quick
->lines
)
2339 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2341 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2342 if (strcmp (this_name
, filename
) == 0)
2344 dw2_instantiate_symtab (objfile
, per_cu
);
2352 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2354 struct dwarf2_per_cu_data
*per_cu
;
2357 dw2_setup (objfile
);
2359 if (!dwarf2_per_objfile
->index_table
)
2362 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2366 /* Note that this just looks at the very first one named NAME -- but
2367 actually we are looking for a function. find_main_filename
2368 should be rewritten so that it doesn't require a custom hook. It
2369 could just use the ordinary symbol tables. */
2370 /* vec[0] is the length, which must always be >0. */
2371 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2373 dw2_require_line_header (objfile
, per_cu
);
2374 if (!per_cu
->v
.quick
->lines
)
2377 return per_cu
->v
.quick
->file_names
[per_cu
->v
.quick
->lines
->num_file_names
- 1];
2381 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2382 struct objfile
*objfile
, int global
,
2383 int (*callback
) (struct block
*,
2384 struct symbol
*, void *),
2385 void *data
, symbol_compare_ftype
*match
,
2386 symbol_compare_ftype
*ordered_compare
)
2388 /* Currently unimplemented; used for Ada. The function can be called if the
2389 current language is Ada for a non-Ada objfile using GNU index. As Ada
2390 does not look for non-Ada symbols this function should just return. */
2394 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2395 int (*file_matcher
) (const char *, void *),
2396 int (*name_matcher
) (const char *, void *),
2402 struct mapped_index
*index
;
2404 dw2_setup (objfile
);
2405 if (!dwarf2_per_objfile
->index_table
)
2407 index
= dwarf2_per_objfile
->index_table
;
2409 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2410 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2413 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2415 per_cu
->v
.quick
->mark
= 0;
2416 if (per_cu
->v
.quick
->symtab
)
2419 dw2_require_line_header (objfile
, per_cu
);
2420 if (!per_cu
->v
.quick
->lines
)
2423 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2425 if (file_matcher (per_cu
->v
.quick
->file_names
[j
], data
))
2427 per_cu
->v
.quick
->mark
= 1;
2433 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2435 offset_type idx
= 2 * iter
;
2437 offset_type
*vec
, vec_len
, vec_idx
;
2439 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2442 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2444 if (! (*name_matcher
) (name
, data
))
2447 /* The name was matched, now expand corresponding CUs that were
2449 vec
= (offset_type
*) (index
->constant_pool
2450 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2451 vec_len
= MAYBE_SWAP (vec
[0]);
2452 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2454 struct dwarf2_per_cu_data
*per_cu
;
2456 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2457 if (per_cu
->v
.quick
->mark
)
2458 dw2_instantiate_symtab (objfile
, per_cu
);
2463 static struct symtab
*
2464 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2465 struct minimal_symbol
*msymbol
,
2467 struct obj_section
*section
,
2470 struct dwarf2_per_cu_data
*data
;
2472 dw2_setup (objfile
);
2474 if (!objfile
->psymtabs_addrmap
)
2477 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2481 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2482 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2483 paddress (get_objfile_arch (objfile
), pc
));
2485 return dw2_instantiate_symtab (objfile
, data
);
2489 dw2_map_symbol_names (struct objfile
*objfile
,
2490 void (*fun
) (const char *, void *),
2494 struct mapped_index
*index
;
2496 dw2_setup (objfile
);
2498 if (!dwarf2_per_objfile
->index_table
)
2500 index
= dwarf2_per_objfile
->index_table
;
2502 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2504 offset_type idx
= 2 * iter
;
2506 offset_type
*vec
, vec_len
, vec_idx
;
2508 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2511 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2513 (*fun
) (name
, data
);
2518 dw2_map_symbol_filenames (struct objfile
*objfile
,
2519 void (*fun
) (const char *, const char *, void *),
2524 dw2_setup (objfile
);
2525 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2526 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2529 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2531 if (per_cu
->v
.quick
->symtab
)
2534 dw2_require_line_header (objfile
, per_cu
);
2535 if (!per_cu
->v
.quick
->lines
)
2538 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2540 const char *this_full_name
= dw2_require_full_path (objfile
, per_cu
,
2542 (*fun
) (per_cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2548 dw2_has_symbols (struct objfile
*objfile
)
2553 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2556 dw2_find_last_source_symtab
,
2557 dw2_forget_cached_source_info
,
2560 dw2_pre_expand_symtabs_matching
,
2564 dw2_expand_symtabs_for_function
,
2565 dw2_expand_all_symtabs
,
2566 dw2_expand_symtabs_with_filename
,
2567 dw2_find_symbol_file
,
2568 dw2_map_matching_symbols
,
2569 dw2_expand_symtabs_matching
,
2570 dw2_find_pc_sect_symtab
,
2571 dw2_map_symbol_names
,
2572 dw2_map_symbol_filenames
2575 /* Initialize for reading DWARF for this objfile. Return 0 if this
2576 file will use psymtabs, or 1 if using the GNU index. */
2579 dwarf2_initialize_objfile (struct objfile
*objfile
)
2581 /* If we're about to read full symbols, don't bother with the
2582 indices. In this case we also don't care if some other debug
2583 format is making psymtabs, because they are all about to be
2585 if ((objfile
->flags
& OBJF_READNOW
))
2589 dwarf2_per_objfile
->using_index
= 1;
2590 create_all_comp_units (objfile
);
2591 create_debug_types_hash_table (objfile
);
2593 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2594 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2596 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2598 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2599 struct dwarf2_per_cu_quick_data
);
2602 /* Return 1 so that gdb sees the "quick" functions. However,
2603 these functions will be no-ops because we will have expanded
2608 if (dwarf2_read_index (objfile
))
2611 dwarf2_build_psymtabs (objfile
);
2617 /* Build a partial symbol table. */
2620 dwarf2_build_psymtabs (struct objfile
*objfile
)
2622 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2624 init_psymbol_list (objfile
, 1024);
2627 dwarf2_build_psymtabs_hard (objfile
);
2630 /* Return TRUE if OFFSET is within CU_HEADER. */
2633 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2635 unsigned int bottom
= cu_header
->offset
;
2636 unsigned int top
= (cu_header
->offset
2638 + cu_header
->initial_length_size
);
2640 return (offset
>= bottom
&& offset
< top
);
2643 /* Read in the comp unit header information from the debug_info at info_ptr.
2644 NOTE: This leaves members offset, first_die_offset to be filled in
2648 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2649 gdb_byte
*info_ptr
, bfd
*abfd
)
2652 unsigned int bytes_read
;
2654 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2655 cu_header
->initial_length_size
= bytes_read
;
2656 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2657 info_ptr
+= bytes_read
;
2658 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2660 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2662 info_ptr
+= bytes_read
;
2663 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2665 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2666 if (signed_addr
< 0)
2667 internal_error (__FILE__
, __LINE__
,
2668 _("read_comp_unit_head: dwarf from non elf file"));
2669 cu_header
->signed_addr_p
= signed_addr
;
2675 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2676 gdb_byte
*buffer
, unsigned int buffer_size
,
2679 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2681 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2683 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2684 error (_("Dwarf Error: wrong version in compilation unit header "
2685 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2686 bfd_get_filename (abfd
));
2688 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2689 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2690 "(offset 0x%lx + 6) [in module %s]"),
2691 (long) header
->abbrev_offset
,
2692 (long) (beg_of_comp_unit
- buffer
),
2693 bfd_get_filename (abfd
));
2695 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2696 > buffer
+ buffer_size
)
2697 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2698 "(offset 0x%lx + 0) [in module %s]"),
2699 (long) header
->length
,
2700 (long) (beg_of_comp_unit
- buffer
),
2701 bfd_get_filename (abfd
));
2706 /* Read in the types comp unit header information from .debug_types entry at
2707 types_ptr. The result is a pointer to one past the end of the header. */
2710 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2711 ULONGEST
*signature
,
2712 gdb_byte
*types_ptr
, bfd
*abfd
)
2714 gdb_byte
*initial_types_ptr
= types_ptr
;
2716 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2717 &dwarf2_per_objfile
->types
);
2718 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2720 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2722 *signature
= read_8_bytes (abfd
, types_ptr
);
2724 types_ptr
+= cu_header
->offset_size
;
2725 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2730 /* Allocate a new partial symtab for file named NAME and mark this new
2731 partial symtab as being an include of PST. */
2734 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2735 struct objfile
*objfile
)
2737 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2739 subpst
->section_offsets
= pst
->section_offsets
;
2740 subpst
->textlow
= 0;
2741 subpst
->texthigh
= 0;
2743 subpst
->dependencies
= (struct partial_symtab
**)
2744 obstack_alloc (&objfile
->objfile_obstack
,
2745 sizeof (struct partial_symtab
*));
2746 subpst
->dependencies
[0] = pst
;
2747 subpst
->number_of_dependencies
= 1;
2749 subpst
->globals_offset
= 0;
2750 subpst
->n_global_syms
= 0;
2751 subpst
->statics_offset
= 0;
2752 subpst
->n_static_syms
= 0;
2753 subpst
->symtab
= NULL
;
2754 subpst
->read_symtab
= pst
->read_symtab
;
2757 /* No private part is necessary for include psymtabs. This property
2758 can be used to differentiate between such include psymtabs and
2759 the regular ones. */
2760 subpst
->read_symtab_private
= NULL
;
2763 /* Read the Line Number Program data and extract the list of files
2764 included by the source file represented by PST. Build an include
2765 partial symtab for each of these included files. */
2768 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2769 struct die_info
*die
,
2770 struct partial_symtab
*pst
)
2772 struct objfile
*objfile
= cu
->objfile
;
2773 bfd
*abfd
= objfile
->obfd
;
2774 struct line_header
*lh
= NULL
;
2775 struct attribute
*attr
;
2777 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2780 unsigned int line_offset
= DW_UNSND (attr
);
2782 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2785 return; /* No linetable, so no includes. */
2787 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2788 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2790 free_line_header (lh
);
2794 hash_type_signature (const void *item
)
2796 const struct signatured_type
*type_sig
= item
;
2798 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2799 return type_sig
->signature
;
2803 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2805 const struct signatured_type
*lhs
= item_lhs
;
2806 const struct signatured_type
*rhs
= item_rhs
;
2808 return lhs
->signature
== rhs
->signature
;
2811 /* Allocate a hash table for signatured types. */
2814 allocate_signatured_type_table (struct objfile
*objfile
)
2816 return htab_create_alloc_ex (41,
2817 hash_type_signature
,
2820 &objfile
->objfile_obstack
,
2821 hashtab_obstack_allocate
,
2822 dummy_obstack_deallocate
);
2825 /* A helper function to add a signatured type CU to a list. */
2828 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2830 struct signatured_type
*sigt
= *slot
;
2831 struct dwarf2_per_cu_data
***datap
= datum
;
2833 **datap
= &sigt
->per_cu
;
2839 /* Create the hash table of all entries in the .debug_types section.
2840 The result is zero if there is an error (e.g. missing .debug_types section),
2841 otherwise non-zero. */
2844 create_debug_types_hash_table (struct objfile
*objfile
)
2848 struct dwarf2_per_cu_data
**iter
;
2850 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2851 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2853 if (info_ptr
== NULL
)
2855 dwarf2_per_objfile
->signatured_types
= NULL
;
2859 types_htab
= allocate_signatured_type_table (objfile
);
2861 if (dwarf2_die_debug
)
2862 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2864 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2866 unsigned int offset
;
2867 unsigned int offset_size
;
2868 unsigned int type_offset
;
2869 unsigned int length
, initial_length_size
;
2870 unsigned short version
;
2872 struct signatured_type
*type_sig
;
2874 gdb_byte
*ptr
= info_ptr
;
2876 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2878 /* We need to read the type's signature in order to build the hash
2879 table, but we don't need to read anything else just yet. */
2881 /* Sanity check to ensure entire cu is present. */
2882 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2883 if (ptr
+ length
+ initial_length_size
2884 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2886 complaint (&symfile_complaints
,
2887 _("debug type entry runs off end of `.debug_types' section, ignored"));
2891 offset_size
= initial_length_size
== 4 ? 4 : 8;
2892 ptr
+= initial_length_size
;
2893 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2895 ptr
+= offset_size
; /* abbrev offset */
2896 ptr
+= 1; /* address size */
2897 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2899 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2901 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2902 memset (type_sig
, 0, sizeof (*type_sig
));
2903 type_sig
->signature
= signature
;
2904 type_sig
->offset
= offset
;
2905 type_sig
->type_offset
= type_offset
;
2906 type_sig
->per_cu
.objfile
= objfile
;
2907 type_sig
->per_cu
.from_debug_types
= 1;
2909 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2910 gdb_assert (slot
!= NULL
);
2913 if (dwarf2_die_debug
)
2914 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2915 offset
, phex (signature
, sizeof (signature
)));
2917 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2920 dwarf2_per_objfile
->signatured_types
= types_htab
;
2922 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2923 dwarf2_per_objfile
->type_comp_units
2924 = obstack_alloc (&objfile
->objfile_obstack
,
2925 dwarf2_per_objfile
->n_type_comp_units
2926 * sizeof (struct dwarf2_per_cu_data
*));
2927 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2928 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2929 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2930 == dwarf2_per_objfile
->n_type_comp_units
);
2935 /* Lookup a signature based type.
2936 Returns NULL if SIG is not present in the table. */
2938 static struct signatured_type
*
2939 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2941 struct signatured_type find_entry
, *entry
;
2943 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2945 complaint (&symfile_complaints
,
2946 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2950 find_entry
.signature
= sig
;
2951 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2955 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2958 init_cu_die_reader (struct die_reader_specs
*reader
,
2959 struct dwarf2_cu
*cu
)
2961 reader
->abfd
= cu
->objfile
->obfd
;
2963 if (cu
->per_cu
->from_debug_types
)
2965 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2966 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2970 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2971 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2975 /* Find the base address of the compilation unit for range lists and
2976 location lists. It will normally be specified by DW_AT_low_pc.
2977 In DWARF-3 draft 4, the base address could be overridden by
2978 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2979 compilation units with discontinuous ranges. */
2982 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2984 struct attribute
*attr
;
2987 cu
->base_address
= 0;
2989 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2992 cu
->base_address
= DW_ADDR (attr
);
2997 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3000 cu
->base_address
= DW_ADDR (attr
);
3006 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3007 to combine the common parts.
3008 Process a compilation unit for a psymtab.
3009 BUFFER is a pointer to the beginning of the dwarf section buffer,
3010 either .debug_info or debug_types.
3011 INFO_PTR is a pointer to the start of the CU.
3012 Returns a pointer to the next CU. */
3015 process_psymtab_comp_unit (struct objfile
*objfile
,
3016 struct dwarf2_per_cu_data
*this_cu
,
3017 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3018 unsigned int buffer_size
)
3020 bfd
*abfd
= objfile
->obfd
;
3021 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3022 struct die_info
*comp_unit_die
;
3023 struct partial_symtab
*pst
;
3025 struct cleanup
*back_to_inner
;
3026 struct dwarf2_cu cu
;
3027 int has_children
, has_pc_info
;
3028 struct attribute
*attr
;
3029 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3030 struct die_reader_specs reader_specs
;
3032 init_one_comp_unit (&cu
, objfile
);
3033 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3035 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3036 buffer
, buffer_size
,
3039 /* Complete the cu_header. */
3040 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3041 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3043 cu
.list_in_scope
= &file_symbols
;
3045 /* If this compilation unit was already read in, free the
3046 cached copy in order to read it in again. This is
3047 necessary because we skipped some symbols when we first
3048 read in the compilation unit (see load_partial_dies).
3049 This problem could be avoided, but the benefit is
3051 if (this_cu
->cu
!= NULL
)
3052 free_one_cached_comp_unit (this_cu
->cu
);
3054 /* Note that this is a pointer to our stack frame, being
3055 added to a global data structure. It will be cleaned up
3056 in free_stack_comp_unit when we finish with this
3057 compilation unit. */
3059 cu
.per_cu
= this_cu
;
3061 /* Read the abbrevs for this compilation unit into a table. */
3062 dwarf2_read_abbrevs (abfd
, &cu
);
3063 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3065 /* Read the compilation unit die. */
3066 if (this_cu
->from_debug_types
)
3067 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3068 init_cu_die_reader (&reader_specs
, &cu
);
3069 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3072 if (this_cu
->from_debug_types
)
3074 /* offset,length haven't been set yet for type units. */
3075 this_cu
->offset
= cu
.header
.offset
;
3076 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3078 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3080 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3081 + cu
.header
.initial_length_size
);
3082 do_cleanups (back_to_inner
);
3086 prepare_one_comp_unit (&cu
, comp_unit_die
);
3088 /* Allocate a new partial symbol table structure. */
3089 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3090 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3091 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3092 /* TEXTLOW and TEXTHIGH are set below. */
3094 objfile
->global_psymbols
.next
,
3095 objfile
->static_psymbols
.next
);
3097 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3099 pst
->dirname
= DW_STRING (attr
);
3101 pst
->read_symtab_private
= this_cu
;
3103 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3105 /* Store the function that reads in the rest of the symbol table */
3106 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3108 this_cu
->v
.psymtab
= pst
;
3110 dwarf2_find_base_address (comp_unit_die
, &cu
);
3112 /* Possibly set the default values of LOWPC and HIGHPC from
3114 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3115 &best_highpc
, &cu
, pst
);
3116 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3117 /* Store the contiguous range if it is not empty; it can be empty for
3118 CUs with no code. */
3119 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3120 best_lowpc
+ baseaddr
,
3121 best_highpc
+ baseaddr
- 1, pst
);
3123 /* Check if comp unit has_children.
3124 If so, read the rest of the partial symbols from this comp unit.
3125 If not, there's no more debug_info for this comp unit. */
3128 struct partial_die_info
*first_die
;
3129 CORE_ADDR lowpc
, highpc
;
3131 lowpc
= ((CORE_ADDR
) -1);
3132 highpc
= ((CORE_ADDR
) 0);
3134 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3136 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3137 ! has_pc_info
, &cu
);
3139 /* If we didn't find a lowpc, set it to highpc to avoid
3140 complaints from `maint check'. */
3141 if (lowpc
== ((CORE_ADDR
) -1))
3144 /* If the compilation unit didn't have an explicit address range,
3145 then use the information extracted from its child dies. */
3149 best_highpc
= highpc
;
3152 pst
->textlow
= best_lowpc
+ baseaddr
;
3153 pst
->texthigh
= best_highpc
+ baseaddr
;
3155 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3156 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3157 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3158 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3159 sort_pst_symbols (pst
);
3161 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3162 + cu
.header
.initial_length_size
);
3164 if (this_cu
->from_debug_types
)
3166 /* It's not clear we want to do anything with stmt lists here.
3167 Waiting to see what gcc ultimately does. */
3171 /* Get the list of files included in the current compilation unit,
3172 and build a psymtab for each of them. */
3173 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3176 do_cleanups (back_to_inner
);
3181 /* Traversal function for htab_traverse_noresize.
3182 Process one .debug_types comp-unit. */
3185 process_type_comp_unit (void **slot
, void *info
)
3187 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3188 struct objfile
*objfile
= (struct objfile
*) info
;
3189 struct dwarf2_per_cu_data
*this_cu
;
3191 this_cu
= &entry
->per_cu
;
3193 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3194 process_psymtab_comp_unit (objfile
, this_cu
,
3195 dwarf2_per_objfile
->types
.buffer
,
3196 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3197 dwarf2_per_objfile
->types
.size
);
3202 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3203 Build partial symbol tables for the .debug_types comp-units. */
3206 build_type_psymtabs (struct objfile
*objfile
)
3208 if (! create_debug_types_hash_table (objfile
))
3211 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3212 process_type_comp_unit
, objfile
);
3215 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3218 psymtabs_addrmap_cleanup (void *o
)
3220 struct objfile
*objfile
= o
;
3222 objfile
->psymtabs_addrmap
= NULL
;
3225 /* Build the partial symbol table by doing a quick pass through the
3226 .debug_info and .debug_abbrev sections. */
3229 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3232 struct cleanup
*back_to
, *addrmap_cleanup
;
3233 struct obstack temp_obstack
;
3235 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3237 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3238 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3240 /* Any cached compilation units will be linked by the per-objfile
3241 read_in_chain. Make sure to free them when we're done. */
3242 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3244 build_type_psymtabs (objfile
);
3246 create_all_comp_units (objfile
);
3248 /* Create a temporary address map on a temporary obstack. We later
3249 copy this to the final obstack. */
3250 obstack_init (&temp_obstack
);
3251 make_cleanup_obstack_free (&temp_obstack
);
3252 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3253 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3255 /* Since the objects we're extracting from .debug_info vary in
3256 length, only the individual functions to extract them (like
3257 read_comp_unit_head and load_partial_die) can really know whether
3258 the buffer is large enough to hold another complete object.
3260 At the moment, they don't actually check that. If .debug_info
3261 holds just one extra byte after the last compilation unit's dies,
3262 then read_comp_unit_head will happily read off the end of the
3263 buffer. read_partial_die is similarly casual. Those functions
3266 For this loop condition, simply checking whether there's any data
3267 left at all should be sufficient. */
3269 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3270 + dwarf2_per_objfile
->info
.size
))
3272 struct dwarf2_per_cu_data
*this_cu
;
3274 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3277 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3278 dwarf2_per_objfile
->info
.buffer
,
3280 dwarf2_per_objfile
->info
.size
);
3283 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3284 &objfile
->objfile_obstack
);
3285 discard_cleanups (addrmap_cleanup
);
3287 do_cleanups (back_to
);
3290 /* Load the partial DIEs for a secondary CU into memory. */
3293 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3294 struct objfile
*objfile
)
3296 bfd
*abfd
= objfile
->obfd
;
3297 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3298 struct die_info
*comp_unit_die
;
3299 struct dwarf2_cu
*cu
;
3300 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3302 struct die_reader_specs reader_specs
;
3305 gdb_assert (! this_cu
->from_debug_types
);
3307 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3308 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3309 beg_of_comp_unit
= info_ptr
;
3311 if (this_cu
->cu
== NULL
)
3313 cu
= xmalloc (sizeof (*cu
));
3314 init_one_comp_unit (cu
, objfile
);
3318 /* If an error occurs while loading, release our storage. */
3319 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3321 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3322 dwarf2_per_objfile
->info
.buffer
,
3323 dwarf2_per_objfile
->info
.size
,
3326 /* Complete the cu_header. */
3327 cu
->header
.offset
= this_cu
->offset
;
3328 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3330 /* Link this compilation unit into the compilation unit tree. */
3332 cu
->per_cu
= this_cu
;
3334 /* Link this CU into read_in_chain. */
3335 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3336 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3341 info_ptr
+= cu
->header
.first_die_offset
;
3344 /* Read the abbrevs for this compilation unit into a table. */
3345 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3346 dwarf2_read_abbrevs (abfd
, cu
);
3347 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3349 /* Read the compilation unit die. */
3350 init_cu_die_reader (&reader_specs
, cu
);
3351 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3354 prepare_one_comp_unit (cu
, comp_unit_die
);
3356 /* Check if comp unit has_children.
3357 If so, read the rest of the partial symbols from this comp unit.
3358 If not, there's no more debug_info for this comp unit. */
3360 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3362 do_cleanups (free_abbrevs_cleanup
);
3366 /* We've successfully allocated this compilation unit. Let our
3367 caller clean it up when finished with it. */
3368 discard_cleanups (free_cu_cleanup
);
3372 /* Create a list of all compilation units in OBJFILE. We do this only
3373 if an inter-comp-unit reference is found; presumably if there is one,
3374 there will be many, and one will occur early in the .debug_info section.
3375 So there's no point in building this list incrementally. */
3378 create_all_comp_units (struct objfile
*objfile
)
3382 struct dwarf2_per_cu_data
**all_comp_units
;
3385 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3386 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3390 all_comp_units
= xmalloc (n_allocated
3391 * sizeof (struct dwarf2_per_cu_data
*));
3393 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3395 unsigned int length
, initial_length_size
;
3396 struct dwarf2_per_cu_data
*this_cu
;
3397 unsigned int offset
;
3399 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3401 /* Read just enough information to find out where the next
3402 compilation unit is. */
3403 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3404 &initial_length_size
);
3406 /* Save the compilation unit for later lookup. */
3407 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3408 sizeof (struct dwarf2_per_cu_data
));
3409 memset (this_cu
, 0, sizeof (*this_cu
));
3410 this_cu
->offset
= offset
;
3411 this_cu
->length
= length
+ initial_length_size
;
3412 this_cu
->objfile
= objfile
;
3414 if (n_comp_units
== n_allocated
)
3417 all_comp_units
= xrealloc (all_comp_units
,
3419 * sizeof (struct dwarf2_per_cu_data
*));
3421 all_comp_units
[n_comp_units
++] = this_cu
;
3423 info_ptr
= info_ptr
+ this_cu
->length
;
3426 dwarf2_per_objfile
->all_comp_units
3427 = obstack_alloc (&objfile
->objfile_obstack
,
3428 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3429 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3430 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3431 xfree (all_comp_units
);
3432 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3435 /* Process all loaded DIEs for compilation unit CU, starting at
3436 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3437 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3438 DW_AT_ranges). If NEED_PC is set, then this function will set
3439 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3440 and record the covered ranges in the addrmap. */
3443 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3444 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3446 struct partial_die_info
*pdi
;
3448 /* Now, march along the PDI's, descending into ones which have
3449 interesting children but skipping the children of the other ones,
3450 until we reach the end of the compilation unit. */
3456 fixup_partial_die (pdi
, cu
);
3458 /* Anonymous namespaces or modules have no name but have interesting
3459 children, so we need to look at them. Ditto for anonymous
3462 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3463 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3467 case DW_TAG_subprogram
:
3468 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3470 case DW_TAG_constant
:
3471 case DW_TAG_variable
:
3472 case DW_TAG_typedef
:
3473 case DW_TAG_union_type
:
3474 if (!pdi
->is_declaration
)
3476 add_partial_symbol (pdi
, cu
);
3479 case DW_TAG_class_type
:
3480 case DW_TAG_interface_type
:
3481 case DW_TAG_structure_type
:
3482 if (!pdi
->is_declaration
)
3484 add_partial_symbol (pdi
, cu
);
3487 case DW_TAG_enumeration_type
:
3488 if (!pdi
->is_declaration
)
3489 add_partial_enumeration (pdi
, cu
);
3491 case DW_TAG_base_type
:
3492 case DW_TAG_subrange_type
:
3493 /* File scope base type definitions are added to the partial
3495 add_partial_symbol (pdi
, cu
);
3497 case DW_TAG_namespace
:
3498 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3501 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3508 /* If the die has a sibling, skip to the sibling. */
3510 pdi
= pdi
->die_sibling
;
3514 /* Functions used to compute the fully scoped name of a partial DIE.
3516 Normally, this is simple. For C++, the parent DIE's fully scoped
3517 name is concatenated with "::" and the partial DIE's name. For
3518 Java, the same thing occurs except that "." is used instead of "::".
3519 Enumerators are an exception; they use the scope of their parent
3520 enumeration type, i.e. the name of the enumeration type is not
3521 prepended to the enumerator.
3523 There are two complexities. One is DW_AT_specification; in this
3524 case "parent" means the parent of the target of the specification,
3525 instead of the direct parent of the DIE. The other is compilers
3526 which do not emit DW_TAG_namespace; in this case we try to guess
3527 the fully qualified name of structure types from their members'
3528 linkage names. This must be done using the DIE's children rather
3529 than the children of any DW_AT_specification target. We only need
3530 to do this for structures at the top level, i.e. if the target of
3531 any DW_AT_specification (if any; otherwise the DIE itself) does not
3534 /* Compute the scope prefix associated with PDI's parent, in
3535 compilation unit CU. The result will be allocated on CU's
3536 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3537 field. NULL is returned if no prefix is necessary. */
3539 partial_die_parent_scope (struct partial_die_info
*pdi
,
3540 struct dwarf2_cu
*cu
)
3542 char *grandparent_scope
;
3543 struct partial_die_info
*parent
, *real_pdi
;
3545 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3546 then this means the parent of the specification DIE. */
3549 while (real_pdi
->has_specification
)
3550 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3552 parent
= real_pdi
->die_parent
;
3556 if (parent
->scope_set
)
3557 return parent
->scope
;
3559 fixup_partial_die (parent
, cu
);
3561 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3563 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3564 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3565 Work around this problem here. */
3566 if (cu
->language
== language_cplus
3567 && parent
->tag
== DW_TAG_namespace
3568 && strcmp (parent
->name
, "::") == 0
3569 && grandparent_scope
== NULL
)
3571 parent
->scope
= NULL
;
3572 parent
->scope_set
= 1;
3576 if (parent
->tag
== DW_TAG_namespace
3577 || parent
->tag
== DW_TAG_module
3578 || parent
->tag
== DW_TAG_structure_type
3579 || parent
->tag
== DW_TAG_class_type
3580 || parent
->tag
== DW_TAG_interface_type
3581 || parent
->tag
== DW_TAG_union_type
3582 || parent
->tag
== DW_TAG_enumeration_type
)
3584 if (grandparent_scope
== NULL
)
3585 parent
->scope
= parent
->name
;
3587 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3588 parent
->name
, 0, cu
);
3590 else if (parent
->tag
== DW_TAG_enumerator
)
3591 /* Enumerators should not get the name of the enumeration as a prefix. */
3592 parent
->scope
= grandparent_scope
;
3595 /* FIXME drow/2004-04-01: What should we be doing with
3596 function-local names? For partial symbols, we should probably be
3598 complaint (&symfile_complaints
,
3599 _("unhandled containing DIE tag %d for DIE at %d"),
3600 parent
->tag
, pdi
->offset
);
3601 parent
->scope
= grandparent_scope
;
3604 parent
->scope_set
= 1;
3605 return parent
->scope
;
3608 /* Return the fully scoped name associated with PDI, from compilation unit
3609 CU. The result will be allocated with malloc. */
3611 partial_die_full_name (struct partial_die_info
*pdi
,
3612 struct dwarf2_cu
*cu
)
3616 /* If this is a template instantiation, we can not work out the
3617 template arguments from partial DIEs. So, unfortunately, we have
3618 to go through the full DIEs. At least any work we do building
3619 types here will be reused if full symbols are loaded later. */
3620 if (pdi
->has_template_arguments
)
3622 fixup_partial_die (pdi
, cu
);
3624 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3626 struct die_info
*die
;
3627 struct attribute attr
;
3628 struct dwarf2_cu
*ref_cu
= cu
;
3631 attr
.form
= DW_FORM_ref_addr
;
3632 attr
.u
.addr
= pdi
->offset
;
3633 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3635 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3639 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3640 if (parent_scope
== NULL
)
3643 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3647 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3649 struct objfile
*objfile
= cu
->objfile
;
3651 char *actual_name
= NULL
;
3652 const struct partial_symbol
*psym
= NULL
;
3654 int built_actual_name
= 0;
3656 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3658 actual_name
= partial_die_full_name (pdi
, cu
);
3660 built_actual_name
= 1;
3662 if (actual_name
== NULL
)
3663 actual_name
= pdi
->name
;
3667 case DW_TAG_subprogram
:
3668 if (pdi
->is_external
|| cu
->language
== language_ada
)
3670 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3671 of the global scope. But in Ada, we want to be able to access
3672 nested procedures globally. So all Ada subprograms are stored
3673 in the global scope. */
3674 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3675 mst_text, objfile); */
3676 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3678 VAR_DOMAIN
, LOC_BLOCK
,
3679 &objfile
->global_psymbols
,
3680 0, pdi
->lowpc
+ baseaddr
,
3681 cu
->language
, objfile
);
3685 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3686 mst_file_text, objfile); */
3687 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3689 VAR_DOMAIN
, LOC_BLOCK
,
3690 &objfile
->static_psymbols
,
3691 0, pdi
->lowpc
+ baseaddr
,
3692 cu
->language
, objfile
);
3695 case DW_TAG_constant
:
3697 struct psymbol_allocation_list
*list
;
3699 if (pdi
->is_external
)
3700 list
= &objfile
->global_psymbols
;
3702 list
= &objfile
->static_psymbols
;
3703 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3704 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3705 list
, 0, 0, cu
->language
, objfile
);
3709 case DW_TAG_variable
:
3711 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3715 && !dwarf2_per_objfile
->has_section_at_zero
)
3717 /* A global or static variable may also have been stripped
3718 out by the linker if unused, in which case its address
3719 will be nullified; do not add such variables into partial
3720 symbol table then. */
3722 else if (pdi
->is_external
)
3725 Don't enter into the minimal symbol tables as there is
3726 a minimal symbol table entry from the ELF symbols already.
3727 Enter into partial symbol table if it has a location
3728 descriptor or a type.
3729 If the location descriptor is missing, new_symbol will create
3730 a LOC_UNRESOLVED symbol, the address of the variable will then
3731 be determined from the minimal symbol table whenever the variable
3733 The address for the partial symbol table entry is not
3734 used by GDB, but it comes in handy for debugging partial symbol
3737 if (pdi
->locdesc
|| pdi
->has_type
)
3738 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3740 VAR_DOMAIN
, LOC_STATIC
,
3741 &objfile
->global_psymbols
,
3743 cu
->language
, objfile
);
3747 /* Static Variable. Skip symbols without location descriptors. */
3748 if (pdi
->locdesc
== NULL
)
3750 if (built_actual_name
)
3751 xfree (actual_name
);
3754 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3755 mst_file_data, objfile); */
3756 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3758 VAR_DOMAIN
, LOC_STATIC
,
3759 &objfile
->static_psymbols
,
3761 cu
->language
, objfile
);
3764 case DW_TAG_typedef
:
3765 case DW_TAG_base_type
:
3766 case DW_TAG_subrange_type
:
3767 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3769 VAR_DOMAIN
, LOC_TYPEDEF
,
3770 &objfile
->static_psymbols
,
3771 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3773 case DW_TAG_namespace
:
3774 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3776 VAR_DOMAIN
, LOC_TYPEDEF
,
3777 &objfile
->global_psymbols
,
3778 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3780 case DW_TAG_class_type
:
3781 case DW_TAG_interface_type
:
3782 case DW_TAG_structure_type
:
3783 case DW_TAG_union_type
:
3784 case DW_TAG_enumeration_type
:
3785 /* Skip external references. The DWARF standard says in the section
3786 about "Structure, Union, and Class Type Entries": "An incomplete
3787 structure, union or class type is represented by a structure,
3788 union or class entry that does not have a byte size attribute
3789 and that has a DW_AT_declaration attribute." */
3790 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3792 if (built_actual_name
)
3793 xfree (actual_name
);
3797 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3798 static vs. global. */
3799 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3801 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3802 (cu
->language
== language_cplus
3803 || cu
->language
== language_java
)
3804 ? &objfile
->global_psymbols
3805 : &objfile
->static_psymbols
,
3806 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3809 case DW_TAG_enumerator
:
3810 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3812 VAR_DOMAIN
, LOC_CONST
,
3813 (cu
->language
== language_cplus
3814 || cu
->language
== language_java
)
3815 ? &objfile
->global_psymbols
3816 : &objfile
->static_psymbols
,
3817 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3823 if (built_actual_name
)
3824 xfree (actual_name
);
3827 /* Read a partial die corresponding to a namespace; also, add a symbol
3828 corresponding to that namespace to the symbol table. NAMESPACE is
3829 the name of the enclosing namespace. */
3832 add_partial_namespace (struct partial_die_info
*pdi
,
3833 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3834 int need_pc
, struct dwarf2_cu
*cu
)
3836 /* Add a symbol for the namespace. */
3838 add_partial_symbol (pdi
, cu
);
3840 /* Now scan partial symbols in that namespace. */
3842 if (pdi
->has_children
)
3843 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3846 /* Read a partial die corresponding to a Fortran module. */
3849 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3850 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3852 /* Now scan partial symbols in that module. */
3854 if (pdi
->has_children
)
3855 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3858 /* Read a partial die corresponding to a subprogram and create a partial
3859 symbol for that subprogram. When the CU language allows it, this
3860 routine also defines a partial symbol for each nested subprogram
3861 that this subprogram contains.
3863 DIE my also be a lexical block, in which case we simply search
3864 recursively for suprograms defined inside that lexical block.
3865 Again, this is only performed when the CU language allows this
3866 type of definitions. */
3869 add_partial_subprogram (struct partial_die_info
*pdi
,
3870 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3871 int need_pc
, struct dwarf2_cu
*cu
)
3873 if (pdi
->tag
== DW_TAG_subprogram
)
3875 if (pdi
->has_pc_info
)
3877 if (pdi
->lowpc
< *lowpc
)
3878 *lowpc
= pdi
->lowpc
;
3879 if (pdi
->highpc
> *highpc
)
3880 *highpc
= pdi
->highpc
;
3884 struct objfile
*objfile
= cu
->objfile
;
3886 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3887 SECT_OFF_TEXT (objfile
));
3888 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3889 pdi
->lowpc
+ baseaddr
,
3890 pdi
->highpc
- 1 + baseaddr
,
3891 cu
->per_cu
->v
.psymtab
);
3893 if (!pdi
->is_declaration
)
3894 /* Ignore subprogram DIEs that do not have a name, they are
3895 illegal. Do not emit a complaint at this point, we will
3896 do so when we convert this psymtab into a symtab. */
3898 add_partial_symbol (pdi
, cu
);
3902 if (! pdi
->has_children
)
3905 if (cu
->language
== language_ada
)
3907 pdi
= pdi
->die_child
;
3910 fixup_partial_die (pdi
, cu
);
3911 if (pdi
->tag
== DW_TAG_subprogram
3912 || pdi
->tag
== DW_TAG_lexical_block
)
3913 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3914 pdi
= pdi
->die_sibling
;
3919 /* Read a partial die corresponding to an enumeration type. */
3922 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3923 struct dwarf2_cu
*cu
)
3925 struct partial_die_info
*pdi
;
3927 if (enum_pdi
->name
!= NULL
)
3928 add_partial_symbol (enum_pdi
, cu
);
3930 pdi
= enum_pdi
->die_child
;
3933 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3934 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3936 add_partial_symbol (pdi
, cu
);
3937 pdi
= pdi
->die_sibling
;
3941 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3942 Return the corresponding abbrev, or NULL if the number is zero (indicating
3943 an empty DIE). In either case *BYTES_READ will be set to the length of
3944 the initial number. */
3946 static struct abbrev_info
*
3947 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3948 struct dwarf2_cu
*cu
)
3950 bfd
*abfd
= cu
->objfile
->obfd
;
3951 unsigned int abbrev_number
;
3952 struct abbrev_info
*abbrev
;
3954 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3956 if (abbrev_number
== 0)
3959 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3962 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3963 bfd_get_filename (abfd
));
3969 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3970 Returns a pointer to the end of a series of DIEs, terminated by an empty
3971 DIE. Any children of the skipped DIEs will also be skipped. */
3974 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3976 struct abbrev_info
*abbrev
;
3977 unsigned int bytes_read
;
3981 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3983 return info_ptr
+ bytes_read
;
3985 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3989 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3990 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3991 abbrev corresponding to that skipped uleb128 should be passed in
3992 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3996 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3997 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
3999 unsigned int bytes_read
;
4000 struct attribute attr
;
4001 bfd
*abfd
= cu
->objfile
->obfd
;
4002 unsigned int form
, i
;
4004 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4006 /* The only abbrev we care about is DW_AT_sibling. */
4007 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4009 read_attribute (&attr
, &abbrev
->attrs
[i
],
4010 abfd
, info_ptr
, cu
);
4011 if (attr
.form
== DW_FORM_ref_addr
)
4012 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4014 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4017 /* If it isn't DW_AT_sibling, skip this attribute. */
4018 form
= abbrev
->attrs
[i
].form
;
4022 case DW_FORM_ref_addr
:
4023 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4024 and later it is offset sized. */
4025 if (cu
->header
.version
== 2)
4026 info_ptr
+= cu
->header
.addr_size
;
4028 info_ptr
+= cu
->header
.offset_size
;
4031 info_ptr
+= cu
->header
.addr_size
;
4038 case DW_FORM_flag_present
:
4053 case DW_FORM_string
:
4054 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4055 info_ptr
+= bytes_read
;
4057 case DW_FORM_sec_offset
:
4059 info_ptr
+= cu
->header
.offset_size
;
4061 case DW_FORM_exprloc
:
4063 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4064 info_ptr
+= bytes_read
;
4066 case DW_FORM_block1
:
4067 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4069 case DW_FORM_block2
:
4070 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4072 case DW_FORM_block4
:
4073 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4077 case DW_FORM_ref_udata
:
4078 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4080 case DW_FORM_indirect
:
4081 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4082 info_ptr
+= bytes_read
;
4083 /* We need to continue parsing from here, so just go back to
4085 goto skip_attribute
;
4088 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4089 dwarf_form_name (form
),
4090 bfd_get_filename (abfd
));
4094 if (abbrev
->has_children
)
4095 return skip_children (buffer
, info_ptr
, cu
);
4100 /* Locate ORIG_PDI's sibling.
4101 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4105 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4106 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4107 bfd
*abfd
, struct dwarf2_cu
*cu
)
4109 /* Do we know the sibling already? */
4111 if (orig_pdi
->sibling
)
4112 return orig_pdi
->sibling
;
4114 /* Are there any children to deal with? */
4116 if (!orig_pdi
->has_children
)
4119 /* Skip the children the long way. */
4121 return skip_children (buffer
, info_ptr
, cu
);
4124 /* Expand this partial symbol table into a full symbol table. */
4127 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4133 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4139 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4140 gdb_flush (gdb_stdout
);
4143 /* Restore our global data. */
4144 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4145 dwarf2_objfile_data_key
);
4147 /* If this psymtab is constructed from a debug-only objfile, the
4148 has_section_at_zero flag will not necessarily be correct. We
4149 can get the correct value for this flag by looking at the data
4150 associated with the (presumably stripped) associated objfile. */
4151 if (pst
->objfile
->separate_debug_objfile_backlink
)
4153 struct dwarf2_per_objfile
*dpo_backlink
4154 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4155 dwarf2_objfile_data_key
);
4157 dwarf2_per_objfile
->has_section_at_zero
4158 = dpo_backlink
->has_section_at_zero
;
4161 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4163 psymtab_to_symtab_1 (pst
);
4165 /* Finish up the debug error message. */
4167 printf_filtered (_("done.\n"));
4172 /* Add PER_CU to the queue. */
4175 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4177 struct dwarf2_queue_item
*item
;
4180 item
= xmalloc (sizeof (*item
));
4181 item
->per_cu
= per_cu
;
4184 if (dwarf2_queue
== NULL
)
4185 dwarf2_queue
= item
;
4187 dwarf2_queue_tail
->next
= item
;
4189 dwarf2_queue_tail
= item
;
4192 /* Process the queue. */
4195 process_queue (struct objfile
*objfile
)
4197 struct dwarf2_queue_item
*item
, *next_item
;
4199 /* The queue starts out with one item, but following a DIE reference
4200 may load a new CU, adding it to the end of the queue. */
4201 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4203 if (dwarf2_per_objfile
->using_index
4204 ? !item
->per_cu
->v
.quick
->symtab
4205 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4206 process_full_comp_unit (item
->per_cu
);
4208 item
->per_cu
->queued
= 0;
4209 next_item
= item
->next
;
4213 dwarf2_queue_tail
= NULL
;
4216 /* Free all allocated queue entries. This function only releases anything if
4217 an error was thrown; if the queue was processed then it would have been
4218 freed as we went along. */
4221 dwarf2_release_queue (void *dummy
)
4223 struct dwarf2_queue_item
*item
, *last
;
4225 item
= dwarf2_queue
;
4228 /* Anything still marked queued is likely to be in an
4229 inconsistent state, so discard it. */
4230 if (item
->per_cu
->queued
)
4232 if (item
->per_cu
->cu
!= NULL
)
4233 free_one_cached_comp_unit (item
->per_cu
->cu
);
4234 item
->per_cu
->queued
= 0;
4242 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4245 /* Read in full symbols for PST, and anything it depends on. */
4248 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4250 struct dwarf2_per_cu_data
*per_cu
;
4251 struct cleanup
*back_to
;
4254 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4255 if (!pst
->dependencies
[i
]->readin
)
4257 /* Inform about additional files that need to be read in. */
4260 /* FIXME: i18n: Need to make this a single string. */
4261 fputs_filtered (" ", gdb_stdout
);
4263 fputs_filtered ("and ", gdb_stdout
);
4265 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4266 wrap_here (""); /* Flush output */
4267 gdb_flush (gdb_stdout
);
4269 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4272 per_cu
= pst
->read_symtab_private
;
4276 /* It's an include file, no symbols to read for it.
4277 Everything is in the parent symtab. */
4282 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4285 /* Load the DIEs associated with PER_CU into memory. */
4288 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4290 bfd
*abfd
= objfile
->obfd
;
4291 struct dwarf2_cu
*cu
;
4292 unsigned int offset
;
4293 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4294 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4295 struct attribute
*attr
;
4298 gdb_assert (! per_cu
->from_debug_types
);
4300 /* Set local variables from the partial symbol table info. */
4301 offset
= per_cu
->offset
;
4303 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4304 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4305 beg_of_comp_unit
= info_ptr
;
4307 if (per_cu
->cu
== NULL
)
4309 cu
= xmalloc (sizeof (*cu
));
4310 init_one_comp_unit (cu
, objfile
);
4314 /* If an error occurs while loading, release our storage. */
4315 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4317 /* Read in the comp_unit header. */
4318 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4320 /* Complete the cu_header. */
4321 cu
->header
.offset
= offset
;
4322 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4324 /* Read the abbrevs for this compilation unit. */
4325 dwarf2_read_abbrevs (abfd
, cu
);
4326 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4328 /* Link this compilation unit into the compilation unit tree. */
4330 cu
->per_cu
= per_cu
;
4332 /* Link this CU into read_in_chain. */
4333 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4334 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4339 info_ptr
+= cu
->header
.first_die_offset
;
4342 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4344 /* We try not to read any attributes in this function, because not
4345 all objfiles needed for references have been loaded yet, and symbol
4346 table processing isn't initialized. But we have to set the CU language,
4347 or we won't be able to build types correctly. */
4348 prepare_one_comp_unit (cu
, cu
->dies
);
4350 /* Similarly, if we do not read the producer, we can not apply
4351 producer-specific interpretation. */
4352 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4354 cu
->producer
= DW_STRING (attr
);
4358 do_cleanups (free_abbrevs_cleanup
);
4360 /* We've successfully allocated this compilation unit. Let our
4361 caller clean it up when finished with it. */
4362 discard_cleanups (free_cu_cleanup
);
4366 /* Add a DIE to the delayed physname list. */
4369 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4370 const char *name
, struct die_info
*die
,
4371 struct dwarf2_cu
*cu
)
4373 struct delayed_method_info mi
;
4375 mi
.fnfield_index
= fnfield_index
;
4379 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4382 /* A cleanup for freeing the delayed method list. */
4385 free_delayed_list (void *ptr
)
4387 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4388 if (cu
->method_list
!= NULL
)
4390 VEC_free (delayed_method_info
, cu
->method_list
);
4391 cu
->method_list
= NULL
;
4395 /* Compute the physnames of any methods on the CU's method list.
4397 The computation of method physnames is delayed in order to avoid the
4398 (bad) condition that one of the method's formal parameters is of an as yet
4402 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4405 struct delayed_method_info
*mi
;
4406 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4409 struct fn_fieldlist
*fn_flp
4410 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4411 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4412 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4416 /* Generate full symbol information for PST and CU, whose DIEs have
4417 already been loaded into memory. */
4420 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4422 struct dwarf2_cu
*cu
= per_cu
->cu
;
4423 struct objfile
*objfile
= per_cu
->objfile
;
4424 CORE_ADDR lowpc
, highpc
;
4425 struct symtab
*symtab
;
4426 struct cleanup
*back_to
, *delayed_list_cleanup
;
4429 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4432 back_to
= make_cleanup (really_free_pendings
, NULL
);
4433 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4435 cu
->list_in_scope
= &file_symbols
;
4437 dwarf2_find_base_address (cu
->dies
, cu
);
4439 /* Do line number decoding in read_file_scope () */
4440 process_die (cu
->dies
, cu
);
4442 /* Now that we have processed all the DIEs in the CU, all the types
4443 should be complete, and it should now be safe to compute all of the
4445 compute_delayed_physnames (cu
);
4446 do_cleanups (delayed_list_cleanup
);
4448 /* Some compilers don't define a DW_AT_high_pc attribute for the
4449 compilation unit. If the DW_AT_high_pc is missing, synthesize
4450 it, by scanning the DIE's below the compilation unit. */
4451 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4453 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4455 /* Set symtab language to language from DW_AT_language.
4456 If the compilation is from a C file generated by language preprocessors,
4457 do not set the language if it was already deduced by start_subfile. */
4459 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4461 symtab
->language
= cu
->language
;
4464 if (dwarf2_per_objfile
->using_index
)
4465 per_cu
->v
.quick
->symtab
= symtab
;
4468 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4469 pst
->symtab
= symtab
;
4473 do_cleanups (back_to
);
4476 /* Process a die and its children. */
4479 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4483 case DW_TAG_padding
:
4485 case DW_TAG_compile_unit
:
4486 read_file_scope (die
, cu
);
4488 case DW_TAG_type_unit
:
4489 read_type_unit_scope (die
, cu
);
4491 case DW_TAG_subprogram
:
4492 case DW_TAG_inlined_subroutine
:
4493 read_func_scope (die
, cu
);
4495 case DW_TAG_lexical_block
:
4496 case DW_TAG_try_block
:
4497 case DW_TAG_catch_block
:
4498 read_lexical_block_scope (die
, cu
);
4500 case DW_TAG_class_type
:
4501 case DW_TAG_interface_type
:
4502 case DW_TAG_structure_type
:
4503 case DW_TAG_union_type
:
4504 process_structure_scope (die
, cu
);
4506 case DW_TAG_enumeration_type
:
4507 process_enumeration_scope (die
, cu
);
4510 /* These dies have a type, but processing them does not create
4511 a symbol or recurse to process the children. Therefore we can
4512 read them on-demand through read_type_die. */
4513 case DW_TAG_subroutine_type
:
4514 case DW_TAG_set_type
:
4515 case DW_TAG_array_type
:
4516 case DW_TAG_pointer_type
:
4517 case DW_TAG_ptr_to_member_type
:
4518 case DW_TAG_reference_type
:
4519 case DW_TAG_string_type
:
4522 case DW_TAG_base_type
:
4523 case DW_TAG_subrange_type
:
4524 case DW_TAG_typedef
:
4525 /* Add a typedef symbol for the type definition, if it has a
4527 new_symbol (die
, read_type_die (die
, cu
), cu
);
4529 case DW_TAG_common_block
:
4530 read_common_block (die
, cu
);
4532 case DW_TAG_common_inclusion
:
4534 case DW_TAG_namespace
:
4535 processing_has_namespace_info
= 1;
4536 read_namespace (die
, cu
);
4539 processing_has_namespace_info
= 1;
4540 read_module (die
, cu
);
4542 case DW_TAG_imported_declaration
:
4543 case DW_TAG_imported_module
:
4544 processing_has_namespace_info
= 1;
4545 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4546 || cu
->language
!= language_fortran
))
4547 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4548 dwarf_tag_name (die
->tag
));
4549 read_import_statement (die
, cu
);
4552 new_symbol (die
, NULL
, cu
);
4557 /* A helper function for dwarf2_compute_name which determines whether DIE
4558 needs to have the name of the scope prepended to the name listed in the
4562 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4564 struct attribute
*attr
;
4568 case DW_TAG_namespace
:
4569 case DW_TAG_typedef
:
4570 case DW_TAG_class_type
:
4571 case DW_TAG_interface_type
:
4572 case DW_TAG_structure_type
:
4573 case DW_TAG_union_type
:
4574 case DW_TAG_enumeration_type
:
4575 case DW_TAG_enumerator
:
4576 case DW_TAG_subprogram
:
4580 case DW_TAG_variable
:
4581 case DW_TAG_constant
:
4582 /* We only need to prefix "globally" visible variables. These include
4583 any variable marked with DW_AT_external or any variable that
4584 lives in a namespace. [Variables in anonymous namespaces
4585 require prefixing, but they are not DW_AT_external.] */
4587 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4589 struct dwarf2_cu
*spec_cu
= cu
;
4591 return die_needs_namespace (die_specification (die
, &spec_cu
),
4595 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4596 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4597 && die
->parent
->tag
!= DW_TAG_module
)
4599 /* A variable in a lexical block of some kind does not need a
4600 namespace, even though in C++ such variables may be external
4601 and have a mangled name. */
4602 if (die
->parent
->tag
== DW_TAG_lexical_block
4603 || die
->parent
->tag
== DW_TAG_try_block
4604 || die
->parent
->tag
== DW_TAG_catch_block
4605 || die
->parent
->tag
== DW_TAG_subprogram
)
4614 /* Retrieve the last character from a mem_file. */
4617 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4619 char *last_char_p
= (char *) object
;
4622 *last_char_p
= buffer
[length
- 1];
4625 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4626 compute the physname for the object, which include a method's
4627 formal parameters (C++/Java) and return type (Java).
4629 For Ada, return the DIE's linkage name rather than the fully qualified
4630 name. PHYSNAME is ignored..
4632 The result is allocated on the objfile_obstack and canonicalized. */
4635 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4639 name
= dwarf2_name (die
, cu
);
4641 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4642 compute it by typename_concat inside GDB. */
4643 if (cu
->language
== language_ada
4644 || (cu
->language
== language_fortran
&& physname
))
4646 /* For Ada unit, we prefer the linkage name over the name, as
4647 the former contains the exported name, which the user expects
4648 to be able to reference. Ideally, we want the user to be able
4649 to reference this entity using either natural or linkage name,
4650 but we haven't started looking at this enhancement yet. */
4651 struct attribute
*attr
;
4653 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4655 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4656 if (attr
&& DW_STRING (attr
))
4657 return DW_STRING (attr
);
4660 /* These are the only languages we know how to qualify names in. */
4662 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4663 || cu
->language
== language_fortran
))
4665 if (die_needs_namespace (die
, cu
))
4669 struct ui_file
*buf
;
4671 prefix
= determine_prefix (die
, cu
);
4672 buf
= mem_fileopen ();
4673 if (*prefix
!= '\0')
4675 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4678 fputs_unfiltered (prefixed_name
, buf
);
4679 xfree (prefixed_name
);
4682 fputs_unfiltered (name
? name
: "", buf
);
4684 /* Template parameters may be specified in the DIE's DW_AT_name, or
4685 as children with DW_TAG_template_type_param or
4686 DW_TAG_value_type_param. If the latter, add them to the name
4687 here. If the name already has template parameters, then
4688 skip this step; some versions of GCC emit both, and
4689 it is more efficient to use the pre-computed name.
4691 Something to keep in mind about this process: it is very
4692 unlikely, or in some cases downright impossible, to produce
4693 something that will match the mangled name of a function.
4694 If the definition of the function has the same debug info,
4695 we should be able to match up with it anyway. But fallbacks
4696 using the minimal symbol, for instance to find a method
4697 implemented in a stripped copy of libstdc++, will not work.
4698 If we do not have debug info for the definition, we will have to
4699 match them up some other way.
4701 When we do name matching there is a related problem with function
4702 templates; two instantiated function templates are allowed to
4703 differ only by their return types, which we do not add here. */
4705 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4707 struct attribute
*attr
;
4708 struct die_info
*child
;
4711 die
->building_fullname
= 1;
4713 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4718 struct dwarf2_locexpr_baton
*baton
;
4721 if (child
->tag
!= DW_TAG_template_type_param
4722 && child
->tag
!= DW_TAG_template_value_param
)
4727 fputs_unfiltered ("<", buf
);
4731 fputs_unfiltered (", ", buf
);
4733 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4736 complaint (&symfile_complaints
,
4737 _("template parameter missing DW_AT_type"));
4738 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4741 type
= die_type (child
, cu
);
4743 if (child
->tag
== DW_TAG_template_type_param
)
4745 c_print_type (type
, "", buf
, -1, 0);
4749 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4752 complaint (&symfile_complaints
,
4753 _("template parameter missing DW_AT_const_value"));
4754 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4758 dwarf2_const_value_attr (attr
, type
, name
,
4759 &cu
->comp_unit_obstack
, cu
,
4760 &value
, &bytes
, &baton
);
4762 if (TYPE_NOSIGN (type
))
4763 /* GDB prints characters as NUMBER 'CHAR'. If that's
4764 changed, this can use value_print instead. */
4765 c_printchar (value
, type
, buf
);
4768 struct value_print_options opts
;
4771 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4775 else if (bytes
!= NULL
)
4777 v
= allocate_value (type
);
4778 memcpy (value_contents_writeable (v
), bytes
,
4779 TYPE_LENGTH (type
));
4782 v
= value_from_longest (type
, value
);
4784 /* Specify decimal so that we do not depend on the radix. */
4785 get_formatted_print_options (&opts
, 'd');
4787 value_print (v
, buf
, &opts
);
4793 die
->building_fullname
= 0;
4797 /* Close the argument list, with a space if necessary
4798 (nested templates). */
4799 char last_char
= '\0';
4800 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4801 if (last_char
== '>')
4802 fputs_unfiltered (" >", buf
);
4804 fputs_unfiltered (">", buf
);
4808 /* For Java and C++ methods, append formal parameter type
4809 information, if PHYSNAME. */
4811 if (physname
&& die
->tag
== DW_TAG_subprogram
4812 && (cu
->language
== language_cplus
4813 || cu
->language
== language_java
))
4815 struct type
*type
= read_type_die (die
, cu
);
4817 c_type_print_args (type
, buf
, 0, cu
->language
);
4819 if (cu
->language
== language_java
)
4821 /* For java, we must append the return type to method
4823 if (die
->tag
== DW_TAG_subprogram
)
4824 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4827 else if (cu
->language
== language_cplus
)
4829 /* Assume that an artificial first parameter is
4830 "this", but do not crash if it is not. RealView
4831 marks unnamed (and thus unused) parameters as
4832 artificial; there is no way to differentiate
4834 if (TYPE_NFIELDS (type
) > 0
4835 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4836 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4837 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4838 fputs_unfiltered (" const", buf
);
4842 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4844 ui_file_delete (buf
);
4846 if (cu
->language
== language_cplus
)
4849 = dwarf2_canonicalize_name (name
, cu
,
4850 &cu
->objfile
->objfile_obstack
);
4861 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4862 If scope qualifiers are appropriate they will be added. The result
4863 will be allocated on the objfile_obstack, or NULL if the DIE does
4864 not have a name. NAME may either be from a previous call to
4865 dwarf2_name or NULL.
4867 The output string will be canonicalized (if C++/Java). */
4870 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4872 return dwarf2_compute_name (name
, die
, cu
, 0);
4875 /* Construct a physname for the given DIE in CU. NAME may either be
4876 from a previous call to dwarf2_name or NULL. The result will be
4877 allocated on the objfile_objstack or NULL if the DIE does not have a
4880 The output string will be canonicalized (if C++/Java). */
4883 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4885 return dwarf2_compute_name (name
, die
, cu
, 1);
4888 /* Read the import statement specified by the given die and record it. */
4891 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4893 struct attribute
*import_attr
;
4894 struct die_info
*imported_die
;
4895 struct dwarf2_cu
*imported_cu
;
4896 const char *imported_name
;
4897 const char *imported_name_prefix
;
4898 const char *canonical_name
;
4899 const char *import_alias
;
4900 const char *imported_declaration
= NULL
;
4901 const char *import_prefix
;
4905 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4906 if (import_attr
== NULL
)
4908 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4909 dwarf_tag_name (die
->tag
));
4914 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4915 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4916 if (imported_name
== NULL
)
4918 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4920 The import in the following code:
4934 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4935 <52> DW_AT_decl_file : 1
4936 <53> DW_AT_decl_line : 6
4937 <54> DW_AT_import : <0x75>
4938 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4940 <5b> DW_AT_decl_file : 1
4941 <5c> DW_AT_decl_line : 2
4942 <5d> DW_AT_type : <0x6e>
4944 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4945 <76> DW_AT_byte_size : 4
4946 <77> DW_AT_encoding : 5 (signed)
4948 imports the wrong die ( 0x75 instead of 0x58 ).
4949 This case will be ignored until the gcc bug is fixed. */
4953 /* Figure out the local name after import. */
4954 import_alias
= dwarf2_name (die
, cu
);
4956 /* Figure out where the statement is being imported to. */
4957 import_prefix
= determine_prefix (die
, cu
);
4959 /* Figure out what the scope of the imported die is and prepend it
4960 to the name of the imported die. */
4961 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4963 if (imported_die
->tag
!= DW_TAG_namespace
4964 && imported_die
->tag
!= DW_TAG_module
)
4966 imported_declaration
= imported_name
;
4967 canonical_name
= imported_name_prefix
;
4969 else if (strlen (imported_name_prefix
) > 0)
4971 temp
= alloca (strlen (imported_name_prefix
)
4972 + 2 + strlen (imported_name
) + 1);
4973 strcpy (temp
, imported_name_prefix
);
4974 strcat (temp
, "::");
4975 strcat (temp
, imported_name
);
4976 canonical_name
= temp
;
4979 canonical_name
= imported_name
;
4981 cp_add_using_directive (import_prefix
,
4984 imported_declaration
,
4985 &cu
->objfile
->objfile_obstack
);
4989 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4991 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4995 free_cu_line_header (void *arg
)
4997 struct dwarf2_cu
*cu
= arg
;
4999 free_line_header (cu
->line_header
);
5000 cu
->line_header
= NULL
;
5004 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5005 char **name
, char **comp_dir
)
5007 struct attribute
*attr
;
5012 /* Find the filename. Do not use dwarf2_name here, since the filename
5013 is not a source language identifier. */
5014 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5017 *name
= DW_STRING (attr
);
5020 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5022 *comp_dir
= DW_STRING (attr
);
5023 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5025 *comp_dir
= ldirname (*name
);
5026 if (*comp_dir
!= NULL
)
5027 make_cleanup (xfree
, *comp_dir
);
5029 if (*comp_dir
!= NULL
)
5031 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5032 directory, get rid of it. */
5033 char *cp
= strchr (*comp_dir
, ':');
5035 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5040 *name
= "<unknown>";
5044 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5046 struct objfile
*objfile
= cu
->objfile
;
5047 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5048 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5049 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5050 struct attribute
*attr
;
5052 char *comp_dir
= NULL
;
5053 struct die_info
*child_die
;
5054 bfd
*abfd
= objfile
->obfd
;
5055 struct line_header
*line_header
= 0;
5058 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5060 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5062 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5063 from finish_block. */
5064 if (lowpc
== ((CORE_ADDR
) -1))
5069 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5071 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5074 set_cu_language (DW_UNSND (attr
), cu
);
5077 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5079 cu
->producer
= DW_STRING (attr
);
5081 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5082 standardised yet. As a workaround for the language detection we fall
5083 back to the DW_AT_producer string. */
5084 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5085 cu
->language
= language_opencl
;
5087 /* We assume that we're processing GCC output. */
5088 processing_gcc_compilation
= 2;
5090 processing_has_namespace_info
= 0;
5092 start_symtab (name
, comp_dir
, lowpc
);
5093 record_debugformat ("DWARF 2");
5094 record_producer (cu
->producer
);
5096 initialize_cu_func_list (cu
);
5098 /* Decode line number information if present. We do this before
5099 processing child DIEs, so that the line header table is available
5100 for DW_AT_decl_file. */
5101 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5104 unsigned int line_offset
= DW_UNSND (attr
);
5105 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5108 cu
->line_header
= line_header
;
5109 make_cleanup (free_cu_line_header
, cu
);
5110 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5114 /* Process all dies in compilation unit. */
5115 if (die
->child
!= NULL
)
5117 child_die
= die
->child
;
5118 while (child_die
&& child_die
->tag
)
5120 process_die (child_die
, cu
);
5121 child_die
= sibling_die (child_die
);
5125 /* Decode macro information, if present. Dwarf 2 macro information
5126 refers to information in the line number info statement program
5127 header, so we can only read it if we've read the header
5129 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5130 if (attr
&& line_header
)
5132 unsigned int macro_offset
= DW_UNSND (attr
);
5134 dwarf_decode_macros (line_header
, macro_offset
,
5135 comp_dir
, abfd
, cu
);
5137 do_cleanups (back_to
);
5140 /* For TUs we want to skip the first top level sibling if it's not the
5141 actual type being defined by this TU. In this case the first top
5142 level sibling is there to provide context only. */
5145 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5147 struct objfile
*objfile
= cu
->objfile
;
5148 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5150 struct attribute
*attr
;
5152 char *comp_dir
= NULL
;
5153 struct die_info
*child_die
;
5154 bfd
*abfd
= objfile
->obfd
;
5156 /* start_symtab needs a low pc, but we don't really have one.
5157 Do what read_file_scope would do in the absence of such info. */
5158 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5160 /* Find the filename. Do not use dwarf2_name here, since the filename
5161 is not a source language identifier. */
5162 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5164 name
= DW_STRING (attr
);
5166 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5168 comp_dir
= DW_STRING (attr
);
5169 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5171 comp_dir
= ldirname (name
);
5172 if (comp_dir
!= NULL
)
5173 make_cleanup (xfree
, comp_dir
);
5179 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5181 set_cu_language (DW_UNSND (attr
), cu
);
5183 /* This isn't technically needed today. It is done for symmetry
5184 with read_file_scope. */
5185 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5187 cu
->producer
= DW_STRING (attr
);
5189 /* We assume that we're processing GCC output. */
5190 processing_gcc_compilation
= 2;
5192 processing_has_namespace_info
= 0;
5194 start_symtab (name
, comp_dir
, lowpc
);
5195 record_debugformat ("DWARF 2");
5196 record_producer (cu
->producer
);
5198 /* Process the dies in the type unit. */
5199 if (die
->child
== NULL
)
5201 dump_die_for_error (die
);
5202 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5203 bfd_get_filename (abfd
));
5206 child_die
= die
->child
;
5208 while (child_die
&& child_die
->tag
)
5210 process_die (child_die
, cu
);
5212 child_die
= sibling_die (child_die
);
5215 do_cleanups (back_to
);
5219 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5220 struct dwarf2_cu
*cu
)
5222 struct function_range
*thisfn
;
5224 thisfn
= (struct function_range
*)
5225 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5226 thisfn
->name
= name
;
5227 thisfn
->lowpc
= lowpc
;
5228 thisfn
->highpc
= highpc
;
5229 thisfn
->seen_line
= 0;
5230 thisfn
->next
= NULL
;
5232 if (cu
->last_fn
== NULL
)
5233 cu
->first_fn
= thisfn
;
5235 cu
->last_fn
->next
= thisfn
;
5237 cu
->last_fn
= thisfn
;
5240 /* qsort helper for inherit_abstract_dies. */
5243 unsigned_int_compar (const void *ap
, const void *bp
)
5245 unsigned int a
= *(unsigned int *) ap
;
5246 unsigned int b
= *(unsigned int *) bp
;
5248 return (a
> b
) - (b
> a
);
5251 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5252 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5253 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5256 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5258 struct die_info
*child_die
;
5259 unsigned die_children_count
;
5260 /* CU offsets which were referenced by children of the current DIE. */
5262 unsigned *offsets_end
, *offsetp
;
5263 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5264 struct die_info
*origin_die
;
5265 /* Iterator of the ORIGIN_DIE children. */
5266 struct die_info
*origin_child_die
;
5267 struct cleanup
*cleanups
;
5268 struct attribute
*attr
;
5269 struct dwarf2_cu
*origin_cu
;
5270 struct pending
**origin_previous_list_in_scope
;
5272 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5276 /* Note that following die references may follow to a die in a
5280 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5282 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5284 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5285 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5287 if (die
->tag
!= origin_die
->tag
5288 && !(die
->tag
== DW_TAG_inlined_subroutine
5289 && origin_die
->tag
== DW_TAG_subprogram
))
5290 complaint (&symfile_complaints
,
5291 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5292 die
->offset
, origin_die
->offset
);
5294 child_die
= die
->child
;
5295 die_children_count
= 0;
5296 while (child_die
&& child_die
->tag
)
5298 child_die
= sibling_die (child_die
);
5299 die_children_count
++;
5301 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5302 cleanups
= make_cleanup (xfree
, offsets
);
5304 offsets_end
= offsets
;
5305 child_die
= die
->child
;
5306 while (child_die
&& child_die
->tag
)
5308 /* For each CHILD_DIE, find the corresponding child of
5309 ORIGIN_DIE. If there is more than one layer of
5310 DW_AT_abstract_origin, follow them all; there shouldn't be,
5311 but GCC versions at least through 4.4 generate this (GCC PR
5313 struct die_info
*child_origin_die
= child_die
;
5314 struct dwarf2_cu
*child_origin_cu
= cu
;
5318 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5322 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5326 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5327 counterpart may exist. */
5328 if (child_origin_die
!= child_die
)
5330 if (child_die
->tag
!= child_origin_die
->tag
5331 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5332 && child_origin_die
->tag
== DW_TAG_subprogram
))
5333 complaint (&symfile_complaints
,
5334 _("Child DIE 0x%x and its abstract origin 0x%x have "
5335 "different tags"), child_die
->offset
,
5336 child_origin_die
->offset
);
5337 if (child_origin_die
->parent
!= origin_die
)
5338 complaint (&symfile_complaints
,
5339 _("Child DIE 0x%x and its abstract origin 0x%x have "
5340 "different parents"), child_die
->offset
,
5341 child_origin_die
->offset
);
5343 *offsets_end
++ = child_origin_die
->offset
;
5345 child_die
= sibling_die (child_die
);
5347 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5348 unsigned_int_compar
);
5349 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5350 if (offsetp
[-1] == *offsetp
)
5351 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5352 "to DIE 0x%x as their abstract origin"),
5353 die
->offset
, *offsetp
);
5356 origin_child_die
= origin_die
->child
;
5357 while (origin_child_die
&& origin_child_die
->tag
)
5359 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5360 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5362 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5364 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5365 process_die (origin_child_die
, origin_cu
);
5367 origin_child_die
= sibling_die (origin_child_die
);
5369 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5371 do_cleanups (cleanups
);
5375 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5377 struct objfile
*objfile
= cu
->objfile
;
5378 struct context_stack
*new;
5381 struct die_info
*child_die
;
5382 struct attribute
*attr
, *call_line
, *call_file
;
5385 struct block
*block
;
5386 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5387 VEC (symbolp
) *template_args
= NULL
;
5388 struct template_symbol
*templ_func
= NULL
;
5392 /* If we do not have call site information, we can't show the
5393 caller of this inlined function. That's too confusing, so
5394 only use the scope for local variables. */
5395 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5396 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5397 if (call_line
== NULL
|| call_file
== NULL
)
5399 read_lexical_block_scope (die
, cu
);
5404 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5406 name
= dwarf2_name (die
, cu
);
5408 /* Ignore functions with missing or empty names. These are actually
5409 illegal according to the DWARF standard. */
5412 complaint (&symfile_complaints
,
5413 _("missing name for subprogram DIE at %d"), die
->offset
);
5417 /* Ignore functions with missing or invalid low and high pc attributes. */
5418 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5420 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5421 if (!attr
|| !DW_UNSND (attr
))
5422 complaint (&symfile_complaints
,
5423 _("cannot get low and high bounds for subprogram DIE at %d"),
5431 /* Record the function range for dwarf_decode_lines. */
5432 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5434 /* If we have any template arguments, then we must allocate a
5435 different sort of symbol. */
5436 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5438 if (child_die
->tag
== DW_TAG_template_type_param
5439 || child_die
->tag
== DW_TAG_template_value_param
)
5441 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5442 struct template_symbol
);
5443 templ_func
->base
.is_cplus_template_function
= 1;
5448 new = push_context (0, lowpc
);
5449 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5450 (struct symbol
*) templ_func
);
5452 /* If there is a location expression for DW_AT_frame_base, record
5454 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5456 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5457 expression is being recorded directly in the function's symbol
5458 and not in a separate frame-base object. I guess this hack is
5459 to avoid adding some sort of frame-base adjunct/annex to the
5460 function's symbol :-(. The problem with doing this is that it
5461 results in a function symbol with a location expression that
5462 has nothing to do with the location of the function, ouch! The
5463 relationship should be: a function's symbol has-a frame base; a
5464 frame-base has-a location expression. */
5465 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5467 cu
->list_in_scope
= &local_symbols
;
5469 if (die
->child
!= NULL
)
5471 child_die
= die
->child
;
5472 while (child_die
&& child_die
->tag
)
5474 if (child_die
->tag
== DW_TAG_template_type_param
5475 || child_die
->tag
== DW_TAG_template_value_param
)
5477 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5480 VEC_safe_push (symbolp
, template_args
, arg
);
5483 process_die (child_die
, cu
);
5484 child_die
= sibling_die (child_die
);
5488 inherit_abstract_dies (die
, cu
);
5490 /* If we have a DW_AT_specification, we might need to import using
5491 directives from the context of the specification DIE. See the
5492 comment in determine_prefix. */
5493 if (cu
->language
== language_cplus
5494 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5496 struct dwarf2_cu
*spec_cu
= cu
;
5497 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5501 child_die
= spec_die
->child
;
5502 while (child_die
&& child_die
->tag
)
5504 if (child_die
->tag
== DW_TAG_imported_module
)
5505 process_die (child_die
, spec_cu
);
5506 child_die
= sibling_die (child_die
);
5509 /* In some cases, GCC generates specification DIEs that
5510 themselves contain DW_AT_specification attributes. */
5511 spec_die
= die_specification (spec_die
, &spec_cu
);
5515 new = pop_context ();
5516 /* Make a block for the local symbols within. */
5517 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5518 lowpc
, highpc
, objfile
);
5520 /* For C++, set the block's scope. */
5521 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5522 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5523 determine_prefix (die
, cu
),
5524 processing_has_namespace_info
);
5526 /* If we have address ranges, record them. */
5527 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5529 /* Attach template arguments to function. */
5530 if (! VEC_empty (symbolp
, template_args
))
5532 gdb_assert (templ_func
!= NULL
);
5534 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5535 templ_func
->template_arguments
5536 = obstack_alloc (&objfile
->objfile_obstack
,
5537 (templ_func
->n_template_arguments
5538 * sizeof (struct symbol
*)));
5539 memcpy (templ_func
->template_arguments
,
5540 VEC_address (symbolp
, template_args
),
5541 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5542 VEC_free (symbolp
, template_args
);
5545 /* In C++, we can have functions nested inside functions (e.g., when
5546 a function declares a class that has methods). This means that
5547 when we finish processing a function scope, we may need to go
5548 back to building a containing block's symbol lists. */
5549 local_symbols
= new->locals
;
5550 param_symbols
= new->params
;
5551 using_directives
= new->using_directives
;
5553 /* If we've finished processing a top-level function, subsequent
5554 symbols go in the file symbol list. */
5555 if (outermost_context_p ())
5556 cu
->list_in_scope
= &file_symbols
;
5559 /* Process all the DIES contained within a lexical block scope. Start
5560 a new scope, process the dies, and then close the scope. */
5563 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5565 struct objfile
*objfile
= cu
->objfile
;
5566 struct context_stack
*new;
5567 CORE_ADDR lowpc
, highpc
;
5568 struct die_info
*child_die
;
5571 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5573 /* Ignore blocks with missing or invalid low and high pc attributes. */
5574 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5575 as multiple lexical blocks? Handling children in a sane way would
5576 be nasty. Might be easier to properly extend generic blocks to
5578 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5583 push_context (0, lowpc
);
5584 if (die
->child
!= NULL
)
5586 child_die
= die
->child
;
5587 while (child_die
&& child_die
->tag
)
5589 process_die (child_die
, cu
);
5590 child_die
= sibling_die (child_die
);
5593 new = pop_context ();
5595 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5598 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5601 /* Note that recording ranges after traversing children, as we
5602 do here, means that recording a parent's ranges entails
5603 walking across all its children's ranges as they appear in
5604 the address map, which is quadratic behavior.
5606 It would be nicer to record the parent's ranges before
5607 traversing its children, simply overriding whatever you find
5608 there. But since we don't even decide whether to create a
5609 block until after we've traversed its children, that's hard
5611 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5613 local_symbols
= new->locals
;
5614 using_directives
= new->using_directives
;
5617 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5618 Return 1 if the attributes are present and valid, otherwise, return 0.
5619 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5622 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5623 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5624 struct partial_symtab
*ranges_pst
)
5626 struct objfile
*objfile
= cu
->objfile
;
5627 struct comp_unit_head
*cu_header
= &cu
->header
;
5628 bfd
*obfd
= objfile
->obfd
;
5629 unsigned int addr_size
= cu_header
->addr_size
;
5630 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5631 /* Base address selection entry. */
5642 found_base
= cu
->base_known
;
5643 base
= cu
->base_address
;
5645 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5646 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5648 complaint (&symfile_complaints
,
5649 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5653 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5655 /* Read in the largest possible address. */
5656 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5657 if ((marker
& mask
) == mask
)
5659 /* If we found the largest possible address, then
5660 read the base address. */
5661 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5662 buffer
+= 2 * addr_size
;
5663 offset
+= 2 * addr_size
;
5669 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5673 CORE_ADDR range_beginning
, range_end
;
5675 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5676 buffer
+= addr_size
;
5677 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5678 buffer
+= addr_size
;
5679 offset
+= 2 * addr_size
;
5681 /* An end of list marker is a pair of zero addresses. */
5682 if (range_beginning
== 0 && range_end
== 0)
5683 /* Found the end of list entry. */
5686 /* Each base address selection entry is a pair of 2 values.
5687 The first is the largest possible address, the second is
5688 the base address. Check for a base address here. */
5689 if ((range_beginning
& mask
) == mask
)
5691 /* If we found the largest possible address, then
5692 read the base address. */
5693 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5700 /* We have no valid base address for the ranges
5702 complaint (&symfile_complaints
,
5703 _("Invalid .debug_ranges data (no base address)"));
5707 range_beginning
+= base
;
5710 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5711 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5712 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5715 /* FIXME: This is recording everything as a low-high
5716 segment of consecutive addresses. We should have a
5717 data structure for discontiguous block ranges
5721 low
= range_beginning
;
5727 if (range_beginning
< low
)
5728 low
= range_beginning
;
5729 if (range_end
> high
)
5735 /* If the first entry is an end-of-list marker, the range
5736 describes an empty scope, i.e. no instructions. */
5742 *high_return
= high
;
5746 /* Get low and high pc attributes from a die. Return 1 if the attributes
5747 are present and valid, otherwise, return 0. Return -1 if the range is
5748 discontinuous, i.e. derived from DW_AT_ranges information. */
5750 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5751 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5752 struct partial_symtab
*pst
)
5754 struct attribute
*attr
;
5759 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5762 high
= DW_ADDR (attr
);
5763 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5765 low
= DW_ADDR (attr
);
5767 /* Found high w/o low attribute. */
5770 /* Found consecutive range of addresses. */
5775 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5778 /* Value of the DW_AT_ranges attribute is the offset in the
5779 .debug_ranges section. */
5780 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5782 /* Found discontinuous range of addresses. */
5790 /* When using the GNU linker, .gnu.linkonce. sections are used to
5791 eliminate duplicate copies of functions and vtables and such.
5792 The linker will arbitrarily choose one and discard the others.
5793 The AT_*_pc values for such functions refer to local labels in
5794 these sections. If the section from that file was discarded, the
5795 labels are not in the output, so the relocs get a value of 0.
5796 If this is a discarded function, mark the pc bounds as invalid,
5797 so that GDB will ignore it. */
5798 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5806 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5807 its low and high PC addresses. Do nothing if these addresses could not
5808 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5809 and HIGHPC to the high address if greater than HIGHPC. */
5812 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5813 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5814 struct dwarf2_cu
*cu
)
5816 CORE_ADDR low
, high
;
5817 struct die_info
*child
= die
->child
;
5819 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5821 *lowpc
= min (*lowpc
, low
);
5822 *highpc
= max (*highpc
, high
);
5825 /* If the language does not allow nested subprograms (either inside
5826 subprograms or lexical blocks), we're done. */
5827 if (cu
->language
!= language_ada
)
5830 /* Check all the children of the given DIE. If it contains nested
5831 subprograms, then check their pc bounds. Likewise, we need to
5832 check lexical blocks as well, as they may also contain subprogram
5834 while (child
&& child
->tag
)
5836 if (child
->tag
== DW_TAG_subprogram
5837 || child
->tag
== DW_TAG_lexical_block
)
5838 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5839 child
= sibling_die (child
);
5843 /* Get the low and high pc's represented by the scope DIE, and store
5844 them in *LOWPC and *HIGHPC. If the correct values can't be
5845 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5848 get_scope_pc_bounds (struct die_info
*die
,
5849 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5850 struct dwarf2_cu
*cu
)
5852 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5853 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5854 CORE_ADDR current_low
, current_high
;
5856 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5858 best_low
= current_low
;
5859 best_high
= current_high
;
5863 struct die_info
*child
= die
->child
;
5865 while (child
&& child
->tag
)
5867 switch (child
->tag
) {
5868 case DW_TAG_subprogram
:
5869 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5871 case DW_TAG_namespace
:
5873 /* FIXME: carlton/2004-01-16: Should we do this for
5874 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5875 that current GCC's always emit the DIEs corresponding
5876 to definitions of methods of classes as children of a
5877 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5878 the DIEs giving the declarations, which could be
5879 anywhere). But I don't see any reason why the
5880 standards says that they have to be there. */
5881 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5883 if (current_low
!= ((CORE_ADDR
) -1))
5885 best_low
= min (best_low
, current_low
);
5886 best_high
= max (best_high
, current_high
);
5894 child
= sibling_die (child
);
5899 *highpc
= best_high
;
5902 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5905 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5906 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5908 struct attribute
*attr
;
5910 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5913 CORE_ADDR high
= DW_ADDR (attr
);
5915 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5918 CORE_ADDR low
= DW_ADDR (attr
);
5920 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5924 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5927 bfd
*obfd
= cu
->objfile
->obfd
;
5929 /* The value of the DW_AT_ranges attribute is the offset of the
5930 address range list in the .debug_ranges section. */
5931 unsigned long offset
= DW_UNSND (attr
);
5932 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5934 /* For some target architectures, but not others, the
5935 read_address function sign-extends the addresses it returns.
5936 To recognize base address selection entries, we need a
5938 unsigned int addr_size
= cu
->header
.addr_size
;
5939 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5941 /* The base address, to which the next pair is relative. Note
5942 that this 'base' is a DWARF concept: most entries in a range
5943 list are relative, to reduce the number of relocs against the
5944 debugging information. This is separate from this function's
5945 'baseaddr' argument, which GDB uses to relocate debugging
5946 information from a shared library based on the address at
5947 which the library was loaded. */
5948 CORE_ADDR base
= cu
->base_address
;
5949 int base_known
= cu
->base_known
;
5951 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5952 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5954 complaint (&symfile_complaints
,
5955 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5962 unsigned int bytes_read
;
5963 CORE_ADDR start
, end
;
5965 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5966 buffer
+= bytes_read
;
5967 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5968 buffer
+= bytes_read
;
5970 /* Did we find the end of the range list? */
5971 if (start
== 0 && end
== 0)
5974 /* Did we find a base address selection entry? */
5975 else if ((start
& base_select_mask
) == base_select_mask
)
5981 /* We found an ordinary address range. */
5986 complaint (&symfile_complaints
,
5987 _("Invalid .debug_ranges data (no base address)"));
5991 record_block_range (block
,
5992 baseaddr
+ base
+ start
,
5993 baseaddr
+ base
+ end
- 1);
5999 /* Add an aggregate field to the field list. */
6002 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6003 struct dwarf2_cu
*cu
)
6005 struct objfile
*objfile
= cu
->objfile
;
6006 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6007 struct nextfield
*new_field
;
6008 struct attribute
*attr
;
6010 char *fieldname
= "";
6012 /* Allocate a new field list entry and link it in. */
6013 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6014 make_cleanup (xfree
, new_field
);
6015 memset (new_field
, 0, sizeof (struct nextfield
));
6017 if (die
->tag
== DW_TAG_inheritance
)
6019 new_field
->next
= fip
->baseclasses
;
6020 fip
->baseclasses
= new_field
;
6024 new_field
->next
= fip
->fields
;
6025 fip
->fields
= new_field
;
6029 /* Handle accessibility and virtuality of field.
6030 The default accessibility for members is public, the default
6031 accessibility for inheritance is private. */
6032 if (die
->tag
!= DW_TAG_inheritance
)
6033 new_field
->accessibility
= DW_ACCESS_public
;
6035 new_field
->accessibility
= DW_ACCESS_private
;
6036 new_field
->virtuality
= DW_VIRTUALITY_none
;
6038 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6040 new_field
->accessibility
= DW_UNSND (attr
);
6041 if (new_field
->accessibility
!= DW_ACCESS_public
)
6042 fip
->non_public_fields
= 1;
6043 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6045 new_field
->virtuality
= DW_UNSND (attr
);
6047 fp
= &new_field
->field
;
6049 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6051 /* Data member other than a C++ static data member. */
6053 /* Get type of field. */
6054 fp
->type
= die_type (die
, cu
);
6056 SET_FIELD_BITPOS (*fp
, 0);
6058 /* Get bit size of field (zero if none). */
6059 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6062 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6066 FIELD_BITSIZE (*fp
) = 0;
6069 /* Get bit offset of field. */
6070 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6073 int byte_offset
= 0;
6075 if (attr_form_is_section_offset (attr
))
6076 dwarf2_complex_location_expr_complaint ();
6077 else if (attr_form_is_constant (attr
))
6078 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6079 else if (attr_form_is_block (attr
))
6080 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6082 dwarf2_complex_location_expr_complaint ();
6084 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6086 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6089 if (gdbarch_bits_big_endian (gdbarch
))
6091 /* For big endian bits, the DW_AT_bit_offset gives the
6092 additional bit offset from the MSB of the containing
6093 anonymous object to the MSB of the field. We don't
6094 have to do anything special since we don't need to
6095 know the size of the anonymous object. */
6096 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6100 /* For little endian bits, compute the bit offset to the
6101 MSB of the anonymous object, subtract off the number of
6102 bits from the MSB of the field to the MSB of the
6103 object, and then subtract off the number of bits of
6104 the field itself. The result is the bit offset of
6105 the LSB of the field. */
6107 int bit_offset
= DW_UNSND (attr
);
6109 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6112 /* The size of the anonymous object containing
6113 the bit field is explicit, so use the
6114 indicated size (in bytes). */
6115 anonymous_size
= DW_UNSND (attr
);
6119 /* The size of the anonymous object containing
6120 the bit field must be inferred from the type
6121 attribute of the data member containing the
6123 anonymous_size
= TYPE_LENGTH (fp
->type
);
6125 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6126 - bit_offset
- FIELD_BITSIZE (*fp
);
6130 /* Get name of field. */
6131 fieldname
= dwarf2_name (die
, cu
);
6132 if (fieldname
== NULL
)
6135 /* The name is already allocated along with this objfile, so we don't
6136 need to duplicate it for the type. */
6137 fp
->name
= fieldname
;
6139 /* Change accessibility for artificial fields (e.g. virtual table
6140 pointer or virtual base class pointer) to private. */
6141 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6143 FIELD_ARTIFICIAL (*fp
) = 1;
6144 new_field
->accessibility
= DW_ACCESS_private
;
6145 fip
->non_public_fields
= 1;
6148 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6150 /* C++ static member. */
6152 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6153 is a declaration, but all versions of G++ as of this writing
6154 (so through at least 3.2.1) incorrectly generate
6155 DW_TAG_variable tags. */
6159 /* Get name of field. */
6160 fieldname
= dwarf2_name (die
, cu
);
6161 if (fieldname
== NULL
)
6164 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6166 /* Only create a symbol if this is an external value.
6167 new_symbol checks this and puts the value in the global symbol
6168 table, which we want. If it is not external, new_symbol
6169 will try to put the value in cu->list_in_scope which is wrong. */
6170 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6172 /* A static const member, not much different than an enum as far as
6173 we're concerned, except that we can support more types. */
6174 new_symbol (die
, NULL
, cu
);
6177 /* Get physical name. */
6178 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6180 /* The name is already allocated along with this objfile, so we don't
6181 need to duplicate it for the type. */
6182 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6183 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6184 FIELD_NAME (*fp
) = fieldname
;
6186 else if (die
->tag
== DW_TAG_inheritance
)
6188 /* C++ base class field. */
6189 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6192 int byte_offset
= 0;
6194 if (attr_form_is_section_offset (attr
))
6195 dwarf2_complex_location_expr_complaint ();
6196 else if (attr_form_is_constant (attr
))
6197 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6198 else if (attr_form_is_block (attr
))
6199 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6201 dwarf2_complex_location_expr_complaint ();
6203 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6205 FIELD_BITSIZE (*fp
) = 0;
6206 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6207 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6208 fip
->nbaseclasses
++;
6212 /* Add a typedef defined in the scope of the FIP's class. */
6215 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6216 struct dwarf2_cu
*cu
)
6218 struct objfile
*objfile
= cu
->objfile
;
6219 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6220 struct typedef_field_list
*new_field
;
6221 struct attribute
*attr
;
6222 struct typedef_field
*fp
;
6223 char *fieldname
= "";
6225 /* Allocate a new field list entry and link it in. */
6226 new_field
= xzalloc (sizeof (*new_field
));
6227 make_cleanup (xfree
, new_field
);
6229 gdb_assert (die
->tag
== DW_TAG_typedef
);
6231 fp
= &new_field
->field
;
6233 /* Get name of field. */
6234 fp
->name
= dwarf2_name (die
, cu
);
6235 if (fp
->name
== NULL
)
6238 fp
->type
= read_type_die (die
, cu
);
6240 new_field
->next
= fip
->typedef_field_list
;
6241 fip
->typedef_field_list
= new_field
;
6242 fip
->typedef_field_list_count
++;
6245 /* Create the vector of fields, and attach it to the type. */
6248 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6249 struct dwarf2_cu
*cu
)
6251 int nfields
= fip
->nfields
;
6253 /* Record the field count, allocate space for the array of fields,
6254 and create blank accessibility bitfields if necessary. */
6255 TYPE_NFIELDS (type
) = nfields
;
6256 TYPE_FIELDS (type
) = (struct field
*)
6257 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6258 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6260 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6262 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6264 TYPE_FIELD_PRIVATE_BITS (type
) =
6265 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6266 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6268 TYPE_FIELD_PROTECTED_BITS (type
) =
6269 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6270 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6272 TYPE_FIELD_IGNORE_BITS (type
) =
6273 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6274 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6277 /* If the type has baseclasses, allocate and clear a bit vector for
6278 TYPE_FIELD_VIRTUAL_BITS. */
6279 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6281 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6282 unsigned char *pointer
;
6284 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6285 pointer
= TYPE_ALLOC (type
, num_bytes
);
6286 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6287 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6288 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6291 /* Copy the saved-up fields into the field vector. Start from the head
6292 of the list, adding to the tail of the field array, so that they end
6293 up in the same order in the array in which they were added to the list. */
6294 while (nfields
-- > 0)
6296 struct nextfield
*fieldp
;
6300 fieldp
= fip
->fields
;
6301 fip
->fields
= fieldp
->next
;
6305 fieldp
= fip
->baseclasses
;
6306 fip
->baseclasses
= fieldp
->next
;
6309 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6310 switch (fieldp
->accessibility
)
6312 case DW_ACCESS_private
:
6313 if (cu
->language
!= language_ada
)
6314 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6317 case DW_ACCESS_protected
:
6318 if (cu
->language
!= language_ada
)
6319 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6322 case DW_ACCESS_public
:
6326 /* Unknown accessibility. Complain and treat it as public. */
6328 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6329 fieldp
->accessibility
);
6333 if (nfields
< fip
->nbaseclasses
)
6335 switch (fieldp
->virtuality
)
6337 case DW_VIRTUALITY_virtual
:
6338 case DW_VIRTUALITY_pure_virtual
:
6339 if (cu
->language
== language_ada
)
6340 error ("unexpected virtuality in component of Ada type");
6341 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6348 /* Add a member function to the proper fieldlist. */
6351 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6352 struct type
*type
, struct dwarf2_cu
*cu
)
6354 struct objfile
*objfile
= cu
->objfile
;
6355 struct attribute
*attr
;
6356 struct fnfieldlist
*flp
;
6358 struct fn_field
*fnp
;
6360 struct nextfnfield
*new_fnfield
;
6361 struct type
*this_type
;
6363 if (cu
->language
== language_ada
)
6364 error ("unexpected member function in Ada type");
6366 /* Get name of member function. */
6367 fieldname
= dwarf2_name (die
, cu
);
6368 if (fieldname
== NULL
)
6371 /* Look up member function name in fieldlist. */
6372 for (i
= 0; i
< fip
->nfnfields
; i
++)
6374 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6378 /* Create new list element if necessary. */
6379 if (i
< fip
->nfnfields
)
6380 flp
= &fip
->fnfieldlists
[i
];
6383 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6385 fip
->fnfieldlists
= (struct fnfieldlist
*)
6386 xrealloc (fip
->fnfieldlists
,
6387 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6388 * sizeof (struct fnfieldlist
));
6389 if (fip
->nfnfields
== 0)
6390 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6392 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6393 flp
->name
= fieldname
;
6396 i
= fip
->nfnfields
++;
6399 /* Create a new member function field and chain it to the field list
6401 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6402 make_cleanup (xfree
, new_fnfield
);
6403 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6404 new_fnfield
->next
= flp
->head
;
6405 flp
->head
= new_fnfield
;
6408 /* Fill in the member function field info. */
6409 fnp
= &new_fnfield
->fnfield
;
6411 /* Delay processing of the physname until later. */
6412 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6414 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6419 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6420 fnp
->physname
= physname
? physname
: "";
6423 fnp
->type
= alloc_type (objfile
);
6424 this_type
= read_type_die (die
, cu
);
6425 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6427 int nparams
= TYPE_NFIELDS (this_type
);
6429 /* TYPE is the domain of this method, and THIS_TYPE is the type
6430 of the method itself (TYPE_CODE_METHOD). */
6431 smash_to_method_type (fnp
->type
, type
,
6432 TYPE_TARGET_TYPE (this_type
),
6433 TYPE_FIELDS (this_type
),
6434 TYPE_NFIELDS (this_type
),
6435 TYPE_VARARGS (this_type
));
6437 /* Handle static member functions.
6438 Dwarf2 has no clean way to discern C++ static and non-static
6439 member functions. G++ helps GDB by marking the first
6440 parameter for non-static member functions (which is the
6441 this pointer) as artificial. We obtain this information
6442 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6443 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6444 fnp
->voffset
= VOFFSET_STATIC
;
6447 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6448 dwarf2_full_name (fieldname
, die
, cu
));
6450 /* Get fcontext from DW_AT_containing_type if present. */
6451 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6452 fnp
->fcontext
= die_containing_type (die
, cu
);
6454 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6455 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6457 /* Get accessibility. */
6458 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6461 switch (DW_UNSND (attr
))
6463 case DW_ACCESS_private
:
6464 fnp
->is_private
= 1;
6466 case DW_ACCESS_protected
:
6467 fnp
->is_protected
= 1;
6472 /* Check for artificial methods. */
6473 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6474 if (attr
&& DW_UNSND (attr
) != 0)
6475 fnp
->is_artificial
= 1;
6477 /* Get index in virtual function table if it is a virtual member
6478 function. For older versions of GCC, this is an offset in the
6479 appropriate virtual table, as specified by DW_AT_containing_type.
6480 For everyone else, it is an expression to be evaluated relative
6481 to the object address. */
6483 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6486 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6488 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6490 /* Old-style GCC. */
6491 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6493 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6494 || (DW_BLOCK (attr
)->size
> 1
6495 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6496 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6498 struct dwarf_block blk
;
6501 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6503 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6504 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6505 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6506 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6507 dwarf2_complex_location_expr_complaint ();
6509 fnp
->voffset
/= cu
->header
.addr_size
;
6513 dwarf2_complex_location_expr_complaint ();
6516 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6518 else if (attr_form_is_section_offset (attr
))
6520 dwarf2_complex_location_expr_complaint ();
6524 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6530 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6531 if (attr
&& DW_UNSND (attr
))
6533 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6534 complaint (&symfile_complaints
,
6535 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6536 fieldname
, die
->offset
);
6537 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6538 TYPE_CPLUS_DYNAMIC (type
) = 1;
6543 /* Create the vector of member function fields, and attach it to the type. */
6546 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6547 struct dwarf2_cu
*cu
)
6549 struct fnfieldlist
*flp
;
6550 int total_length
= 0;
6553 if (cu
->language
== language_ada
)
6554 error ("unexpected member functions in Ada type");
6556 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6557 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6558 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6560 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6562 struct nextfnfield
*nfp
= flp
->head
;
6563 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6566 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6567 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6568 fn_flp
->fn_fields
= (struct fn_field
*)
6569 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6570 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6571 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6573 total_length
+= flp
->length
;
6576 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6577 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6580 /* Returns non-zero if NAME is the name of a vtable member in CU's
6581 language, zero otherwise. */
6583 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6585 static const char vptr
[] = "_vptr";
6586 static const char vtable
[] = "vtable";
6588 /* Look for the C++ and Java forms of the vtable. */
6589 if ((cu
->language
== language_java
6590 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6591 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6592 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6598 /* GCC outputs unnamed structures that are really pointers to member
6599 functions, with the ABI-specified layout. If TYPE describes
6600 such a structure, smash it into a member function type.
6602 GCC shouldn't do this; it should just output pointer to member DIEs.
6603 This is GCC PR debug/28767. */
6606 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6608 struct type
*pfn_type
, *domain_type
, *new_type
;
6610 /* Check for a structure with no name and two children. */
6611 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6614 /* Check for __pfn and __delta members. */
6615 if (TYPE_FIELD_NAME (type
, 0) == NULL
6616 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6617 || TYPE_FIELD_NAME (type
, 1) == NULL
6618 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6621 /* Find the type of the method. */
6622 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6623 if (pfn_type
== NULL
6624 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6625 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6628 /* Look for the "this" argument. */
6629 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6630 if (TYPE_NFIELDS (pfn_type
) == 0
6631 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6632 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6635 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6636 new_type
= alloc_type (objfile
);
6637 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6638 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6639 TYPE_VARARGS (pfn_type
));
6640 smash_to_methodptr_type (type
, new_type
);
6643 /* Called when we find the DIE that starts a structure or union scope
6644 (definition) to create a type for the structure or union. Fill in
6645 the type's name and general properties; the members will not be
6646 processed until process_structure_type.
6648 NOTE: we need to call these functions regardless of whether or not the
6649 DIE has a DW_AT_name attribute, since it might be an anonymous
6650 structure or union. This gets the type entered into our set of
6653 However, if the structure is incomplete (an opaque struct/union)
6654 then suppress creating a symbol table entry for it since gdb only
6655 wants to find the one with the complete definition. Note that if
6656 it is complete, we just call new_symbol, which does it's own
6657 checking about whether the struct/union is anonymous or not (and
6658 suppresses creating a symbol table entry itself). */
6660 static struct type
*
6661 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6663 struct objfile
*objfile
= cu
->objfile
;
6665 struct attribute
*attr
;
6668 /* If the definition of this type lives in .debug_types, read that type.
6669 Don't follow DW_AT_specification though, that will take us back up
6670 the chain and we want to go down. */
6671 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6674 struct dwarf2_cu
*type_cu
= cu
;
6675 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6677 /* We could just recurse on read_structure_type, but we need to call
6678 get_die_type to ensure only one type for this DIE is created.
6679 This is important, for example, because for c++ classes we need
6680 TYPE_NAME set which is only done by new_symbol. Blech. */
6681 type
= read_type_die (type_die
, type_cu
);
6683 /* TYPE_CU may not be the same as CU.
6684 Ensure TYPE is recorded in CU's type_hash table. */
6685 return set_die_type (die
, type
, cu
);
6688 type
= alloc_type (objfile
);
6689 INIT_CPLUS_SPECIFIC (type
);
6691 name
= dwarf2_name (die
, cu
);
6694 if (cu
->language
== language_cplus
6695 || cu
->language
== language_java
)
6697 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6699 /* dwarf2_full_name might have already finished building the DIE's
6700 type. If so, there is no need to continue. */
6701 if (get_die_type (die
, cu
) != NULL
)
6702 return get_die_type (die
, cu
);
6704 TYPE_TAG_NAME (type
) = full_name
;
6705 if (die
->tag
== DW_TAG_structure_type
6706 || die
->tag
== DW_TAG_class_type
)
6707 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6711 /* The name is already allocated along with this objfile, so
6712 we don't need to duplicate it for the type. */
6713 TYPE_TAG_NAME (type
) = (char *) name
;
6714 if (die
->tag
== DW_TAG_class_type
)
6715 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6719 if (die
->tag
== DW_TAG_structure_type
)
6721 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6723 else if (die
->tag
== DW_TAG_union_type
)
6725 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6729 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6732 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6733 TYPE_DECLARED_CLASS (type
) = 1;
6735 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6738 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6742 TYPE_LENGTH (type
) = 0;
6745 TYPE_STUB_SUPPORTED (type
) = 1;
6746 if (die_is_declaration (die
, cu
))
6747 TYPE_STUB (type
) = 1;
6748 else if (attr
== NULL
&& die
->child
== NULL
6749 && producer_is_realview (cu
->producer
))
6750 /* RealView does not output the required DW_AT_declaration
6751 on incomplete types. */
6752 TYPE_STUB (type
) = 1;
6754 /* We need to add the type field to the die immediately so we don't
6755 infinitely recurse when dealing with pointers to the structure
6756 type within the structure itself. */
6757 set_die_type (die
, type
, cu
);
6759 /* set_die_type should be already done. */
6760 set_descriptive_type (type
, die
, cu
);
6765 /* Finish creating a structure or union type, including filling in
6766 its members and creating a symbol for it. */
6769 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6771 struct objfile
*objfile
= cu
->objfile
;
6772 struct die_info
*child_die
= die
->child
;
6775 type
= get_die_type (die
, cu
);
6777 type
= read_structure_type (die
, cu
);
6779 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6781 struct field_info fi
;
6782 struct die_info
*child_die
;
6783 VEC (symbolp
) *template_args
= NULL
;
6784 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6786 memset (&fi
, 0, sizeof (struct field_info
));
6788 child_die
= die
->child
;
6790 while (child_die
&& child_die
->tag
)
6792 if (child_die
->tag
== DW_TAG_member
6793 || child_die
->tag
== DW_TAG_variable
)
6795 /* NOTE: carlton/2002-11-05: A C++ static data member
6796 should be a DW_TAG_member that is a declaration, but
6797 all versions of G++ as of this writing (so through at
6798 least 3.2.1) incorrectly generate DW_TAG_variable
6799 tags for them instead. */
6800 dwarf2_add_field (&fi
, child_die
, cu
);
6802 else if (child_die
->tag
== DW_TAG_subprogram
)
6804 /* C++ member function. */
6805 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6807 else if (child_die
->tag
== DW_TAG_inheritance
)
6809 /* C++ base class field. */
6810 dwarf2_add_field (&fi
, child_die
, cu
);
6812 else if (child_die
->tag
== DW_TAG_typedef
)
6813 dwarf2_add_typedef (&fi
, child_die
, cu
);
6814 else if (child_die
->tag
== DW_TAG_template_type_param
6815 || child_die
->tag
== DW_TAG_template_value_param
)
6817 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6820 VEC_safe_push (symbolp
, template_args
, arg
);
6823 child_die
= sibling_die (child_die
);
6826 /* Attach template arguments to type. */
6827 if (! VEC_empty (symbolp
, template_args
))
6829 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6830 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6831 = VEC_length (symbolp
, template_args
);
6832 TYPE_TEMPLATE_ARGUMENTS (type
)
6833 = obstack_alloc (&objfile
->objfile_obstack
,
6834 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6835 * sizeof (struct symbol
*)));
6836 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6837 VEC_address (symbolp
, template_args
),
6838 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6839 * sizeof (struct symbol
*)));
6840 VEC_free (symbolp
, template_args
);
6843 /* Attach fields and member functions to the type. */
6845 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6848 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6850 /* Get the type which refers to the base class (possibly this
6851 class itself) which contains the vtable pointer for the current
6852 class from the DW_AT_containing_type attribute. This use of
6853 DW_AT_containing_type is a GNU extension. */
6855 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6857 struct type
*t
= die_containing_type (die
, cu
);
6859 TYPE_VPTR_BASETYPE (type
) = t
;
6864 /* Our own class provides vtbl ptr. */
6865 for (i
= TYPE_NFIELDS (t
) - 1;
6866 i
>= TYPE_N_BASECLASSES (t
);
6869 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6871 if (is_vtable_name (fieldname
, cu
))
6873 TYPE_VPTR_FIELDNO (type
) = i
;
6878 /* Complain if virtual function table field not found. */
6879 if (i
< TYPE_N_BASECLASSES (t
))
6880 complaint (&symfile_complaints
,
6881 _("virtual function table pointer not found when defining class '%s'"),
6882 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6887 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6890 else if (cu
->producer
6891 && strncmp (cu
->producer
,
6892 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6894 /* The IBM XLC compiler does not provide direct indication
6895 of the containing type, but the vtable pointer is
6896 always named __vfp. */
6900 for (i
= TYPE_NFIELDS (type
) - 1;
6901 i
>= TYPE_N_BASECLASSES (type
);
6904 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6906 TYPE_VPTR_FIELDNO (type
) = i
;
6907 TYPE_VPTR_BASETYPE (type
) = type
;
6914 /* Copy fi.typedef_field_list linked list elements content into the
6915 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6916 if (fi
.typedef_field_list
)
6918 int i
= fi
.typedef_field_list_count
;
6920 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6921 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6922 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6923 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6925 /* Reverse the list order to keep the debug info elements order. */
6928 struct typedef_field
*dest
, *src
;
6930 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6931 src
= &fi
.typedef_field_list
->field
;
6932 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6937 do_cleanups (back_to
);
6940 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6942 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6943 snapshots) has been known to create a die giving a declaration
6944 for a class that has, as a child, a die giving a definition for a
6945 nested class. So we have to process our children even if the
6946 current die is a declaration. Normally, of course, a declaration
6947 won't have any children at all. */
6949 while (child_die
!= NULL
&& child_die
->tag
)
6951 if (child_die
->tag
== DW_TAG_member
6952 || child_die
->tag
== DW_TAG_variable
6953 || child_die
->tag
== DW_TAG_inheritance
6954 || child_die
->tag
== DW_TAG_template_value_param
6955 || child_die
->tag
== DW_TAG_template_type_param
)
6960 process_die (child_die
, cu
);
6962 child_die
= sibling_die (child_die
);
6965 /* Do not consider external references. According to the DWARF standard,
6966 these DIEs are identified by the fact that they have no byte_size
6967 attribute, and a declaration attribute. */
6968 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6969 || !die_is_declaration (die
, cu
))
6970 new_symbol (die
, type
, cu
);
6973 /* Given a DW_AT_enumeration_type die, set its type. We do not
6974 complete the type's fields yet, or create any symbols. */
6976 static struct type
*
6977 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6979 struct objfile
*objfile
= cu
->objfile
;
6981 struct attribute
*attr
;
6984 /* If the definition of this type lives in .debug_types, read that type.
6985 Don't follow DW_AT_specification though, that will take us back up
6986 the chain and we want to go down. */
6987 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6990 struct dwarf2_cu
*type_cu
= cu
;
6991 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6993 type
= read_type_die (type_die
, type_cu
);
6995 /* TYPE_CU may not be the same as CU.
6996 Ensure TYPE is recorded in CU's type_hash table. */
6997 return set_die_type (die
, type
, cu
);
7000 type
= alloc_type (objfile
);
7002 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7003 name
= dwarf2_full_name (NULL
, die
, cu
);
7005 TYPE_TAG_NAME (type
) = (char *) name
;
7007 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7010 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7014 TYPE_LENGTH (type
) = 0;
7017 /* The enumeration DIE can be incomplete. In Ada, any type can be
7018 declared as private in the package spec, and then defined only
7019 inside the package body. Such types are known as Taft Amendment
7020 Types. When another package uses such a type, an incomplete DIE
7021 may be generated by the compiler. */
7022 if (die_is_declaration (die
, cu
))
7023 TYPE_STUB (type
) = 1;
7025 return set_die_type (die
, type
, cu
);
7028 /* Given a pointer to a die which begins an enumeration, process all
7029 the dies that define the members of the enumeration, and create the
7030 symbol for the enumeration type.
7032 NOTE: We reverse the order of the element list. */
7035 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7037 struct type
*this_type
;
7039 this_type
= get_die_type (die
, cu
);
7040 if (this_type
== NULL
)
7041 this_type
= read_enumeration_type (die
, cu
);
7043 if (die
->child
!= NULL
)
7045 struct die_info
*child_die
;
7047 struct field
*fields
= NULL
;
7049 int unsigned_enum
= 1;
7052 child_die
= die
->child
;
7053 while (child_die
&& child_die
->tag
)
7055 if (child_die
->tag
!= DW_TAG_enumerator
)
7057 process_die (child_die
, cu
);
7061 name
= dwarf2_name (child_die
, cu
);
7064 sym
= new_symbol (child_die
, this_type
, cu
);
7065 if (SYMBOL_VALUE (sym
) < 0)
7068 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7070 fields
= (struct field
*)
7072 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7073 * sizeof (struct field
));
7076 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7077 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7078 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7079 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7085 child_die
= sibling_die (child_die
);
7090 TYPE_NFIELDS (this_type
) = num_fields
;
7091 TYPE_FIELDS (this_type
) = (struct field
*)
7092 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7093 memcpy (TYPE_FIELDS (this_type
), fields
,
7094 sizeof (struct field
) * num_fields
);
7098 TYPE_UNSIGNED (this_type
) = 1;
7101 new_symbol (die
, this_type
, cu
);
7104 /* Extract all information from a DW_TAG_array_type DIE and put it in
7105 the DIE's type field. For now, this only handles one dimensional
7108 static struct type
*
7109 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7111 struct objfile
*objfile
= cu
->objfile
;
7112 struct die_info
*child_die
;
7114 struct type
*element_type
, *range_type
, *index_type
;
7115 struct type
**range_types
= NULL
;
7116 struct attribute
*attr
;
7118 struct cleanup
*back_to
;
7121 element_type
= die_type (die
, cu
);
7123 /* The die_type call above may have already set the type for this DIE. */
7124 type
= get_die_type (die
, cu
);
7128 /* Irix 6.2 native cc creates array types without children for
7129 arrays with unspecified length. */
7130 if (die
->child
== NULL
)
7132 index_type
= objfile_type (objfile
)->builtin_int
;
7133 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7134 type
= create_array_type (NULL
, element_type
, range_type
);
7135 return set_die_type (die
, type
, cu
);
7138 back_to
= make_cleanup (null_cleanup
, NULL
);
7139 child_die
= die
->child
;
7140 while (child_die
&& child_die
->tag
)
7142 if (child_die
->tag
== DW_TAG_subrange_type
)
7144 struct type
*child_type
= read_type_die (child_die
, cu
);
7146 if (child_type
!= NULL
)
7148 /* The range type was succesfully read. Save it for
7149 the array type creation. */
7150 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7152 range_types
= (struct type
**)
7153 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7154 * sizeof (struct type
*));
7156 make_cleanup (free_current_contents
, &range_types
);
7158 range_types
[ndim
++] = child_type
;
7161 child_die
= sibling_die (child_die
);
7164 /* Dwarf2 dimensions are output from left to right, create the
7165 necessary array types in backwards order. */
7167 type
= element_type
;
7169 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7174 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7179 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7182 /* Understand Dwarf2 support for vector types (like they occur on
7183 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7184 array type. This is not part of the Dwarf2/3 standard yet, but a
7185 custom vendor extension. The main difference between a regular
7186 array and the vector variant is that vectors are passed by value
7188 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7190 make_vector_type (type
);
7192 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7193 implementation may choose to implement triple vectors using this
7195 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7198 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7199 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7201 complaint (&symfile_complaints
, _("\
7202 DW_AT_byte_size for array type smaller than the total size of elements"));
7205 name
= dwarf2_name (die
, cu
);
7207 TYPE_NAME (type
) = name
;
7209 /* Install the type in the die. */
7210 set_die_type (die
, type
, cu
);
7212 /* set_die_type should be already done. */
7213 set_descriptive_type (type
, die
, cu
);
7215 do_cleanups (back_to
);
7220 static enum dwarf_array_dim_ordering
7221 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7223 struct attribute
*attr
;
7225 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7227 if (attr
) return DW_SND (attr
);
7230 GNU F77 is a special case, as at 08/2004 array type info is the
7231 opposite order to the dwarf2 specification, but data is still
7232 laid out as per normal fortran.
7234 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7238 if (cu
->language
== language_fortran
7239 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7241 return DW_ORD_row_major
;
7244 switch (cu
->language_defn
->la_array_ordering
)
7246 case array_column_major
:
7247 return DW_ORD_col_major
;
7248 case array_row_major
:
7250 return DW_ORD_row_major
;
7254 /* Extract all information from a DW_TAG_set_type DIE and put it in
7255 the DIE's type field. */
7257 static struct type
*
7258 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7260 struct type
*domain_type
, *set_type
;
7261 struct attribute
*attr
;
7263 domain_type
= die_type (die
, cu
);
7265 /* The die_type call above may have already set the type for this DIE. */
7266 set_type
= get_die_type (die
, cu
);
7270 set_type
= create_set_type (NULL
, domain_type
);
7272 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7274 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7276 return set_die_type (die
, set_type
, cu
);
7279 /* First cut: install each common block member as a global variable. */
7282 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7284 struct die_info
*child_die
;
7285 struct attribute
*attr
;
7287 CORE_ADDR base
= (CORE_ADDR
) 0;
7289 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7292 /* Support the .debug_loc offsets */
7293 if (attr_form_is_block (attr
))
7295 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7297 else if (attr_form_is_section_offset (attr
))
7299 dwarf2_complex_location_expr_complaint ();
7303 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7304 "common block member");
7307 if (die
->child
!= NULL
)
7309 child_die
= die
->child
;
7310 while (child_die
&& child_die
->tag
)
7312 sym
= new_symbol (child_die
, NULL
, cu
);
7313 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7314 if (sym
!= NULL
&& attr
!= NULL
)
7316 CORE_ADDR byte_offset
= 0;
7318 if (attr_form_is_section_offset (attr
))
7319 dwarf2_complex_location_expr_complaint ();
7320 else if (attr_form_is_constant (attr
))
7321 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7322 else if (attr_form_is_block (attr
))
7323 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7325 dwarf2_complex_location_expr_complaint ();
7327 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7328 add_symbol_to_list (sym
, &global_symbols
);
7330 child_die
= sibling_die (child_die
);
7335 /* Create a type for a C++ namespace. */
7337 static struct type
*
7338 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7340 struct objfile
*objfile
= cu
->objfile
;
7341 const char *previous_prefix
, *name
;
7345 /* For extensions, reuse the type of the original namespace. */
7346 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7348 struct die_info
*ext_die
;
7349 struct dwarf2_cu
*ext_cu
= cu
;
7351 ext_die
= dwarf2_extension (die
, &ext_cu
);
7352 type
= read_type_die (ext_die
, ext_cu
);
7354 /* EXT_CU may not be the same as CU.
7355 Ensure TYPE is recorded in CU's type_hash table. */
7356 return set_die_type (die
, type
, cu
);
7359 name
= namespace_name (die
, &is_anonymous
, cu
);
7361 /* Now build the name of the current namespace. */
7363 previous_prefix
= determine_prefix (die
, cu
);
7364 if (previous_prefix
[0] != '\0')
7365 name
= typename_concat (&objfile
->objfile_obstack
,
7366 previous_prefix
, name
, 0, cu
);
7368 /* Create the type. */
7369 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7371 TYPE_NAME (type
) = (char *) name
;
7372 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7374 return set_die_type (die
, type
, cu
);
7377 /* Read a C++ namespace. */
7380 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7382 struct objfile
*objfile
= cu
->objfile
;
7386 /* Add a symbol associated to this if we haven't seen the namespace
7387 before. Also, add a using directive if it's an anonymous
7390 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7394 type
= read_type_die (die
, cu
);
7395 new_symbol (die
, type
, cu
);
7397 name
= namespace_name (die
, &is_anonymous
, cu
);
7400 const char *previous_prefix
= determine_prefix (die
, cu
);
7402 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7403 NULL
, &objfile
->objfile_obstack
);
7407 if (die
->child
!= NULL
)
7409 struct die_info
*child_die
= die
->child
;
7411 while (child_die
&& child_die
->tag
)
7413 process_die (child_die
, cu
);
7414 child_die
= sibling_die (child_die
);
7419 /* Read a Fortran module as type. This DIE can be only a declaration used for
7420 imported module. Still we need that type as local Fortran "use ... only"
7421 declaration imports depend on the created type in determine_prefix. */
7423 static struct type
*
7424 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7426 struct objfile
*objfile
= cu
->objfile
;
7430 module_name
= dwarf2_name (die
, cu
);
7432 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7434 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7436 /* determine_prefix uses TYPE_TAG_NAME. */
7437 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7439 return set_die_type (die
, type
, cu
);
7442 /* Read a Fortran module. */
7445 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7447 struct die_info
*child_die
= die
->child
;
7449 while (child_die
&& child_die
->tag
)
7451 process_die (child_die
, cu
);
7452 child_die
= sibling_die (child_die
);
7456 /* Return the name of the namespace represented by DIE. Set
7457 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7461 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7463 struct die_info
*current_die
;
7464 const char *name
= NULL
;
7466 /* Loop through the extensions until we find a name. */
7468 for (current_die
= die
;
7469 current_die
!= NULL
;
7470 current_die
= dwarf2_extension (die
, &cu
))
7472 name
= dwarf2_name (current_die
, cu
);
7477 /* Is it an anonymous namespace? */
7479 *is_anonymous
= (name
== NULL
);
7481 name
= "(anonymous namespace)";
7486 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7487 the user defined type vector. */
7489 static struct type
*
7490 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7492 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7493 struct comp_unit_head
*cu_header
= &cu
->header
;
7495 struct attribute
*attr_byte_size
;
7496 struct attribute
*attr_address_class
;
7497 int byte_size
, addr_class
;
7498 struct type
*target_type
;
7500 target_type
= die_type (die
, cu
);
7502 /* The die_type call above may have already set the type for this DIE. */
7503 type
= get_die_type (die
, cu
);
7507 type
= lookup_pointer_type (target_type
);
7509 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7511 byte_size
= DW_UNSND (attr_byte_size
);
7513 byte_size
= cu_header
->addr_size
;
7515 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7516 if (attr_address_class
)
7517 addr_class
= DW_UNSND (attr_address_class
);
7519 addr_class
= DW_ADDR_none
;
7521 /* If the pointer size or address class is different than the
7522 default, create a type variant marked as such and set the
7523 length accordingly. */
7524 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7526 if (gdbarch_address_class_type_flags_p (gdbarch
))
7530 type_flags
= gdbarch_address_class_type_flags
7531 (gdbarch
, byte_size
, addr_class
);
7532 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7534 type
= make_type_with_address_space (type
, type_flags
);
7536 else if (TYPE_LENGTH (type
) != byte_size
)
7538 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7542 /* Should we also complain about unhandled address classes? */
7546 TYPE_LENGTH (type
) = byte_size
;
7547 return set_die_type (die
, type
, cu
);
7550 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7551 the user defined type vector. */
7553 static struct type
*
7554 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7557 struct type
*to_type
;
7558 struct type
*domain
;
7560 to_type
= die_type (die
, cu
);
7561 domain
= die_containing_type (die
, cu
);
7563 /* The calls above may have already set the type for this DIE. */
7564 type
= get_die_type (die
, cu
);
7568 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7569 type
= lookup_methodptr_type (to_type
);
7571 type
= lookup_memberptr_type (to_type
, domain
);
7573 return set_die_type (die
, type
, cu
);
7576 /* Extract all information from a DW_TAG_reference_type DIE and add to
7577 the user defined type vector. */
7579 static struct type
*
7580 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7582 struct comp_unit_head
*cu_header
= &cu
->header
;
7583 struct type
*type
, *target_type
;
7584 struct attribute
*attr
;
7586 target_type
= die_type (die
, cu
);
7588 /* The die_type call above may have already set the type for this DIE. */
7589 type
= get_die_type (die
, cu
);
7593 type
= lookup_reference_type (target_type
);
7594 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7597 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7601 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7603 return set_die_type (die
, type
, cu
);
7606 static struct type
*
7607 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7609 struct type
*base_type
, *cv_type
;
7611 base_type
= die_type (die
, cu
);
7613 /* The die_type call above may have already set the type for this DIE. */
7614 cv_type
= get_die_type (die
, cu
);
7618 /* In case the const qualifier is applied to an array type, the element type
7619 is so qualified, not the array type (section 6.7.3 of C99). */
7620 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7622 struct type
*el_type
, *inner_array
;
7624 base_type
= copy_type (base_type
);
7625 inner_array
= base_type
;
7627 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7629 TYPE_TARGET_TYPE (inner_array
) =
7630 copy_type (TYPE_TARGET_TYPE (inner_array
));
7631 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7634 el_type
= TYPE_TARGET_TYPE (inner_array
);
7635 TYPE_TARGET_TYPE (inner_array
) =
7636 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7638 return set_die_type (die
, base_type
, cu
);
7641 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7642 return set_die_type (die
, cv_type
, cu
);
7645 static struct type
*
7646 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7648 struct type
*base_type
, *cv_type
;
7650 base_type
= die_type (die
, cu
);
7652 /* The die_type call above may have already set the type for this DIE. */
7653 cv_type
= get_die_type (die
, cu
);
7657 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7658 return set_die_type (die
, cv_type
, cu
);
7661 /* Extract all information from a DW_TAG_string_type DIE and add to
7662 the user defined type vector. It isn't really a user defined type,
7663 but it behaves like one, with other DIE's using an AT_user_def_type
7664 attribute to reference it. */
7666 static struct type
*
7667 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7669 struct objfile
*objfile
= cu
->objfile
;
7670 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7671 struct type
*type
, *range_type
, *index_type
, *char_type
;
7672 struct attribute
*attr
;
7673 unsigned int length
;
7675 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7678 length
= DW_UNSND (attr
);
7682 /* check for the DW_AT_byte_size attribute */
7683 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7686 length
= DW_UNSND (attr
);
7694 index_type
= objfile_type (objfile
)->builtin_int
;
7695 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7696 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7697 type
= create_string_type (NULL
, char_type
, range_type
);
7699 return set_die_type (die
, type
, cu
);
7702 /* Handle DIES due to C code like:
7706 int (*funcp)(int a, long l);
7710 ('funcp' generates a DW_TAG_subroutine_type DIE)
7713 static struct type
*
7714 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7716 struct type
*type
; /* Type that this function returns */
7717 struct type
*ftype
; /* Function that returns above type */
7718 struct attribute
*attr
;
7720 type
= die_type (die
, cu
);
7722 /* The die_type call above may have already set the type for this DIE. */
7723 ftype
= get_die_type (die
, cu
);
7727 ftype
= lookup_function_type (type
);
7729 /* All functions in C++, Pascal and Java have prototypes. */
7730 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7731 if ((attr
&& (DW_UNSND (attr
) != 0))
7732 || cu
->language
== language_cplus
7733 || cu
->language
== language_java
7734 || cu
->language
== language_pascal
)
7735 TYPE_PROTOTYPED (ftype
) = 1;
7736 else if (producer_is_realview (cu
->producer
))
7737 /* RealView does not emit DW_AT_prototyped. We can not
7738 distinguish prototyped and unprototyped functions; default to
7739 prototyped, since that is more common in modern code (and
7740 RealView warns about unprototyped functions). */
7741 TYPE_PROTOTYPED (ftype
) = 1;
7743 /* Store the calling convention in the type if it's available in
7744 the subroutine die. Otherwise set the calling convention to
7745 the default value DW_CC_normal. */
7746 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7747 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7749 /* We need to add the subroutine type to the die immediately so
7750 we don't infinitely recurse when dealing with parameters
7751 declared as the same subroutine type. */
7752 set_die_type (die
, ftype
, cu
);
7754 if (die
->child
!= NULL
)
7756 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7757 struct die_info
*child_die
;
7758 int nparams
, iparams
;
7760 /* Count the number of parameters.
7761 FIXME: GDB currently ignores vararg functions, but knows about
7762 vararg member functions. */
7764 child_die
= die
->child
;
7765 while (child_die
&& child_die
->tag
)
7767 if (child_die
->tag
== DW_TAG_formal_parameter
)
7769 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7770 TYPE_VARARGS (ftype
) = 1;
7771 child_die
= sibling_die (child_die
);
7774 /* Allocate storage for parameters and fill them in. */
7775 TYPE_NFIELDS (ftype
) = nparams
;
7776 TYPE_FIELDS (ftype
) = (struct field
*)
7777 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7779 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7780 even if we error out during the parameters reading below. */
7781 for (iparams
= 0; iparams
< nparams
; iparams
++)
7782 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7785 child_die
= die
->child
;
7786 while (child_die
&& child_die
->tag
)
7788 if (child_die
->tag
== DW_TAG_formal_parameter
)
7790 struct type
*arg_type
;
7792 /* DWARF version 2 has no clean way to discern C++
7793 static and non-static member functions. G++ helps
7794 GDB by marking the first parameter for non-static
7795 member functions (which is the this pointer) as
7796 artificial. We pass this information to
7797 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7799 DWARF version 3 added DW_AT_object_pointer, which GCC
7800 4.5 does not yet generate. */
7801 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7803 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7806 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7808 /* GCC/43521: In java, the formal parameter
7809 "this" is sometimes not marked with DW_AT_artificial. */
7810 if (cu
->language
== language_java
)
7812 const char *name
= dwarf2_name (child_die
, cu
);
7814 if (name
&& !strcmp (name
, "this"))
7815 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7818 arg_type
= die_type (child_die
, cu
);
7820 /* RealView does not mark THIS as const, which the testsuite
7821 expects. GCC marks THIS as const in method definitions,
7822 but not in the class specifications (GCC PR 43053). */
7823 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7824 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7827 struct dwarf2_cu
*arg_cu
= cu
;
7828 const char *name
= dwarf2_name (child_die
, cu
);
7830 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7833 /* If the compiler emits this, use it. */
7834 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7837 else if (name
&& strcmp (name
, "this") == 0)
7838 /* Function definitions will have the argument names. */
7840 else if (name
== NULL
&& iparams
== 0)
7841 /* Declarations may not have the names, so like
7842 elsewhere in GDB, assume an artificial first
7843 argument is "this". */
7847 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7851 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7854 child_die
= sibling_die (child_die
);
7861 static struct type
*
7862 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7864 struct objfile
*objfile
= cu
->objfile
;
7865 const char *name
= NULL
;
7866 struct type
*this_type
;
7868 name
= dwarf2_full_name (NULL
, die
, cu
);
7869 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7870 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7871 TYPE_NAME (this_type
) = (char *) name
;
7872 set_die_type (die
, this_type
, cu
);
7873 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7877 /* Find a representation of a given base type and install
7878 it in the TYPE field of the die. */
7880 static struct type
*
7881 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7883 struct objfile
*objfile
= cu
->objfile
;
7885 struct attribute
*attr
;
7886 int encoding
= 0, size
= 0;
7888 enum type_code code
= TYPE_CODE_INT
;
7890 struct type
*target_type
= NULL
;
7892 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7895 encoding
= DW_UNSND (attr
);
7897 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7900 size
= DW_UNSND (attr
);
7902 name
= dwarf2_name (die
, cu
);
7905 complaint (&symfile_complaints
,
7906 _("DW_AT_name missing from DW_TAG_base_type"));
7911 case DW_ATE_address
:
7912 /* Turn DW_ATE_address into a void * pointer. */
7913 code
= TYPE_CODE_PTR
;
7914 type_flags
|= TYPE_FLAG_UNSIGNED
;
7915 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7917 case DW_ATE_boolean
:
7918 code
= TYPE_CODE_BOOL
;
7919 type_flags
|= TYPE_FLAG_UNSIGNED
;
7921 case DW_ATE_complex_float
:
7922 code
= TYPE_CODE_COMPLEX
;
7923 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7925 case DW_ATE_decimal_float
:
7926 code
= TYPE_CODE_DECFLOAT
;
7929 code
= TYPE_CODE_FLT
;
7933 case DW_ATE_unsigned
:
7934 type_flags
|= TYPE_FLAG_UNSIGNED
;
7936 case DW_ATE_signed_char
:
7937 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7938 || cu
->language
== language_pascal
)
7939 code
= TYPE_CODE_CHAR
;
7941 case DW_ATE_unsigned_char
:
7942 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7943 || cu
->language
== language_pascal
)
7944 code
= TYPE_CODE_CHAR
;
7945 type_flags
|= TYPE_FLAG_UNSIGNED
;
7948 /* We just treat this as an integer and then recognize the
7949 type by name elsewhere. */
7953 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7954 dwarf_type_encoding_name (encoding
));
7958 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7959 TYPE_NAME (type
) = name
;
7960 TYPE_TARGET_TYPE (type
) = target_type
;
7962 if (name
&& strcmp (name
, "char") == 0)
7963 TYPE_NOSIGN (type
) = 1;
7965 return set_die_type (die
, type
, cu
);
7968 /* Read the given DW_AT_subrange DIE. */
7970 static struct type
*
7971 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7973 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7974 struct type
*base_type
;
7975 struct type
*range_type
;
7976 struct attribute
*attr
;
7980 LONGEST negative_mask
;
7982 base_type
= die_type (die
, cu
);
7983 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7984 check_typedef (base_type
);
7986 /* The die_type call above may have already set the type for this DIE. */
7987 range_type
= get_die_type (die
, cu
);
7991 if (cu
->language
== language_fortran
)
7993 /* FORTRAN implies a lower bound of 1, if not given. */
7997 /* FIXME: For variable sized arrays either of these could be
7998 a variable rather than a constant value. We'll allow it,
7999 but we don't know how to handle it. */
8000 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8002 low
= dwarf2_get_attr_constant_value (attr
, 0);
8004 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8007 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8009 /* GCC encodes arrays with unspecified or dynamic length
8010 with a DW_FORM_block1 attribute or a reference attribute.
8011 FIXME: GDB does not yet know how to handle dynamic
8012 arrays properly, treat them as arrays with unspecified
8015 FIXME: jimb/2003-09-22: GDB does not really know
8016 how to handle arrays of unspecified length
8017 either; we just represent them as zero-length
8018 arrays. Choose an appropriate upper bound given
8019 the lower bound we've computed above. */
8023 high
= dwarf2_get_attr_constant_value (attr
, 1);
8027 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8030 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8031 high
= low
+ count
- 1;
8035 /* Dwarf-2 specifications explicitly allows to create subrange types
8036 without specifying a base type.
8037 In that case, the base type must be set to the type of
8038 the lower bound, upper bound or count, in that order, if any of these
8039 three attributes references an object that has a type.
8040 If no base type is found, the Dwarf-2 specifications say that
8041 a signed integer type of size equal to the size of an address should
8043 For the following C code: `extern char gdb_int [];'
8044 GCC produces an empty range DIE.
8045 FIXME: muller/2010-05-28: Possible references to object for low bound,
8046 high bound or count are not yet handled by this code.
8048 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8050 struct objfile
*objfile
= cu
->objfile
;
8051 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8052 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8053 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8055 /* Test "int", "long int", and "long long int" objfile types,
8056 and select the first one having a size above or equal to the
8057 architecture address size. */
8058 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8059 base_type
= int_type
;
8062 int_type
= objfile_type (objfile
)->builtin_long
;
8063 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8064 base_type
= int_type
;
8067 int_type
= objfile_type (objfile
)->builtin_long_long
;
8068 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8069 base_type
= int_type
;
8075 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8076 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8077 low
|= negative_mask
;
8078 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8079 high
|= negative_mask
;
8081 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8083 /* Mark arrays with dynamic length at least as an array of unspecified
8084 length. GDB could check the boundary but before it gets implemented at
8085 least allow accessing the array elements. */
8086 if (attr
&& attr
->form
== DW_FORM_block1
)
8087 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8089 name
= dwarf2_name (die
, cu
);
8091 TYPE_NAME (range_type
) = name
;
8093 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8095 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8097 set_die_type (die
, range_type
, cu
);
8099 /* set_die_type should be already done. */
8100 set_descriptive_type (range_type
, die
, cu
);
8105 static struct type
*
8106 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8110 /* For now, we only support the C meaning of an unspecified type: void. */
8112 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8113 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8115 return set_die_type (die
, type
, cu
);
8118 /* Trivial hash function for die_info: the hash value of a DIE
8119 is its offset in .debug_info for this objfile. */
8122 die_hash (const void *item
)
8124 const struct die_info
*die
= item
;
8129 /* Trivial comparison function for die_info structures: two DIEs
8130 are equal if they have the same offset. */
8133 die_eq (const void *item_lhs
, const void *item_rhs
)
8135 const struct die_info
*die_lhs
= item_lhs
;
8136 const struct die_info
*die_rhs
= item_rhs
;
8138 return die_lhs
->offset
== die_rhs
->offset
;
8141 /* Read a whole compilation unit into a linked list of dies. */
8143 static struct die_info
*
8144 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8146 struct die_reader_specs reader_specs
;
8147 int read_abbrevs
= 0;
8148 struct cleanup
*back_to
= NULL
;
8149 struct die_info
*die
;
8151 if (cu
->dwarf2_abbrevs
== NULL
)
8153 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8154 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8158 gdb_assert (cu
->die_hash
== NULL
);
8160 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8164 &cu
->comp_unit_obstack
,
8165 hashtab_obstack_allocate
,
8166 dummy_obstack_deallocate
);
8168 init_cu_die_reader (&reader_specs
, cu
);
8170 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8173 do_cleanups (back_to
);
8178 /* Main entry point for reading a DIE and all children.
8179 Read the DIE and dump it if requested. */
8181 static struct die_info
*
8182 read_die_and_children (const struct die_reader_specs
*reader
,
8184 gdb_byte
**new_info_ptr
,
8185 struct die_info
*parent
)
8187 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8188 new_info_ptr
, parent
);
8190 if (dwarf2_die_debug
)
8192 fprintf_unfiltered (gdb_stdlog
,
8193 "\nRead die from %s of %s:\n",
8194 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8196 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8198 : "unknown section",
8199 reader
->abfd
->filename
);
8200 dump_die (result
, dwarf2_die_debug
);
8206 /* Read a single die and all its descendents. Set the die's sibling
8207 field to NULL; set other fields in the die correctly, and set all
8208 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8209 location of the info_ptr after reading all of those dies. PARENT
8210 is the parent of the die in question. */
8212 static struct die_info
*
8213 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8215 gdb_byte
**new_info_ptr
,
8216 struct die_info
*parent
)
8218 struct die_info
*die
;
8222 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8225 *new_info_ptr
= cur_ptr
;
8228 store_in_ref_table (die
, reader
->cu
);
8231 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8235 *new_info_ptr
= cur_ptr
;
8238 die
->sibling
= NULL
;
8239 die
->parent
= parent
;
8243 /* Read a die, all of its descendents, and all of its siblings; set
8244 all of the fields of all of the dies correctly. Arguments are as
8245 in read_die_and_children. */
8247 static struct die_info
*
8248 read_die_and_siblings (const struct die_reader_specs
*reader
,
8250 gdb_byte
**new_info_ptr
,
8251 struct die_info
*parent
)
8253 struct die_info
*first_die
, *last_sibling
;
8257 first_die
= last_sibling
= NULL
;
8261 struct die_info
*die
8262 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8266 *new_info_ptr
= cur_ptr
;
8273 last_sibling
->sibling
= die
;
8279 /* Read the die from the .debug_info section buffer. Set DIEP to
8280 point to a newly allocated die with its information, except for its
8281 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8282 whether the die has children or not. */
8285 read_full_die (const struct die_reader_specs
*reader
,
8286 struct die_info
**diep
, gdb_byte
*info_ptr
,
8289 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8290 struct abbrev_info
*abbrev
;
8291 struct die_info
*die
;
8292 struct dwarf2_cu
*cu
= reader
->cu
;
8293 bfd
*abfd
= reader
->abfd
;
8295 offset
= info_ptr
- reader
->buffer
;
8296 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8297 info_ptr
+= bytes_read
;
8305 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8307 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8309 bfd_get_filename (abfd
));
8311 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8312 die
->offset
= offset
;
8313 die
->tag
= abbrev
->tag
;
8314 die
->abbrev
= abbrev_number
;
8316 die
->num_attrs
= abbrev
->num_attrs
;
8318 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8319 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8320 abfd
, info_ptr
, cu
);
8323 *has_children
= abbrev
->has_children
;
8327 /* In DWARF version 2, the description of the debugging information is
8328 stored in a separate .debug_abbrev section. Before we read any
8329 dies from a section we read in all abbreviations and install them
8330 in a hash table. This function also sets flags in CU describing
8331 the data found in the abbrev table. */
8334 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8336 struct comp_unit_head
*cu_header
= &cu
->header
;
8337 gdb_byte
*abbrev_ptr
;
8338 struct abbrev_info
*cur_abbrev
;
8339 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8340 unsigned int abbrev_form
, hash_number
;
8341 struct attr_abbrev
*cur_attrs
;
8342 unsigned int allocated_attrs
;
8344 /* Initialize dwarf2 abbrevs */
8345 obstack_init (&cu
->abbrev_obstack
);
8346 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8348 * sizeof (struct abbrev_info
*)));
8349 memset (cu
->dwarf2_abbrevs
, 0,
8350 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8352 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8353 &dwarf2_per_objfile
->abbrev
);
8354 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8355 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8356 abbrev_ptr
+= bytes_read
;
8358 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8359 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8361 /* loop until we reach an abbrev number of 0 */
8362 while (abbrev_number
)
8364 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8366 /* read in abbrev header */
8367 cur_abbrev
->number
= abbrev_number
;
8368 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8369 abbrev_ptr
+= bytes_read
;
8370 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8373 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8374 cu
->has_namespace_info
= 1;
8376 /* now read in declarations */
8377 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8378 abbrev_ptr
+= bytes_read
;
8379 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8380 abbrev_ptr
+= bytes_read
;
8383 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8385 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8387 = xrealloc (cur_attrs
, (allocated_attrs
8388 * sizeof (struct attr_abbrev
)));
8391 /* Record whether this compilation unit might have
8392 inter-compilation-unit references. If we don't know what form
8393 this attribute will have, then it might potentially be a
8394 DW_FORM_ref_addr, so we conservatively expect inter-CU
8397 if (abbrev_form
== DW_FORM_ref_addr
8398 || abbrev_form
== DW_FORM_indirect
)
8399 cu
->has_form_ref_addr
= 1;
8401 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8402 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8403 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8404 abbrev_ptr
+= bytes_read
;
8405 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8406 abbrev_ptr
+= bytes_read
;
8409 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8410 (cur_abbrev
->num_attrs
8411 * sizeof (struct attr_abbrev
)));
8412 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8413 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8415 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8416 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8417 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8419 /* Get next abbreviation.
8420 Under Irix6 the abbreviations for a compilation unit are not
8421 always properly terminated with an abbrev number of 0.
8422 Exit loop if we encounter an abbreviation which we have
8423 already read (which means we are about to read the abbreviations
8424 for the next compile unit) or if the end of the abbreviation
8425 table is reached. */
8426 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8427 >= dwarf2_per_objfile
->abbrev
.size
)
8429 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8430 abbrev_ptr
+= bytes_read
;
8431 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8438 /* Release the memory used by the abbrev table for a compilation unit. */
8441 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8443 struct dwarf2_cu
*cu
= ptr_to_cu
;
8445 obstack_free (&cu
->abbrev_obstack
, NULL
);
8446 cu
->dwarf2_abbrevs
= NULL
;
8449 /* Lookup an abbrev_info structure in the abbrev hash table. */
8451 static struct abbrev_info
*
8452 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8454 unsigned int hash_number
;
8455 struct abbrev_info
*abbrev
;
8457 hash_number
= number
% ABBREV_HASH_SIZE
;
8458 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8462 if (abbrev
->number
== number
)
8465 abbrev
= abbrev
->next
;
8470 /* Returns nonzero if TAG represents a type that we might generate a partial
8474 is_type_tag_for_partial (int tag
)
8479 /* Some types that would be reasonable to generate partial symbols for,
8480 that we don't at present. */
8481 case DW_TAG_array_type
:
8482 case DW_TAG_file_type
:
8483 case DW_TAG_ptr_to_member_type
:
8484 case DW_TAG_set_type
:
8485 case DW_TAG_string_type
:
8486 case DW_TAG_subroutine_type
:
8488 case DW_TAG_base_type
:
8489 case DW_TAG_class_type
:
8490 case DW_TAG_interface_type
:
8491 case DW_TAG_enumeration_type
:
8492 case DW_TAG_structure_type
:
8493 case DW_TAG_subrange_type
:
8494 case DW_TAG_typedef
:
8495 case DW_TAG_union_type
:
8502 /* Load all DIEs that are interesting for partial symbols into memory. */
8504 static struct partial_die_info
*
8505 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8506 int building_psymtab
, struct dwarf2_cu
*cu
)
8508 struct partial_die_info
*part_die
;
8509 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8510 struct abbrev_info
*abbrev
;
8511 unsigned int bytes_read
;
8512 unsigned int load_all
= 0;
8514 int nesting_level
= 1;
8519 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8523 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8527 &cu
->comp_unit_obstack
,
8528 hashtab_obstack_allocate
,
8529 dummy_obstack_deallocate
);
8531 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8532 sizeof (struct partial_die_info
));
8536 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8538 /* A NULL abbrev means the end of a series of children. */
8541 if (--nesting_level
== 0)
8543 /* PART_DIE was probably the last thing allocated on the
8544 comp_unit_obstack, so we could call obstack_free
8545 here. We don't do that because the waste is small,
8546 and will be cleaned up when we're done with this
8547 compilation unit. This way, we're also more robust
8548 against other users of the comp_unit_obstack. */
8551 info_ptr
+= bytes_read
;
8552 last_die
= parent_die
;
8553 parent_die
= parent_die
->die_parent
;
8557 /* Check for template arguments. We never save these; if
8558 they're seen, we just mark the parent, and go on our way. */
8559 if (parent_die
!= NULL
8560 && cu
->language
== language_cplus
8561 && (abbrev
->tag
== DW_TAG_template_type_param
8562 || abbrev
->tag
== DW_TAG_template_value_param
))
8564 parent_die
->has_template_arguments
= 1;
8568 /* We don't need a partial DIE for the template argument. */
8569 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8575 /* We only recurse into subprograms looking for template arguments.
8576 Skip their other children. */
8578 && cu
->language
== language_cplus
8579 && parent_die
!= NULL
8580 && parent_die
->tag
== DW_TAG_subprogram
)
8582 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8586 /* Check whether this DIE is interesting enough to save. Normally
8587 we would not be interested in members here, but there may be
8588 later variables referencing them via DW_AT_specification (for
8591 && !is_type_tag_for_partial (abbrev
->tag
)
8592 && abbrev
->tag
!= DW_TAG_constant
8593 && abbrev
->tag
!= DW_TAG_enumerator
8594 && abbrev
->tag
!= DW_TAG_subprogram
8595 && abbrev
->tag
!= DW_TAG_lexical_block
8596 && abbrev
->tag
!= DW_TAG_variable
8597 && abbrev
->tag
!= DW_TAG_namespace
8598 && abbrev
->tag
!= DW_TAG_module
8599 && abbrev
->tag
!= DW_TAG_member
)
8601 /* Otherwise we skip to the next sibling, if any. */
8602 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8606 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8607 buffer
, info_ptr
, cu
);
8609 /* This two-pass algorithm for processing partial symbols has a
8610 high cost in cache pressure. Thus, handle some simple cases
8611 here which cover the majority of C partial symbols. DIEs
8612 which neither have specification tags in them, nor could have
8613 specification tags elsewhere pointing at them, can simply be
8614 processed and discarded.
8616 This segment is also optional; scan_partial_symbols and
8617 add_partial_symbol will handle these DIEs if we chain
8618 them in normally. When compilers which do not emit large
8619 quantities of duplicate debug information are more common,
8620 this code can probably be removed. */
8622 /* Any complete simple types at the top level (pretty much all
8623 of them, for a language without namespaces), can be processed
8625 if (parent_die
== NULL
8626 && part_die
->has_specification
== 0
8627 && part_die
->is_declaration
== 0
8628 && (part_die
->tag
== DW_TAG_typedef
8629 || part_die
->tag
== DW_TAG_base_type
8630 || part_die
->tag
== DW_TAG_subrange_type
))
8632 if (building_psymtab
&& part_die
->name
!= NULL
)
8633 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8634 VAR_DOMAIN
, LOC_TYPEDEF
,
8635 &cu
->objfile
->static_psymbols
,
8636 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8637 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8641 /* If we're at the second level, and we're an enumerator, and
8642 our parent has no specification (meaning possibly lives in a
8643 namespace elsewhere), then we can add the partial symbol now
8644 instead of queueing it. */
8645 if (part_die
->tag
== DW_TAG_enumerator
8646 && parent_die
!= NULL
8647 && parent_die
->die_parent
== NULL
8648 && parent_die
->tag
== DW_TAG_enumeration_type
8649 && parent_die
->has_specification
== 0)
8651 if (part_die
->name
== NULL
)
8652 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8653 else if (building_psymtab
)
8654 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8655 VAR_DOMAIN
, LOC_CONST
,
8656 (cu
->language
== language_cplus
8657 || cu
->language
== language_java
)
8658 ? &cu
->objfile
->global_psymbols
8659 : &cu
->objfile
->static_psymbols
,
8660 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8662 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8666 /* We'll save this DIE so link it in. */
8667 part_die
->die_parent
= parent_die
;
8668 part_die
->die_sibling
= NULL
;
8669 part_die
->die_child
= NULL
;
8671 if (last_die
&& last_die
== parent_die
)
8672 last_die
->die_child
= part_die
;
8674 last_die
->die_sibling
= part_die
;
8676 last_die
= part_die
;
8678 if (first_die
== NULL
)
8679 first_die
= part_die
;
8681 /* Maybe add the DIE to the hash table. Not all DIEs that we
8682 find interesting need to be in the hash table, because we
8683 also have the parent/sibling/child chains; only those that we
8684 might refer to by offset later during partial symbol reading.
8686 For now this means things that might have be the target of a
8687 DW_AT_specification, DW_AT_abstract_origin, or
8688 DW_AT_extension. DW_AT_extension will refer only to
8689 namespaces; DW_AT_abstract_origin refers to functions (and
8690 many things under the function DIE, but we do not recurse
8691 into function DIEs during partial symbol reading) and
8692 possibly variables as well; DW_AT_specification refers to
8693 declarations. Declarations ought to have the DW_AT_declaration
8694 flag. It happens that GCC forgets to put it in sometimes, but
8695 only for functions, not for types.
8697 Adding more things than necessary to the hash table is harmless
8698 except for the performance cost. Adding too few will result in
8699 wasted time in find_partial_die, when we reread the compilation
8700 unit with load_all_dies set. */
8703 || abbrev
->tag
== DW_TAG_constant
8704 || abbrev
->tag
== DW_TAG_subprogram
8705 || abbrev
->tag
== DW_TAG_variable
8706 || abbrev
->tag
== DW_TAG_namespace
8707 || part_die
->is_declaration
)
8711 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8712 part_die
->offset
, INSERT
);
8716 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8717 sizeof (struct partial_die_info
));
8719 /* For some DIEs we want to follow their children (if any). For C
8720 we have no reason to follow the children of structures; for other
8721 languages we have to, so that we can get at method physnames
8722 to infer fully qualified class names, for DW_AT_specification,
8723 and for C++ template arguments. For C++, we also look one level
8724 inside functions to find template arguments (if the name of the
8725 function does not already contain the template arguments).
8727 For Ada, we need to scan the children of subprograms and lexical
8728 blocks as well because Ada allows the definition of nested
8729 entities that could be interesting for the debugger, such as
8730 nested subprograms for instance. */
8731 if (last_die
->has_children
8733 || last_die
->tag
== DW_TAG_namespace
8734 || last_die
->tag
== DW_TAG_module
8735 || last_die
->tag
== DW_TAG_enumeration_type
8736 || (cu
->language
== language_cplus
8737 && last_die
->tag
== DW_TAG_subprogram
8738 && (last_die
->name
== NULL
8739 || strchr (last_die
->name
, '<') == NULL
))
8740 || (cu
->language
!= language_c
8741 && (last_die
->tag
== DW_TAG_class_type
8742 || last_die
->tag
== DW_TAG_interface_type
8743 || last_die
->tag
== DW_TAG_structure_type
8744 || last_die
->tag
== DW_TAG_union_type
))
8745 || (cu
->language
== language_ada
8746 && (last_die
->tag
== DW_TAG_subprogram
8747 || last_die
->tag
== DW_TAG_lexical_block
))))
8750 parent_die
= last_die
;
8754 /* Otherwise we skip to the next sibling, if any. */
8755 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8757 /* Back to the top, do it again. */
8761 /* Read a minimal amount of information into the minimal die structure. */
8764 read_partial_die (struct partial_die_info
*part_die
,
8765 struct abbrev_info
*abbrev
,
8766 unsigned int abbrev_len
, bfd
*abfd
,
8767 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8768 struct dwarf2_cu
*cu
)
8771 struct attribute attr
;
8772 int has_low_pc_attr
= 0;
8773 int has_high_pc_attr
= 0;
8775 memset (part_die
, 0, sizeof (struct partial_die_info
));
8777 part_die
->offset
= info_ptr
- buffer
;
8779 info_ptr
+= abbrev_len
;
8784 part_die
->tag
= abbrev
->tag
;
8785 part_die
->has_children
= abbrev
->has_children
;
8787 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8789 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8791 /* Store the data if it is of an attribute we want to keep in a
8792 partial symbol table. */
8796 switch (part_die
->tag
)
8798 case DW_TAG_compile_unit
:
8799 case DW_TAG_type_unit
:
8800 /* Compilation units have a DW_AT_name that is a filename, not
8801 a source language identifier. */
8802 case DW_TAG_enumeration_type
:
8803 case DW_TAG_enumerator
:
8804 /* These tags always have simple identifiers already; no need
8805 to canonicalize them. */
8806 part_die
->name
= DW_STRING (&attr
);
8810 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8811 &cu
->objfile
->objfile_obstack
);
8815 case DW_AT_linkage_name
:
8816 case DW_AT_MIPS_linkage_name
:
8817 /* Note that both forms of linkage name might appear. We
8818 assume they will be the same, and we only store the last
8820 if (cu
->language
== language_ada
)
8821 part_die
->name
= DW_STRING (&attr
);
8822 part_die
->linkage_name
= DW_STRING (&attr
);
8825 has_low_pc_attr
= 1;
8826 part_die
->lowpc
= DW_ADDR (&attr
);
8829 has_high_pc_attr
= 1;
8830 part_die
->highpc
= DW_ADDR (&attr
);
8832 case DW_AT_location
:
8833 /* Support the .debug_loc offsets */
8834 if (attr_form_is_block (&attr
))
8836 part_die
->locdesc
= DW_BLOCK (&attr
);
8838 else if (attr_form_is_section_offset (&attr
))
8840 dwarf2_complex_location_expr_complaint ();
8844 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8845 "partial symbol information");
8848 case DW_AT_external
:
8849 part_die
->is_external
= DW_UNSND (&attr
);
8851 case DW_AT_declaration
:
8852 part_die
->is_declaration
= DW_UNSND (&attr
);
8855 part_die
->has_type
= 1;
8857 case DW_AT_abstract_origin
:
8858 case DW_AT_specification
:
8859 case DW_AT_extension
:
8860 part_die
->has_specification
= 1;
8861 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8864 /* Ignore absolute siblings, they might point outside of
8865 the current compile unit. */
8866 if (attr
.form
== DW_FORM_ref_addr
)
8867 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8869 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8871 case DW_AT_byte_size
:
8872 part_die
->has_byte_size
= 1;
8874 case DW_AT_calling_convention
:
8875 /* DWARF doesn't provide a way to identify a program's source-level
8876 entry point. DW_AT_calling_convention attributes are only meant
8877 to describe functions' calling conventions.
8879 However, because it's a necessary piece of information in
8880 Fortran, and because DW_CC_program is the only piece of debugging
8881 information whose definition refers to a 'main program' at all,
8882 several compilers have begun marking Fortran main programs with
8883 DW_CC_program --- even when those functions use the standard
8884 calling conventions.
8886 So until DWARF specifies a way to provide this information and
8887 compilers pick up the new representation, we'll support this
8889 if (DW_UNSND (&attr
) == DW_CC_program
8890 && cu
->language
== language_fortran
)
8892 set_main_name (part_die
->name
);
8894 /* As this DIE has a static linkage the name would be difficult
8895 to look up later. */
8896 language_of_main
= language_fortran
;
8904 /* When using the GNU linker, .gnu.linkonce. sections are used to
8905 eliminate duplicate copies of functions and vtables and such.
8906 The linker will arbitrarily choose one and discard the others.
8907 The AT_*_pc values for such functions refer to local labels in
8908 these sections. If the section from that file was discarded, the
8909 labels are not in the output, so the relocs get a value of 0.
8910 If this is a discarded function, mark the pc bounds as invalid,
8911 so that GDB will ignore it. */
8912 if (has_low_pc_attr
&& has_high_pc_attr
8913 && part_die
->lowpc
< part_die
->highpc
8914 && (part_die
->lowpc
!= 0
8915 || dwarf2_per_objfile
->has_section_at_zero
))
8916 part_die
->has_pc_info
= 1;
8921 /* Find a cached partial DIE at OFFSET in CU. */
8923 static struct partial_die_info
*
8924 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8926 struct partial_die_info
*lookup_die
= NULL
;
8927 struct partial_die_info part_die
;
8929 part_die
.offset
= offset
;
8930 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8935 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8936 except in the case of .debug_types DIEs which do not reference
8937 outside their CU (they do however referencing other types via
8940 static struct partial_die_info
*
8941 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8943 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8944 struct partial_die_info
*pd
= NULL
;
8946 if (cu
->per_cu
->from_debug_types
)
8948 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8954 if (offset_in_cu_p (&cu
->header
, offset
))
8956 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8961 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8963 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8964 load_partial_comp_unit (per_cu
, cu
->objfile
);
8966 per_cu
->cu
->last_used
= 0;
8967 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8969 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8971 struct cleanup
*back_to
;
8972 struct partial_die_info comp_unit_die
;
8973 struct abbrev_info
*abbrev
;
8974 unsigned int bytes_read
;
8977 per_cu
->load_all_dies
= 1;
8979 /* Re-read the DIEs. */
8980 back_to
= make_cleanup (null_cleanup
, 0);
8981 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8983 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8984 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8986 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8987 + per_cu
->cu
->header
.offset
8988 + per_cu
->cu
->header
.first_die_offset
);
8989 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8990 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8991 per_cu
->cu
->objfile
->obfd
,
8992 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8994 if (comp_unit_die
.has_children
)
8995 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8996 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8998 do_cleanups (back_to
);
9000 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9006 internal_error (__FILE__
, __LINE__
,
9007 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
9008 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9012 /* See if we can figure out if the class lives in a namespace. We do
9013 this by looking for a member function; its demangled name will
9014 contain namespace info, if there is any. */
9017 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9018 struct dwarf2_cu
*cu
)
9020 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9021 what template types look like, because the demangler
9022 frequently doesn't give the same name as the debug info. We
9023 could fix this by only using the demangled name to get the
9024 prefix (but see comment in read_structure_type). */
9026 struct partial_die_info
*real_pdi
;
9027 struct partial_die_info
*child_pdi
;
9029 /* If this DIE (this DIE's specification, if any) has a parent, then
9030 we should not do this. We'll prepend the parent's fully qualified
9031 name when we create the partial symbol. */
9033 real_pdi
= struct_pdi
;
9034 while (real_pdi
->has_specification
)
9035 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9037 if (real_pdi
->die_parent
!= NULL
)
9040 for (child_pdi
= struct_pdi
->die_child
;
9042 child_pdi
= child_pdi
->die_sibling
)
9044 if (child_pdi
->tag
== DW_TAG_subprogram
9045 && child_pdi
->linkage_name
!= NULL
)
9047 char *actual_class_name
9048 = language_class_name_from_physname (cu
->language_defn
,
9049 child_pdi
->linkage_name
);
9050 if (actual_class_name
!= NULL
)
9053 = obsavestring (actual_class_name
,
9054 strlen (actual_class_name
),
9055 &cu
->objfile
->objfile_obstack
);
9056 xfree (actual_class_name
);
9063 /* Adjust PART_DIE before generating a symbol for it. This function
9064 may set the is_external flag or change the DIE's name. */
9067 fixup_partial_die (struct partial_die_info
*part_die
,
9068 struct dwarf2_cu
*cu
)
9070 /* Once we've fixed up a die, there's no point in doing so again.
9071 This also avoids a memory leak if we were to call
9072 guess_partial_die_structure_name multiple times. */
9073 if (part_die
->fixup_called
)
9076 /* If we found a reference attribute and the DIE has no name, try
9077 to find a name in the referred to DIE. */
9079 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9081 struct partial_die_info
*spec_die
;
9083 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9085 fixup_partial_die (spec_die
, cu
);
9089 part_die
->name
= spec_die
->name
;
9091 /* Copy DW_AT_external attribute if it is set. */
9092 if (spec_die
->is_external
)
9093 part_die
->is_external
= spec_die
->is_external
;
9097 /* Set default names for some unnamed DIEs. */
9099 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9100 part_die
->name
= "(anonymous namespace)";
9102 /* If there is no parent die to provide a namespace, and there are
9103 children, see if we can determine the namespace from their linkage
9105 NOTE: We need to do this even if cu->has_namespace_info != 0.
9106 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9107 if (cu
->language
== language_cplus
9108 && dwarf2_per_objfile
->types
.asection
!= NULL
9109 && part_die
->die_parent
== NULL
9110 && part_die
->has_children
9111 && (part_die
->tag
== DW_TAG_class_type
9112 || part_die
->tag
== DW_TAG_structure_type
9113 || part_die
->tag
== DW_TAG_union_type
))
9114 guess_partial_die_structure_name (part_die
, cu
);
9116 part_die
->fixup_called
= 1;
9119 /* Read an attribute value described by an attribute form. */
9122 read_attribute_value (struct attribute
*attr
, unsigned form
,
9123 bfd
*abfd
, gdb_byte
*info_ptr
,
9124 struct dwarf2_cu
*cu
)
9126 struct comp_unit_head
*cu_header
= &cu
->header
;
9127 unsigned int bytes_read
;
9128 struct dwarf_block
*blk
;
9133 case DW_FORM_ref_addr
:
9134 if (cu
->header
.version
== 2)
9135 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9137 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9138 info_ptr
+= bytes_read
;
9141 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9142 info_ptr
+= bytes_read
;
9144 case DW_FORM_block2
:
9145 blk
= dwarf_alloc_block (cu
);
9146 blk
->size
= read_2_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
;
9152 case DW_FORM_block4
:
9153 blk
= dwarf_alloc_block (cu
);
9154 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9156 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9157 info_ptr
+= blk
->size
;
9158 DW_BLOCK (attr
) = blk
;
9161 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9165 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9169 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9172 case DW_FORM_sec_offset
:
9173 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9174 info_ptr
+= bytes_read
;
9176 case DW_FORM_string
:
9177 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9178 DW_STRING_IS_CANONICAL (attr
) = 0;
9179 info_ptr
+= bytes_read
;
9182 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9184 DW_STRING_IS_CANONICAL (attr
) = 0;
9185 info_ptr
+= bytes_read
;
9187 case DW_FORM_exprloc
:
9189 blk
= dwarf_alloc_block (cu
);
9190 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9191 info_ptr
+= bytes_read
;
9192 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9193 info_ptr
+= blk
->size
;
9194 DW_BLOCK (attr
) = blk
;
9196 case DW_FORM_block1
:
9197 blk
= dwarf_alloc_block (cu
);
9198 blk
->size
= read_1_byte (abfd
, info_ptr
);
9200 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9201 info_ptr
+= blk
->size
;
9202 DW_BLOCK (attr
) = blk
;
9205 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9209 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9212 case DW_FORM_flag_present
:
9213 DW_UNSND (attr
) = 1;
9216 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9217 info_ptr
+= bytes_read
;
9220 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9221 info_ptr
+= bytes_read
;
9224 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9228 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9232 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9236 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9240 /* Convert the signature to something we can record in DW_UNSND
9242 NOTE: This is NULL if the type wasn't found. */
9243 DW_SIGNATURED_TYPE (attr
) =
9244 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9247 case DW_FORM_ref_udata
:
9248 DW_ADDR (attr
) = (cu
->header
.offset
9249 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9250 info_ptr
+= bytes_read
;
9252 case DW_FORM_indirect
:
9253 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9254 info_ptr
+= bytes_read
;
9255 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9258 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9259 dwarf_form_name (form
),
9260 bfd_get_filename (abfd
));
9263 /* We have seen instances where the compiler tried to emit a byte
9264 size attribute of -1 which ended up being encoded as an unsigned
9265 0xffffffff. Although 0xffffffff is technically a valid size value,
9266 an object of this size seems pretty unlikely so we can relatively
9267 safely treat these cases as if the size attribute was invalid and
9268 treat them as zero by default. */
9269 if (attr
->name
== DW_AT_byte_size
9270 && form
== DW_FORM_data4
9271 && DW_UNSND (attr
) >= 0xffffffff)
9274 (&symfile_complaints
,
9275 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9276 hex_string (DW_UNSND (attr
)));
9277 DW_UNSND (attr
) = 0;
9283 /* Read an attribute described by an abbreviated attribute. */
9286 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9287 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9289 attr
->name
= abbrev
->name
;
9290 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9293 /* read dwarf information from a buffer */
9296 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9298 return bfd_get_8 (abfd
, buf
);
9302 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9304 return bfd_get_signed_8 (abfd
, buf
);
9308 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9310 return bfd_get_16 (abfd
, buf
);
9314 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9316 return bfd_get_signed_16 (abfd
, buf
);
9320 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9322 return bfd_get_32 (abfd
, buf
);
9326 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9328 return bfd_get_signed_32 (abfd
, buf
);
9332 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9334 return bfd_get_64 (abfd
, buf
);
9338 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9339 unsigned int *bytes_read
)
9341 struct comp_unit_head
*cu_header
= &cu
->header
;
9342 CORE_ADDR retval
= 0;
9344 if (cu_header
->signed_addr_p
)
9346 switch (cu_header
->addr_size
)
9349 retval
= bfd_get_signed_16 (abfd
, buf
);
9352 retval
= bfd_get_signed_32 (abfd
, buf
);
9355 retval
= bfd_get_signed_64 (abfd
, buf
);
9358 internal_error (__FILE__
, __LINE__
,
9359 _("read_address: bad switch, signed [in module %s]"),
9360 bfd_get_filename (abfd
));
9365 switch (cu_header
->addr_size
)
9368 retval
= bfd_get_16 (abfd
, buf
);
9371 retval
= bfd_get_32 (abfd
, buf
);
9374 retval
= bfd_get_64 (abfd
, buf
);
9377 internal_error (__FILE__
, __LINE__
,
9378 _("read_address: bad switch, unsigned [in module %s]"),
9379 bfd_get_filename (abfd
));
9383 *bytes_read
= cu_header
->addr_size
;
9387 /* Read the initial length from a section. The (draft) DWARF 3
9388 specification allows the initial length to take up either 4 bytes
9389 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9390 bytes describe the length and all offsets will be 8 bytes in length
9393 An older, non-standard 64-bit format is also handled by this
9394 function. The older format in question stores the initial length
9395 as an 8-byte quantity without an escape value. Lengths greater
9396 than 2^32 aren't very common which means that the initial 4 bytes
9397 is almost always zero. Since a length value of zero doesn't make
9398 sense for the 32-bit format, this initial zero can be considered to
9399 be an escape value which indicates the presence of the older 64-bit
9400 format. As written, the code can't detect (old format) lengths
9401 greater than 4GB. If it becomes necessary to handle lengths
9402 somewhat larger than 4GB, we could allow other small values (such
9403 as the non-sensical values of 1, 2, and 3) to also be used as
9404 escape values indicating the presence of the old format.
9406 The value returned via bytes_read should be used to increment the
9407 relevant pointer after calling read_initial_length().
9409 [ Note: read_initial_length() and read_offset() are based on the
9410 document entitled "DWARF Debugging Information Format", revision
9411 3, draft 8, dated November 19, 2001. This document was obtained
9414 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9416 This document is only a draft and is subject to change. (So beware.)
9418 Details regarding the older, non-standard 64-bit format were
9419 determined empirically by examining 64-bit ELF files produced by
9420 the SGI toolchain on an IRIX 6.5 machine.
9422 - Kevin, July 16, 2002
9426 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9428 LONGEST length
= bfd_get_32 (abfd
, buf
);
9430 if (length
== 0xffffffff)
9432 length
= bfd_get_64 (abfd
, buf
+ 4);
9435 else if (length
== 0)
9437 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9438 length
= bfd_get_64 (abfd
, buf
);
9449 /* Cover function for read_initial_length.
9450 Returns the length of the object at BUF, and stores the size of the
9451 initial length in *BYTES_READ and stores the size that offsets will be in
9453 If the initial length size is not equivalent to that specified in
9454 CU_HEADER then issue a complaint.
9455 This is useful when reading non-comp-unit headers. */
9458 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9459 const struct comp_unit_head
*cu_header
,
9460 unsigned int *bytes_read
,
9461 unsigned int *offset_size
)
9463 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9465 gdb_assert (cu_header
->initial_length_size
== 4
9466 || cu_header
->initial_length_size
== 8
9467 || cu_header
->initial_length_size
== 12);
9469 if (cu_header
->initial_length_size
!= *bytes_read
)
9470 complaint (&symfile_complaints
,
9471 _("intermixed 32-bit and 64-bit DWARF sections"));
9473 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9477 /* Read an offset from the data stream. The size of the offset is
9478 given by cu_header->offset_size. */
9481 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9482 unsigned int *bytes_read
)
9484 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9486 *bytes_read
= cu_header
->offset_size
;
9490 /* Read an offset from the data stream. */
9493 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9497 switch (offset_size
)
9500 retval
= bfd_get_32 (abfd
, buf
);
9503 retval
= bfd_get_64 (abfd
, buf
);
9506 internal_error (__FILE__
, __LINE__
,
9507 _("read_offset_1: bad switch [in module %s]"),
9508 bfd_get_filename (abfd
));
9515 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9517 /* If the size of a host char is 8 bits, we can return a pointer
9518 to the buffer, otherwise we have to copy the data to a buffer
9519 allocated on the temporary obstack. */
9520 gdb_assert (HOST_CHAR_BIT
== 8);
9525 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9527 /* If the size of a host char is 8 bits, we can return a pointer
9528 to the string, otherwise we have to copy the string to a buffer
9529 allocated on the temporary obstack. */
9530 gdb_assert (HOST_CHAR_BIT
== 8);
9533 *bytes_read_ptr
= 1;
9536 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9537 return (char *) buf
;
9541 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9542 const struct comp_unit_head
*cu_header
,
9543 unsigned int *bytes_read_ptr
)
9545 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9547 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9548 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9550 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9551 bfd_get_filename (abfd
));
9554 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9556 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9557 bfd_get_filename (abfd
));
9560 gdb_assert (HOST_CHAR_BIT
== 8);
9561 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9563 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9566 static unsigned long
9567 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9569 unsigned long result
;
9570 unsigned int num_read
;
9580 byte
= bfd_get_8 (abfd
, buf
);
9583 result
|= ((unsigned long)(byte
& 127) << shift
);
9584 if ((byte
& 128) == 0)
9590 *bytes_read_ptr
= num_read
;
9595 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9598 int i
, shift
, num_read
;
9607 byte
= bfd_get_8 (abfd
, buf
);
9610 result
|= ((long)(byte
& 127) << shift
);
9612 if ((byte
& 128) == 0)
9617 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9618 result
|= -(((long)1) << shift
);
9619 *bytes_read_ptr
= num_read
;
9623 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9626 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9632 byte
= bfd_get_8 (abfd
, buf
);
9634 if ((byte
& 128) == 0)
9640 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9647 cu
->language
= language_c
;
9649 case DW_LANG_C_plus_plus
:
9650 cu
->language
= language_cplus
;
9653 cu
->language
= language_d
;
9655 case DW_LANG_Fortran77
:
9656 case DW_LANG_Fortran90
:
9657 case DW_LANG_Fortran95
:
9658 cu
->language
= language_fortran
;
9660 case DW_LANG_Mips_Assembler
:
9661 cu
->language
= language_asm
;
9664 cu
->language
= language_java
;
9668 cu
->language
= language_ada
;
9670 case DW_LANG_Modula2
:
9671 cu
->language
= language_m2
;
9673 case DW_LANG_Pascal83
:
9674 cu
->language
= language_pascal
;
9677 cu
->language
= language_objc
;
9679 case DW_LANG_Cobol74
:
9680 case DW_LANG_Cobol85
:
9682 cu
->language
= language_minimal
;
9685 cu
->language_defn
= language_def (cu
->language
);
9688 /* Return the named attribute or NULL if not there. */
9690 static struct attribute
*
9691 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9694 struct attribute
*spec
= NULL
;
9696 for (i
= 0; i
< die
->num_attrs
; ++i
)
9698 if (die
->attrs
[i
].name
== name
)
9699 return &die
->attrs
[i
];
9700 if (die
->attrs
[i
].name
== DW_AT_specification
9701 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9702 spec
= &die
->attrs
[i
];
9707 die
= follow_die_ref (die
, spec
, &cu
);
9708 return dwarf2_attr (die
, name
, cu
);
9714 /* Return the named attribute or NULL if not there,
9715 but do not follow DW_AT_specification, etc.
9716 This is for use in contexts where we're reading .debug_types dies.
9717 Following DW_AT_specification, DW_AT_abstract_origin will take us
9718 back up the chain, and we want to go down. */
9720 static struct attribute
*
9721 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9722 struct dwarf2_cu
*cu
)
9726 for (i
= 0; i
< die
->num_attrs
; ++i
)
9727 if (die
->attrs
[i
].name
== name
)
9728 return &die
->attrs
[i
];
9733 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9734 and holds a non-zero value. This function should only be used for
9735 DW_FORM_flag or DW_FORM_flag_present attributes. */
9738 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9740 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9742 return (attr
&& DW_UNSND (attr
));
9746 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9748 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9749 which value is non-zero. However, we have to be careful with
9750 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9751 (via dwarf2_flag_true_p) follows this attribute. So we may
9752 end up accidently finding a declaration attribute that belongs
9753 to a different DIE referenced by the specification attribute,
9754 even though the given DIE does not have a declaration attribute. */
9755 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9756 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9759 /* Return the die giving the specification for DIE, if there is
9760 one. *SPEC_CU is the CU containing DIE on input, and the CU
9761 containing the return value on output. If there is no
9762 specification, but there is an abstract origin, that is
9765 static struct die_info
*
9766 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9768 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9771 if (spec_attr
== NULL
)
9772 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9774 if (spec_attr
== NULL
)
9777 return follow_die_ref (die
, spec_attr
, spec_cu
);
9780 /* Free the line_header structure *LH, and any arrays and strings it
9783 free_line_header (struct line_header
*lh
)
9785 if (lh
->standard_opcode_lengths
)
9786 xfree (lh
->standard_opcode_lengths
);
9788 /* Remember that all the lh->file_names[i].name pointers are
9789 pointers into debug_line_buffer, and don't need to be freed. */
9791 xfree (lh
->file_names
);
9793 /* Similarly for the include directory names. */
9794 if (lh
->include_dirs
)
9795 xfree (lh
->include_dirs
);
9801 /* Add an entry to LH's include directory table. */
9803 add_include_dir (struct line_header
*lh
, char *include_dir
)
9805 /* Grow the array if necessary. */
9806 if (lh
->include_dirs_size
== 0)
9808 lh
->include_dirs_size
= 1; /* for testing */
9809 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9810 * sizeof (*lh
->include_dirs
));
9812 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9814 lh
->include_dirs_size
*= 2;
9815 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9816 (lh
->include_dirs_size
9817 * sizeof (*lh
->include_dirs
)));
9820 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9824 /* Add an entry to LH's file name table. */
9826 add_file_name (struct line_header
*lh
,
9828 unsigned int dir_index
,
9829 unsigned int mod_time
,
9830 unsigned int length
)
9832 struct file_entry
*fe
;
9834 /* Grow the array if necessary. */
9835 if (lh
->file_names_size
== 0)
9837 lh
->file_names_size
= 1; /* for testing */
9838 lh
->file_names
= xmalloc (lh
->file_names_size
9839 * sizeof (*lh
->file_names
));
9841 else if (lh
->num_file_names
>= lh
->file_names_size
)
9843 lh
->file_names_size
*= 2;
9844 lh
->file_names
= xrealloc (lh
->file_names
,
9845 (lh
->file_names_size
9846 * sizeof (*lh
->file_names
)));
9849 fe
= &lh
->file_names
[lh
->num_file_names
++];
9851 fe
->dir_index
= dir_index
;
9852 fe
->mod_time
= mod_time
;
9853 fe
->length
= length
;
9859 /* Read the statement program header starting at OFFSET in
9860 .debug_line, according to the endianness of ABFD. Return a pointer
9861 to a struct line_header, allocated using xmalloc.
9863 NOTE: the strings in the include directory and file name tables of
9864 the returned object point into debug_line_buffer, and must not be
9866 static struct line_header
*
9867 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9868 struct dwarf2_cu
*cu
)
9870 struct cleanup
*back_to
;
9871 struct line_header
*lh
;
9873 unsigned int bytes_read
, offset_size
;
9875 char *cur_dir
, *cur_file
;
9877 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9878 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9880 complaint (&symfile_complaints
, _("missing .debug_line section"));
9884 /* Make sure that at least there's room for the total_length field.
9885 That could be 12 bytes long, but we're just going to fudge that. */
9886 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9888 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9892 lh
= xmalloc (sizeof (*lh
));
9893 memset (lh
, 0, sizeof (*lh
));
9894 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9897 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9899 /* Read in the header. */
9901 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9902 &bytes_read
, &offset_size
);
9903 line_ptr
+= bytes_read
;
9904 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9905 + dwarf2_per_objfile
->line
.size
))
9907 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9910 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9911 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9913 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9914 line_ptr
+= offset_size
;
9915 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9917 if (lh
->version
>= 4)
9919 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9923 lh
->maximum_ops_per_instruction
= 1;
9925 if (lh
->maximum_ops_per_instruction
== 0)
9927 lh
->maximum_ops_per_instruction
= 1;
9928 complaint (&symfile_complaints
,
9929 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9932 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9934 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9936 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9938 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9940 lh
->standard_opcode_lengths
9941 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9943 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9944 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9946 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9950 /* Read directory table. */
9951 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9953 line_ptr
+= bytes_read
;
9954 add_include_dir (lh
, cur_dir
);
9956 line_ptr
+= bytes_read
;
9958 /* Read file name table. */
9959 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9961 unsigned int dir_index
, mod_time
, length
;
9963 line_ptr
+= bytes_read
;
9964 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9965 line_ptr
+= bytes_read
;
9966 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9967 line_ptr
+= bytes_read
;
9968 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9969 line_ptr
+= bytes_read
;
9971 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9973 line_ptr
+= bytes_read
;
9974 lh
->statement_program_start
= line_ptr
;
9976 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9977 + dwarf2_per_objfile
->line
.size
))
9978 complaint (&symfile_complaints
,
9979 _("line number info header doesn't fit in `.debug_line' section"));
9981 discard_cleanups (back_to
);
9985 /* This function exists to work around a bug in certain compilers
9986 (particularly GCC 2.95), in which the first line number marker of a
9987 function does not show up until after the prologue, right before
9988 the second line number marker. This function shifts ADDRESS down
9989 to the beginning of the function if necessary, and is called on
9990 addresses passed to record_line. */
9993 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9995 struct function_range
*fn
;
9997 /* Find the function_range containing address. */
10001 if (!cu
->cached_fn
)
10002 cu
->cached_fn
= cu
->first_fn
;
10004 fn
= cu
->cached_fn
;
10006 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10012 while (fn
&& fn
!= cu
->cached_fn
)
10013 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10023 if (address
!= fn
->lowpc
)
10024 complaint (&symfile_complaints
,
10025 _("misplaced first line number at 0x%lx for '%s'"),
10026 (unsigned long) address
, fn
->name
);
10031 /* Subroutine of dwarf_decode_lines to simplify it.
10032 Return the file name of the psymtab for included file FILE_INDEX
10033 in line header LH of PST.
10034 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10035 If space for the result is malloc'd, it will be freed by a cleanup.
10036 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10039 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10040 const struct partial_symtab
*pst
,
10041 const char *comp_dir
)
10043 const struct file_entry fe
= lh
->file_names
[file_index
];
10044 char *include_name
= fe
.name
;
10045 char *include_name_to_compare
= include_name
;
10046 char *dir_name
= NULL
;
10047 const char *pst_filename
;
10048 char *copied_name
= NULL
;
10052 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10054 if (!IS_ABSOLUTE_PATH (include_name
)
10055 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10057 /* Avoid creating a duplicate psymtab for PST.
10058 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10059 Before we do the comparison, however, we need to account
10060 for DIR_NAME and COMP_DIR.
10061 First prepend dir_name (if non-NULL). If we still don't
10062 have an absolute path prepend comp_dir (if non-NULL).
10063 However, the directory we record in the include-file's
10064 psymtab does not contain COMP_DIR (to match the
10065 corresponding symtab(s)).
10070 bash$ gcc -g ./hello.c
10071 include_name = "hello.c"
10073 DW_AT_comp_dir = comp_dir = "/tmp"
10074 DW_AT_name = "./hello.c" */
10076 if (dir_name
!= NULL
)
10078 include_name
= concat (dir_name
, SLASH_STRING
,
10079 include_name
, (char *)NULL
);
10080 include_name_to_compare
= include_name
;
10081 make_cleanup (xfree
, include_name
);
10083 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10085 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10086 include_name
, (char *)NULL
);
10090 pst_filename
= pst
->filename
;
10091 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10093 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10094 pst_filename
, (char *)NULL
);
10095 pst_filename
= copied_name
;
10098 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10100 if (include_name_to_compare
!= include_name
)
10101 xfree (include_name_to_compare
);
10102 if (copied_name
!= NULL
)
10103 xfree (copied_name
);
10107 return include_name
;
10110 /* Decode the Line Number Program (LNP) for the given line_header
10111 structure and CU. The actual information extracted and the type
10112 of structures created from the LNP depends on the value of PST.
10114 1. If PST is NULL, then this procedure uses the data from the program
10115 to create all necessary symbol tables, and their linetables.
10117 2. If PST is not NULL, this procedure reads the program to determine
10118 the list of files included by the unit represented by PST, and
10119 builds all the associated partial symbol tables.
10121 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10122 It is used for relative paths in the line table.
10123 NOTE: When processing partial symtabs (pst != NULL),
10124 comp_dir == pst->dirname.
10126 NOTE: It is important that psymtabs have the same file name (via strcmp)
10127 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10128 symtab we don't use it in the name of the psymtabs we create.
10129 E.g. expand_line_sal requires this when finding psymtabs to expand.
10130 A good testcase for this is mb-inline.exp. */
10133 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10134 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10136 gdb_byte
*line_ptr
, *extended_end
;
10137 gdb_byte
*line_end
;
10138 unsigned int bytes_read
, extended_len
;
10139 unsigned char op_code
, extended_op
, adj_opcode
;
10140 CORE_ADDR baseaddr
;
10141 struct objfile
*objfile
= cu
->objfile
;
10142 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10143 const int decode_for_pst_p
= (pst
!= NULL
);
10144 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10146 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10148 line_ptr
= lh
->statement_program_start
;
10149 line_end
= lh
->statement_program_end
;
10151 /* Read the statement sequences until there's nothing left. */
10152 while (line_ptr
< line_end
)
10154 /* state machine registers */
10155 CORE_ADDR address
= 0;
10156 unsigned int file
= 1;
10157 unsigned int line
= 1;
10158 unsigned int column
= 0;
10159 int is_stmt
= lh
->default_is_stmt
;
10160 int basic_block
= 0;
10161 int end_sequence
= 0;
10163 unsigned char op_index
= 0;
10165 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10167 /* Start a subfile for the current file of the state machine. */
10168 /* lh->include_dirs and lh->file_names are 0-based, but the
10169 directory and file name numbers in the statement program
10171 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10175 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10177 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10180 /* Decode the table. */
10181 while (!end_sequence
)
10183 op_code
= read_1_byte (abfd
, line_ptr
);
10185 if (line_ptr
> line_end
)
10187 dwarf2_debug_line_missing_end_sequence_complaint ();
10191 if (op_code
>= lh
->opcode_base
)
10193 /* Special operand. */
10194 adj_opcode
= op_code
- lh
->opcode_base
;
10195 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10196 / lh
->maximum_ops_per_instruction
)
10197 * lh
->minimum_instruction_length
);
10198 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10199 % lh
->maximum_ops_per_instruction
);
10200 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10201 if (lh
->num_file_names
< file
|| file
== 0)
10202 dwarf2_debug_line_missing_file_complaint ();
10203 /* For now we ignore lines not starting on an
10204 instruction boundary. */
10205 else if (op_index
== 0)
10207 lh
->file_names
[file
- 1].included_p
= 1;
10208 if (!decode_for_pst_p
&& is_stmt
)
10210 if (last_subfile
!= current_subfile
)
10212 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10214 record_line (last_subfile
, 0, addr
);
10215 last_subfile
= current_subfile
;
10217 /* Append row to matrix using current values. */
10218 addr
= check_cu_functions (address
, cu
);
10219 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10220 record_line (current_subfile
, line
, addr
);
10225 else switch (op_code
)
10227 case DW_LNS_extended_op
:
10228 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10229 line_ptr
+= bytes_read
;
10230 extended_end
= line_ptr
+ extended_len
;
10231 extended_op
= read_1_byte (abfd
, line_ptr
);
10233 switch (extended_op
)
10235 case DW_LNE_end_sequence
:
10238 case DW_LNE_set_address
:
10239 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10241 line_ptr
+= bytes_read
;
10242 address
+= baseaddr
;
10244 case DW_LNE_define_file
:
10247 unsigned int dir_index
, mod_time
, length
;
10249 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10250 line_ptr
+= bytes_read
;
10252 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10253 line_ptr
+= bytes_read
;
10255 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10256 line_ptr
+= bytes_read
;
10258 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10259 line_ptr
+= bytes_read
;
10260 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10263 case DW_LNE_set_discriminator
:
10264 /* The discriminator is not interesting to the debugger;
10266 line_ptr
= extended_end
;
10269 complaint (&symfile_complaints
,
10270 _("mangled .debug_line section"));
10273 /* Make sure that we parsed the extended op correctly. If e.g.
10274 we expected a different address size than the producer used,
10275 we may have read the wrong number of bytes. */
10276 if (line_ptr
!= extended_end
)
10278 complaint (&symfile_complaints
,
10279 _("mangled .debug_line section"));
10284 if (lh
->num_file_names
< file
|| file
== 0)
10285 dwarf2_debug_line_missing_file_complaint ();
10288 lh
->file_names
[file
- 1].included_p
= 1;
10289 if (!decode_for_pst_p
&& is_stmt
)
10291 if (last_subfile
!= current_subfile
)
10293 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10295 record_line (last_subfile
, 0, addr
);
10296 last_subfile
= current_subfile
;
10298 addr
= check_cu_functions (address
, cu
);
10299 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10300 record_line (current_subfile
, line
, addr
);
10305 case DW_LNS_advance_pc
:
10308 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10310 address
+= (((op_index
+ adjust
)
10311 / lh
->maximum_ops_per_instruction
)
10312 * lh
->minimum_instruction_length
);
10313 op_index
= ((op_index
+ adjust
)
10314 % lh
->maximum_ops_per_instruction
);
10315 line_ptr
+= bytes_read
;
10318 case DW_LNS_advance_line
:
10319 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10320 line_ptr
+= bytes_read
;
10322 case DW_LNS_set_file
:
10324 /* The arrays lh->include_dirs and lh->file_names are
10325 0-based, but the directory and file name numbers in
10326 the statement program are 1-based. */
10327 struct file_entry
*fe
;
10330 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10331 line_ptr
+= bytes_read
;
10332 if (lh
->num_file_names
< file
|| file
== 0)
10333 dwarf2_debug_line_missing_file_complaint ();
10336 fe
= &lh
->file_names
[file
- 1];
10338 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10339 if (!decode_for_pst_p
)
10341 last_subfile
= current_subfile
;
10342 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10347 case DW_LNS_set_column
:
10348 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10349 line_ptr
+= bytes_read
;
10351 case DW_LNS_negate_stmt
:
10352 is_stmt
= (!is_stmt
);
10354 case DW_LNS_set_basic_block
:
10357 /* Add to the address register of the state machine the
10358 address increment value corresponding to special opcode
10359 255. I.e., this value is scaled by the minimum
10360 instruction length since special opcode 255 would have
10361 scaled the the increment. */
10362 case DW_LNS_const_add_pc
:
10364 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10366 address
+= (((op_index
+ adjust
)
10367 / lh
->maximum_ops_per_instruction
)
10368 * lh
->minimum_instruction_length
);
10369 op_index
= ((op_index
+ adjust
)
10370 % lh
->maximum_ops_per_instruction
);
10373 case DW_LNS_fixed_advance_pc
:
10374 address
+= read_2_bytes (abfd
, line_ptr
);
10380 /* Unknown standard opcode, ignore it. */
10383 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10385 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10386 line_ptr
+= bytes_read
;
10391 if (lh
->num_file_names
< file
|| file
== 0)
10392 dwarf2_debug_line_missing_file_complaint ();
10395 lh
->file_names
[file
- 1].included_p
= 1;
10396 if (!decode_for_pst_p
)
10398 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10399 record_line (current_subfile
, 0, addr
);
10404 if (decode_for_pst_p
)
10408 /* Now that we're done scanning the Line Header Program, we can
10409 create the psymtab of each included file. */
10410 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10411 if (lh
->file_names
[file_index
].included_p
== 1)
10413 char *include_name
=
10414 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10415 if (include_name
!= NULL
)
10416 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10421 /* Make sure a symtab is created for every file, even files
10422 which contain only variables (i.e. no code with associated
10426 struct file_entry
*fe
;
10428 for (i
= 0; i
< lh
->num_file_names
; i
++)
10432 fe
= &lh
->file_names
[i
];
10434 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10435 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10437 /* Skip the main file; we don't need it, and it must be
10438 allocated last, so that it will show up before the
10439 non-primary symtabs in the objfile's symtab list. */
10440 if (current_subfile
== first_subfile
)
10443 if (current_subfile
->symtab
== NULL
)
10444 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10446 fe
->symtab
= current_subfile
->symtab
;
10451 /* Start a subfile for DWARF. FILENAME is the name of the file and
10452 DIRNAME the name of the source directory which contains FILENAME
10453 or NULL if not known. COMP_DIR is the compilation directory for the
10454 linetable's compilation unit or NULL if not known.
10455 This routine tries to keep line numbers from identical absolute and
10456 relative file names in a common subfile.
10458 Using the `list' example from the GDB testsuite, which resides in
10459 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10460 of /srcdir/list0.c yields the following debugging information for list0.c:
10462 DW_AT_name: /srcdir/list0.c
10463 DW_AT_comp_dir: /compdir
10464 files.files[0].name: list0.h
10465 files.files[0].dir: /srcdir
10466 files.files[1].name: list0.c
10467 files.files[1].dir: /srcdir
10469 The line number information for list0.c has to end up in a single
10470 subfile, so that `break /srcdir/list0.c:1' works as expected.
10471 start_subfile will ensure that this happens provided that we pass the
10472 concatenation of files.files[1].dir and files.files[1].name as the
10476 dwarf2_start_subfile (char *filename
, const char *dirname
, const char *comp_dir
)
10480 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10481 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10482 second argument to start_subfile. To be consistent, we do the
10483 same here. In order not to lose the line information directory,
10484 we concatenate it to the filename when it makes sense.
10485 Note that the Dwarf3 standard says (speaking of filenames in line
10486 information): ``The directory index is ignored for file names
10487 that represent full path names''. Thus ignoring dirname in the
10488 `else' branch below isn't an issue. */
10490 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10491 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10493 fullname
= filename
;
10495 start_subfile (fullname
, comp_dir
);
10497 if (fullname
!= filename
)
10502 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10503 struct dwarf2_cu
*cu
)
10505 struct objfile
*objfile
= cu
->objfile
;
10506 struct comp_unit_head
*cu_header
= &cu
->header
;
10508 /* NOTE drow/2003-01-30: There used to be a comment and some special
10509 code here to turn a symbol with DW_AT_external and a
10510 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10511 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10512 with some versions of binutils) where shared libraries could have
10513 relocations against symbols in their debug information - the
10514 minimal symbol would have the right address, but the debug info
10515 would not. It's no longer necessary, because we will explicitly
10516 apply relocations when we read in the debug information now. */
10518 /* A DW_AT_location attribute with no contents indicates that a
10519 variable has been optimized away. */
10520 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10522 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10526 /* Handle one degenerate form of location expression specially, to
10527 preserve GDB's previous behavior when section offsets are
10528 specified. If this is just a DW_OP_addr then mark this symbol
10531 if (attr_form_is_block (attr
)
10532 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10533 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10535 unsigned int dummy
;
10537 SYMBOL_VALUE_ADDRESS (sym
) =
10538 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10539 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10540 fixup_symbol_section (sym
, objfile
);
10541 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10542 SYMBOL_SECTION (sym
));
10546 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10547 expression evaluator, and use LOC_COMPUTED only when necessary
10548 (i.e. when the value of a register or memory location is
10549 referenced, or a thread-local block, etc.). Then again, it might
10550 not be worthwhile. I'm assuming that it isn't unless performance
10551 or memory numbers show me otherwise. */
10553 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10554 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10557 /* Given a pointer to a DWARF information entry, figure out if we need
10558 to make a symbol table entry for it, and if so, create a new entry
10559 and return a pointer to it.
10560 If TYPE is NULL, determine symbol type from the die, otherwise
10561 used the passed type.
10562 If SPACE is not NULL, use it to hold the new symbol. If it is
10563 NULL, allocate a new symbol on the objfile's obstack. */
10565 static struct symbol
*
10566 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10567 struct symbol
*space
)
10569 struct objfile
*objfile
= cu
->objfile
;
10570 struct symbol
*sym
= NULL
;
10572 struct attribute
*attr
= NULL
;
10573 struct attribute
*attr2
= NULL
;
10574 CORE_ADDR baseaddr
;
10575 struct pending
**list_to_add
= NULL
;
10577 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10579 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10581 name
= dwarf2_name (die
, cu
);
10584 const char *linkagename
;
10585 int suppress_add
= 0;
10590 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10591 OBJSTAT (objfile
, n_syms
++);
10593 /* Cache this symbol's name and the name's demangled form (if any). */
10594 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10595 linkagename
= dwarf2_physname (name
, die
, cu
);
10596 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10598 /* Fortran does not have mangling standard and the mangling does differ
10599 between gfortran, iFort etc. */
10600 if (cu
->language
== language_fortran
10601 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10602 symbol_set_demangled_name (&(sym
->ginfo
),
10603 (char *) dwarf2_full_name (name
, die
, cu
),
10606 /* Default assumptions.
10607 Use the passed type or decode it from the die. */
10608 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10609 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10611 SYMBOL_TYPE (sym
) = type
;
10613 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10614 attr
= dwarf2_attr (die
,
10615 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10619 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10622 attr
= dwarf2_attr (die
,
10623 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10627 int file_index
= DW_UNSND (attr
);
10629 if (cu
->line_header
== NULL
10630 || file_index
> cu
->line_header
->num_file_names
)
10631 complaint (&symfile_complaints
,
10632 _("file index out of range"));
10633 else if (file_index
> 0)
10635 struct file_entry
*fe
;
10637 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10638 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10645 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10648 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10650 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10651 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10652 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10653 add_symbol_to_list (sym
, cu
->list_in_scope
);
10655 case DW_TAG_subprogram
:
10656 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10658 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10659 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10660 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10661 || cu
->language
== language_ada
)
10663 /* Subprograms marked external are stored as a global symbol.
10664 Ada subprograms, whether marked external or not, are always
10665 stored as a global symbol, because we want to be able to
10666 access them globally. For instance, we want to be able
10667 to break on a nested subprogram without having to
10668 specify the context. */
10669 list_to_add
= &global_symbols
;
10673 list_to_add
= cu
->list_in_scope
;
10676 case DW_TAG_inlined_subroutine
:
10677 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10679 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10680 SYMBOL_INLINED (sym
) = 1;
10681 /* Do not add the symbol to any lists. It will be found via
10682 BLOCK_FUNCTION from the blockvector. */
10684 case DW_TAG_template_value_param
:
10686 /* Fall through. */
10687 case DW_TAG_constant
:
10688 case DW_TAG_variable
:
10689 case DW_TAG_member
:
10690 /* Compilation with minimal debug info may result in variables
10691 with missing type entries. Change the misleading `void' type
10692 to something sensible. */
10693 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10695 = objfile_type (objfile
)->nodebug_data_symbol
;
10697 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10698 /* In the case of DW_TAG_member, we should only be called for
10699 static const members. */
10700 if (die
->tag
== DW_TAG_member
)
10702 /* dwarf2_add_field uses die_is_declaration,
10703 so we do the same. */
10704 gdb_assert (die_is_declaration (die
, cu
));
10709 dwarf2_const_value (attr
, sym
, cu
);
10710 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10713 if (attr2
&& (DW_UNSND (attr2
) != 0))
10714 list_to_add
= &global_symbols
;
10716 list_to_add
= cu
->list_in_scope
;
10720 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10723 var_decode_location (attr
, sym
, cu
);
10724 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10725 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10726 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10727 && !dwarf2_per_objfile
->has_section_at_zero
)
10729 /* When a static variable is eliminated by the linker,
10730 the corresponding debug information is not stripped
10731 out, but the variable address is set to null;
10732 do not add such variables into symbol table. */
10734 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10736 /* Workaround gfortran PR debug/40040 - it uses
10737 DW_AT_location for variables in -fPIC libraries which may
10738 get overriden by other libraries/executable and get
10739 a different address. Resolve it by the minimal symbol
10740 which may come from inferior's executable using copy
10741 relocation. Make this workaround only for gfortran as for
10742 other compilers GDB cannot guess the minimal symbol
10743 Fortran mangling kind. */
10744 if (cu
->language
== language_fortran
&& die
->parent
10745 && die
->parent
->tag
== DW_TAG_module
10747 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10748 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10750 /* A variable with DW_AT_external is never static,
10751 but it may be block-scoped. */
10752 list_to_add
= (cu
->list_in_scope
== &file_symbols
10753 ? &global_symbols
: cu
->list_in_scope
);
10756 list_to_add
= cu
->list_in_scope
;
10760 /* We do not know the address of this symbol.
10761 If it is an external symbol and we have type information
10762 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10763 The address of the variable will then be determined from
10764 the minimal symbol table whenever the variable is
10766 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10767 if (attr2
&& (DW_UNSND (attr2
) != 0)
10768 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10770 /* A variable with DW_AT_external is never static, but it
10771 may be block-scoped. */
10772 list_to_add
= (cu
->list_in_scope
== &file_symbols
10773 ? &global_symbols
: cu
->list_in_scope
);
10775 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10777 else if (!die_is_declaration (die
, cu
))
10779 /* Use the default LOC_OPTIMIZED_OUT class. */
10780 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10782 list_to_add
= cu
->list_in_scope
;
10786 case DW_TAG_formal_parameter
:
10787 /* If we are inside a function, mark this as an argument. If
10788 not, we might be looking at an argument to an inlined function
10789 when we do not have enough information to show inlined frames;
10790 pretend it's a local variable in that case so that the user can
10792 if (context_stack_depth
> 0
10793 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10794 SYMBOL_IS_ARGUMENT (sym
) = 1;
10795 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10798 var_decode_location (attr
, sym
, cu
);
10800 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10803 dwarf2_const_value (attr
, sym
, cu
);
10805 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10806 if (attr
&& DW_UNSND (attr
))
10808 struct type
*ref_type
;
10810 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10811 SYMBOL_TYPE (sym
) = ref_type
;
10814 list_to_add
= cu
->list_in_scope
;
10816 case DW_TAG_unspecified_parameters
:
10817 /* From varargs functions; gdb doesn't seem to have any
10818 interest in this information, so just ignore it for now.
10821 case DW_TAG_template_type_param
:
10823 /* Fall through. */
10824 case DW_TAG_class_type
:
10825 case DW_TAG_interface_type
:
10826 case DW_TAG_structure_type
:
10827 case DW_TAG_union_type
:
10828 case DW_TAG_set_type
:
10829 case DW_TAG_enumeration_type
:
10830 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10831 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10834 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10835 really ever be static objects: otherwise, if you try
10836 to, say, break of a class's method and you're in a file
10837 which doesn't mention that class, it won't work unless
10838 the check for all static symbols in lookup_symbol_aux
10839 saves you. See the OtherFileClass tests in
10840 gdb.c++/namespace.exp. */
10844 list_to_add
= (cu
->list_in_scope
== &file_symbols
10845 && (cu
->language
== language_cplus
10846 || cu
->language
== language_java
)
10847 ? &global_symbols
: cu
->list_in_scope
);
10849 /* The semantics of C++ state that "struct foo {
10850 ... }" also defines a typedef for "foo". A Java
10851 class declaration also defines a typedef for the
10853 if (cu
->language
== language_cplus
10854 || cu
->language
== language_java
10855 || cu
->language
== language_ada
)
10857 /* The symbol's name is already allocated along
10858 with this objfile, so we don't need to
10859 duplicate it for the type. */
10860 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10861 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10866 case DW_TAG_typedef
:
10867 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10868 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10869 list_to_add
= cu
->list_in_scope
;
10871 case DW_TAG_base_type
:
10872 case DW_TAG_subrange_type
:
10873 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10874 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10875 list_to_add
= cu
->list_in_scope
;
10877 case DW_TAG_enumerator
:
10878 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10881 dwarf2_const_value (attr
, sym
, cu
);
10884 /* NOTE: carlton/2003-11-10: See comment above in the
10885 DW_TAG_class_type, etc. block. */
10887 list_to_add
= (cu
->list_in_scope
== &file_symbols
10888 && (cu
->language
== language_cplus
10889 || cu
->language
== language_java
)
10890 ? &global_symbols
: cu
->list_in_scope
);
10893 case DW_TAG_namespace
:
10894 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10895 list_to_add
= &global_symbols
;
10898 /* Not a tag we recognize. Hopefully we aren't processing
10899 trash data, but since we must specifically ignore things
10900 we don't recognize, there is nothing else we should do at
10902 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10903 dwarf_tag_name (die
->tag
));
10909 sym
->hash_next
= objfile
->template_symbols
;
10910 objfile
->template_symbols
= sym
;
10911 list_to_add
= NULL
;
10914 if (list_to_add
!= NULL
)
10915 add_symbol_to_list (sym
, list_to_add
);
10917 /* For the benefit of old versions of GCC, check for anonymous
10918 namespaces based on the demangled name. */
10919 if (!processing_has_namespace_info
10920 && cu
->language
== language_cplus
)
10921 cp_scan_for_anonymous_namespaces (sym
);
10926 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10928 static struct symbol
*
10929 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10931 return new_symbol_full (die
, type
, cu
, NULL
);
10934 /* Given an attr with a DW_FORM_dataN value in host byte order,
10935 zero-extend it as appropriate for the symbol's type. The DWARF
10936 standard (v4) is not entirely clear about the meaning of using
10937 DW_FORM_dataN for a constant with a signed type, where the type is
10938 wider than the data. The conclusion of a discussion on the DWARF
10939 list was that this is unspecified. We choose to always zero-extend
10940 because that is the interpretation long in use by GCC. */
10943 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10944 const char *name
, struct obstack
*obstack
,
10945 struct dwarf2_cu
*cu
, long *value
, int bits
)
10947 struct objfile
*objfile
= cu
->objfile
;
10948 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10949 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10950 LONGEST l
= DW_UNSND (attr
);
10952 if (bits
< sizeof (*value
) * 8)
10954 l
&= ((LONGEST
) 1 << bits
) - 1;
10957 else if (bits
== sizeof (*value
) * 8)
10961 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10962 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10969 /* Read a constant value from an attribute. Either set *VALUE, or if
10970 the value does not fit in *VALUE, set *BYTES - either already
10971 allocated on the objfile obstack, or newly allocated on OBSTACK,
10972 or, set *BATON, if we translated the constant to a location
10976 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10977 const char *name
, struct obstack
*obstack
,
10978 struct dwarf2_cu
*cu
,
10979 long *value
, gdb_byte
**bytes
,
10980 struct dwarf2_locexpr_baton
**baton
)
10982 struct objfile
*objfile
= cu
->objfile
;
10983 struct comp_unit_head
*cu_header
= &cu
->header
;
10984 struct dwarf_block
*blk
;
10985 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10986 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10992 switch (attr
->form
)
10998 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10999 dwarf2_const_value_length_mismatch_complaint (name
,
11000 cu_header
->addr_size
,
11001 TYPE_LENGTH (type
));
11002 /* Symbols of this form are reasonably rare, so we just
11003 piggyback on the existing location code rather than writing
11004 a new implementation of symbol_computed_ops. */
11005 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11006 sizeof (struct dwarf2_locexpr_baton
));
11007 (*baton
)->per_cu
= cu
->per_cu
;
11008 gdb_assert ((*baton
)->per_cu
);
11010 (*baton
)->size
= 2 + cu_header
->addr_size
;
11011 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11012 (*baton
)->data
= data
;
11014 data
[0] = DW_OP_addr
;
11015 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11016 byte_order
, DW_ADDR (attr
));
11017 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11020 case DW_FORM_string
:
11022 /* DW_STRING is already allocated on the objfile obstack, point
11024 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11026 case DW_FORM_block1
:
11027 case DW_FORM_block2
:
11028 case DW_FORM_block4
:
11029 case DW_FORM_block
:
11030 case DW_FORM_exprloc
:
11031 blk
= DW_BLOCK (attr
);
11032 if (TYPE_LENGTH (type
) != blk
->size
)
11033 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11034 TYPE_LENGTH (type
));
11035 *bytes
= blk
->data
;
11038 /* The DW_AT_const_value attributes are supposed to carry the
11039 symbol's value "represented as it would be on the target
11040 architecture." By the time we get here, it's already been
11041 converted to host endianness, so we just need to sign- or
11042 zero-extend it as appropriate. */
11043 case DW_FORM_data1
:
11044 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
11046 case DW_FORM_data2
:
11047 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
11049 case DW_FORM_data4
:
11050 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
11052 case DW_FORM_data8
:
11053 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
11056 case DW_FORM_sdata
:
11057 *value
= DW_SND (attr
);
11060 case DW_FORM_udata
:
11061 *value
= DW_UNSND (attr
);
11065 complaint (&symfile_complaints
,
11066 _("unsupported const value attribute form: '%s'"),
11067 dwarf_form_name (attr
->form
));
11074 /* Copy constant value from an attribute to a symbol. */
11077 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11078 struct dwarf2_cu
*cu
)
11080 struct objfile
*objfile
= cu
->objfile
;
11081 struct comp_unit_head
*cu_header
= &cu
->header
;
11084 struct dwarf2_locexpr_baton
*baton
;
11086 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11087 SYMBOL_PRINT_NAME (sym
),
11088 &objfile
->objfile_obstack
, cu
,
11089 &value
, &bytes
, &baton
);
11093 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11094 SYMBOL_LOCATION_BATON (sym
) = baton
;
11095 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11097 else if (bytes
!= NULL
)
11099 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11100 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11104 SYMBOL_VALUE (sym
) = value
;
11105 SYMBOL_CLASS (sym
) = LOC_CONST
;
11109 /* Return the type of the die in question using its DW_AT_type attribute. */
11111 static struct type
*
11112 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11114 struct attribute
*type_attr
;
11116 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11119 /* A missing DW_AT_type represents a void type. */
11120 return objfile_type (cu
->objfile
)->builtin_void
;
11123 return lookup_die_type (die
, type_attr
, cu
);
11126 /* True iff CU's producer generates GNAT Ada auxiliary information
11127 that allows to find parallel types through that information instead
11128 of having to do expensive parallel lookups by type name. */
11131 need_gnat_info (struct dwarf2_cu
*cu
)
11133 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11134 of GNAT produces this auxiliary information, without any indication
11135 that it is produced. Part of enhancing the FSF version of GNAT
11136 to produce that information will be to put in place an indicator
11137 that we can use in order to determine whether the descriptive type
11138 info is available or not. One suggestion that has been made is
11139 to use a new attribute, attached to the CU die. For now, assume
11140 that the descriptive type info is not available. */
11144 /* Return the auxiliary type of the die in question using its
11145 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11146 attribute is not present. */
11148 static struct type
*
11149 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11151 struct attribute
*type_attr
;
11153 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11157 return lookup_die_type (die
, type_attr
, cu
);
11160 /* If DIE has a descriptive_type attribute, then set the TYPE's
11161 descriptive type accordingly. */
11164 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11165 struct dwarf2_cu
*cu
)
11167 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11169 if (descriptive_type
)
11171 ALLOCATE_GNAT_AUX_TYPE (type
);
11172 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11176 /* Return the containing type of the die in question using its
11177 DW_AT_containing_type attribute. */
11179 static struct type
*
11180 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11182 struct attribute
*type_attr
;
11184 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11186 error (_("Dwarf Error: Problem turning containing type into gdb type "
11187 "[in module %s]"), cu
->objfile
->name
);
11189 return lookup_die_type (die
, type_attr
, cu
);
11192 /* Look up the type of DIE in CU using its type attribute ATTR.
11193 If there is no type substitute an error marker. */
11195 static struct type
*
11196 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11197 struct dwarf2_cu
*cu
)
11199 struct type
*this_type
;
11201 /* First see if we have it cached. */
11203 if (is_ref_attr (attr
))
11205 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11207 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11209 else if (attr
->form
== DW_FORM_sig8
)
11211 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11212 struct dwarf2_cu
*sig_cu
;
11213 unsigned int offset
;
11215 /* sig_type will be NULL if the signatured type is missing from
11217 if (sig_type
== NULL
)
11218 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11219 "at 0x%x [in module %s]"),
11220 die
->offset
, cu
->objfile
->name
);
11222 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11223 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11224 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11228 dump_die_for_error (die
);
11229 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11230 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11233 /* If not cached we need to read it in. */
11235 if (this_type
== NULL
)
11237 struct die_info
*type_die
;
11238 struct dwarf2_cu
*type_cu
= cu
;
11240 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11241 /* If the type is cached, we should have found it above. */
11242 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11243 this_type
= read_type_die_1 (type_die
, type_cu
);
11246 /* If we still don't have a type use an error marker. */
11248 if (this_type
== NULL
)
11250 char *message
, *saved
;
11252 /* read_type_die already issued a complaint. */
11253 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11257 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11258 message
, strlen (message
));
11261 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11267 /* Return the type in DIE, CU.
11268 Returns NULL for invalid types.
11270 This first does a lookup in the appropriate type_hash table,
11271 and only reads the die in if necessary.
11273 NOTE: This can be called when reading in partial or full symbols. */
11275 static struct type
*
11276 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11278 struct type
*this_type
;
11280 this_type
= get_die_type (die
, cu
);
11284 return read_type_die_1 (die
, cu
);
11287 /* Read the type in DIE, CU.
11288 Returns NULL for invalid types. */
11290 static struct type
*
11291 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11293 struct type
*this_type
= NULL
;
11297 case DW_TAG_class_type
:
11298 case DW_TAG_interface_type
:
11299 case DW_TAG_structure_type
:
11300 case DW_TAG_union_type
:
11301 this_type
= read_structure_type (die
, cu
);
11303 case DW_TAG_enumeration_type
:
11304 this_type
= read_enumeration_type (die
, cu
);
11306 case DW_TAG_subprogram
:
11307 case DW_TAG_subroutine_type
:
11308 case DW_TAG_inlined_subroutine
:
11309 this_type
= read_subroutine_type (die
, cu
);
11311 case DW_TAG_array_type
:
11312 this_type
= read_array_type (die
, cu
);
11314 case DW_TAG_set_type
:
11315 this_type
= read_set_type (die
, cu
);
11317 case DW_TAG_pointer_type
:
11318 this_type
= read_tag_pointer_type (die
, cu
);
11320 case DW_TAG_ptr_to_member_type
:
11321 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11323 case DW_TAG_reference_type
:
11324 this_type
= read_tag_reference_type (die
, cu
);
11326 case DW_TAG_const_type
:
11327 this_type
= read_tag_const_type (die
, cu
);
11329 case DW_TAG_volatile_type
:
11330 this_type
= read_tag_volatile_type (die
, cu
);
11332 case DW_TAG_string_type
:
11333 this_type
= read_tag_string_type (die
, cu
);
11335 case DW_TAG_typedef
:
11336 this_type
= read_typedef (die
, cu
);
11338 case DW_TAG_subrange_type
:
11339 this_type
= read_subrange_type (die
, cu
);
11341 case DW_TAG_base_type
:
11342 this_type
= read_base_type (die
, cu
);
11344 case DW_TAG_unspecified_type
:
11345 this_type
= read_unspecified_type (die
, cu
);
11347 case DW_TAG_namespace
:
11348 this_type
= read_namespace_type (die
, cu
);
11350 case DW_TAG_module
:
11351 this_type
= read_module_type (die
, cu
);
11354 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11355 dwarf_tag_name (die
->tag
));
11362 /* See if we can figure out if the class lives in a namespace. We do
11363 this by looking for a member function; its demangled name will
11364 contain namespace info, if there is any.
11365 Return the computed name or NULL.
11366 Space for the result is allocated on the objfile's obstack.
11367 This is the full-die version of guess_partial_die_structure_name.
11368 In this case we know DIE has no useful parent. */
11371 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11373 struct die_info
*spec_die
;
11374 struct dwarf2_cu
*spec_cu
;
11375 struct die_info
*child
;
11378 spec_die
= die_specification (die
, &spec_cu
);
11379 if (spec_die
!= NULL
)
11385 for (child
= die
->child
;
11387 child
= child
->sibling
)
11389 if (child
->tag
== DW_TAG_subprogram
)
11391 struct attribute
*attr
;
11393 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11395 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11399 = language_class_name_from_physname (cu
->language_defn
,
11403 if (actual_name
!= NULL
)
11405 char *die_name
= dwarf2_name (die
, cu
);
11407 if (die_name
!= NULL
11408 && strcmp (die_name
, actual_name
) != 0)
11410 /* Strip off the class name from the full name.
11411 We want the prefix. */
11412 int die_name_len
= strlen (die_name
);
11413 int actual_name_len
= strlen (actual_name
);
11415 /* Test for '::' as a sanity check. */
11416 if (actual_name_len
> die_name_len
+ 2
11417 && actual_name
[actual_name_len
- die_name_len
- 1] == ':')
11419 obsavestring (actual_name
,
11420 actual_name_len
- die_name_len
- 2,
11421 &cu
->objfile
->objfile_obstack
);
11424 xfree (actual_name
);
11433 /* Return the name of the namespace/class that DIE is defined within,
11434 or "" if we can't tell. The caller should not xfree the result.
11436 For example, if we're within the method foo() in the following
11446 then determine_prefix on foo's die will return "N::C". */
11449 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11451 struct die_info
*parent
, *spec_die
;
11452 struct dwarf2_cu
*spec_cu
;
11453 struct type
*parent_type
;
11455 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11456 && cu
->language
!= language_fortran
)
11459 /* We have to be careful in the presence of DW_AT_specification.
11460 For example, with GCC 3.4, given the code
11464 // Definition of N::foo.
11468 then we'll have a tree of DIEs like this:
11470 1: DW_TAG_compile_unit
11471 2: DW_TAG_namespace // N
11472 3: DW_TAG_subprogram // declaration of N::foo
11473 4: DW_TAG_subprogram // definition of N::foo
11474 DW_AT_specification // refers to die #3
11476 Thus, when processing die #4, we have to pretend that we're in
11477 the context of its DW_AT_specification, namely the contex of die
11480 spec_die
= die_specification (die
, &spec_cu
);
11481 if (spec_die
== NULL
)
11482 parent
= die
->parent
;
11485 parent
= spec_die
->parent
;
11489 if (parent
== NULL
)
11491 else if (parent
->building_fullname
)
11494 const char *parent_name
;
11496 /* It has been seen on RealView 2.2 built binaries,
11497 DW_TAG_template_type_param types actually _defined_ as
11498 children of the parent class:
11501 template class <class Enum> Class{};
11502 Class<enum E> class_e;
11504 1: DW_TAG_class_type (Class)
11505 2: DW_TAG_enumeration_type (E)
11506 3: DW_TAG_enumerator (enum1:0)
11507 3: DW_TAG_enumerator (enum2:1)
11509 2: DW_TAG_template_type_param
11510 DW_AT_type DW_FORM_ref_udata (E)
11512 Besides being broken debug info, it can put GDB into an
11513 infinite loop. Consider:
11515 When we're building the full name for Class<E>, we'll start
11516 at Class, and go look over its template type parameters,
11517 finding E. We'll then try to build the full name of E, and
11518 reach here. We're now trying to build the full name of E,
11519 and look over the parent DIE for containing scope. In the
11520 broken case, if we followed the parent DIE of E, we'd again
11521 find Class, and once again go look at its template type
11522 arguments, etc., etc. Simply don't consider such parent die
11523 as source-level parent of this die (it can't be, the language
11524 doesn't allow it), and break the loop here. */
11525 name
= dwarf2_name (die
, cu
);
11526 parent_name
= dwarf2_name (parent
, cu
);
11527 complaint (&symfile_complaints
,
11528 _("template param type '%s' defined within parent '%s'"),
11529 name
? name
: "<unknown>",
11530 parent_name
? parent_name
: "<unknown>");
11534 switch (parent
->tag
)
11536 case DW_TAG_namespace
:
11537 parent_type
= read_type_die (parent
, cu
);
11538 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11539 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11540 Work around this problem here. */
11541 if (cu
->language
== language_cplus
11542 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11544 /* We give a name to even anonymous namespaces. */
11545 return TYPE_TAG_NAME (parent_type
);
11546 case DW_TAG_class_type
:
11547 case DW_TAG_interface_type
:
11548 case DW_TAG_structure_type
:
11549 case DW_TAG_union_type
:
11550 case DW_TAG_module
:
11551 parent_type
= read_type_die (parent
, cu
);
11552 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11553 return TYPE_TAG_NAME (parent_type
);
11555 /* An anonymous structure is only allowed non-static data
11556 members; no typedefs, no member functions, et cetera.
11557 So it does not need a prefix. */
11559 case DW_TAG_compile_unit
:
11560 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11561 if (cu
->language
== language_cplus
11562 && dwarf2_per_objfile
->types
.asection
!= NULL
11563 && die
->child
!= NULL
11564 && (die
->tag
== DW_TAG_class_type
11565 || die
->tag
== DW_TAG_structure_type
11566 || die
->tag
== DW_TAG_union_type
))
11568 char *name
= guess_full_die_structure_name (die
, cu
);
11574 return determine_prefix (parent
, cu
);
11578 /* Return a newly-allocated string formed by concatenating PREFIX and
11579 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11580 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11581 perform an obconcat, otherwise allocate storage for the result. The CU argument
11582 is used to determine the language and hence, the appropriate separator. */
11584 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11587 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11588 int physname
, struct dwarf2_cu
*cu
)
11590 const char *lead
= "";
11593 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11595 else if (cu
->language
== language_java
)
11597 else if (cu
->language
== language_fortran
&& physname
)
11599 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11600 DW_AT_MIPS_linkage_name is preferred and used instead. */
11608 if (prefix
== NULL
)
11610 if (suffix
== NULL
)
11615 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11617 strcpy (retval
, lead
);
11618 strcat (retval
, prefix
);
11619 strcat (retval
, sep
);
11620 strcat (retval
, suffix
);
11625 /* We have an obstack. */
11626 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11630 /* Return sibling of die, NULL if no sibling. */
11632 static struct die_info
*
11633 sibling_die (struct die_info
*die
)
11635 return die
->sibling
;
11638 /* Get name of a die, return NULL if not found. */
11641 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11642 struct obstack
*obstack
)
11644 if (name
&& cu
->language
== language_cplus
)
11646 char *canon_name
= cp_canonicalize_string (name
);
11648 if (canon_name
!= NULL
)
11650 if (strcmp (canon_name
, name
) != 0)
11651 name
= obsavestring (canon_name
, strlen (canon_name
),
11653 xfree (canon_name
);
11660 /* Get name of a die, return NULL if not found. */
11663 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11665 struct attribute
*attr
;
11667 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11668 if (!attr
|| !DW_STRING (attr
))
11673 case DW_TAG_compile_unit
:
11674 /* Compilation units have a DW_AT_name that is a filename, not
11675 a source language identifier. */
11676 case DW_TAG_enumeration_type
:
11677 case DW_TAG_enumerator
:
11678 /* These tags always have simple identifiers already; no need
11679 to canonicalize them. */
11680 return DW_STRING (attr
);
11682 case DW_TAG_subprogram
:
11683 /* Java constructors will all be named "<init>", so return
11684 the class name when we see this special case. */
11685 if (cu
->language
== language_java
11686 && DW_STRING (attr
) != NULL
11687 && strcmp (DW_STRING (attr
), "<init>") == 0)
11689 struct dwarf2_cu
*spec_cu
= cu
;
11690 struct die_info
*spec_die
;
11692 /* GCJ will output '<init>' for Java constructor names.
11693 For this special case, return the name of the parent class. */
11695 /* GCJ may output suprogram DIEs with AT_specification set.
11696 If so, use the name of the specified DIE. */
11697 spec_die
= die_specification (die
, &spec_cu
);
11698 if (spec_die
!= NULL
)
11699 return dwarf2_name (spec_die
, spec_cu
);
11704 if (die
->tag
== DW_TAG_class_type
)
11705 return dwarf2_name (die
, cu
);
11707 while (die
->tag
!= DW_TAG_compile_unit
);
11711 case DW_TAG_class_type
:
11712 case DW_TAG_interface_type
:
11713 case DW_TAG_structure_type
:
11714 case DW_TAG_union_type
:
11715 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11716 structures or unions. These were of the form "._%d" in GCC 4.1,
11717 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11718 and GCC 4.4. We work around this problem by ignoring these. */
11719 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11720 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11728 if (!DW_STRING_IS_CANONICAL (attr
))
11731 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11732 &cu
->objfile
->objfile_obstack
);
11733 DW_STRING_IS_CANONICAL (attr
) = 1;
11735 return DW_STRING (attr
);
11738 /* Return the die that this die in an extension of, or NULL if there
11739 is none. *EXT_CU is the CU containing DIE on input, and the CU
11740 containing the return value on output. */
11742 static struct die_info
*
11743 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11745 struct attribute
*attr
;
11747 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11751 return follow_die_ref (die
, attr
, ext_cu
);
11754 /* Convert a DIE tag into its string name. */
11757 dwarf_tag_name (unsigned tag
)
11761 case DW_TAG_padding
:
11762 return "DW_TAG_padding";
11763 case DW_TAG_array_type
:
11764 return "DW_TAG_array_type";
11765 case DW_TAG_class_type
:
11766 return "DW_TAG_class_type";
11767 case DW_TAG_entry_point
:
11768 return "DW_TAG_entry_point";
11769 case DW_TAG_enumeration_type
:
11770 return "DW_TAG_enumeration_type";
11771 case DW_TAG_formal_parameter
:
11772 return "DW_TAG_formal_parameter";
11773 case DW_TAG_imported_declaration
:
11774 return "DW_TAG_imported_declaration";
11776 return "DW_TAG_label";
11777 case DW_TAG_lexical_block
:
11778 return "DW_TAG_lexical_block";
11779 case DW_TAG_member
:
11780 return "DW_TAG_member";
11781 case DW_TAG_pointer_type
:
11782 return "DW_TAG_pointer_type";
11783 case DW_TAG_reference_type
:
11784 return "DW_TAG_reference_type";
11785 case DW_TAG_compile_unit
:
11786 return "DW_TAG_compile_unit";
11787 case DW_TAG_string_type
:
11788 return "DW_TAG_string_type";
11789 case DW_TAG_structure_type
:
11790 return "DW_TAG_structure_type";
11791 case DW_TAG_subroutine_type
:
11792 return "DW_TAG_subroutine_type";
11793 case DW_TAG_typedef
:
11794 return "DW_TAG_typedef";
11795 case DW_TAG_union_type
:
11796 return "DW_TAG_union_type";
11797 case DW_TAG_unspecified_parameters
:
11798 return "DW_TAG_unspecified_parameters";
11799 case DW_TAG_variant
:
11800 return "DW_TAG_variant";
11801 case DW_TAG_common_block
:
11802 return "DW_TAG_common_block";
11803 case DW_TAG_common_inclusion
:
11804 return "DW_TAG_common_inclusion";
11805 case DW_TAG_inheritance
:
11806 return "DW_TAG_inheritance";
11807 case DW_TAG_inlined_subroutine
:
11808 return "DW_TAG_inlined_subroutine";
11809 case DW_TAG_module
:
11810 return "DW_TAG_module";
11811 case DW_TAG_ptr_to_member_type
:
11812 return "DW_TAG_ptr_to_member_type";
11813 case DW_TAG_set_type
:
11814 return "DW_TAG_set_type";
11815 case DW_TAG_subrange_type
:
11816 return "DW_TAG_subrange_type";
11817 case DW_TAG_with_stmt
:
11818 return "DW_TAG_with_stmt";
11819 case DW_TAG_access_declaration
:
11820 return "DW_TAG_access_declaration";
11821 case DW_TAG_base_type
:
11822 return "DW_TAG_base_type";
11823 case DW_TAG_catch_block
:
11824 return "DW_TAG_catch_block";
11825 case DW_TAG_const_type
:
11826 return "DW_TAG_const_type";
11827 case DW_TAG_constant
:
11828 return "DW_TAG_constant";
11829 case DW_TAG_enumerator
:
11830 return "DW_TAG_enumerator";
11831 case DW_TAG_file_type
:
11832 return "DW_TAG_file_type";
11833 case DW_TAG_friend
:
11834 return "DW_TAG_friend";
11835 case DW_TAG_namelist
:
11836 return "DW_TAG_namelist";
11837 case DW_TAG_namelist_item
:
11838 return "DW_TAG_namelist_item";
11839 case DW_TAG_packed_type
:
11840 return "DW_TAG_packed_type";
11841 case DW_TAG_subprogram
:
11842 return "DW_TAG_subprogram";
11843 case DW_TAG_template_type_param
:
11844 return "DW_TAG_template_type_param";
11845 case DW_TAG_template_value_param
:
11846 return "DW_TAG_template_value_param";
11847 case DW_TAG_thrown_type
:
11848 return "DW_TAG_thrown_type";
11849 case DW_TAG_try_block
:
11850 return "DW_TAG_try_block";
11851 case DW_TAG_variant_part
:
11852 return "DW_TAG_variant_part";
11853 case DW_TAG_variable
:
11854 return "DW_TAG_variable";
11855 case DW_TAG_volatile_type
:
11856 return "DW_TAG_volatile_type";
11857 case DW_TAG_dwarf_procedure
:
11858 return "DW_TAG_dwarf_procedure";
11859 case DW_TAG_restrict_type
:
11860 return "DW_TAG_restrict_type";
11861 case DW_TAG_interface_type
:
11862 return "DW_TAG_interface_type";
11863 case DW_TAG_namespace
:
11864 return "DW_TAG_namespace";
11865 case DW_TAG_imported_module
:
11866 return "DW_TAG_imported_module";
11867 case DW_TAG_unspecified_type
:
11868 return "DW_TAG_unspecified_type";
11869 case DW_TAG_partial_unit
:
11870 return "DW_TAG_partial_unit";
11871 case DW_TAG_imported_unit
:
11872 return "DW_TAG_imported_unit";
11873 case DW_TAG_condition
:
11874 return "DW_TAG_condition";
11875 case DW_TAG_shared_type
:
11876 return "DW_TAG_shared_type";
11877 case DW_TAG_type_unit
:
11878 return "DW_TAG_type_unit";
11879 case DW_TAG_MIPS_loop
:
11880 return "DW_TAG_MIPS_loop";
11881 case DW_TAG_HP_array_descriptor
:
11882 return "DW_TAG_HP_array_descriptor";
11883 case DW_TAG_format_label
:
11884 return "DW_TAG_format_label";
11885 case DW_TAG_function_template
:
11886 return "DW_TAG_function_template";
11887 case DW_TAG_class_template
:
11888 return "DW_TAG_class_template";
11889 case DW_TAG_GNU_BINCL
:
11890 return "DW_TAG_GNU_BINCL";
11891 case DW_TAG_GNU_EINCL
:
11892 return "DW_TAG_GNU_EINCL";
11893 case DW_TAG_upc_shared_type
:
11894 return "DW_TAG_upc_shared_type";
11895 case DW_TAG_upc_strict_type
:
11896 return "DW_TAG_upc_strict_type";
11897 case DW_TAG_upc_relaxed_type
:
11898 return "DW_TAG_upc_relaxed_type";
11899 case DW_TAG_PGI_kanji_type
:
11900 return "DW_TAG_PGI_kanji_type";
11901 case DW_TAG_PGI_interface_block
:
11902 return "DW_TAG_PGI_interface_block";
11904 return "DW_TAG_<unknown>";
11908 /* Convert a DWARF attribute code into its string name. */
11911 dwarf_attr_name (unsigned attr
)
11915 case DW_AT_sibling
:
11916 return "DW_AT_sibling";
11917 case DW_AT_location
:
11918 return "DW_AT_location";
11920 return "DW_AT_name";
11921 case DW_AT_ordering
:
11922 return "DW_AT_ordering";
11923 case DW_AT_subscr_data
:
11924 return "DW_AT_subscr_data";
11925 case DW_AT_byte_size
:
11926 return "DW_AT_byte_size";
11927 case DW_AT_bit_offset
:
11928 return "DW_AT_bit_offset";
11929 case DW_AT_bit_size
:
11930 return "DW_AT_bit_size";
11931 case DW_AT_element_list
:
11932 return "DW_AT_element_list";
11933 case DW_AT_stmt_list
:
11934 return "DW_AT_stmt_list";
11936 return "DW_AT_low_pc";
11937 case DW_AT_high_pc
:
11938 return "DW_AT_high_pc";
11939 case DW_AT_language
:
11940 return "DW_AT_language";
11942 return "DW_AT_member";
11944 return "DW_AT_discr";
11945 case DW_AT_discr_value
:
11946 return "DW_AT_discr_value";
11947 case DW_AT_visibility
:
11948 return "DW_AT_visibility";
11950 return "DW_AT_import";
11951 case DW_AT_string_length
:
11952 return "DW_AT_string_length";
11953 case DW_AT_common_reference
:
11954 return "DW_AT_common_reference";
11955 case DW_AT_comp_dir
:
11956 return "DW_AT_comp_dir";
11957 case DW_AT_const_value
:
11958 return "DW_AT_const_value";
11959 case DW_AT_containing_type
:
11960 return "DW_AT_containing_type";
11961 case DW_AT_default_value
:
11962 return "DW_AT_default_value";
11964 return "DW_AT_inline";
11965 case DW_AT_is_optional
:
11966 return "DW_AT_is_optional";
11967 case DW_AT_lower_bound
:
11968 return "DW_AT_lower_bound";
11969 case DW_AT_producer
:
11970 return "DW_AT_producer";
11971 case DW_AT_prototyped
:
11972 return "DW_AT_prototyped";
11973 case DW_AT_return_addr
:
11974 return "DW_AT_return_addr";
11975 case DW_AT_start_scope
:
11976 return "DW_AT_start_scope";
11977 case DW_AT_bit_stride
:
11978 return "DW_AT_bit_stride";
11979 case DW_AT_upper_bound
:
11980 return "DW_AT_upper_bound";
11981 case DW_AT_abstract_origin
:
11982 return "DW_AT_abstract_origin";
11983 case DW_AT_accessibility
:
11984 return "DW_AT_accessibility";
11985 case DW_AT_address_class
:
11986 return "DW_AT_address_class";
11987 case DW_AT_artificial
:
11988 return "DW_AT_artificial";
11989 case DW_AT_base_types
:
11990 return "DW_AT_base_types";
11991 case DW_AT_calling_convention
:
11992 return "DW_AT_calling_convention";
11994 return "DW_AT_count";
11995 case DW_AT_data_member_location
:
11996 return "DW_AT_data_member_location";
11997 case DW_AT_decl_column
:
11998 return "DW_AT_decl_column";
11999 case DW_AT_decl_file
:
12000 return "DW_AT_decl_file";
12001 case DW_AT_decl_line
:
12002 return "DW_AT_decl_line";
12003 case DW_AT_declaration
:
12004 return "DW_AT_declaration";
12005 case DW_AT_discr_list
:
12006 return "DW_AT_discr_list";
12007 case DW_AT_encoding
:
12008 return "DW_AT_encoding";
12009 case DW_AT_external
:
12010 return "DW_AT_external";
12011 case DW_AT_frame_base
:
12012 return "DW_AT_frame_base";
12014 return "DW_AT_friend";
12015 case DW_AT_identifier_case
:
12016 return "DW_AT_identifier_case";
12017 case DW_AT_macro_info
:
12018 return "DW_AT_macro_info";
12019 case DW_AT_namelist_items
:
12020 return "DW_AT_namelist_items";
12021 case DW_AT_priority
:
12022 return "DW_AT_priority";
12023 case DW_AT_segment
:
12024 return "DW_AT_segment";
12025 case DW_AT_specification
:
12026 return "DW_AT_specification";
12027 case DW_AT_static_link
:
12028 return "DW_AT_static_link";
12030 return "DW_AT_type";
12031 case DW_AT_use_location
:
12032 return "DW_AT_use_location";
12033 case DW_AT_variable_parameter
:
12034 return "DW_AT_variable_parameter";
12035 case DW_AT_virtuality
:
12036 return "DW_AT_virtuality";
12037 case DW_AT_vtable_elem_location
:
12038 return "DW_AT_vtable_elem_location";
12039 /* DWARF 3 values. */
12040 case DW_AT_allocated
:
12041 return "DW_AT_allocated";
12042 case DW_AT_associated
:
12043 return "DW_AT_associated";
12044 case DW_AT_data_location
:
12045 return "DW_AT_data_location";
12046 case DW_AT_byte_stride
:
12047 return "DW_AT_byte_stride";
12048 case DW_AT_entry_pc
:
12049 return "DW_AT_entry_pc";
12050 case DW_AT_use_UTF8
:
12051 return "DW_AT_use_UTF8";
12052 case DW_AT_extension
:
12053 return "DW_AT_extension";
12055 return "DW_AT_ranges";
12056 case DW_AT_trampoline
:
12057 return "DW_AT_trampoline";
12058 case DW_AT_call_column
:
12059 return "DW_AT_call_column";
12060 case DW_AT_call_file
:
12061 return "DW_AT_call_file";
12062 case DW_AT_call_line
:
12063 return "DW_AT_call_line";
12064 case DW_AT_description
:
12065 return "DW_AT_description";
12066 case DW_AT_binary_scale
:
12067 return "DW_AT_binary_scale";
12068 case DW_AT_decimal_scale
:
12069 return "DW_AT_decimal_scale";
12071 return "DW_AT_small";
12072 case DW_AT_decimal_sign
:
12073 return "DW_AT_decimal_sign";
12074 case DW_AT_digit_count
:
12075 return "DW_AT_digit_count";
12076 case DW_AT_picture_string
:
12077 return "DW_AT_picture_string";
12078 case DW_AT_mutable
:
12079 return "DW_AT_mutable";
12080 case DW_AT_threads_scaled
:
12081 return "DW_AT_threads_scaled";
12082 case DW_AT_explicit
:
12083 return "DW_AT_explicit";
12084 case DW_AT_object_pointer
:
12085 return "DW_AT_object_pointer";
12086 case DW_AT_endianity
:
12087 return "DW_AT_endianity";
12088 case DW_AT_elemental
:
12089 return "DW_AT_elemental";
12091 return "DW_AT_pure";
12092 case DW_AT_recursive
:
12093 return "DW_AT_recursive";
12094 /* DWARF 4 values. */
12095 case DW_AT_signature
:
12096 return "DW_AT_signature";
12097 case DW_AT_linkage_name
:
12098 return "DW_AT_linkage_name";
12099 /* SGI/MIPS extensions. */
12100 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12101 case DW_AT_MIPS_fde
:
12102 return "DW_AT_MIPS_fde";
12104 case DW_AT_MIPS_loop_begin
:
12105 return "DW_AT_MIPS_loop_begin";
12106 case DW_AT_MIPS_tail_loop_begin
:
12107 return "DW_AT_MIPS_tail_loop_begin";
12108 case DW_AT_MIPS_epilog_begin
:
12109 return "DW_AT_MIPS_epilog_begin";
12110 case DW_AT_MIPS_loop_unroll_factor
:
12111 return "DW_AT_MIPS_loop_unroll_factor";
12112 case DW_AT_MIPS_software_pipeline_depth
:
12113 return "DW_AT_MIPS_software_pipeline_depth";
12114 case DW_AT_MIPS_linkage_name
:
12115 return "DW_AT_MIPS_linkage_name";
12116 case DW_AT_MIPS_stride
:
12117 return "DW_AT_MIPS_stride";
12118 case DW_AT_MIPS_abstract_name
:
12119 return "DW_AT_MIPS_abstract_name";
12120 case DW_AT_MIPS_clone_origin
:
12121 return "DW_AT_MIPS_clone_origin";
12122 case DW_AT_MIPS_has_inlines
:
12123 return "DW_AT_MIPS_has_inlines";
12124 /* HP extensions. */
12125 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12126 case DW_AT_HP_block_index
:
12127 return "DW_AT_HP_block_index";
12129 case DW_AT_HP_unmodifiable
:
12130 return "DW_AT_HP_unmodifiable";
12131 case DW_AT_HP_actuals_stmt_list
:
12132 return "DW_AT_HP_actuals_stmt_list";
12133 case DW_AT_HP_proc_per_section
:
12134 return "DW_AT_HP_proc_per_section";
12135 case DW_AT_HP_raw_data_ptr
:
12136 return "DW_AT_HP_raw_data_ptr";
12137 case DW_AT_HP_pass_by_reference
:
12138 return "DW_AT_HP_pass_by_reference";
12139 case DW_AT_HP_opt_level
:
12140 return "DW_AT_HP_opt_level";
12141 case DW_AT_HP_prof_version_id
:
12142 return "DW_AT_HP_prof_version_id";
12143 case DW_AT_HP_opt_flags
:
12144 return "DW_AT_HP_opt_flags";
12145 case DW_AT_HP_cold_region_low_pc
:
12146 return "DW_AT_HP_cold_region_low_pc";
12147 case DW_AT_HP_cold_region_high_pc
:
12148 return "DW_AT_HP_cold_region_high_pc";
12149 case DW_AT_HP_all_variables_modifiable
:
12150 return "DW_AT_HP_all_variables_modifiable";
12151 case DW_AT_HP_linkage_name
:
12152 return "DW_AT_HP_linkage_name";
12153 case DW_AT_HP_prof_flags
:
12154 return "DW_AT_HP_prof_flags";
12155 /* GNU extensions. */
12156 case DW_AT_sf_names
:
12157 return "DW_AT_sf_names";
12158 case DW_AT_src_info
:
12159 return "DW_AT_src_info";
12160 case DW_AT_mac_info
:
12161 return "DW_AT_mac_info";
12162 case DW_AT_src_coords
:
12163 return "DW_AT_src_coords";
12164 case DW_AT_body_begin
:
12165 return "DW_AT_body_begin";
12166 case DW_AT_body_end
:
12167 return "DW_AT_body_end";
12168 case DW_AT_GNU_vector
:
12169 return "DW_AT_GNU_vector";
12170 case DW_AT_GNU_odr_signature
:
12171 return "DW_AT_GNU_odr_signature";
12172 /* VMS extensions. */
12173 case DW_AT_VMS_rtnbeg_pd_address
:
12174 return "DW_AT_VMS_rtnbeg_pd_address";
12175 /* UPC extension. */
12176 case DW_AT_upc_threads_scaled
:
12177 return "DW_AT_upc_threads_scaled";
12178 /* PGI (STMicroelectronics) extensions. */
12179 case DW_AT_PGI_lbase
:
12180 return "DW_AT_PGI_lbase";
12181 case DW_AT_PGI_soffset
:
12182 return "DW_AT_PGI_soffset";
12183 case DW_AT_PGI_lstride
:
12184 return "DW_AT_PGI_lstride";
12186 return "DW_AT_<unknown>";
12190 /* Convert a DWARF value form code into its string name. */
12193 dwarf_form_name (unsigned form
)
12198 return "DW_FORM_addr";
12199 case DW_FORM_block2
:
12200 return "DW_FORM_block2";
12201 case DW_FORM_block4
:
12202 return "DW_FORM_block4";
12203 case DW_FORM_data2
:
12204 return "DW_FORM_data2";
12205 case DW_FORM_data4
:
12206 return "DW_FORM_data4";
12207 case DW_FORM_data8
:
12208 return "DW_FORM_data8";
12209 case DW_FORM_string
:
12210 return "DW_FORM_string";
12211 case DW_FORM_block
:
12212 return "DW_FORM_block";
12213 case DW_FORM_block1
:
12214 return "DW_FORM_block1";
12215 case DW_FORM_data1
:
12216 return "DW_FORM_data1";
12218 return "DW_FORM_flag";
12219 case DW_FORM_sdata
:
12220 return "DW_FORM_sdata";
12222 return "DW_FORM_strp";
12223 case DW_FORM_udata
:
12224 return "DW_FORM_udata";
12225 case DW_FORM_ref_addr
:
12226 return "DW_FORM_ref_addr";
12228 return "DW_FORM_ref1";
12230 return "DW_FORM_ref2";
12232 return "DW_FORM_ref4";
12234 return "DW_FORM_ref8";
12235 case DW_FORM_ref_udata
:
12236 return "DW_FORM_ref_udata";
12237 case DW_FORM_indirect
:
12238 return "DW_FORM_indirect";
12239 case DW_FORM_sec_offset
:
12240 return "DW_FORM_sec_offset";
12241 case DW_FORM_exprloc
:
12242 return "DW_FORM_exprloc";
12243 case DW_FORM_flag_present
:
12244 return "DW_FORM_flag_present";
12246 return "DW_FORM_sig8";
12248 return "DW_FORM_<unknown>";
12252 /* Convert a DWARF stack opcode into its string name. */
12255 dwarf_stack_op_name (unsigned op
, int def
)
12260 return "DW_OP_addr";
12262 return "DW_OP_deref";
12263 case DW_OP_const1u
:
12264 return "DW_OP_const1u";
12265 case DW_OP_const1s
:
12266 return "DW_OP_const1s";
12267 case DW_OP_const2u
:
12268 return "DW_OP_const2u";
12269 case DW_OP_const2s
:
12270 return "DW_OP_const2s";
12271 case DW_OP_const4u
:
12272 return "DW_OP_const4u";
12273 case DW_OP_const4s
:
12274 return "DW_OP_const4s";
12275 case DW_OP_const8u
:
12276 return "DW_OP_const8u";
12277 case DW_OP_const8s
:
12278 return "DW_OP_const8s";
12280 return "DW_OP_constu";
12282 return "DW_OP_consts";
12284 return "DW_OP_dup";
12286 return "DW_OP_drop";
12288 return "DW_OP_over";
12290 return "DW_OP_pick";
12292 return "DW_OP_swap";
12294 return "DW_OP_rot";
12296 return "DW_OP_xderef";
12298 return "DW_OP_abs";
12300 return "DW_OP_and";
12302 return "DW_OP_div";
12304 return "DW_OP_minus";
12306 return "DW_OP_mod";
12308 return "DW_OP_mul";
12310 return "DW_OP_neg";
12312 return "DW_OP_not";
12316 return "DW_OP_plus";
12317 case DW_OP_plus_uconst
:
12318 return "DW_OP_plus_uconst";
12320 return "DW_OP_shl";
12322 return "DW_OP_shr";
12324 return "DW_OP_shra";
12326 return "DW_OP_xor";
12328 return "DW_OP_bra";
12342 return "DW_OP_skip";
12344 return "DW_OP_lit0";
12346 return "DW_OP_lit1";
12348 return "DW_OP_lit2";
12350 return "DW_OP_lit3";
12352 return "DW_OP_lit4";
12354 return "DW_OP_lit5";
12356 return "DW_OP_lit6";
12358 return "DW_OP_lit7";
12360 return "DW_OP_lit8";
12362 return "DW_OP_lit9";
12364 return "DW_OP_lit10";
12366 return "DW_OP_lit11";
12368 return "DW_OP_lit12";
12370 return "DW_OP_lit13";
12372 return "DW_OP_lit14";
12374 return "DW_OP_lit15";
12376 return "DW_OP_lit16";
12378 return "DW_OP_lit17";
12380 return "DW_OP_lit18";
12382 return "DW_OP_lit19";
12384 return "DW_OP_lit20";
12386 return "DW_OP_lit21";
12388 return "DW_OP_lit22";
12390 return "DW_OP_lit23";
12392 return "DW_OP_lit24";
12394 return "DW_OP_lit25";
12396 return "DW_OP_lit26";
12398 return "DW_OP_lit27";
12400 return "DW_OP_lit28";
12402 return "DW_OP_lit29";
12404 return "DW_OP_lit30";
12406 return "DW_OP_lit31";
12408 return "DW_OP_reg0";
12410 return "DW_OP_reg1";
12412 return "DW_OP_reg2";
12414 return "DW_OP_reg3";
12416 return "DW_OP_reg4";
12418 return "DW_OP_reg5";
12420 return "DW_OP_reg6";
12422 return "DW_OP_reg7";
12424 return "DW_OP_reg8";
12426 return "DW_OP_reg9";
12428 return "DW_OP_reg10";
12430 return "DW_OP_reg11";
12432 return "DW_OP_reg12";
12434 return "DW_OP_reg13";
12436 return "DW_OP_reg14";
12438 return "DW_OP_reg15";
12440 return "DW_OP_reg16";
12442 return "DW_OP_reg17";
12444 return "DW_OP_reg18";
12446 return "DW_OP_reg19";
12448 return "DW_OP_reg20";
12450 return "DW_OP_reg21";
12452 return "DW_OP_reg22";
12454 return "DW_OP_reg23";
12456 return "DW_OP_reg24";
12458 return "DW_OP_reg25";
12460 return "DW_OP_reg26";
12462 return "DW_OP_reg27";
12464 return "DW_OP_reg28";
12466 return "DW_OP_reg29";
12468 return "DW_OP_reg30";
12470 return "DW_OP_reg31";
12472 return "DW_OP_breg0";
12474 return "DW_OP_breg1";
12476 return "DW_OP_breg2";
12478 return "DW_OP_breg3";
12480 return "DW_OP_breg4";
12482 return "DW_OP_breg5";
12484 return "DW_OP_breg6";
12486 return "DW_OP_breg7";
12488 return "DW_OP_breg8";
12490 return "DW_OP_breg9";
12492 return "DW_OP_breg10";
12494 return "DW_OP_breg11";
12496 return "DW_OP_breg12";
12498 return "DW_OP_breg13";
12500 return "DW_OP_breg14";
12502 return "DW_OP_breg15";
12504 return "DW_OP_breg16";
12506 return "DW_OP_breg17";
12508 return "DW_OP_breg18";
12510 return "DW_OP_breg19";
12512 return "DW_OP_breg20";
12514 return "DW_OP_breg21";
12516 return "DW_OP_breg22";
12518 return "DW_OP_breg23";
12520 return "DW_OP_breg24";
12522 return "DW_OP_breg25";
12524 return "DW_OP_breg26";
12526 return "DW_OP_breg27";
12528 return "DW_OP_breg28";
12530 return "DW_OP_breg29";
12532 return "DW_OP_breg30";
12534 return "DW_OP_breg31";
12536 return "DW_OP_regx";
12538 return "DW_OP_fbreg";
12540 return "DW_OP_bregx";
12542 return "DW_OP_piece";
12543 case DW_OP_deref_size
:
12544 return "DW_OP_deref_size";
12545 case DW_OP_xderef_size
:
12546 return "DW_OP_xderef_size";
12548 return "DW_OP_nop";
12549 /* DWARF 3 extensions. */
12550 case DW_OP_push_object_address
:
12551 return "DW_OP_push_object_address";
12553 return "DW_OP_call2";
12555 return "DW_OP_call4";
12556 case DW_OP_call_ref
:
12557 return "DW_OP_call_ref";
12558 case DW_OP_form_tls_address
:
12559 return "DW_OP_form_tls_address";
12560 case DW_OP_call_frame_cfa
:
12561 return "DW_OP_call_frame_cfa";
12562 case DW_OP_bit_piece
:
12563 return "DW_OP_bit_piece";
12564 /* DWARF 4 extensions. */
12565 case DW_OP_implicit_value
:
12566 return "DW_OP_implicit_value";
12567 case DW_OP_stack_value
:
12568 return "DW_OP_stack_value";
12569 /* GNU extensions. */
12570 case DW_OP_GNU_push_tls_address
:
12571 return "DW_OP_GNU_push_tls_address";
12572 case DW_OP_GNU_uninit
:
12573 return "DW_OP_GNU_uninit";
12574 case DW_OP_GNU_implicit_pointer
:
12575 return "DW_OP_GNU_implicit_pointer";
12577 return def
? "OP_<unknown>" : NULL
;
12582 dwarf_bool_name (unsigned mybool
)
12590 /* Convert a DWARF type code into its string name. */
12593 dwarf_type_encoding_name (unsigned enc
)
12598 return "DW_ATE_void";
12599 case DW_ATE_address
:
12600 return "DW_ATE_address";
12601 case DW_ATE_boolean
:
12602 return "DW_ATE_boolean";
12603 case DW_ATE_complex_float
:
12604 return "DW_ATE_complex_float";
12606 return "DW_ATE_float";
12607 case DW_ATE_signed
:
12608 return "DW_ATE_signed";
12609 case DW_ATE_signed_char
:
12610 return "DW_ATE_signed_char";
12611 case DW_ATE_unsigned
:
12612 return "DW_ATE_unsigned";
12613 case DW_ATE_unsigned_char
:
12614 return "DW_ATE_unsigned_char";
12616 case DW_ATE_imaginary_float
:
12617 return "DW_ATE_imaginary_float";
12618 case DW_ATE_packed_decimal
:
12619 return "DW_ATE_packed_decimal";
12620 case DW_ATE_numeric_string
:
12621 return "DW_ATE_numeric_string";
12622 case DW_ATE_edited
:
12623 return "DW_ATE_edited";
12624 case DW_ATE_signed_fixed
:
12625 return "DW_ATE_signed_fixed";
12626 case DW_ATE_unsigned_fixed
:
12627 return "DW_ATE_unsigned_fixed";
12628 case DW_ATE_decimal_float
:
12629 return "DW_ATE_decimal_float";
12632 return "DW_ATE_UTF";
12633 /* HP extensions. */
12634 case DW_ATE_HP_float80
:
12635 return "DW_ATE_HP_float80";
12636 case DW_ATE_HP_complex_float80
:
12637 return "DW_ATE_HP_complex_float80";
12638 case DW_ATE_HP_float128
:
12639 return "DW_ATE_HP_float128";
12640 case DW_ATE_HP_complex_float128
:
12641 return "DW_ATE_HP_complex_float128";
12642 case DW_ATE_HP_floathpintel
:
12643 return "DW_ATE_HP_floathpintel";
12644 case DW_ATE_HP_imaginary_float80
:
12645 return "DW_ATE_HP_imaginary_float80";
12646 case DW_ATE_HP_imaginary_float128
:
12647 return "DW_ATE_HP_imaginary_float128";
12649 return "DW_ATE_<unknown>";
12653 /* Convert a DWARF call frame info operation to its string name. */
12657 dwarf_cfi_name (unsigned cfi_opc
)
12661 case DW_CFA_advance_loc
:
12662 return "DW_CFA_advance_loc";
12663 case DW_CFA_offset
:
12664 return "DW_CFA_offset";
12665 case DW_CFA_restore
:
12666 return "DW_CFA_restore";
12668 return "DW_CFA_nop";
12669 case DW_CFA_set_loc
:
12670 return "DW_CFA_set_loc";
12671 case DW_CFA_advance_loc1
:
12672 return "DW_CFA_advance_loc1";
12673 case DW_CFA_advance_loc2
:
12674 return "DW_CFA_advance_loc2";
12675 case DW_CFA_advance_loc4
:
12676 return "DW_CFA_advance_loc4";
12677 case DW_CFA_offset_extended
:
12678 return "DW_CFA_offset_extended";
12679 case DW_CFA_restore_extended
:
12680 return "DW_CFA_restore_extended";
12681 case DW_CFA_undefined
:
12682 return "DW_CFA_undefined";
12683 case DW_CFA_same_value
:
12684 return "DW_CFA_same_value";
12685 case DW_CFA_register
:
12686 return "DW_CFA_register";
12687 case DW_CFA_remember_state
:
12688 return "DW_CFA_remember_state";
12689 case DW_CFA_restore_state
:
12690 return "DW_CFA_restore_state";
12691 case DW_CFA_def_cfa
:
12692 return "DW_CFA_def_cfa";
12693 case DW_CFA_def_cfa_register
:
12694 return "DW_CFA_def_cfa_register";
12695 case DW_CFA_def_cfa_offset
:
12696 return "DW_CFA_def_cfa_offset";
12698 case DW_CFA_def_cfa_expression
:
12699 return "DW_CFA_def_cfa_expression";
12700 case DW_CFA_expression
:
12701 return "DW_CFA_expression";
12702 case DW_CFA_offset_extended_sf
:
12703 return "DW_CFA_offset_extended_sf";
12704 case DW_CFA_def_cfa_sf
:
12705 return "DW_CFA_def_cfa_sf";
12706 case DW_CFA_def_cfa_offset_sf
:
12707 return "DW_CFA_def_cfa_offset_sf";
12708 case DW_CFA_val_offset
:
12709 return "DW_CFA_val_offset";
12710 case DW_CFA_val_offset_sf
:
12711 return "DW_CFA_val_offset_sf";
12712 case DW_CFA_val_expression
:
12713 return "DW_CFA_val_expression";
12714 /* SGI/MIPS specific. */
12715 case DW_CFA_MIPS_advance_loc8
:
12716 return "DW_CFA_MIPS_advance_loc8";
12717 /* GNU extensions. */
12718 case DW_CFA_GNU_window_save
:
12719 return "DW_CFA_GNU_window_save";
12720 case DW_CFA_GNU_args_size
:
12721 return "DW_CFA_GNU_args_size";
12722 case DW_CFA_GNU_negative_offset_extended
:
12723 return "DW_CFA_GNU_negative_offset_extended";
12725 return "DW_CFA_<unknown>";
12731 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12735 print_spaces (indent
, f
);
12736 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12737 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12739 if (die
->parent
!= NULL
)
12741 print_spaces (indent
, f
);
12742 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12743 die
->parent
->offset
);
12746 print_spaces (indent
, f
);
12747 fprintf_unfiltered (f
, " has children: %s\n",
12748 dwarf_bool_name (die
->child
!= NULL
));
12750 print_spaces (indent
, f
);
12751 fprintf_unfiltered (f
, " attributes:\n");
12753 for (i
= 0; i
< die
->num_attrs
; ++i
)
12755 print_spaces (indent
, f
);
12756 fprintf_unfiltered (f
, " %s (%s) ",
12757 dwarf_attr_name (die
->attrs
[i
].name
),
12758 dwarf_form_name (die
->attrs
[i
].form
));
12760 switch (die
->attrs
[i
].form
)
12762 case DW_FORM_ref_addr
:
12764 fprintf_unfiltered (f
, "address: ");
12765 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12767 case DW_FORM_block2
:
12768 case DW_FORM_block4
:
12769 case DW_FORM_block
:
12770 case DW_FORM_block1
:
12771 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12773 case DW_FORM_exprloc
:
12774 fprintf_unfiltered (f
, "expression: size %u",
12775 DW_BLOCK (&die
->attrs
[i
])->size
);
12780 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12781 (long) (DW_ADDR (&die
->attrs
[i
])));
12783 case DW_FORM_data1
:
12784 case DW_FORM_data2
:
12785 case DW_FORM_data4
:
12786 case DW_FORM_data8
:
12787 case DW_FORM_udata
:
12788 case DW_FORM_sdata
:
12789 fprintf_unfiltered (f
, "constant: %s",
12790 pulongest (DW_UNSND (&die
->attrs
[i
])));
12792 case DW_FORM_sec_offset
:
12793 fprintf_unfiltered (f
, "section offset: %s",
12794 pulongest (DW_UNSND (&die
->attrs
[i
])));
12797 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12798 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12799 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12801 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12803 case DW_FORM_string
:
12805 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12806 DW_STRING (&die
->attrs
[i
])
12807 ? DW_STRING (&die
->attrs
[i
]) : "",
12808 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12811 if (DW_UNSND (&die
->attrs
[i
]))
12812 fprintf_unfiltered (f
, "flag: TRUE");
12814 fprintf_unfiltered (f
, "flag: FALSE");
12816 case DW_FORM_flag_present
:
12817 fprintf_unfiltered (f
, "flag: TRUE");
12819 case DW_FORM_indirect
:
12820 /* the reader will have reduced the indirect form to
12821 the "base form" so this form should not occur */
12822 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12825 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12826 die
->attrs
[i
].form
);
12829 fprintf_unfiltered (f
, "\n");
12834 dump_die_for_error (struct die_info
*die
)
12836 dump_die_shallow (gdb_stderr
, 0, die
);
12840 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12842 int indent
= level
* 4;
12844 gdb_assert (die
!= NULL
);
12846 if (level
>= max_level
)
12849 dump_die_shallow (f
, indent
, die
);
12851 if (die
->child
!= NULL
)
12853 print_spaces (indent
, f
);
12854 fprintf_unfiltered (f
, " Children:");
12855 if (level
+ 1 < max_level
)
12857 fprintf_unfiltered (f
, "\n");
12858 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12862 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12866 if (die
->sibling
!= NULL
&& level
> 0)
12868 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12872 /* This is called from the pdie macro in gdbinit.in.
12873 It's not static so gcc will keep a copy callable from gdb. */
12876 dump_die (struct die_info
*die
, int max_level
)
12878 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12882 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12886 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12892 is_ref_attr (struct attribute
*attr
)
12894 switch (attr
->form
)
12896 case DW_FORM_ref_addr
:
12901 case DW_FORM_ref_udata
:
12908 static unsigned int
12909 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12911 if (is_ref_attr (attr
))
12912 return DW_ADDR (attr
);
12914 complaint (&symfile_complaints
,
12915 _("unsupported die ref attribute form: '%s'"),
12916 dwarf_form_name (attr
->form
));
12920 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12921 * the value held by the attribute is not constant. */
12924 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12926 if (attr
->form
== DW_FORM_sdata
)
12927 return DW_SND (attr
);
12928 else if (attr
->form
== DW_FORM_udata
12929 || attr
->form
== DW_FORM_data1
12930 || attr
->form
== DW_FORM_data2
12931 || attr
->form
== DW_FORM_data4
12932 || attr
->form
== DW_FORM_data8
)
12933 return DW_UNSND (attr
);
12936 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12937 dwarf_form_name (attr
->form
));
12938 return default_value
;
12942 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12943 unit and add it to our queue.
12944 The result is non-zero if PER_CU was queued, otherwise the result is zero
12945 meaning either PER_CU is already queued or it is already loaded. */
12948 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12949 struct dwarf2_per_cu_data
*per_cu
)
12951 /* We may arrive here during partial symbol reading, if we need full
12952 DIEs to process an unusual case (e.g. template arguments). Do
12953 not queue PER_CU, just tell our caller to load its DIEs. */
12954 if (dwarf2_per_objfile
->reading_partial_symbols
)
12956 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12961 /* Mark the dependence relation so that we don't flush PER_CU
12963 dwarf2_add_dependence (this_cu
, per_cu
);
12965 /* If it's already on the queue, we have nothing to do. */
12966 if (per_cu
->queued
)
12969 /* If the compilation unit is already loaded, just mark it as
12971 if (per_cu
->cu
!= NULL
)
12973 per_cu
->cu
->last_used
= 0;
12977 /* Add it to the queue. */
12978 queue_comp_unit (per_cu
, this_cu
->objfile
);
12983 /* Follow reference or signature attribute ATTR of SRC_DIE.
12984 On entry *REF_CU is the CU of SRC_DIE.
12985 On exit *REF_CU is the CU of the result. */
12987 static struct die_info
*
12988 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12989 struct dwarf2_cu
**ref_cu
)
12991 struct die_info
*die
;
12993 if (is_ref_attr (attr
))
12994 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12995 else if (attr
->form
== DW_FORM_sig8
)
12996 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12999 dump_die_for_error (src_die
);
13000 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13001 (*ref_cu
)->objfile
->name
);
13007 /* Follow reference OFFSET.
13008 On entry *REF_CU is the CU of the source die referencing OFFSET.
13009 On exit *REF_CU is the CU of the result.
13010 Returns NULL if OFFSET is invalid. */
13012 static struct die_info
*
13013 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13015 struct die_info temp_die
;
13016 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13018 gdb_assert (cu
->per_cu
!= NULL
);
13022 if (cu
->per_cu
->from_debug_types
)
13024 /* .debug_types CUs cannot reference anything outside their CU.
13025 If they need to, they have to reference a signatured type via
13027 if (! offset_in_cu_p (&cu
->header
, offset
))
13030 else if (! offset_in_cu_p (&cu
->header
, offset
))
13032 struct dwarf2_per_cu_data
*per_cu
;
13034 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13036 /* If necessary, add it to the queue and load its DIEs. */
13037 if (maybe_queue_comp_unit (cu
, per_cu
))
13038 load_full_comp_unit (per_cu
, cu
->objfile
);
13040 target_cu
= per_cu
->cu
;
13042 else if (cu
->dies
== NULL
)
13044 /* We're loading full DIEs during partial symbol reading. */
13045 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13046 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13049 *ref_cu
= target_cu
;
13050 temp_die
.offset
= offset
;
13051 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13054 /* Follow reference attribute ATTR of SRC_DIE.
13055 On entry *REF_CU is the CU of SRC_DIE.
13056 On exit *REF_CU is the CU of the result. */
13058 static struct die_info
*
13059 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13060 struct dwarf2_cu
**ref_cu
)
13062 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13063 struct dwarf2_cu
*cu
= *ref_cu
;
13064 struct die_info
*die
;
13066 die
= follow_die_offset (offset
, ref_cu
);
13068 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13069 "at 0x%x [in module %s]"),
13070 offset
, src_die
->offset
, cu
->objfile
->name
);
13075 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13076 value is intended for DW_OP_call*. */
13078 struct dwarf2_locexpr_baton
13079 dwarf2_fetch_die_location_block (unsigned int offset
,
13080 struct dwarf2_per_cu_data
*per_cu
,
13081 CORE_ADDR (*get_frame_pc
) (void *baton
),
13084 struct dwarf2_cu
*cu
= per_cu
->cu
;
13085 struct die_info
*die
;
13086 struct attribute
*attr
;
13087 struct dwarf2_locexpr_baton retval
;
13089 dw2_setup (per_cu
->objfile
);
13091 die
= follow_die_offset (offset
, &cu
);
13093 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13094 offset
, per_cu
->cu
->objfile
->name
);
13096 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13099 /* DWARF: "If there is no such attribute, then there is no effect.". */
13101 retval
.data
= NULL
;
13104 else if (attr_form_is_section_offset (attr
))
13106 struct dwarf2_loclist_baton loclist_baton
;
13107 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13110 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13112 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13114 retval
.size
= size
;
13118 if (!attr_form_is_block (attr
))
13119 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13120 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13121 offset
, per_cu
->cu
->objfile
->name
);
13123 retval
.data
= DW_BLOCK (attr
)->data
;
13124 retval
.size
= DW_BLOCK (attr
)->size
;
13126 retval
.per_cu
= cu
->per_cu
;
13130 /* Follow the signature attribute ATTR in SRC_DIE.
13131 On entry *REF_CU is the CU of SRC_DIE.
13132 On exit *REF_CU is the CU of the result. */
13134 static struct die_info
*
13135 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13136 struct dwarf2_cu
**ref_cu
)
13138 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13139 struct die_info temp_die
;
13140 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13141 struct dwarf2_cu
*sig_cu
;
13142 struct die_info
*die
;
13144 /* sig_type will be NULL if the signatured type is missing from
13146 if (sig_type
== NULL
)
13147 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13148 "at 0x%x [in module %s]"),
13149 src_die
->offset
, objfile
->name
);
13151 /* If necessary, add it to the queue and load its DIEs. */
13153 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13154 read_signatured_type (objfile
, sig_type
);
13156 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13158 sig_cu
= sig_type
->per_cu
.cu
;
13159 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13160 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13167 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
13168 "at 0x%x [in module %s]"),
13169 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13172 /* Given an offset of a signatured type, return its signatured_type. */
13174 static struct signatured_type
*
13175 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13177 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13178 unsigned int length
, initial_length_size
;
13179 unsigned int sig_offset
;
13180 struct signatured_type find_entry
, *type_sig
;
13182 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13183 sig_offset
= (initial_length_size
13185 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13186 + 1 /*address_size*/);
13187 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13188 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13190 /* This is only used to lookup previously recorded types.
13191 If we didn't find it, it's our bug. */
13192 gdb_assert (type_sig
!= NULL
);
13193 gdb_assert (offset
== type_sig
->offset
);
13198 /* Read in signatured type at OFFSET and build its CU and die(s). */
13201 read_signatured_type_at_offset (struct objfile
*objfile
,
13202 unsigned int offset
)
13204 struct signatured_type
*type_sig
;
13206 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13208 /* We have the section offset, but we need the signature to do the
13209 hash table lookup. */
13210 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13212 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13214 read_signatured_type (objfile
, type_sig
);
13216 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13219 /* Read in a signatured type and build its CU and DIEs. */
13222 read_signatured_type (struct objfile
*objfile
,
13223 struct signatured_type
*type_sig
)
13225 gdb_byte
*types_ptr
;
13226 struct die_reader_specs reader_specs
;
13227 struct dwarf2_cu
*cu
;
13228 ULONGEST signature
;
13229 struct cleanup
*back_to
, *free_cu_cleanup
;
13231 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13232 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13234 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13236 cu
= xmalloc (sizeof (*cu
));
13237 init_one_comp_unit (cu
, objfile
);
13239 type_sig
->per_cu
.cu
= cu
;
13240 cu
->per_cu
= &type_sig
->per_cu
;
13242 /* If an error occurs while loading, release our storage. */
13243 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13245 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13246 types_ptr
, objfile
->obfd
);
13247 gdb_assert (signature
== type_sig
->signature
);
13250 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13254 &cu
->comp_unit_obstack
,
13255 hashtab_obstack_allocate
,
13256 dummy_obstack_deallocate
);
13258 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13259 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13261 init_cu_die_reader (&reader_specs
, cu
);
13263 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13266 /* We try not to read any attributes in this function, because not
13267 all objfiles needed for references have been loaded yet, and symbol
13268 table processing isn't initialized. But we have to set the CU language,
13269 or we won't be able to build types correctly. */
13270 prepare_one_comp_unit (cu
, cu
->dies
);
13272 do_cleanups (back_to
);
13274 /* We've successfully allocated this compilation unit. Let our caller
13275 clean it up when finished with it. */
13276 discard_cleanups (free_cu_cleanup
);
13278 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13279 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13282 /* Decode simple location descriptions.
13283 Given a pointer to a dwarf block that defines a location, compute
13284 the location and return the value.
13286 NOTE drow/2003-11-18: This function is called in two situations
13287 now: for the address of static or global variables (partial symbols
13288 only) and for offsets into structures which are expected to be
13289 (more or less) constant. The partial symbol case should go away,
13290 and only the constant case should remain. That will let this
13291 function complain more accurately. A few special modes are allowed
13292 without complaint for global variables (for instance, global
13293 register values and thread-local values).
13295 A location description containing no operations indicates that the
13296 object is optimized out. The return value is 0 for that case.
13297 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13298 callers will only want a very basic result and this can become a
13301 Note that stack[0] is unused except as a default error return. */
13304 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13306 struct objfile
*objfile
= cu
->objfile
;
13308 int size
= blk
->size
;
13309 gdb_byte
*data
= blk
->data
;
13310 CORE_ADDR stack
[64];
13312 unsigned int bytes_read
, unsnd
;
13318 stack
[++stacki
] = 0;
13357 stack
[++stacki
] = op
- DW_OP_lit0
;
13392 stack
[++stacki
] = op
- DW_OP_reg0
;
13394 dwarf2_complex_location_expr_complaint ();
13398 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13400 stack
[++stacki
] = unsnd
;
13402 dwarf2_complex_location_expr_complaint ();
13406 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13411 case DW_OP_const1u
:
13412 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13416 case DW_OP_const1s
:
13417 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13421 case DW_OP_const2u
:
13422 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13426 case DW_OP_const2s
:
13427 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13431 case DW_OP_const4u
:
13432 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13436 case DW_OP_const4s
:
13437 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13442 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13448 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13453 stack
[stacki
+ 1] = stack
[stacki
];
13458 stack
[stacki
- 1] += stack
[stacki
];
13462 case DW_OP_plus_uconst
:
13463 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13468 stack
[stacki
- 1] -= stack
[stacki
];
13473 /* If we're not the last op, then we definitely can't encode
13474 this using GDB's address_class enum. This is valid for partial
13475 global symbols, although the variable's address will be bogus
13478 dwarf2_complex_location_expr_complaint ();
13481 case DW_OP_GNU_push_tls_address
:
13482 /* The top of the stack has the offset from the beginning
13483 of the thread control block at which the variable is located. */
13484 /* Nothing should follow this operator, so the top of stack would
13486 /* This is valid for partial global symbols, but the variable's
13487 address will be bogus in the psymtab. */
13489 dwarf2_complex_location_expr_complaint ();
13492 case DW_OP_GNU_uninit
:
13496 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13497 dwarf_stack_op_name (op
, 1));
13498 return (stack
[stacki
]);
13501 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13502 outside of the allocated space. Also enforce minimum>0. */
13503 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13505 complaint (&symfile_complaints
,
13506 _("location description stack overflow"));
13512 complaint (&symfile_complaints
,
13513 _("location description stack underflow"));
13517 return (stack
[stacki
]);
13520 /* memory allocation interface */
13522 static struct dwarf_block
*
13523 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13525 struct dwarf_block
*blk
;
13527 blk
= (struct dwarf_block
*)
13528 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13532 static struct abbrev_info
*
13533 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13535 struct abbrev_info
*abbrev
;
13537 abbrev
= (struct abbrev_info
*)
13538 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13539 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13543 static struct die_info
*
13544 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13546 struct die_info
*die
;
13547 size_t size
= sizeof (struct die_info
);
13550 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13552 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13553 memset (die
, 0, sizeof (struct die_info
));
13558 /* Macro support. */
13561 /* Return the full name of file number I in *LH's file name table.
13562 Use COMP_DIR as the name of the current directory of the
13563 compilation. The result is allocated using xmalloc; the caller is
13564 responsible for freeing it. */
13566 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13568 /* Is the file number a valid index into the line header's file name
13569 table? Remember that file numbers start with one, not zero. */
13570 if (1 <= file
&& file
<= lh
->num_file_names
)
13572 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13574 if (IS_ABSOLUTE_PATH (fe
->name
))
13575 return xstrdup (fe
->name
);
13583 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13589 dir_len
= strlen (dir
);
13590 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13591 strcpy (full_name
, dir
);
13592 full_name
[dir_len
] = '/';
13593 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13597 return xstrdup (fe
->name
);
13602 /* The compiler produced a bogus file number. We can at least
13603 record the macro definitions made in the file, even if we
13604 won't be able to find the file by name. */
13605 char fake_name
[80];
13607 sprintf (fake_name
, "<bad macro file number %d>", file
);
13609 complaint (&symfile_complaints
,
13610 _("bad file number in macro information (%d)"),
13613 return xstrdup (fake_name
);
13618 static struct macro_source_file
*
13619 macro_start_file (int file
, int line
,
13620 struct macro_source_file
*current_file
,
13621 const char *comp_dir
,
13622 struct line_header
*lh
, struct objfile
*objfile
)
13624 /* The full name of this source file. */
13625 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13627 /* We don't create a macro table for this compilation unit
13628 at all until we actually get a filename. */
13629 if (! pending_macros
)
13630 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13631 objfile
->macro_cache
);
13633 if (! current_file
)
13634 /* If we have no current file, then this must be the start_file
13635 directive for the compilation unit's main source file. */
13636 current_file
= macro_set_main (pending_macros
, full_name
);
13638 current_file
= macro_include (current_file
, line
, full_name
);
13642 return current_file
;
13646 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13647 followed by a null byte. */
13649 copy_string (const char *buf
, int len
)
13651 char *s
= xmalloc (len
+ 1);
13653 memcpy (s
, buf
, len
);
13659 static const char *
13660 consume_improper_spaces (const char *p
, const char *body
)
13664 complaint (&symfile_complaints
,
13665 _("macro definition contains spaces in formal argument list:\n`%s'"),
13677 parse_macro_definition (struct macro_source_file
*file
, int line
,
13682 /* The body string takes one of two forms. For object-like macro
13683 definitions, it should be:
13685 <macro name> " " <definition>
13687 For function-like macro definitions, it should be:
13689 <macro name> "() " <definition>
13691 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13693 Spaces may appear only where explicitly indicated, and in the
13696 The Dwarf 2 spec says that an object-like macro's name is always
13697 followed by a space, but versions of GCC around March 2002 omit
13698 the space when the macro's definition is the empty string.
13700 The Dwarf 2 spec says that there should be no spaces between the
13701 formal arguments in a function-like macro's formal argument list,
13702 but versions of GCC around March 2002 include spaces after the
13706 /* Find the extent of the macro name. The macro name is terminated
13707 by either a space or null character (for an object-like macro) or
13708 an opening paren (for a function-like macro). */
13709 for (p
= body
; *p
; p
++)
13710 if (*p
== ' ' || *p
== '(')
13713 if (*p
== ' ' || *p
== '\0')
13715 /* It's an object-like macro. */
13716 int name_len
= p
- body
;
13717 char *name
= copy_string (body
, name_len
);
13718 const char *replacement
;
13721 replacement
= body
+ name_len
+ 1;
13724 dwarf2_macro_malformed_definition_complaint (body
);
13725 replacement
= body
+ name_len
;
13728 macro_define_object (file
, line
, name
, replacement
);
13732 else if (*p
== '(')
13734 /* It's a function-like macro. */
13735 char *name
= copy_string (body
, p
- body
);
13738 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13742 p
= consume_improper_spaces (p
, body
);
13744 /* Parse the formal argument list. */
13745 while (*p
&& *p
!= ')')
13747 /* Find the extent of the current argument name. */
13748 const char *arg_start
= p
;
13750 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13753 if (! *p
|| p
== arg_start
)
13754 dwarf2_macro_malformed_definition_complaint (body
);
13757 /* Make sure argv has room for the new argument. */
13758 if (argc
>= argv_size
)
13761 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13764 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13767 p
= consume_improper_spaces (p
, body
);
13769 /* Consume the comma, if present. */
13774 p
= consume_improper_spaces (p
, body
);
13783 /* Perfectly formed definition, no complaints. */
13784 macro_define_function (file
, line
, name
,
13785 argc
, (const char **) argv
,
13787 else if (*p
== '\0')
13789 /* Complain, but do define it. */
13790 dwarf2_macro_malformed_definition_complaint (body
);
13791 macro_define_function (file
, line
, name
,
13792 argc
, (const char **) argv
,
13796 /* Just complain. */
13797 dwarf2_macro_malformed_definition_complaint (body
);
13800 /* Just complain. */
13801 dwarf2_macro_malformed_definition_complaint (body
);
13807 for (i
= 0; i
< argc
; i
++)
13813 dwarf2_macro_malformed_definition_complaint (body
);
13818 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13819 char *comp_dir
, bfd
*abfd
,
13820 struct dwarf2_cu
*cu
)
13822 gdb_byte
*mac_ptr
, *mac_end
;
13823 struct macro_source_file
*current_file
= 0;
13824 enum dwarf_macinfo_record_type macinfo_type
;
13825 int at_commandline
;
13827 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13828 &dwarf2_per_objfile
->macinfo
);
13829 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13831 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13835 /* First pass: Find the name of the base filename.
13836 This filename is needed in order to process all macros whose definition
13837 (or undefinition) comes from the command line. These macros are defined
13838 before the first DW_MACINFO_start_file entry, and yet still need to be
13839 associated to the base file.
13841 To determine the base file name, we scan the macro definitions until we
13842 reach the first DW_MACINFO_start_file entry. We then initialize
13843 CURRENT_FILE accordingly so that any macro definition found before the
13844 first DW_MACINFO_start_file can still be associated to the base file. */
13846 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13847 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13848 + dwarf2_per_objfile
->macinfo
.size
;
13852 /* Do we at least have room for a macinfo type byte? */
13853 if (mac_ptr
>= mac_end
)
13855 /* Complaint is printed during the second pass as GDB will probably
13856 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13860 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13863 switch (macinfo_type
)
13865 /* A zero macinfo type indicates the end of the macro
13870 case DW_MACINFO_define
:
13871 case DW_MACINFO_undef
:
13872 /* Only skip the data by MAC_PTR. */
13874 unsigned int bytes_read
;
13876 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13877 mac_ptr
+= bytes_read
;
13878 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13879 mac_ptr
+= bytes_read
;
13883 case DW_MACINFO_start_file
:
13885 unsigned int bytes_read
;
13888 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13889 mac_ptr
+= bytes_read
;
13890 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13891 mac_ptr
+= bytes_read
;
13893 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13898 case DW_MACINFO_end_file
:
13899 /* No data to skip by MAC_PTR. */
13902 case DW_MACINFO_vendor_ext
:
13903 /* Only skip the data by MAC_PTR. */
13905 unsigned int bytes_read
;
13907 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13908 mac_ptr
+= bytes_read
;
13909 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13910 mac_ptr
+= bytes_read
;
13917 } while (macinfo_type
!= 0 && current_file
== NULL
);
13919 /* Second pass: Process all entries.
13921 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13922 command-line macro definitions/undefinitions. This flag is unset when we
13923 reach the first DW_MACINFO_start_file entry. */
13925 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13927 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13928 GDB is still reading the definitions from command line. First
13929 DW_MACINFO_start_file will need to be ignored as it was already executed
13930 to create CURRENT_FILE for the main source holding also the command line
13931 definitions. On first met DW_MACINFO_start_file this flag is reset to
13932 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13934 at_commandline
= 1;
13938 /* Do we at least have room for a macinfo type byte? */
13939 if (mac_ptr
>= mac_end
)
13941 dwarf2_macros_too_long_complaint ();
13945 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13948 switch (macinfo_type
)
13950 /* A zero macinfo type indicates the end of the macro
13955 case DW_MACINFO_define
:
13956 case DW_MACINFO_undef
:
13958 unsigned int bytes_read
;
13962 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13963 mac_ptr
+= bytes_read
;
13964 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13965 mac_ptr
+= bytes_read
;
13967 if (! current_file
)
13969 /* DWARF violation as no main source is present. */
13970 complaint (&symfile_complaints
,
13971 _("debug info with no main source gives macro %s "
13973 macinfo_type
== DW_MACINFO_define
?
13975 macinfo_type
== DW_MACINFO_undef
?
13976 _("undefinition") :
13977 _("something-or-other"), line
, body
);
13980 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13981 complaint (&symfile_complaints
,
13982 _("debug info gives %s macro %s with %s line %d: %s"),
13983 at_commandline
? _("command-line") : _("in-file"),
13984 macinfo_type
== DW_MACINFO_define
?
13986 macinfo_type
== DW_MACINFO_undef
?
13987 _("undefinition") :
13988 _("something-or-other"),
13989 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13991 if (macinfo_type
== DW_MACINFO_define
)
13992 parse_macro_definition (current_file
, line
, body
);
13993 else if (macinfo_type
== DW_MACINFO_undef
)
13994 macro_undef (current_file
, line
, body
);
13998 case DW_MACINFO_start_file
:
14000 unsigned int bytes_read
;
14003 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14004 mac_ptr
+= bytes_read
;
14005 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14006 mac_ptr
+= bytes_read
;
14008 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
14009 complaint (&symfile_complaints
,
14010 _("debug info gives source %d included "
14011 "from %s at %s line %d"),
14012 file
, at_commandline
? _("command-line") : _("file"),
14013 line
== 0 ? _("zero") : _("non-zero"), line
);
14015 if (at_commandline
)
14017 /* This DW_MACINFO_start_file was executed in the pass one. */
14018 at_commandline
= 0;
14021 current_file
= macro_start_file (file
, line
,
14022 current_file
, comp_dir
,
14027 case DW_MACINFO_end_file
:
14028 if (! current_file
)
14029 complaint (&symfile_complaints
,
14030 _("macro debug info has an unmatched `close_file' directive"));
14033 current_file
= current_file
->included_by
;
14034 if (! current_file
)
14036 enum dwarf_macinfo_record_type next_type
;
14038 /* GCC circa March 2002 doesn't produce the zero
14039 type byte marking the end of the compilation
14040 unit. Complain if it's not there, but exit no
14043 /* Do we at least have room for a macinfo type byte? */
14044 if (mac_ptr
>= mac_end
)
14046 dwarf2_macros_too_long_complaint ();
14050 /* We don't increment mac_ptr here, so this is just
14052 next_type
= read_1_byte (abfd
, mac_ptr
);
14053 if (next_type
!= 0)
14054 complaint (&symfile_complaints
,
14055 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
14062 case DW_MACINFO_vendor_ext
:
14064 unsigned int bytes_read
;
14068 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14069 mac_ptr
+= bytes_read
;
14070 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14071 mac_ptr
+= bytes_read
;
14073 /* We don't recognize any vendor extensions. */
14077 } while (macinfo_type
!= 0);
14080 /* Check if the attribute's form is a DW_FORM_block*
14081 if so return true else false. */
14083 attr_form_is_block (struct attribute
*attr
)
14085 return (attr
== NULL
? 0 :
14086 attr
->form
== DW_FORM_block1
14087 || attr
->form
== DW_FORM_block2
14088 || attr
->form
== DW_FORM_block4
14089 || attr
->form
== DW_FORM_block
14090 || attr
->form
== DW_FORM_exprloc
);
14093 /* Return non-zero if ATTR's value is a section offset --- classes
14094 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14095 You may use DW_UNSND (attr) to retrieve such offsets.
14097 Section 7.5.4, "Attribute Encodings", explains that no attribute
14098 may have a value that belongs to more than one of these classes; it
14099 would be ambiguous if we did, because we use the same forms for all
14102 attr_form_is_section_offset (struct attribute
*attr
)
14104 return (attr
->form
== DW_FORM_data4
14105 || attr
->form
== DW_FORM_data8
14106 || attr
->form
== DW_FORM_sec_offset
);
14110 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14111 zero otherwise. When this function returns true, you can apply
14112 dwarf2_get_attr_constant_value to it.
14114 However, note that for some attributes you must check
14115 attr_form_is_section_offset before using this test. DW_FORM_data4
14116 and DW_FORM_data8 are members of both the constant class, and of
14117 the classes that contain offsets into other debug sections
14118 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14119 that, if an attribute's can be either a constant or one of the
14120 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14121 taken as section offsets, not constants. */
14123 attr_form_is_constant (struct attribute
*attr
)
14125 switch (attr
->form
)
14127 case DW_FORM_sdata
:
14128 case DW_FORM_udata
:
14129 case DW_FORM_data1
:
14130 case DW_FORM_data2
:
14131 case DW_FORM_data4
:
14132 case DW_FORM_data8
:
14139 /* A helper function that fills in a dwarf2_loclist_baton. */
14142 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14143 struct dwarf2_loclist_baton
*baton
,
14144 struct attribute
*attr
)
14146 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14147 &dwarf2_per_objfile
->loc
);
14149 baton
->per_cu
= cu
->per_cu
;
14150 gdb_assert (baton
->per_cu
);
14151 /* We don't know how long the location list is, but make sure we
14152 don't run off the edge of the section. */
14153 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14154 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14155 baton
->base_address
= cu
->base_address
;
14159 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14160 struct dwarf2_cu
*cu
)
14162 if (attr_form_is_section_offset (attr
)
14163 /* ".debug_loc" may not exist at all, or the offset may be outside
14164 the section. If so, fall through to the complaint in the
14166 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
14168 struct dwarf2_loclist_baton
*baton
;
14170 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14171 sizeof (struct dwarf2_loclist_baton
));
14173 fill_in_loclist_baton (cu
, baton
, attr
);
14175 if (cu
->base_known
== 0)
14176 complaint (&symfile_complaints
,
14177 _("Location list used without specifying the CU base address."));
14179 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14180 SYMBOL_LOCATION_BATON (sym
) = baton
;
14184 struct dwarf2_locexpr_baton
*baton
;
14186 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14187 sizeof (struct dwarf2_locexpr_baton
));
14188 baton
->per_cu
= cu
->per_cu
;
14189 gdb_assert (baton
->per_cu
);
14191 if (attr_form_is_block (attr
))
14193 /* Note that we're just copying the block's data pointer
14194 here, not the actual data. We're still pointing into the
14195 info_buffer for SYM's objfile; right now we never release
14196 that buffer, but when we do clean up properly this may
14198 baton
->size
= DW_BLOCK (attr
)->size
;
14199 baton
->data
= DW_BLOCK (attr
)->data
;
14203 dwarf2_invalid_attrib_class_complaint ("location description",
14204 SYMBOL_NATURAL_NAME (sym
));
14206 baton
->data
= NULL
;
14209 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14210 SYMBOL_LOCATION_BATON (sym
) = baton
;
14214 /* Return the OBJFILE associated with the compilation unit CU. If CU
14215 came from a separate debuginfo file, then the master objfile is
14219 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14221 struct objfile
*objfile
= per_cu
->objfile
;
14223 /* Return the master objfile, so that we can report and look up the
14224 correct file containing this variable. */
14225 if (objfile
->separate_debug_objfile_backlink
)
14226 objfile
= objfile
->separate_debug_objfile_backlink
;
14231 /* Return the address size given in the compilation unit header for CU. */
14234 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14237 return per_cu
->cu
->header
.addr_size
;
14240 /* If the CU is not currently read in, we re-read its header. */
14241 struct objfile
*objfile
= per_cu
->objfile
;
14242 struct dwarf2_per_objfile
*per_objfile
14243 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14244 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14245 struct comp_unit_head cu_header
;
14247 memset (&cu_header
, 0, sizeof cu_header
);
14248 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14249 return cu_header
.addr_size
;
14253 /* Return the offset size given in the compilation unit header for CU. */
14256 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14259 return per_cu
->cu
->header
.offset_size
;
14262 /* If the CU is not currently read in, we re-read its header. */
14263 struct objfile
*objfile
= per_cu
->objfile
;
14264 struct dwarf2_per_objfile
*per_objfile
14265 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14266 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14267 struct comp_unit_head cu_header
;
14269 memset (&cu_header
, 0, sizeof cu_header
);
14270 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14271 return cu_header
.offset_size
;
14275 /* Return the text offset of the CU. The returned offset comes from
14276 this CU's objfile. If this objfile came from a separate debuginfo
14277 file, then the offset may be different from the corresponding
14278 offset in the parent objfile. */
14281 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14283 struct objfile
*objfile
= per_cu
->objfile
;
14285 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14288 /* Locate the .debug_info compilation unit from CU's objfile which contains
14289 the DIE at OFFSET. Raises an error on failure. */
14291 static struct dwarf2_per_cu_data
*
14292 dwarf2_find_containing_comp_unit (unsigned int offset
,
14293 struct objfile
*objfile
)
14295 struct dwarf2_per_cu_data
*this_cu
;
14299 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14302 int mid
= low
+ (high
- low
) / 2;
14304 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14309 gdb_assert (low
== high
);
14310 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14313 error (_("Dwarf Error: could not find partial DIE containing "
14314 "offset 0x%lx [in module %s]"),
14315 (long) offset
, bfd_get_filename (objfile
->obfd
));
14317 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14318 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14322 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14323 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14324 && offset
>= this_cu
->offset
+ this_cu
->length
)
14325 error (_("invalid dwarf2 offset %u"), offset
);
14326 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14331 /* Locate the compilation unit from OBJFILE which is located at exactly
14332 OFFSET. Raises an error on failure. */
14334 static struct dwarf2_per_cu_data
*
14335 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14337 struct dwarf2_per_cu_data
*this_cu
;
14339 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14340 if (this_cu
->offset
!= offset
)
14341 error (_("no compilation unit with offset %u."), offset
);
14345 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14348 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14350 memset (cu
, 0, sizeof (*cu
));
14351 cu
->objfile
= objfile
;
14352 obstack_init (&cu
->comp_unit_obstack
);
14355 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14358 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14360 struct attribute
*attr
;
14362 /* Set the language we're debugging. */
14363 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14365 set_cu_language (DW_UNSND (attr
), cu
);
14367 set_cu_language (language_minimal
, cu
);
14370 /* Release one cached compilation unit, CU. We unlink it from the tree
14371 of compilation units, but we don't remove it from the read_in_chain;
14372 the caller is responsible for that.
14373 NOTE: DATA is a void * because this function is also used as a
14374 cleanup routine. */
14377 free_one_comp_unit (void *data
)
14379 struct dwarf2_cu
*cu
= data
;
14381 if (cu
->per_cu
!= NULL
)
14382 cu
->per_cu
->cu
= NULL
;
14385 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14390 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14391 when we're finished with it. We can't free the pointer itself, but be
14392 sure to unlink it from the cache. Also release any associated storage
14393 and perform cache maintenance.
14395 Only used during partial symbol parsing. */
14398 free_stack_comp_unit (void *data
)
14400 struct dwarf2_cu
*cu
= data
;
14402 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14403 cu
->partial_dies
= NULL
;
14405 if (cu
->per_cu
!= NULL
)
14407 /* This compilation unit is on the stack in our caller, so we
14408 should not xfree it. Just unlink it. */
14409 cu
->per_cu
->cu
= NULL
;
14412 /* If we had a per-cu pointer, then we may have other compilation
14413 units loaded, so age them now. */
14414 age_cached_comp_units ();
14418 /* Free all cached compilation units. */
14421 free_cached_comp_units (void *data
)
14423 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14425 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14426 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14427 while (per_cu
!= NULL
)
14429 struct dwarf2_per_cu_data
*next_cu
;
14431 next_cu
= per_cu
->cu
->read_in_chain
;
14433 free_one_comp_unit (per_cu
->cu
);
14434 *last_chain
= next_cu
;
14440 /* Increase the age counter on each cached compilation unit, and free
14441 any that are too old. */
14444 age_cached_comp_units (void)
14446 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14448 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14449 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14450 while (per_cu
!= NULL
)
14452 per_cu
->cu
->last_used
++;
14453 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14454 dwarf2_mark (per_cu
->cu
);
14455 per_cu
= per_cu
->cu
->read_in_chain
;
14458 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14459 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14460 while (per_cu
!= NULL
)
14462 struct dwarf2_per_cu_data
*next_cu
;
14464 next_cu
= per_cu
->cu
->read_in_chain
;
14466 if (!per_cu
->cu
->mark
)
14468 free_one_comp_unit (per_cu
->cu
);
14469 *last_chain
= next_cu
;
14472 last_chain
= &per_cu
->cu
->read_in_chain
;
14478 /* Remove a single compilation unit from the cache. */
14481 free_one_cached_comp_unit (void *target_cu
)
14483 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14485 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14486 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14487 while (per_cu
!= NULL
)
14489 struct dwarf2_per_cu_data
*next_cu
;
14491 next_cu
= per_cu
->cu
->read_in_chain
;
14493 if (per_cu
->cu
== target_cu
)
14495 free_one_comp_unit (per_cu
->cu
);
14496 *last_chain
= next_cu
;
14500 last_chain
= &per_cu
->cu
->read_in_chain
;
14506 /* Release all extra memory associated with OBJFILE. */
14509 dwarf2_free_objfile (struct objfile
*objfile
)
14511 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14513 if (dwarf2_per_objfile
== NULL
)
14516 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14517 free_cached_comp_units (NULL
);
14519 if (dwarf2_per_objfile
->using_index
)
14523 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14526 struct dwarf2_per_cu_data
*per_cu
=
14527 dwarf2_per_objfile
->all_comp_units
[i
];
14529 if (!per_cu
->v
.quick
->lines
)
14532 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
14534 if (per_cu
->v
.quick
->file_names
)
14535 xfree ((void *) per_cu
->v
.quick
->file_names
[j
]);
14536 if (per_cu
->v
.quick
->full_names
)
14537 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
14540 free_line_header (per_cu
->v
.quick
->lines
);
14544 /* Everything else should be on the objfile obstack. */
14547 /* A pair of DIE offset and GDB type pointer. We store these
14548 in a hash table separate from the DIEs, and preserve them
14549 when the DIEs are flushed out of cache. */
14551 struct dwarf2_offset_and_type
14553 unsigned int offset
;
14557 /* Hash function for a dwarf2_offset_and_type. */
14560 offset_and_type_hash (const void *item
)
14562 const struct dwarf2_offset_and_type
*ofs
= item
;
14564 return ofs
->offset
;
14567 /* Equality function for a dwarf2_offset_and_type. */
14570 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14572 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14573 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14575 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14578 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14579 table if necessary. For convenience, return TYPE.
14581 The DIEs reading must have careful ordering to:
14582 * Not cause infite loops trying to read in DIEs as a prerequisite for
14583 reading current DIE.
14584 * Not trying to dereference contents of still incompletely read in types
14585 while reading in other DIEs.
14586 * Enable referencing still incompletely read in types just by a pointer to
14587 the type without accessing its fields.
14589 Therefore caller should follow these rules:
14590 * Try to fetch any prerequisite types we may need to build this DIE type
14591 before building the type and calling set_die_type.
14592 * After building type call set_die_type for current DIE as soon as
14593 possible before fetching more types to complete the current type.
14594 * Make the type as complete as possible before fetching more types. */
14596 static struct type
*
14597 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14599 struct dwarf2_offset_and_type
**slot
, ofs
;
14600 struct objfile
*objfile
= cu
->objfile
;
14601 htab_t
*type_hash_ptr
;
14603 /* For Ada types, make sure that the gnat-specific data is always
14604 initialized (if not already set). There are a few types where
14605 we should not be doing so, because the type-specific area is
14606 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14607 where the type-specific area is used to store the floatformat).
14608 But this is not a problem, because the gnat-specific information
14609 is actually not needed for these types. */
14610 if (need_gnat_info (cu
)
14611 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14612 && TYPE_CODE (type
) != TYPE_CODE_FLT
14613 && !HAVE_GNAT_AUX_INFO (type
))
14614 INIT_GNAT_SPECIFIC (type
);
14616 if (cu
->per_cu
->from_debug_types
)
14617 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14619 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14621 if (*type_hash_ptr
== NULL
)
14624 = htab_create_alloc_ex (127,
14625 offset_and_type_hash
,
14626 offset_and_type_eq
,
14628 &objfile
->objfile_obstack
,
14629 hashtab_obstack_allocate
,
14630 dummy_obstack_deallocate
);
14633 ofs
.offset
= die
->offset
;
14635 slot
= (struct dwarf2_offset_and_type
**)
14636 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14638 complaint (&symfile_complaints
,
14639 _("A problem internal to GDB: DIE 0x%x has type already set"),
14641 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14646 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14647 table, or return NULL if the die does not have a saved type. */
14649 static struct type
*
14650 get_die_type_at_offset (unsigned int offset
,
14651 struct dwarf2_per_cu_data
*per_cu
)
14653 struct dwarf2_offset_and_type
*slot
, ofs
;
14656 if (per_cu
->from_debug_types
)
14657 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14659 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14660 if (type_hash
== NULL
)
14663 ofs
.offset
= offset
;
14664 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14671 /* Look up the type for DIE in the appropriate type_hash table,
14672 or return NULL if DIE does not have a saved type. */
14674 static struct type
*
14675 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14677 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14680 /* Add a dependence relationship from CU to REF_PER_CU. */
14683 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14684 struct dwarf2_per_cu_data
*ref_per_cu
)
14688 if (cu
->dependencies
== NULL
)
14690 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14691 NULL
, &cu
->comp_unit_obstack
,
14692 hashtab_obstack_allocate
,
14693 dummy_obstack_deallocate
);
14695 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14697 *slot
= ref_per_cu
;
14700 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14701 Set the mark field in every compilation unit in the
14702 cache that we must keep because we are keeping CU. */
14705 dwarf2_mark_helper (void **slot
, void *data
)
14707 struct dwarf2_per_cu_data
*per_cu
;
14709 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14710 if (per_cu
->cu
->mark
)
14712 per_cu
->cu
->mark
= 1;
14714 if (per_cu
->cu
->dependencies
!= NULL
)
14715 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14720 /* Set the mark field in CU and in every other compilation unit in the
14721 cache that we must keep because we are keeping CU. */
14724 dwarf2_mark (struct dwarf2_cu
*cu
)
14729 if (cu
->dependencies
!= NULL
)
14730 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14734 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14738 per_cu
->cu
->mark
= 0;
14739 per_cu
= per_cu
->cu
->read_in_chain
;
14743 /* Trivial hash function for partial_die_info: the hash value of a DIE
14744 is its offset in .debug_info for this objfile. */
14747 partial_die_hash (const void *item
)
14749 const struct partial_die_info
*part_die
= item
;
14751 return part_die
->offset
;
14754 /* Trivial comparison function for partial_die_info structures: two DIEs
14755 are equal if they have the same offset. */
14758 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14760 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14761 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14763 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14766 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14767 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14770 set_dwarf2_cmd (char *args
, int from_tty
)
14772 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14776 show_dwarf2_cmd (char *args
, int from_tty
)
14778 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14781 /* If section described by INFO was mmapped, munmap it now. */
14784 munmap_section_buffer (struct dwarf2_section_info
*info
)
14786 if (info
->was_mmapped
)
14789 intptr_t begin
= (intptr_t) info
->buffer
;
14790 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14791 size_t map_length
= info
->size
+ begin
- map_begin
;
14793 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14795 /* Without HAVE_MMAP, we should never be here to begin with. */
14796 gdb_assert_not_reached ("no mmap support");
14801 /* munmap debug sections for OBJFILE, if necessary. */
14804 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14806 struct dwarf2_per_objfile
*data
= d
;
14808 /* This is sorted according to the order they're defined in to make it easier
14809 to keep in sync. */
14810 munmap_section_buffer (&data
->info
);
14811 munmap_section_buffer (&data
->abbrev
);
14812 munmap_section_buffer (&data
->line
);
14813 munmap_section_buffer (&data
->loc
);
14814 munmap_section_buffer (&data
->macinfo
);
14815 munmap_section_buffer (&data
->str
);
14816 munmap_section_buffer (&data
->ranges
);
14817 munmap_section_buffer (&data
->types
);
14818 munmap_section_buffer (&data
->frame
);
14819 munmap_section_buffer (&data
->eh_frame
);
14820 munmap_section_buffer (&data
->gdb_index
);
14825 /* The contents of the hash table we create when building the string
14827 struct strtab_entry
14829 offset_type offset
;
14833 /* Hash function for a strtab_entry. */
14836 hash_strtab_entry (const void *e
)
14838 const struct strtab_entry
*entry
= e
;
14839 return mapped_index_string_hash (entry
->str
);
14842 /* Equality function for a strtab_entry. */
14845 eq_strtab_entry (const void *a
, const void *b
)
14847 const struct strtab_entry
*ea
= a
;
14848 const struct strtab_entry
*eb
= b
;
14849 return !strcmp (ea
->str
, eb
->str
);
14852 /* Create a strtab_entry hash table. */
14855 create_strtab (void)
14857 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14858 xfree
, xcalloc
, xfree
);
14861 /* Add a string to the constant pool. Return the string's offset in
14865 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14868 struct strtab_entry entry
;
14869 struct strtab_entry
*result
;
14872 slot
= htab_find_slot (table
, &entry
, INSERT
);
14877 result
= XNEW (struct strtab_entry
);
14878 result
->offset
= obstack_object_size (cpool
);
14880 obstack_grow_str0 (cpool
, str
);
14883 return result
->offset
;
14886 /* An entry in the symbol table. */
14887 struct symtab_index_entry
14889 /* The name of the symbol. */
14891 /* The offset of the name in the constant pool. */
14892 offset_type index_offset
;
14893 /* A sorted vector of the indices of all the CUs that hold an object
14895 VEC (offset_type
) *cu_indices
;
14898 /* The symbol table. This is a power-of-2-sized hash table. */
14899 struct mapped_symtab
14901 offset_type n_elements
;
14903 struct symtab_index_entry
**data
;
14906 /* Hash function for a symtab_index_entry. */
14909 hash_symtab_entry (const void *e
)
14911 const struct symtab_index_entry
*entry
= e
;
14912 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14913 sizeof (offset_type
) * VEC_length (offset_type
,
14914 entry
->cu_indices
),
14918 /* Equality function for a symtab_index_entry. */
14921 eq_symtab_entry (const void *a
, const void *b
)
14923 const struct symtab_index_entry
*ea
= a
;
14924 const struct symtab_index_entry
*eb
= b
;
14925 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14926 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14928 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14929 VEC_address (offset_type
, eb
->cu_indices
),
14930 sizeof (offset_type
) * len
);
14933 /* Destroy a symtab_index_entry. */
14936 delete_symtab_entry (void *p
)
14938 struct symtab_index_entry
*entry
= p
;
14939 VEC_free (offset_type
, entry
->cu_indices
);
14943 /* Create a hash table holding symtab_index_entry objects. */
14946 create_symbol_hash_table (void)
14948 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14949 delete_symtab_entry
, xcalloc
, xfree
);
14952 /* Create a new mapped symtab object. */
14954 static struct mapped_symtab
*
14955 create_mapped_symtab (void)
14957 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14958 symtab
->n_elements
= 0;
14959 symtab
->size
= 1024;
14960 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14964 /* Destroy a mapped_symtab. */
14967 cleanup_mapped_symtab (void *p
)
14969 struct mapped_symtab
*symtab
= p
;
14970 /* The contents of the array are freed when the other hash table is
14972 xfree (symtab
->data
);
14976 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14979 static struct symtab_index_entry
**
14980 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14982 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14984 index
= hash
& (symtab
->size
- 1);
14985 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14989 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14990 return &symtab
->data
[index
];
14991 index
= (index
+ step
) & (symtab
->size
- 1);
14995 /* Expand SYMTAB's hash table. */
14998 hash_expand (struct mapped_symtab
*symtab
)
15000 offset_type old_size
= symtab
->size
;
15002 struct symtab_index_entry
**old_entries
= symtab
->data
;
15005 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15007 for (i
= 0; i
< old_size
; ++i
)
15009 if (old_entries
[i
])
15011 struct symtab_index_entry
**slot
= find_slot (symtab
,
15012 old_entries
[i
]->name
);
15013 *slot
= old_entries
[i
];
15017 xfree (old_entries
);
15020 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15021 is the index of the CU in which the symbol appears. */
15024 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15025 offset_type cu_index
)
15027 struct symtab_index_entry
**slot
;
15029 ++symtab
->n_elements
;
15030 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15031 hash_expand (symtab
);
15033 slot
= find_slot (symtab
, name
);
15036 *slot
= XNEW (struct symtab_index_entry
);
15037 (*slot
)->name
= name
;
15038 (*slot
)->cu_indices
= NULL
;
15040 /* Don't push an index twice. Due to how we add entries we only
15041 have to check the last one. */
15042 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15043 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15044 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15047 /* Add a vector of indices to the constant pool. */
15050 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15051 struct symtab_index_entry
*entry
)
15055 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15058 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15059 offset_type val
= MAYBE_SWAP (len
);
15064 entry
->index_offset
= obstack_object_size (cpool
);
15066 obstack_grow (cpool
, &val
, sizeof (val
));
15068 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15071 val
= MAYBE_SWAP (iter
);
15072 obstack_grow (cpool
, &val
, sizeof (val
));
15077 struct symtab_index_entry
*old_entry
= *slot
;
15078 entry
->index_offset
= old_entry
->index_offset
;
15081 return entry
->index_offset
;
15084 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15085 constant pool entries going into the obstack CPOOL. */
15088 write_hash_table (struct mapped_symtab
*symtab
,
15089 struct obstack
*output
, struct obstack
*cpool
)
15092 htab_t symbol_hash_table
;
15095 symbol_hash_table
= create_symbol_hash_table ();
15096 str_table
= create_strtab ();
15098 /* We add all the index vectors to the constant pool first, to
15099 ensure alignment is ok. */
15100 for (i
= 0; i
< symtab
->size
; ++i
)
15102 if (symtab
->data
[i
])
15103 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15106 /* Now write out the hash table. */
15107 for (i
= 0; i
< symtab
->size
; ++i
)
15109 offset_type str_off
, vec_off
;
15111 if (symtab
->data
[i
])
15113 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15114 vec_off
= symtab
->data
[i
]->index_offset
;
15118 /* While 0 is a valid constant pool index, it is not valid
15119 to have 0 for both offsets. */
15124 str_off
= MAYBE_SWAP (str_off
);
15125 vec_off
= MAYBE_SWAP (vec_off
);
15127 obstack_grow (output
, &str_off
, sizeof (str_off
));
15128 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15131 htab_delete (str_table
);
15132 htab_delete (symbol_hash_table
);
15135 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
15136 from PST; CU_INDEX is the index of the CU in the vector of all
15140 add_address_entry (struct objfile
*objfile
,
15141 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
15142 unsigned int cu_index
)
15144 offset_type offset
;
15146 CORE_ADDR baseaddr
;
15148 /* Don't bother recording empty ranges. */
15149 if (pst
->textlow
== pst
->texthigh
)
15152 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15154 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
15155 obstack_grow (addr_obstack
, addr
, 8);
15156 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
15157 obstack_grow (addr_obstack
, addr
, 8);
15158 offset
= MAYBE_SWAP (cu_index
);
15159 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
15162 /* Add a list of partial symbols to SYMTAB. */
15165 write_psymbols (struct mapped_symtab
*symtab
,
15167 struct partial_symbol
**psymp
,
15169 offset_type cu_index
,
15172 for (; count
-- > 0; ++psymp
)
15174 void **slot
, *lookup
;
15176 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15177 error (_("Ada is not currently supported by the index"));
15179 /* We only want to add a given psymbol once. However, we also
15180 want to account for whether it is global or static. So, we
15181 may add it twice, using slightly different values. */
15184 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15186 lookup
= (void *) val
;
15191 /* Only add a given psymbol once. */
15192 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15196 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15201 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15202 exception if there is an error. */
15205 write_obstack (FILE *file
, struct obstack
*obstack
)
15207 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15209 != obstack_object_size (obstack
))
15210 error (_("couldn't data write to file"));
15213 /* Unlink a file if the argument is not NULL. */
15216 unlink_if_set (void *p
)
15218 char **filename
= p
;
15220 unlink (*filename
);
15223 /* A helper struct used when iterating over debug_types. */
15224 struct signatured_type_index_data
15226 struct objfile
*objfile
;
15227 struct mapped_symtab
*symtab
;
15228 struct obstack
*types_list
;
15233 /* A helper function that writes a single signatured_type to an
15237 write_one_signatured_type (void **slot
, void *d
)
15239 struct signatured_type_index_data
*info
= d
;
15240 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15241 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15242 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15245 write_psymbols (info
->symtab
,
15247 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15248 psymtab
->n_global_syms
, info
->cu_index
,
15250 write_psymbols (info
->symtab
,
15252 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15253 psymtab
->n_static_syms
, info
->cu_index
,
15256 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15257 obstack_grow (info
->types_list
, val
, 8);
15258 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15259 obstack_grow (info
->types_list
, val
, 8);
15260 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15261 obstack_grow (info
->types_list
, val
, 8);
15268 /* A cleanup function for an htab_t. */
15271 cleanup_htab (void *arg
)
15276 /* Create an index file for OBJFILE in the directory DIR. */
15279 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15281 struct cleanup
*cleanup
;
15282 char *filename
, *cleanup_filename
;
15283 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15284 struct obstack cu_list
, types_cu_list
;
15287 struct mapped_symtab
*symtab
;
15288 offset_type val
, size_of_contents
, total_len
;
15293 if (!objfile
->psymtabs
)
15295 if (dwarf2_per_objfile
->using_index
)
15296 error (_("Cannot use an index to create the index"));
15298 if (stat (objfile
->name
, &st
) < 0)
15299 perror_with_name (_("Could not stat"));
15301 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15302 INDEX_SUFFIX
, (char *) NULL
);
15303 cleanup
= make_cleanup (xfree
, filename
);
15305 out_file
= fopen (filename
, "wb");
15307 error (_("Can't open `%s' for writing"), filename
);
15309 cleanup_filename
= filename
;
15310 make_cleanup (unlink_if_set
, &cleanup_filename
);
15312 symtab
= create_mapped_symtab ();
15313 make_cleanup (cleanup_mapped_symtab
, symtab
);
15315 obstack_init (&addr_obstack
);
15316 make_cleanup_obstack_free (&addr_obstack
);
15318 obstack_init (&cu_list
);
15319 make_cleanup_obstack_free (&cu_list
);
15321 obstack_init (&types_cu_list
);
15322 make_cleanup_obstack_free (&types_cu_list
);
15324 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15325 NULL
, xcalloc
, xfree
);
15326 make_cleanup (cleanup_htab
, psyms_seen
);
15328 /* The list is already sorted, so we don't need to do additional
15329 work here. Also, the debug_types entries do not appear in
15330 all_comp_units, but only in their own hash table. */
15331 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15333 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15334 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15337 write_psymbols (symtab
,
15339 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15340 psymtab
->n_global_syms
, i
,
15342 write_psymbols (symtab
,
15344 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15345 psymtab
->n_static_syms
, i
,
15348 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
15350 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15351 obstack_grow (&cu_list
, val
, 8);
15352 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15353 obstack_grow (&cu_list
, val
, 8);
15356 /* Write out the .debug_type entries, if any. */
15357 if (dwarf2_per_objfile
->signatured_types
)
15359 struct signatured_type_index_data sig_data
;
15361 sig_data
.objfile
= objfile
;
15362 sig_data
.symtab
= symtab
;
15363 sig_data
.types_list
= &types_cu_list
;
15364 sig_data
.psyms_seen
= psyms_seen
;
15365 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15366 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15367 write_one_signatured_type
, &sig_data
);
15370 obstack_init (&constant_pool
);
15371 make_cleanup_obstack_free (&constant_pool
);
15372 obstack_init (&symtab_obstack
);
15373 make_cleanup_obstack_free (&symtab_obstack
);
15374 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15376 obstack_init (&contents
);
15377 make_cleanup_obstack_free (&contents
);
15378 size_of_contents
= 6 * sizeof (offset_type
);
15379 total_len
= size_of_contents
;
15381 /* The version number. */
15382 val
= MAYBE_SWAP (3);
15383 obstack_grow (&contents
, &val
, sizeof (val
));
15385 /* The offset of the CU list from the start of the file. */
15386 val
= MAYBE_SWAP (total_len
);
15387 obstack_grow (&contents
, &val
, sizeof (val
));
15388 total_len
+= obstack_object_size (&cu_list
);
15390 /* The offset of the types CU list from the start of the file. */
15391 val
= MAYBE_SWAP (total_len
);
15392 obstack_grow (&contents
, &val
, sizeof (val
));
15393 total_len
+= obstack_object_size (&types_cu_list
);
15395 /* The offset of the address table from the start of the file. */
15396 val
= MAYBE_SWAP (total_len
);
15397 obstack_grow (&contents
, &val
, sizeof (val
));
15398 total_len
+= obstack_object_size (&addr_obstack
);
15400 /* The offset of the symbol table from the start of the file. */
15401 val
= MAYBE_SWAP (total_len
);
15402 obstack_grow (&contents
, &val
, sizeof (val
));
15403 total_len
+= obstack_object_size (&symtab_obstack
);
15405 /* The offset of the constant pool from the start of the file. */
15406 val
= MAYBE_SWAP (total_len
);
15407 obstack_grow (&contents
, &val
, sizeof (val
));
15408 total_len
+= obstack_object_size (&constant_pool
);
15410 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15412 write_obstack (out_file
, &contents
);
15413 write_obstack (out_file
, &cu_list
);
15414 write_obstack (out_file
, &types_cu_list
);
15415 write_obstack (out_file
, &addr_obstack
);
15416 write_obstack (out_file
, &symtab_obstack
);
15417 write_obstack (out_file
, &constant_pool
);
15421 /* We want to keep the file, so we set cleanup_filename to NULL
15422 here. See unlink_if_set. */
15423 cleanup_filename
= NULL
;
15425 do_cleanups (cleanup
);
15428 /* The mapped index file format is designed to be directly mmap()able
15429 on any architecture. In most cases, a datum is represented using a
15430 little-endian 32-bit integer value, called an offset_type. Big
15431 endian machines must byte-swap the values before using them.
15432 Exceptions to this rule are noted. The data is laid out such that
15433 alignment is always respected.
15435 A mapped index consists of several sections.
15437 1. The file header. This is a sequence of values, of offset_type
15438 unless otherwise noted:
15440 [0] The version number, currently 3. Versions 1 and 2 are
15442 [1] The offset, from the start of the file, of the CU list.
15443 [2] The offset, from the start of the file, of the types CU list.
15444 Note that this section can be empty, in which case this offset will
15445 be equal to the next offset.
15446 [3] The offset, from the start of the file, of the address section.
15447 [4] The offset, from the start of the file, of the symbol table.
15448 [5] The offset, from the start of the file, of the constant pool.
15450 2. The CU list. This is a sequence of pairs of 64-bit
15451 little-endian values, sorted by the CU offset. The first element
15452 in each pair is the offset of a CU in the .debug_info section. The
15453 second element in each pair is the length of that CU. References
15454 to a CU elsewhere in the map are done using a CU index, which is
15455 just the 0-based index into this table. Note that if there are
15456 type CUs, then conceptually CUs and type CUs form a single list for
15457 the purposes of CU indices.
15459 3. The types CU list. This is a sequence of triplets of 64-bit
15460 little-endian values. In a triplet, the first value is the CU
15461 offset, the second value is the type offset in the CU, and the
15462 third value is the type signature. The types CU list is not
15465 4. The address section. The address section consists of a sequence
15466 of address entries. Each address entry has three elements.
15467 [0] The low address. This is a 64-bit little-endian value.
15468 [1] The high address. This is a 64-bit little-endian value.
15469 Like DW_AT_high_pc, the value is one byte beyond the end.
15470 [2] The CU index. This is an offset_type value.
15472 5. The symbol table. This is a hash table. The size of the hash
15473 table is always a power of 2. The initial hash and the step are
15474 currently defined by the `find_slot' function.
15476 Each slot in the hash table consists of a pair of offset_type
15477 values. The first value is the offset of the symbol's name in the
15478 constant pool. The second value is the offset of the CU vector in
15481 If both values are 0, then this slot in the hash table is empty.
15482 This is ok because while 0 is a valid constant pool index, it
15483 cannot be a valid index for both a string and a CU vector.
15485 A string in the constant pool is stored as a \0-terminated string,
15488 A CU vector in the constant pool is a sequence of offset_type
15489 values. The first value is the number of CU indices in the vector.
15490 Each subsequent value is the index of a CU in the CU list. This
15491 element in the hash table is used to indicate which CUs define the
15494 6. The constant pool. This is simply a bunch of bytes. It is
15495 organized so that alignment is correct: CU vectors are stored
15496 first, followed by strings. */
15499 save_gdb_index_command (char *arg
, int from_tty
)
15501 struct objfile
*objfile
;
15504 error (_("usage: save gdb-index DIRECTORY"));
15506 ALL_OBJFILES (objfile
)
15510 /* If the objfile does not correspond to an actual file, skip it. */
15511 if (stat (objfile
->name
, &st
) < 0)
15514 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15515 if (dwarf2_per_objfile
)
15517 volatile struct gdb_exception except
;
15519 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15521 write_psymtabs_to_index (objfile
, arg
);
15523 if (except
.reason
< 0)
15524 exception_fprintf (gdb_stderr
, except
,
15525 _("Error while writing index for `%s': "),
15533 int dwarf2_always_disassemble
;
15536 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15537 struct cmd_list_element
*c
, const char *value
)
15539 fprintf_filtered (file
, _("\
15540 Whether to always disassemble DWARF expressions is %s.\n"),
15544 void _initialize_dwarf2_read (void);
15547 _initialize_dwarf2_read (void)
15549 struct cmd_list_element
*c
;
15551 dwarf2_objfile_data_key
15552 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15554 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15555 Set DWARF 2 specific variables.\n\
15556 Configure DWARF 2 variables such as the cache size"),
15557 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15558 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15560 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15561 Show DWARF 2 specific variables\n\
15562 Show DWARF 2 variables such as the cache size"),
15563 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15564 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15566 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15567 &dwarf2_max_cache_age
, _("\
15568 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15569 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15570 A higher limit means that cached compilation units will be stored\n\
15571 in memory longer, and more total memory will be used. Zero disables\n\
15572 caching, which can slow down startup."),
15574 show_dwarf2_max_cache_age
,
15575 &set_dwarf2_cmdlist
,
15576 &show_dwarf2_cmdlist
);
15578 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15579 &dwarf2_always_disassemble
, _("\
15580 Set whether `info address' always disassembles DWARF expressions."), _("\
15581 Show whether `info address' always disassembles DWARF expressions."), _("\
15582 When enabled, DWARF expressions are always printed in an assembly-like\n\
15583 syntax. When disabled, expressions will be printed in a more\n\
15584 conversational style, when possible."),
15586 show_dwarf2_always_disassemble
,
15587 &set_dwarf2_cmdlist
,
15588 &show_dwarf2_cmdlist
);
15590 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15591 Set debugging of the dwarf2 DIE reader."), _("\
15592 Show debugging of the dwarf2 DIE reader."), _("\
15593 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15594 The value is the maximum depth to print."),
15597 &setdebuglist
, &showdebuglist
);
15599 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15601 Save a .gdb-index file.\n\
15602 Usage: save gdb-index DIRECTORY"),
15604 set_cmd_completer (c
, filename_completer
);