1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
127 static int processing_has_namespace_info
;
129 static const struct objfile_data
*dwarf2_objfile_data_key
;
131 struct dwarf2_section_info
137 /* True if we have tried to read this section. */
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type
;
145 DEF_VEC_I (offset_type
);
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
151 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size
;
157 /* The hash table. */
158 const offset_type
*index_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type index_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 struct dwarf2_per_objfile
167 struct dwarf2_section_info info
;
168 struct dwarf2_section_info abbrev
;
169 struct dwarf2_section_info line
;
170 struct dwarf2_section_info loc
;
171 struct dwarf2_section_info macinfo
;
172 struct dwarf2_section_info str
;
173 struct dwarf2_section_info ranges
;
174 struct dwarf2_section_info types
;
175 struct dwarf2_section_info frame
;
176 struct dwarf2_section_info eh_frame
;
177 struct dwarf2_section_info gdb_index
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units
;
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data
**type_comp_units
;
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data
*read_in_chain
;
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types
;
203 /* A flag indicating wether this objfile has a section loaded at a
205 int has_section_at_zero
;
207 /* True if we are using the mapped index. */
208 unsigned char using_index
;
210 /* The mapped index. */
211 struct mapped_index
*index_table
;
213 /* Set during partial symbol reading, to prevent queueing of full
215 int reading_partial_symbols
;
218 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
220 /* names of the debugging sections */
222 /* Note that if the debugging section has been compressed, it might
223 have a name like .zdebug_info. */
225 #define INFO_SECTION "debug_info"
226 #define ABBREV_SECTION "debug_abbrev"
227 #define LINE_SECTION "debug_line"
228 #define LOC_SECTION "debug_loc"
229 #define MACINFO_SECTION "debug_macinfo"
230 #define STR_SECTION "debug_str"
231 #define RANGES_SECTION "debug_ranges"
232 #define TYPES_SECTION "debug_types"
233 #define FRAME_SECTION "debug_frame"
234 #define EH_FRAME_SECTION "eh_frame"
235 #define GDB_INDEX_SECTION "gdb_index"
237 /* local data types */
239 /* We hold several abbreviation tables in memory at the same time. */
240 #ifndef ABBREV_HASH_SIZE
241 #define ABBREV_HASH_SIZE 121
244 /* The data in a compilation unit header, after target2host
245 translation, looks like this. */
246 struct comp_unit_head
250 unsigned char addr_size
;
251 unsigned char signed_addr_p
;
252 unsigned int abbrev_offset
;
254 /* Size of file offsets; either 4 or 8. */
255 unsigned int offset_size
;
257 /* Size of the length field; either 4 or 12. */
258 unsigned int initial_length_size
;
260 /* Offset to the first byte of this compilation unit header in the
261 .debug_info section, for resolving relative reference dies. */
264 /* Offset to first die in this cu from the start of the cu.
265 This will be the first byte following the compilation unit header. */
266 unsigned int first_die_offset
;
269 /* Type used for delaying computation of method physnames.
270 See comments for compute_delayed_physnames. */
271 struct delayed_method_info
273 /* The type to which the method is attached, i.e., its parent class. */
276 /* The index of the method in the type's function fieldlists. */
279 /* The index of the method in the fieldlist. */
282 /* The name of the DIE. */
285 /* The DIE associated with this method. */
286 struct die_info
*die
;
289 typedef struct delayed_method_info delayed_method_info
;
290 DEF_VEC_O (delayed_method_info
);
292 /* Internal state when decoding a particular compilation unit. */
295 /* The objfile containing this compilation unit. */
296 struct objfile
*objfile
;
298 /* The header of the compilation unit. */
299 struct comp_unit_head header
;
301 /* Base address of this compilation unit. */
302 CORE_ADDR base_address
;
304 /* Non-zero if base_address has been set. */
307 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
309 /* The language we are debugging. */
310 enum language language
;
311 const struct language_defn
*language_defn
;
313 const char *producer
;
315 /* The generic symbol table building routines have separate lists for
316 file scope symbols and all all other scopes (local scopes). So
317 we need to select the right one to pass to add_symbol_to_list().
318 We do it by keeping a pointer to the correct list in list_in_scope.
320 FIXME: The original dwarf code just treated the file scope as the
321 first local scope, and all other local scopes as nested local
322 scopes, and worked fine. Check to see if we really need to
323 distinguish these in buildsym.c. */
324 struct pending
**list_in_scope
;
326 /* DWARF abbreviation table associated with this compilation unit. */
327 struct abbrev_info
**dwarf2_abbrevs
;
329 /* Storage for the abbrev table. */
330 struct obstack abbrev_obstack
;
332 /* Hash table holding all the loaded partial DIEs. */
335 /* Storage for things with the same lifetime as this read-in compilation
336 unit, including partial DIEs. */
337 struct obstack comp_unit_obstack
;
339 /* When multiple dwarf2_cu structures are living in memory, this field
340 chains them all together, so that they can be released efficiently.
341 We will probably also want a generation counter so that most-recently-used
342 compilation units are cached... */
343 struct dwarf2_per_cu_data
*read_in_chain
;
345 /* Backchain to our per_cu entry if the tree has been built. */
346 struct dwarf2_per_cu_data
*per_cu
;
348 /* Pointer to the die -> type map. Although it is stored
349 permanently in per_cu, we copy it here to avoid double
353 /* How many compilation units ago was this CU last referenced? */
356 /* A hash table of die offsets for following references. */
359 /* Full DIEs if read in. */
360 struct die_info
*dies
;
362 /* A set of pointers to dwarf2_per_cu_data objects for compilation
363 units referenced by this one. Only set during full symbol processing;
364 partial symbol tables do not have dependencies. */
367 /* Header data from the line table, during full symbol processing. */
368 struct line_header
*line_header
;
370 /* A list of methods which need to have physnames computed
371 after all type information has been read. */
372 VEC (delayed_method_info
) *method_list
;
374 /* Mark used when releasing cached dies. */
375 unsigned int mark
: 1;
377 /* This flag will be set if this compilation unit might include
378 inter-compilation-unit references. */
379 unsigned int has_form_ref_addr
: 1;
381 /* This flag will be set if this compilation unit includes any
382 DW_TAG_namespace DIEs. If we know that there are explicit
383 DIEs for namespaces, we don't need to try to infer them
384 from mangled names. */
385 unsigned int has_namespace_info
: 1;
388 /* When using the index (and thus not using psymtabs), each CU has an
389 object of this type. This is used to hold information needed by
390 the various "quick" methods. */
391 struct dwarf2_per_cu_quick_data
393 /* The line table. This can be NULL if there was no line table. */
394 struct line_header
*lines
;
396 /* The file names from the line table. */
397 const char **file_names
;
398 /* The file names from the line table after being run through
400 const char **full_names
;
402 /* The corresponding symbol table. This is NULL if symbols for this
403 CU have not yet been read. */
404 struct symtab
*symtab
;
406 /* A temporary mark bit used when iterating over all CUs in
407 expand_symtabs_matching. */
408 unsigned int mark
: 1;
410 /* True if we've tried to read the line table. */
411 unsigned int read_lines
: 1;
414 /* Persistent data held for a compilation unit, even when not
415 processing it. We put a pointer to this structure in the
416 read_symtab_private field of the psymtab. If we encounter
417 inter-compilation-unit references, we also maintain a sorted
418 list of all compilation units. */
420 struct dwarf2_per_cu_data
422 /* The start offset and length of this compilation unit. 2**29-1
423 bytes should suffice to store the length of any compilation unit
424 - if it doesn't, GDB will fall over anyway.
425 NOTE: Unlike comp_unit_head.length, this length includes
426 initial_length_size. */
428 unsigned int length
: 29;
430 /* Flag indicating this compilation unit will be read in before
431 any of the current compilation units are processed. */
432 unsigned int queued
: 1;
434 /* This flag will be set if we need to load absolutely all DIEs
435 for this compilation unit, instead of just the ones we think
436 are interesting. It gets set if we look for a DIE in the
437 hash table and don't find it. */
438 unsigned int load_all_dies
: 1;
440 /* Non-zero if this CU is from .debug_types.
441 Otherwise it's from .debug_info. */
442 unsigned int from_debug_types
: 1;
444 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
445 of the CU cache it gets reset to NULL again. */
446 struct dwarf2_cu
*cu
;
448 /* If full symbols for this CU have been read in, then this field
449 holds a map of DIE offsets to types. It isn't always possible
450 to reconstruct this information later, so we have to preserve
454 /* The corresponding objfile. */
455 struct objfile
*objfile
;
457 /* When using partial symbol tables, the 'psymtab' field is active.
458 Otherwise the 'quick' field is active. */
461 /* The partial symbol table associated with this compilation unit,
462 or NULL for partial units (which do not have an associated
464 struct partial_symtab
*psymtab
;
466 /* Data needed by the "quick" functions. */
467 struct dwarf2_per_cu_quick_data
*quick
;
471 /* Entry in the signatured_types hash table. */
473 struct signatured_type
477 /* Offset in .debug_types of the TU (type_unit) for this type. */
480 /* Offset in .debug_types of the type defined by this TU. */
481 unsigned int type_offset
;
483 /* The CU(/TU) of this type. */
484 struct dwarf2_per_cu_data per_cu
;
487 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
488 which are used for both .debug_info and .debug_types dies.
489 All parameters here are unchanging for the life of the call.
490 This struct exists to abstract away the constant parameters of
493 struct die_reader_specs
495 /* The bfd of this objfile. */
498 /* The CU of the DIE we are parsing. */
499 struct dwarf2_cu
*cu
;
501 /* Pointer to start of section buffer.
502 This is either the start of .debug_info or .debug_types. */
503 const gdb_byte
*buffer
;
506 /* The line number information for a compilation unit (found in the
507 .debug_line section) begins with a "statement program header",
508 which contains the following information. */
511 unsigned int total_length
;
512 unsigned short version
;
513 unsigned int header_length
;
514 unsigned char minimum_instruction_length
;
515 unsigned char maximum_ops_per_instruction
;
516 unsigned char default_is_stmt
;
518 unsigned char line_range
;
519 unsigned char opcode_base
;
521 /* standard_opcode_lengths[i] is the number of operands for the
522 standard opcode whose value is i. This means that
523 standard_opcode_lengths[0] is unused, and the last meaningful
524 element is standard_opcode_lengths[opcode_base - 1]. */
525 unsigned char *standard_opcode_lengths
;
527 /* The include_directories table. NOTE! These strings are not
528 allocated with xmalloc; instead, they are pointers into
529 debug_line_buffer. If you try to free them, `free' will get
531 unsigned int num_include_dirs
, include_dirs_size
;
534 /* The file_names table. NOTE! These strings are not allocated
535 with xmalloc; instead, they are pointers into debug_line_buffer.
536 Don't try to free them directly. */
537 unsigned int num_file_names
, file_names_size
;
541 unsigned int dir_index
;
542 unsigned int mod_time
;
544 int included_p
; /* Non-zero if referenced by the Line Number Program. */
545 struct symtab
*symtab
; /* The associated symbol table, if any. */
548 /* The start and end of the statement program following this
549 header. These point into dwarf2_per_objfile->line_buffer. */
550 gdb_byte
*statement_program_start
, *statement_program_end
;
553 /* When we construct a partial symbol table entry we only
554 need this much information. */
555 struct partial_die_info
557 /* Offset of this DIE. */
560 /* DWARF-2 tag for this DIE. */
561 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
563 /* Assorted flags describing the data found in this DIE. */
564 unsigned int has_children
: 1;
565 unsigned int is_external
: 1;
566 unsigned int is_declaration
: 1;
567 unsigned int has_type
: 1;
568 unsigned int has_specification
: 1;
569 unsigned int has_pc_info
: 1;
571 /* Flag set if the SCOPE field of this structure has been
573 unsigned int scope_set
: 1;
575 /* Flag set if the DIE has a byte_size attribute. */
576 unsigned int has_byte_size
: 1;
578 /* Flag set if any of the DIE's children are template arguments. */
579 unsigned int has_template_arguments
: 1;
581 /* The name of this DIE. Normally the value of DW_AT_name, but
582 sometimes a default name for unnamed DIEs. */
585 /* The scope to prepend to our children. This is generally
586 allocated on the comp_unit_obstack, so will disappear
587 when this compilation unit leaves the cache. */
590 /* The location description associated with this DIE, if any. */
591 struct dwarf_block
*locdesc
;
593 /* If HAS_PC_INFO, the PC range associated with this DIE. */
597 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
598 DW_AT_sibling, if any. */
601 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
602 DW_AT_specification (or DW_AT_abstract_origin or
604 unsigned int spec_offset
;
606 /* Pointers to this DIE's parent, first child, and next sibling,
608 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
611 /* This data structure holds the information of an abbrev. */
614 unsigned int number
; /* number identifying abbrev */
615 enum dwarf_tag tag
; /* dwarf tag */
616 unsigned short has_children
; /* boolean */
617 unsigned short num_attrs
; /* number of attributes */
618 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
619 struct abbrev_info
*next
; /* next in chain */
624 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
625 ENUM_BITFIELD(dwarf_form
) form
: 16;
628 /* Attributes have a name and a value */
631 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
632 ENUM_BITFIELD(dwarf_form
) form
: 15;
634 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
635 field should be in u.str (existing only for DW_STRING) but it is kept
636 here for better struct attribute alignment. */
637 unsigned int string_is_canonical
: 1;
642 struct dwarf_block
*blk
;
646 struct signatured_type
*signatured_type
;
651 /* This data structure holds a complete die structure. */
654 /* DWARF-2 tag for this DIE. */
655 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
657 /* Number of attributes */
658 unsigned char num_attrs
;
660 /* True if we're presently building the full type name for the
661 type derived from this DIE. */
662 unsigned char building_fullname
: 1;
667 /* Offset in .debug_info or .debug_types section. */
670 /* The dies in a compilation unit form an n-ary tree. PARENT
671 points to this die's parent; CHILD points to the first child of
672 this node; and all the children of a given node are chained
673 together via their SIBLING fields, terminated by a die whose
675 struct die_info
*child
; /* Its first child, if any. */
676 struct die_info
*sibling
; /* Its next sibling, if any. */
677 struct die_info
*parent
; /* Its parent, if any. */
679 /* An array of attributes, with NUM_ATTRS elements. There may be
680 zero, but it's not common and zero-sized arrays are not
681 sufficiently portable C. */
682 struct attribute attrs
[1];
685 struct function_range
688 CORE_ADDR lowpc
, highpc
;
690 struct function_range
*next
;
693 /* Get at parts of an attribute structure */
695 #define DW_STRING(attr) ((attr)->u.str)
696 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
697 #define DW_UNSND(attr) ((attr)->u.unsnd)
698 #define DW_BLOCK(attr) ((attr)->u.blk)
699 #define DW_SND(attr) ((attr)->u.snd)
700 #define DW_ADDR(attr) ((attr)->u.addr)
701 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
703 /* Blocks are a bunch of untyped bytes. */
710 #ifndef ATTR_ALLOC_CHUNK
711 #define ATTR_ALLOC_CHUNK 4
714 /* Allocate fields for structs, unions and enums in this size. */
715 #ifndef DW_FIELD_ALLOC_CHUNK
716 #define DW_FIELD_ALLOC_CHUNK 4
719 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
720 but this would require a corresponding change in unpack_field_as_long
722 static int bits_per_byte
= 8;
724 /* The routines that read and process dies for a C struct or C++ class
725 pass lists of data member fields and lists of member function fields
726 in an instance of a field_info structure, as defined below. */
729 /* List of data member and baseclasses fields. */
732 struct nextfield
*next
;
737 *fields
, *baseclasses
;
739 /* Number of fields (including baseclasses). */
742 /* Number of baseclasses. */
745 /* Set if the accesibility of one of the fields is not public. */
746 int non_public_fields
;
748 /* Member function fields array, entries are allocated in the order they
749 are encountered in the object file. */
752 struct nextfnfield
*next
;
753 struct fn_field fnfield
;
757 /* Member function fieldlist array, contains name of possibly overloaded
758 member function, number of overloaded member functions and a pointer
759 to the head of the member function field chain. */
764 struct nextfnfield
*head
;
768 /* Number of entries in the fnfieldlists array. */
771 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
772 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
773 struct typedef_field_list
775 struct typedef_field field
;
776 struct typedef_field_list
*next
;
779 unsigned typedef_field_list_count
;
782 /* One item on the queue of compilation units to read in full symbols
784 struct dwarf2_queue_item
786 struct dwarf2_per_cu_data
*per_cu
;
787 struct dwarf2_queue_item
*next
;
790 /* The current queue. */
791 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
793 /* Loaded secondary compilation units are kept in memory until they
794 have not been referenced for the processing of this many
795 compilation units. Set this to zero to disable caching. Cache
796 sizes of up to at least twenty will improve startup time for
797 typical inter-CU-reference binaries, at an obvious memory cost. */
798 static int dwarf2_max_cache_age
= 5;
800 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
801 struct cmd_list_element
*c
, const char *value
)
803 fprintf_filtered (file
, _("\
804 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
809 /* Various complaints about symbol reading that don't abort the process */
812 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
814 complaint (&symfile_complaints
,
815 _("statement list doesn't fit in .debug_line section"));
819 dwarf2_debug_line_missing_file_complaint (void)
821 complaint (&symfile_complaints
,
822 _(".debug_line section has line data without a file"));
826 dwarf2_debug_line_missing_end_sequence_complaint (void)
828 complaint (&symfile_complaints
,
829 _(".debug_line section has line program sequence without an end"));
833 dwarf2_complex_location_expr_complaint (void)
835 complaint (&symfile_complaints
, _("location expression too complex"));
839 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
842 complaint (&symfile_complaints
,
843 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
848 dwarf2_macros_too_long_complaint (void)
850 complaint (&symfile_complaints
,
851 _("macro info runs off end of `.debug_macinfo' section"));
855 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
857 complaint (&symfile_complaints
,
858 _("macro debug info contains a malformed macro definition:\n`%s'"),
863 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
865 complaint (&symfile_complaints
,
866 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
869 /* local function prototypes */
871 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
873 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
876 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
878 struct partial_symtab
*);
880 static void dwarf2_build_psymtabs_hard (struct objfile
*);
882 static void scan_partial_symbols (struct partial_die_info
*,
883 CORE_ADDR
*, CORE_ADDR
*,
884 int, struct dwarf2_cu
*);
886 static void add_partial_symbol (struct partial_die_info
*,
889 static void add_partial_namespace (struct partial_die_info
*pdi
,
890 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
891 int need_pc
, struct dwarf2_cu
*cu
);
893 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
894 CORE_ADDR
*highpc
, int need_pc
,
895 struct dwarf2_cu
*cu
);
897 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
898 struct dwarf2_cu
*cu
);
900 static void add_partial_subprogram (struct partial_die_info
*pdi
,
901 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
902 int need_pc
, struct dwarf2_cu
*cu
);
904 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
905 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
906 bfd
*abfd
, struct dwarf2_cu
*cu
);
908 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
910 static void psymtab_to_symtab_1 (struct partial_symtab
*);
912 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
914 static void dwarf2_free_abbrev_table (void *);
916 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
919 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
922 static struct partial_die_info
*load_partial_dies (bfd
*,
923 gdb_byte
*, gdb_byte
*,
924 int, struct dwarf2_cu
*);
926 static gdb_byte
*read_partial_die (struct partial_die_info
*,
927 struct abbrev_info
*abbrev
,
929 gdb_byte
*, gdb_byte
*,
932 static struct partial_die_info
*find_partial_die (unsigned int,
935 static void fixup_partial_die (struct partial_die_info
*,
938 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
939 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
941 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
942 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
944 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
946 static int read_1_signed_byte (bfd
*, gdb_byte
*);
948 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
950 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
952 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
954 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
957 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
959 static LONGEST read_checked_initial_length_and_offset
960 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
961 unsigned int *, unsigned int *);
963 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
966 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
968 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
970 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
972 static char *read_indirect_string (bfd
*, gdb_byte
*,
973 const struct comp_unit_head
*,
976 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
978 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
980 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
982 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
984 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
987 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
991 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
992 struct dwarf2_cu
*cu
);
994 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
996 static struct die_info
*die_specification (struct die_info
*die
,
997 struct dwarf2_cu
**);
999 static void free_line_header (struct line_header
*lh
);
1001 static void add_file_name (struct line_header
*, char *, unsigned int,
1002 unsigned int, unsigned int);
1004 static struct line_header
*(dwarf_decode_line_header
1005 (unsigned int offset
,
1006 bfd
*abfd
, struct dwarf2_cu
*cu
));
1008 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
1009 struct dwarf2_cu
*, struct partial_symtab
*);
1011 static void dwarf2_start_subfile (char *, char *, char *);
1013 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1014 struct dwarf2_cu
*);
1016 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1017 struct dwarf2_cu
*, struct symbol
*);
1019 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1020 struct dwarf2_cu
*);
1022 static void dwarf2_const_value_attr (struct attribute
*attr
,
1025 struct obstack
*obstack
,
1026 struct dwarf2_cu
*cu
, long *value
,
1028 struct dwarf2_locexpr_baton
**baton
);
1030 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1032 static int need_gnat_info (struct dwarf2_cu
*);
1034 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
1036 static void set_descriptive_type (struct type
*, struct die_info
*,
1037 struct dwarf2_cu
*);
1039 static struct type
*die_containing_type (struct die_info
*,
1040 struct dwarf2_cu
*);
1042 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
1044 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1046 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1048 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1049 const char *suffix
, int physname
,
1050 struct dwarf2_cu
*cu
);
1052 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1054 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1056 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1058 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1060 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1061 struct dwarf2_cu
*, struct partial_symtab
*);
1063 static int dwarf2_get_pc_bounds (struct die_info
*,
1064 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1065 struct partial_symtab
*);
1067 static void get_scope_pc_bounds (struct die_info
*,
1068 CORE_ADDR
*, CORE_ADDR
*,
1069 struct dwarf2_cu
*);
1071 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1072 CORE_ADDR
, struct dwarf2_cu
*);
1074 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1075 struct dwarf2_cu
*);
1077 static void dwarf2_attach_fields_to_type (struct field_info
*,
1078 struct type
*, struct dwarf2_cu
*);
1080 static void dwarf2_add_member_fn (struct field_info
*,
1081 struct die_info
*, struct type
*,
1082 struct dwarf2_cu
*);
1084 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1085 struct type
*, struct dwarf2_cu
*);
1087 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1089 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1091 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1093 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1095 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1097 static struct type
*read_module_type (struct die_info
*die
,
1098 struct dwarf2_cu
*cu
);
1100 static const char *namespace_name (struct die_info
*die
,
1101 int *is_anonymous
, struct dwarf2_cu
*);
1103 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1105 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1107 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1108 struct dwarf2_cu
*);
1110 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1112 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1114 gdb_byte
**new_info_ptr
,
1115 struct die_info
*parent
);
1117 static struct die_info
*read_die_and_children (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_siblings (const struct die_reader_specs
*reader
,
1124 gdb_byte
**new_info_ptr
,
1125 struct die_info
*parent
);
1127 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1128 struct die_info
**, gdb_byte
*,
1131 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1133 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1136 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1138 static const char *dwarf2_full_name (char *name
,
1139 struct die_info
*die
,
1140 struct dwarf2_cu
*cu
);
1142 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1143 struct dwarf2_cu
**);
1145 static char *dwarf_tag_name (unsigned int);
1147 static char *dwarf_attr_name (unsigned int);
1149 static char *dwarf_form_name (unsigned int);
1151 static char *dwarf_bool_name (unsigned int);
1153 static char *dwarf_type_encoding_name (unsigned int);
1156 static char *dwarf_cfi_name (unsigned int);
1159 static struct die_info
*sibling_die (struct die_info
*);
1161 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1163 static void dump_die_for_error (struct die_info
*);
1165 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1168 /*static*/ void dump_die (struct die_info
*, int max_level
);
1170 static void store_in_ref_table (struct die_info
*,
1171 struct dwarf2_cu
*);
1173 static int is_ref_attr (struct attribute
*);
1175 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1177 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1179 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1181 struct dwarf2_cu
**);
1183 static struct die_info
*follow_die_ref (struct die_info
*,
1185 struct dwarf2_cu
**);
1187 static struct die_info
*follow_die_sig (struct die_info
*,
1189 struct dwarf2_cu
**);
1191 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1192 unsigned int offset
);
1194 static void read_signatured_type (struct objfile
*,
1195 struct signatured_type
*type_sig
);
1197 /* memory allocation interface */
1199 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1201 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1203 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1205 static void initialize_cu_func_list (struct dwarf2_cu
*);
1207 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1208 struct dwarf2_cu
*);
1210 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1211 char *, bfd
*, struct dwarf2_cu
*);
1213 static int attr_form_is_block (struct attribute
*);
1215 static int attr_form_is_section_offset (struct attribute
*);
1217 static int attr_form_is_constant (struct attribute
*);
1219 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1221 struct dwarf2_cu
*cu
);
1223 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1224 struct abbrev_info
*abbrev
,
1225 struct dwarf2_cu
*cu
);
1227 static void free_stack_comp_unit (void *);
1229 static hashval_t
partial_die_hash (const void *item
);
1231 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1233 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1234 (unsigned int offset
, struct objfile
*objfile
);
1236 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1237 (unsigned int offset
, struct objfile
*objfile
);
1239 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1241 static void free_one_comp_unit (void *);
1243 static void free_cached_comp_units (void *);
1245 static void age_cached_comp_units (void);
1247 static void free_one_cached_comp_unit (void *);
1249 static struct type
*set_die_type (struct die_info
*, struct type
*,
1250 struct dwarf2_cu
*);
1252 static void create_all_comp_units (struct objfile
*);
1254 static int create_debug_types_hash_table (struct objfile
*objfile
);
1256 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1259 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1261 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1262 struct dwarf2_per_cu_data
*);
1264 static void dwarf2_mark (struct dwarf2_cu
*);
1266 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1268 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1270 static void dwarf2_release_queue (void *dummy
);
1272 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1273 struct objfile
*objfile
);
1275 static void process_queue (struct objfile
*objfile
);
1277 static void find_file_and_directory (struct die_info
*die
,
1278 struct dwarf2_cu
*cu
,
1279 char **name
, char **comp_dir
);
1281 static char *file_full_name (int file
, struct line_header
*lh
,
1282 const char *comp_dir
);
1284 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1287 unsigned int buffer_size
,
1290 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1291 struct dwarf2_cu
*cu
);
1293 static htab_t
allocate_signatured_type_hash_table (struct objfile
*objfile
);
1297 /* Convert VALUE between big- and little-endian. */
1299 byte_swap (offset_type value
)
1303 result
= (value
& 0xff) << 24;
1304 result
|= (value
& 0xff00) << 8;
1305 result
|= (value
& 0xff0000) >> 8;
1306 result
|= (value
& 0xff000000) >> 24;
1310 #define MAYBE_SWAP(V) byte_swap (V)
1313 #define MAYBE_SWAP(V) (V)
1314 #endif /* WORDS_BIGENDIAN */
1316 /* The suffix for an index file. */
1317 #define INDEX_SUFFIX ".gdb-index"
1319 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1320 struct dwarf2_cu
*cu
);
1322 /* Try to locate the sections we need for DWARF 2 debugging
1323 information and return true if we have enough to do something. */
1326 dwarf2_has_info (struct objfile
*objfile
)
1328 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1329 if (!dwarf2_per_objfile
)
1331 /* Initialize per-objfile state. */
1332 struct dwarf2_per_objfile
*data
1333 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1335 memset (data
, 0, sizeof (*data
));
1336 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1337 dwarf2_per_objfile
= data
;
1339 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1340 dwarf2_per_objfile
->objfile
= objfile
;
1342 return (dwarf2_per_objfile
->info
.asection
!= NULL
1343 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1346 /* When loading sections, we can either look for ".<name>", or for
1347 * ".z<name>", which indicates a compressed section. */
1350 section_is_p (const char *section_name
, const char *name
)
1352 return (section_name
[0] == '.'
1353 && (strcmp (section_name
+ 1, name
) == 0
1354 || (section_name
[1] == 'z'
1355 && strcmp (section_name
+ 2, name
) == 0)));
1358 /* This function is mapped across the sections and remembers the
1359 offset and size of each of the debugging sections we are interested
1363 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1365 if (section_is_p (sectp
->name
, INFO_SECTION
))
1367 dwarf2_per_objfile
->info
.asection
= sectp
;
1368 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1370 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1372 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1373 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1375 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1377 dwarf2_per_objfile
->line
.asection
= sectp
;
1378 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1380 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1382 dwarf2_per_objfile
->loc
.asection
= sectp
;
1383 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1385 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1387 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1388 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1390 else if (section_is_p (sectp
->name
, STR_SECTION
))
1392 dwarf2_per_objfile
->str
.asection
= sectp
;
1393 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1395 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1397 dwarf2_per_objfile
->frame
.asection
= sectp
;
1398 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1400 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1402 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1404 if (aflag
& SEC_HAS_CONTENTS
)
1406 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1407 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1410 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1412 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1413 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1415 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1417 dwarf2_per_objfile
->types
.asection
= sectp
;
1418 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1420 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1422 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1423 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1426 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1427 && bfd_section_vma (abfd
, sectp
) == 0)
1428 dwarf2_per_objfile
->has_section_at_zero
= 1;
1431 /* Decompress a section that was compressed using zlib. Store the
1432 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1435 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1436 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1438 bfd
*abfd
= objfile
->obfd
;
1440 error (_("Support for zlib-compressed DWARF data (from '%s') "
1441 "is disabled in this copy of GDB"),
1442 bfd_get_filename (abfd
));
1444 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1445 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1446 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1447 bfd_size_type uncompressed_size
;
1448 gdb_byte
*uncompressed_buffer
;
1451 int header_size
= 12;
1453 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1454 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1455 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1456 bfd_get_filename (abfd
));
1458 /* Read the zlib header. In this case, it should be "ZLIB" followed
1459 by the uncompressed section size, 8 bytes in big-endian order. */
1460 if (compressed_size
< header_size
1461 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1462 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1463 bfd_get_filename (abfd
));
1464 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1465 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1466 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1467 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1468 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1469 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1470 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1471 uncompressed_size
+= compressed_buffer
[11];
1473 /* It is possible the section consists of several compressed
1474 buffers concatenated together, so we uncompress in a loop. */
1478 strm
.avail_in
= compressed_size
- header_size
;
1479 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1480 strm
.avail_out
= uncompressed_size
;
1481 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1483 rc
= inflateInit (&strm
);
1484 while (strm
.avail_in
> 0)
1487 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1488 bfd_get_filename (abfd
), rc
);
1489 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1490 + (uncompressed_size
- strm
.avail_out
));
1491 rc
= inflate (&strm
, Z_FINISH
);
1492 if (rc
!= Z_STREAM_END
)
1493 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1494 bfd_get_filename (abfd
), rc
);
1495 rc
= inflateReset (&strm
);
1497 rc
= inflateEnd (&strm
);
1499 || strm
.avail_out
!= 0)
1500 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1501 bfd_get_filename (abfd
), rc
);
1503 do_cleanups (cleanup
);
1504 *outbuf
= uncompressed_buffer
;
1505 *outsize
= uncompressed_size
;
1509 /* Read the contents of the section SECTP from object file specified by
1510 OBJFILE, store info about the section into INFO.
1511 If the section is compressed, uncompress it before returning. */
1514 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1516 bfd
*abfd
= objfile
->obfd
;
1517 asection
*sectp
= info
->asection
;
1518 gdb_byte
*buf
, *retbuf
;
1519 unsigned char header
[4];
1523 info
->buffer
= NULL
;
1524 info
->was_mmapped
= 0;
1527 if (info
->asection
== NULL
|| info
->size
== 0)
1530 /* Check if the file has a 4-byte header indicating compression. */
1531 if (info
->size
> sizeof (header
)
1532 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1533 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1535 /* Upon decompression, update the buffer and its size. */
1536 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1538 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1546 pagesize
= getpagesize ();
1548 /* Only try to mmap sections which are large enough: we don't want to
1549 waste space due to fragmentation. Also, only try mmap for sections
1550 without relocations. */
1552 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1554 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1555 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1556 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1557 MAP_PRIVATE
, pg_offset
);
1559 if (retbuf
!= MAP_FAILED
)
1561 info
->was_mmapped
= 1;
1562 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1563 #if HAVE_POSIX_MADVISE
1564 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1571 /* If we get here, we are a normal, not-compressed section. */
1573 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1575 /* When debugging .o files, we may need to apply relocations; see
1576 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1577 We never compress sections in .o files, so we only need to
1578 try this when the section is not compressed. */
1579 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1582 info
->buffer
= retbuf
;
1586 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1587 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1588 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1589 bfd_get_filename (abfd
));
1592 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1596 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1597 asection
**sectp
, gdb_byte
**bufp
,
1598 bfd_size_type
*sizep
)
1600 struct dwarf2_per_objfile
*data
1601 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1602 struct dwarf2_section_info
*info
;
1604 /* We may see an objfile without any DWARF, in which case we just
1613 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1614 info
= &data
->eh_frame
;
1615 else if (section_is_p (section_name
, FRAME_SECTION
))
1616 info
= &data
->frame
;
1618 gdb_assert_not_reached ("unexpected section");
1620 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1621 /* We haven't read this section in yet. Do it now. */
1622 dwarf2_read_section (objfile
, info
);
1624 *sectp
= info
->asection
;
1625 *bufp
= info
->buffer
;
1626 *sizep
= info
->size
;
1631 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1634 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1635 struct dwarf2_per_cu_data
*per_cu
)
1637 struct cleanup
*back_to
;
1639 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1641 queue_comp_unit (per_cu
, objfile
);
1643 if (per_cu
->from_debug_types
)
1644 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1646 load_full_comp_unit (per_cu
, objfile
);
1648 process_queue (objfile
);
1650 /* Age the cache, releasing compilation units that have not
1651 been used recently. */
1652 age_cached_comp_units ();
1654 do_cleanups (back_to
);
1657 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1658 the objfile from which this CU came. Returns the resulting symbol
1660 static struct symtab
*
1661 dw2_instantiate_symtab (struct objfile
*objfile
,
1662 struct dwarf2_per_cu_data
*per_cu
)
1664 if (!per_cu
->v
.quick
->symtab
)
1666 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1667 increment_reading_symtab ();
1668 dw2_do_instantiate_symtab (objfile
, per_cu
);
1669 do_cleanups (back_to
);
1671 return per_cu
->v
.quick
->symtab
;
1674 /* Return the CU given its index. */
1675 static struct dwarf2_per_cu_data
*
1676 dw2_get_cu (int index
)
1678 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1680 index
-= dwarf2_per_objfile
->n_comp_units
;
1681 return dwarf2_per_objfile
->type_comp_units
[index
];
1683 return dwarf2_per_objfile
->all_comp_units
[index
];
1686 /* A helper function that knows how to read a 64-bit value in a way
1687 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1690 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1692 if (sizeof (ULONGEST
) < 8)
1696 /* Ignore the upper 4 bytes if they are all zero. */
1697 for (i
= 0; i
< 4; ++i
)
1698 if (bytes
[i
+ 4] != 0)
1701 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1704 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1708 /* Read the CU list from the mapped index, and use it to create all
1709 the CU objects for this objfile. Return 0 if something went wrong,
1710 1 if everything went ok. */
1712 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1713 offset_type cu_list_elements
)
1717 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1718 dwarf2_per_objfile
->all_comp_units
1719 = obstack_alloc (&objfile
->objfile_obstack
,
1720 dwarf2_per_objfile
->n_comp_units
1721 * sizeof (struct dwarf2_per_cu_data
*));
1723 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1725 struct dwarf2_per_cu_data
*the_cu
;
1726 ULONGEST offset
, length
;
1728 if (!extract_cu_value (cu_list
, &offset
)
1729 || !extract_cu_value (cu_list
+ 8, &length
))
1733 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1734 struct dwarf2_per_cu_data
);
1735 the_cu
->offset
= offset
;
1736 the_cu
->length
= length
;
1737 the_cu
->objfile
= objfile
;
1738 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1739 struct dwarf2_per_cu_quick_data
);
1740 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1746 /* Create the signatured type hash table from the index. */
1748 create_signatured_type_hash_from_index (struct objfile
*objfile
,
1749 const gdb_byte
*bytes
,
1750 offset_type elements
)
1755 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1756 dwarf2_per_objfile
->type_comp_units
1757 = obstack_alloc (&objfile
->objfile_obstack
,
1758 dwarf2_per_objfile
->n_type_comp_units
1759 * sizeof (struct dwarf2_per_cu_data
*));
1761 type_hash
= allocate_signatured_type_hash_table (objfile
);
1763 for (i
= 0; i
< elements
; i
+= 3)
1765 struct signatured_type
*type_sig
;
1766 ULONGEST offset
, type_offset
, signature
;
1769 if (!extract_cu_value (bytes
, &offset
)
1770 || !extract_cu_value (bytes
+ 8, &type_offset
))
1772 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1775 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1776 struct signatured_type
);
1777 type_sig
->signature
= signature
;
1778 type_sig
->offset
= offset
;
1779 type_sig
->type_offset
= type_offset
;
1780 type_sig
->per_cu
.from_debug_types
= 1;
1781 type_sig
->per_cu
.offset
= offset
;
1782 type_sig
->per_cu
.objfile
= objfile
;
1783 type_sig
->per_cu
.v
.quick
1784 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1785 struct dwarf2_per_cu_quick_data
);
1787 slot
= htab_find_slot (type_hash
, type_sig
, INSERT
);
1790 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1793 dwarf2_per_objfile
->signatured_types
= type_hash
;
1798 /* Read the address map data from the mapped index, and use it to
1799 populate the objfile's psymtabs_addrmap. */
1801 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1803 const gdb_byte
*iter
, *end
;
1804 struct obstack temp_obstack
;
1805 struct addrmap
*mutable_map
;
1806 struct cleanup
*cleanup
;
1809 obstack_init (&temp_obstack
);
1810 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1811 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1813 iter
= index
->address_table
;
1814 end
= iter
+ index
->address_table_size
;
1816 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1820 ULONGEST hi
, lo
, cu_index
;
1821 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1823 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1825 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1828 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1829 dw2_get_cu (cu_index
));
1832 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1833 &objfile
->objfile_obstack
);
1834 do_cleanups (cleanup
);
1837 /* The hash function for strings in the mapped index. This is the
1838 same as the hashtab.c hash function, but we keep a separate copy to
1839 maintain control over the implementation. This is necessary
1840 because the hash function is tied to the format of the mapped index
1843 mapped_index_string_hash (const void *p
)
1845 const unsigned char *str
= (const unsigned char *) p
;
1849 while ((c
= *str
++) != 0)
1850 r
= r
* 67 + c
- 113;
1855 /* Find a slot in the mapped index INDEX for the object named NAME.
1856 If NAME is found, set *VEC_OUT to point to the CU vector in the
1857 constant pool and return 1. If NAME cannot be found, return 0. */
1859 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1860 offset_type
**vec_out
)
1862 offset_type hash
= mapped_index_string_hash (name
);
1863 offset_type slot
, step
;
1865 slot
= hash
& (index
->index_table_slots
- 1);
1866 step
= ((hash
* 17) & (index
->index_table_slots
- 1)) | 1;
1870 /* Convert a slot number to an offset into the table. */
1871 offset_type i
= 2 * slot
;
1873 if (index
->index_table
[i
] == 0 && index
->index_table
[i
+ 1] == 0)
1876 str
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[i
]);
1877 if (!strcmp (name
, str
))
1879 *vec_out
= (offset_type
*) (index
->constant_pool
1880 + MAYBE_SWAP (index
->index_table
[i
+ 1]));
1884 slot
= (slot
+ step
) & (index
->index_table_slots
- 1);
1888 /* Read the index file. If everything went ok, initialize the "quick"
1889 elements of all the CUs and return 1. Otherwise, return 0. */
1891 dwarf2_read_index (struct objfile
*objfile
)
1894 struct mapped_index
*map
;
1895 offset_type
*metadata
;
1896 const gdb_byte
*cu_list
;
1897 const gdb_byte
*types_list
= NULL
;
1898 offset_type version
, cu_list_elements
;
1899 offset_type types_list_elements
= 0;
1902 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1903 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1905 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1907 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1908 /* Version check. */
1909 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1912 /* Index version 1 neglected to account for .debug_types. So,
1913 if we see .debug_types, we cannot use this index. */
1914 if (dwarf2_per_objfile
->types
.asection
!= NULL
1915 && dwarf2_per_objfile
->types
.size
!= 0)
1918 else if (version
!= 2)
1921 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1922 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1924 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1927 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1928 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1934 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1935 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1936 - MAYBE_SWAP (metadata
[i
]))
1941 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1942 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1943 - MAYBE_SWAP (metadata
[i
]));
1946 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1947 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1948 - MAYBE_SWAP (metadata
[i
]))
1949 / (2 * sizeof (offset_type
)));
1952 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1954 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1958 && types_list_elements
1959 && !create_signatured_type_hash_from_index (objfile
, types_list
,
1960 types_list_elements
))
1963 create_addrmap_from_index (objfile
, map
);
1965 dwarf2_per_objfile
->index_table
= map
;
1966 dwarf2_per_objfile
->using_index
= 1;
1971 /* A helper for the "quick" functions which sets the global
1972 dwarf2_per_objfile according to OBJFILE. */
1974 dw2_setup (struct objfile
*objfile
)
1976 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1977 gdb_assert (dwarf2_per_objfile
);
1980 /* A helper for the "quick" functions which attempts to read the line
1981 table for THIS_CU. */
1983 dw2_require_line_header (struct objfile
*objfile
,
1984 struct dwarf2_per_cu_data
*this_cu
)
1986 bfd
*abfd
= objfile
->obfd
;
1987 struct line_header
*lh
= NULL
;
1988 struct attribute
*attr
;
1989 struct cleanup
*cleanups
;
1990 struct die_info
*comp_unit_die
;
1991 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
1992 int has_children
, i
;
1993 struct dwarf2_cu cu
;
1994 unsigned int bytes_read
, buffer_size
;
1995 struct die_reader_specs reader_specs
;
1996 char *name
, *comp_dir
;
1998 if (this_cu
->v
.quick
->read_lines
)
2000 this_cu
->v
.quick
->read_lines
= 1;
2002 memset (&cu
, 0, sizeof (cu
));
2003 cu
.objfile
= objfile
;
2004 obstack_init (&cu
.comp_unit_obstack
);
2006 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2008 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2009 buffer_size
= dwarf2_per_objfile
->info
.size
;
2010 buffer
= dwarf2_per_objfile
->info
.buffer
;
2011 info_ptr
= buffer
+ this_cu
->offset
;
2012 beg_of_comp_unit
= info_ptr
;
2014 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2015 buffer
, buffer_size
,
2018 /* Complete the cu_header. */
2019 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2020 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2023 cu
.per_cu
= this_cu
;
2025 dwarf2_read_abbrevs (abfd
, &cu
);
2026 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2028 if (this_cu
->from_debug_types
)
2029 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2030 init_cu_die_reader (&reader_specs
, &cu
);
2031 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2034 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2037 unsigned int line_offset
= DW_UNSND (attr
);
2038 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2042 do_cleanups (cleanups
);
2046 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2048 this_cu
->v
.quick
->lines
= lh
;
2050 this_cu
->v
.quick
->file_names
2051 = obstack_alloc (&objfile
->objfile_obstack
,
2052 lh
->num_file_names
* sizeof (char *));
2053 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2054 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2056 do_cleanups (cleanups
);
2059 /* A helper for the "quick" functions which computes and caches the
2060 real path for a given file name from the line table.
2061 dw2_require_line_header must have been called before this is
2064 dw2_require_full_path (struct objfile
*objfile
,
2065 struct dwarf2_per_cu_data
*cu
,
2068 if (!cu
->v
.quick
->full_names
)
2069 cu
->v
.quick
->full_names
2070 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2071 cu
->v
.quick
->lines
->num_file_names
,
2074 if (!cu
->v
.quick
->full_names
[index
])
2075 cu
->v
.quick
->full_names
[index
]
2076 = gdb_realpath (cu
->v
.quick
->file_names
[index
]);
2078 return cu
->v
.quick
->full_names
[index
];
2081 static struct symtab
*
2082 dw2_find_last_source_symtab (struct objfile
*objfile
)
2085 dw2_setup (objfile
);
2086 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2087 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2091 dw2_forget_cached_source_info (struct objfile
*objfile
)
2095 dw2_setup (objfile
);
2096 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2097 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2099 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2101 if (cu
->v
.quick
->full_names
)
2105 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2106 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
2112 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2113 const char *full_path
, const char *real_path
,
2114 struct symtab
**result
)
2117 int check_basename
= lbasename (name
) == name
;
2118 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2120 dw2_setup (objfile
);
2121 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2122 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2125 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2127 if (cu
->v
.quick
->symtab
)
2130 dw2_require_line_header (objfile
, cu
);
2131 if (!cu
->v
.quick
->lines
)
2134 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2136 const char *this_name
= cu
->v
.quick
->file_names
[j
];
2138 if (FILENAME_CMP (name
, this_name
) == 0)
2140 *result
= dw2_instantiate_symtab (objfile
, cu
);
2144 if (check_basename
&& ! base_cu
2145 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2148 if (full_path
!= NULL
)
2150 const char *this_full_name
= dw2_require_full_path (objfile
,
2154 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2156 *result
= dw2_instantiate_symtab (objfile
, cu
);
2161 if (real_path
!= NULL
)
2163 const char *this_full_name
= dw2_require_full_path (objfile
,
2166 if (this_full_name
!= NULL
)
2168 char *rp
= gdb_realpath (this_full_name
);
2169 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2172 *result
= dw2_instantiate_symtab (objfile
, cu
);
2183 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2190 static struct symtab
*
2191 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2192 const char *name
, domain_enum domain
)
2194 /* We do all the work in the pre_expand_symtabs_matching hook
2199 /* A helper function that expands all symtabs that hold an object
2202 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2204 dw2_setup (objfile
);
2206 if (dwarf2_per_objfile
->index_table
)
2210 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2213 offset_type i
, len
= MAYBE_SWAP (*vec
);
2214 for (i
= 0; i
< len
; ++i
)
2216 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2217 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (cu_index
);
2219 dw2_instantiate_symtab (objfile
, cu
);
2226 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2227 int kind
, const char *name
,
2230 dw2_do_expand_symtabs_matching (objfile
, name
);
2234 dw2_print_stats (struct objfile
*objfile
)
2238 dw2_setup (objfile
);
2240 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2241 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2243 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2245 if (!cu
->v
.quick
->symtab
)
2248 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2252 dw2_dump (struct objfile
*objfile
)
2254 /* Nothing worth printing. */
2258 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2259 struct section_offsets
*delta
)
2261 /* There's nothing to relocate here. */
2265 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2266 const char *func_name
)
2268 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2272 dw2_expand_all_symtabs (struct objfile
*objfile
)
2276 dw2_setup (objfile
);
2278 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2279 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2281 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2283 dw2_instantiate_symtab (objfile
, cu
);
2288 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2289 const char *filename
)
2293 dw2_setup (objfile
);
2294 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2295 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2298 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2300 if (cu
->v
.quick
->symtab
)
2303 dw2_require_line_header (objfile
, cu
);
2304 if (!cu
->v
.quick
->lines
)
2307 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2309 const char *this_name
= cu
->v
.quick
->file_names
[j
];
2310 if (strcmp (this_name
, filename
) == 0)
2312 dw2_instantiate_symtab (objfile
, cu
);
2320 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2322 struct dwarf2_per_cu_data
*cu
;
2325 dw2_setup (objfile
);
2327 if (!dwarf2_per_objfile
->index_table
)
2330 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2334 /* Note that this just looks at the very first one named NAME -- but
2335 actually we are looking for a function. find_main_filename
2336 should be rewritten so that it doesn't require a custom hook. It
2337 could just use the ordinary symbol tables. */
2338 /* vec[0] is the length, which must always be >0. */
2339 cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2341 dw2_require_line_header (objfile
, cu
);
2342 if (!cu
->v
.quick
->lines
)
2345 return cu
->v
.quick
->file_names
[cu
->v
.quick
->lines
->num_file_names
- 1];
2349 dw2_map_ada_symtabs (struct objfile
*objfile
,
2350 int (*wild_match
) (const char *, int, const char *),
2351 int (*is_name_suffix
) (const char *),
2352 void (*callback
) (struct objfile
*,
2353 struct symtab
*, void *),
2354 const char *name
, int global
,
2355 domain_enum
namespace, int wild
,
2358 /* For now, we don't support Ada, so this function can't be
2360 internal_error (__FILE__
, __LINE__
,
2361 _("map_ada_symtabs called via index method"));
2365 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2366 int (*file_matcher
) (const char *, void *),
2367 int (*name_matcher
) (const char *, void *),
2374 dw2_setup (objfile
);
2375 if (!dwarf2_per_objfile
->index_table
)
2378 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2379 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2382 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2384 cu
->v
.quick
->mark
= 0;
2385 if (cu
->v
.quick
->symtab
)
2388 dw2_require_line_header (objfile
, cu
);
2389 if (!cu
->v
.quick
->lines
)
2392 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2394 if (file_matcher (cu
->v
.quick
->file_names
[j
], data
))
2396 cu
->v
.quick
->mark
= 1;
2403 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2406 offset_type idx
= 2 * iter
;
2408 offset_type
*vec
, vec_len
, vec_idx
;
2410 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2411 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2414 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2415 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2417 if (! (*name_matcher
) (name
, data
))
2420 /* The name was matched, now expand corresponding CUs that were
2422 vec
= (offset_type
*) (dwarf2_per_objfile
->index_table
->constant_pool
2423 + dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1]);
2424 vec_len
= MAYBE_SWAP (vec
[0]);
2425 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2427 struct dwarf2_per_cu_data
*cu
;
2429 cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2430 if (cu
->v
.quick
->mark
)
2431 dw2_instantiate_symtab (objfile
, cu
);
2436 static struct symtab
*
2437 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2438 struct minimal_symbol
*msymbol
,
2440 struct obj_section
*section
,
2443 struct dwarf2_per_cu_data
*data
;
2445 dw2_setup (objfile
);
2447 if (!objfile
->psymtabs_addrmap
)
2450 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2454 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2455 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2456 paddress (get_objfile_arch (objfile
), pc
));
2458 return dw2_instantiate_symtab (objfile
, data
);
2462 dw2_map_symbol_names (struct objfile
*objfile
,
2463 void (*fun
) (const char *, void *),
2467 dw2_setup (objfile
);
2469 if (!dwarf2_per_objfile
->index_table
)
2473 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2476 offset_type idx
= 2 * iter
;
2478 offset_type
*vec
, vec_len
, vec_idx
;
2480 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2481 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2484 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2485 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2487 (*fun
) (name
, data
);
2492 dw2_map_symbol_filenames (struct objfile
*objfile
,
2493 void (*fun
) (const char *, const char *, void *),
2498 dw2_setup (objfile
);
2499 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2500 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2503 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2505 if (cu
->v
.quick
->symtab
)
2508 dw2_require_line_header (objfile
, cu
);
2509 if (!cu
->v
.quick
->lines
)
2512 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2514 const char *this_full_name
= dw2_require_full_path (objfile
, cu
, j
);
2515 (*fun
) (cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2521 dw2_has_symbols (struct objfile
*objfile
)
2526 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2529 dw2_find_last_source_symtab
,
2530 dw2_forget_cached_source_info
,
2533 dw2_pre_expand_symtabs_matching
,
2537 dw2_expand_symtabs_for_function
,
2538 dw2_expand_all_symtabs
,
2539 dw2_expand_symtabs_with_filename
,
2540 dw2_find_symbol_file
,
2541 dw2_map_ada_symtabs
,
2542 dw2_expand_symtabs_matching
,
2543 dw2_find_pc_sect_symtab
,
2544 dw2_map_symbol_names
,
2545 dw2_map_symbol_filenames
2548 /* Initialize for reading DWARF for this objfile. Return 0 if this
2549 file will use psymtabs, or 1 if using the GNU index. */
2552 dwarf2_initialize_objfile (struct objfile
*objfile
)
2554 /* If we're about to read full symbols, don't bother with the
2555 indices. In this case we also don't care if some other debug
2556 format is making psymtabs, because they are all about to be
2558 if ((objfile
->flags
& OBJF_READNOW
))
2562 dwarf2_per_objfile
->using_index
= 1;
2563 create_all_comp_units (objfile
);
2564 create_debug_types_hash_table (objfile
);
2566 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2567 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2569 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2571 cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2572 struct dwarf2_per_cu_quick_data
);
2575 /* Return 1 so that gdb sees the "quick" functions. However,
2576 these functions will be no-ops because we will have expanded
2581 if (dwarf2_read_index (objfile
))
2584 dwarf2_build_psymtabs (objfile
);
2590 /* Build a partial symbol table. */
2593 dwarf2_build_psymtabs (struct objfile
*objfile
)
2595 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2597 init_psymbol_list (objfile
, 1024);
2600 dwarf2_build_psymtabs_hard (objfile
);
2603 /* Return TRUE if OFFSET is within CU_HEADER. */
2606 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2608 unsigned int bottom
= cu_header
->offset
;
2609 unsigned int top
= (cu_header
->offset
2611 + cu_header
->initial_length_size
);
2613 return (offset
>= bottom
&& offset
< top
);
2616 /* Read in the comp unit header information from the debug_info at info_ptr.
2617 NOTE: This leaves members offset, first_die_offset to be filled in
2621 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2622 gdb_byte
*info_ptr
, bfd
*abfd
)
2625 unsigned int bytes_read
;
2627 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2628 cu_header
->initial_length_size
= bytes_read
;
2629 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2630 info_ptr
+= bytes_read
;
2631 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2633 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2635 info_ptr
+= bytes_read
;
2636 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2638 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2639 if (signed_addr
< 0)
2640 internal_error (__FILE__
, __LINE__
,
2641 _("read_comp_unit_head: dwarf from non elf file"));
2642 cu_header
->signed_addr_p
= signed_addr
;
2648 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2649 gdb_byte
*buffer
, unsigned int buffer_size
,
2652 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2654 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2656 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2657 error (_("Dwarf Error: wrong version in compilation unit header "
2658 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2659 bfd_get_filename (abfd
));
2661 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2662 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2663 "(offset 0x%lx + 6) [in module %s]"),
2664 (long) header
->abbrev_offset
,
2665 (long) (beg_of_comp_unit
- buffer
),
2666 bfd_get_filename (abfd
));
2668 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2669 > buffer
+ buffer_size
)
2670 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2671 "(offset 0x%lx + 0) [in module %s]"),
2672 (long) header
->length
,
2673 (long) (beg_of_comp_unit
- buffer
),
2674 bfd_get_filename (abfd
));
2679 /* Read in the types comp unit header information from .debug_types entry at
2680 types_ptr. The result is a pointer to one past the end of the header. */
2683 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2684 ULONGEST
*signature
,
2685 gdb_byte
*types_ptr
, bfd
*abfd
)
2687 gdb_byte
*initial_types_ptr
= types_ptr
;
2689 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2690 &dwarf2_per_objfile
->types
);
2691 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2693 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2695 *signature
= read_8_bytes (abfd
, types_ptr
);
2697 types_ptr
+= cu_header
->offset_size
;
2698 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2703 /* Allocate a new partial symtab for file named NAME and mark this new
2704 partial symtab as being an include of PST. */
2707 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2708 struct objfile
*objfile
)
2710 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2712 subpst
->section_offsets
= pst
->section_offsets
;
2713 subpst
->textlow
= 0;
2714 subpst
->texthigh
= 0;
2716 subpst
->dependencies
= (struct partial_symtab
**)
2717 obstack_alloc (&objfile
->objfile_obstack
,
2718 sizeof (struct partial_symtab
*));
2719 subpst
->dependencies
[0] = pst
;
2720 subpst
->number_of_dependencies
= 1;
2722 subpst
->globals_offset
= 0;
2723 subpst
->n_global_syms
= 0;
2724 subpst
->statics_offset
= 0;
2725 subpst
->n_static_syms
= 0;
2726 subpst
->symtab
= NULL
;
2727 subpst
->read_symtab
= pst
->read_symtab
;
2730 /* No private part is necessary for include psymtabs. This property
2731 can be used to differentiate between such include psymtabs and
2732 the regular ones. */
2733 subpst
->read_symtab_private
= NULL
;
2736 /* Read the Line Number Program data and extract the list of files
2737 included by the source file represented by PST. Build an include
2738 partial symtab for each of these included files. */
2741 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2742 struct die_info
*die
,
2743 struct partial_symtab
*pst
)
2745 struct objfile
*objfile
= cu
->objfile
;
2746 bfd
*abfd
= objfile
->obfd
;
2747 struct line_header
*lh
= NULL
;
2748 struct attribute
*attr
;
2750 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2753 unsigned int line_offset
= DW_UNSND (attr
);
2755 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2758 return; /* No linetable, so no includes. */
2760 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
2762 free_line_header (lh
);
2766 hash_type_signature (const void *item
)
2768 const struct signatured_type
*type_sig
= item
;
2770 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2771 return type_sig
->signature
;
2775 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2777 const struct signatured_type
*lhs
= item_lhs
;
2778 const struct signatured_type
*rhs
= item_rhs
;
2780 return lhs
->signature
== rhs
->signature
;
2783 /* Allocate a hash table for signatured types. */
2786 allocate_signatured_type_hash_table (struct objfile
*objfile
)
2788 return htab_create_alloc_ex (41,
2789 hash_type_signature
,
2792 &objfile
->objfile_obstack
,
2793 hashtab_obstack_allocate
,
2794 dummy_obstack_deallocate
);
2797 /* A helper function to add a signatured type CU to a list. */
2800 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2802 struct signatured_type
*sigt
= *slot
;
2803 struct dwarf2_per_cu_data
***datap
= datum
;
2805 **datap
= &sigt
->per_cu
;
2811 /* Create the hash table of all entries in the .debug_types section.
2812 The result is zero if there is an error (e.g. missing .debug_types section),
2813 otherwise non-zero. */
2816 create_debug_types_hash_table (struct objfile
*objfile
)
2820 struct dwarf2_per_cu_data
**iter
;
2822 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2823 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2825 if (info_ptr
== NULL
)
2827 dwarf2_per_objfile
->signatured_types
= NULL
;
2831 types_htab
= allocate_signatured_type_hash_table (objfile
);
2833 if (dwarf2_die_debug
)
2834 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2836 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2838 unsigned int offset
;
2839 unsigned int offset_size
;
2840 unsigned int type_offset
;
2841 unsigned int length
, initial_length_size
;
2842 unsigned short version
;
2844 struct signatured_type
*type_sig
;
2846 gdb_byte
*ptr
= info_ptr
;
2848 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2850 /* We need to read the type's signature in order to build the hash
2851 table, but we don't need to read anything else just yet. */
2853 /* Sanity check to ensure entire cu is present. */
2854 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2855 if (ptr
+ length
+ initial_length_size
2856 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2858 complaint (&symfile_complaints
,
2859 _("debug type entry runs off end of `.debug_types' section, ignored"));
2863 offset_size
= initial_length_size
== 4 ? 4 : 8;
2864 ptr
+= initial_length_size
;
2865 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2867 ptr
+= offset_size
; /* abbrev offset */
2868 ptr
+= 1; /* address size */
2869 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2871 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2873 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2874 memset (type_sig
, 0, sizeof (*type_sig
));
2875 type_sig
->signature
= signature
;
2876 type_sig
->offset
= offset
;
2877 type_sig
->type_offset
= type_offset
;
2878 type_sig
->per_cu
.objfile
= objfile
;
2879 type_sig
->per_cu
.from_debug_types
= 1;
2881 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2882 gdb_assert (slot
!= NULL
);
2885 if (dwarf2_die_debug
)
2886 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2887 offset
, phex (signature
, sizeof (signature
)));
2889 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2892 dwarf2_per_objfile
->signatured_types
= types_htab
;
2894 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2895 dwarf2_per_objfile
->type_comp_units
2896 = obstack_alloc (&objfile
->objfile_obstack
,
2897 dwarf2_per_objfile
->n_type_comp_units
2898 * sizeof (struct dwarf2_per_cu_data
*));
2899 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2900 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2901 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2902 == dwarf2_per_objfile
->n_type_comp_units
);
2907 /* Lookup a signature based type.
2908 Returns NULL if SIG is not present in the table. */
2910 static struct signatured_type
*
2911 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2913 struct signatured_type find_entry
, *entry
;
2915 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2917 complaint (&symfile_complaints
,
2918 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2922 find_entry
.signature
= sig
;
2923 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2927 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2930 init_cu_die_reader (struct die_reader_specs
*reader
,
2931 struct dwarf2_cu
*cu
)
2933 reader
->abfd
= cu
->objfile
->obfd
;
2935 if (cu
->per_cu
->from_debug_types
)
2937 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2938 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2942 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2943 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2947 /* Find the base address of the compilation unit for range lists and
2948 location lists. It will normally be specified by DW_AT_low_pc.
2949 In DWARF-3 draft 4, the base address could be overridden by
2950 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2951 compilation units with discontinuous ranges. */
2954 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2956 struct attribute
*attr
;
2959 cu
->base_address
= 0;
2961 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2964 cu
->base_address
= DW_ADDR (attr
);
2969 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2972 cu
->base_address
= DW_ADDR (attr
);
2978 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2979 to combine the common parts.
2980 Process a compilation unit for a psymtab.
2981 BUFFER is a pointer to the beginning of the dwarf section buffer,
2982 either .debug_info or debug_types.
2983 INFO_PTR is a pointer to the start of the CU.
2984 Returns a pointer to the next CU. */
2987 process_psymtab_comp_unit (struct objfile
*objfile
,
2988 struct dwarf2_per_cu_data
*this_cu
,
2989 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2990 unsigned int buffer_size
)
2992 bfd
*abfd
= objfile
->obfd
;
2993 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2994 struct die_info
*comp_unit_die
;
2995 struct partial_symtab
*pst
;
2997 struct cleanup
*back_to_inner
;
2998 struct dwarf2_cu cu
;
2999 int has_children
, has_pc_info
;
3000 struct attribute
*attr
;
3001 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3002 struct die_reader_specs reader_specs
;
3004 memset (&cu
, 0, sizeof (cu
));
3005 cu
.objfile
= objfile
;
3006 obstack_init (&cu
.comp_unit_obstack
);
3008 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3010 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3011 buffer
, buffer_size
,
3014 /* Complete the cu_header. */
3015 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3016 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3018 cu
.list_in_scope
= &file_symbols
;
3020 /* If this compilation unit was already read in, free the
3021 cached copy in order to read it in again. This is
3022 necessary because we skipped some symbols when we first
3023 read in the compilation unit (see load_partial_dies).
3024 This problem could be avoided, but the benefit is
3026 if (this_cu
->cu
!= NULL
)
3027 free_one_cached_comp_unit (this_cu
->cu
);
3029 /* Note that this is a pointer to our stack frame, being
3030 added to a global data structure. It will be cleaned up
3031 in free_stack_comp_unit when we finish with this
3032 compilation unit. */
3034 cu
.per_cu
= this_cu
;
3036 /* Read the abbrevs for this compilation unit into a table. */
3037 dwarf2_read_abbrevs (abfd
, &cu
);
3038 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3040 /* Read the compilation unit die. */
3041 if (this_cu
->from_debug_types
)
3042 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3043 init_cu_die_reader (&reader_specs
, &cu
);
3044 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3047 if (this_cu
->from_debug_types
)
3049 /* offset,length haven't been set yet for type units. */
3050 this_cu
->offset
= cu
.header
.offset
;
3051 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3053 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3055 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3056 + cu
.header
.initial_length_size
);
3057 do_cleanups (back_to_inner
);
3061 /* Set the language we're debugging. */
3062 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
3064 set_cu_language (DW_UNSND (attr
), &cu
);
3066 set_cu_language (language_minimal
, &cu
);
3068 /* Allocate a new partial symbol table structure. */
3069 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3070 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3071 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3072 /* TEXTLOW and TEXTHIGH are set below. */
3074 objfile
->global_psymbols
.next
,
3075 objfile
->static_psymbols
.next
);
3077 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3079 pst
->dirname
= DW_STRING (attr
);
3081 pst
->read_symtab_private
= this_cu
;
3083 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3085 /* Store the function that reads in the rest of the symbol table */
3086 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3088 this_cu
->v
.psymtab
= pst
;
3090 dwarf2_find_base_address (comp_unit_die
, &cu
);
3092 /* Possibly set the default values of LOWPC and HIGHPC from
3094 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3095 &best_highpc
, &cu
, pst
);
3096 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3097 /* Store the contiguous range if it is not empty; it can be empty for
3098 CUs with no code. */
3099 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3100 best_lowpc
+ baseaddr
,
3101 best_highpc
+ baseaddr
- 1, pst
);
3103 /* Check if comp unit has_children.
3104 If so, read the rest of the partial symbols from this comp unit.
3105 If not, there's no more debug_info for this comp unit. */
3108 struct partial_die_info
*first_die
;
3109 CORE_ADDR lowpc
, highpc
;
3111 lowpc
= ((CORE_ADDR
) -1);
3112 highpc
= ((CORE_ADDR
) 0);
3114 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3116 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3117 ! has_pc_info
, &cu
);
3119 /* If we didn't find a lowpc, set it to highpc to avoid
3120 complaints from `maint check'. */
3121 if (lowpc
== ((CORE_ADDR
) -1))
3124 /* If the compilation unit didn't have an explicit address range,
3125 then use the information extracted from its child dies. */
3129 best_highpc
= highpc
;
3132 pst
->textlow
= best_lowpc
+ baseaddr
;
3133 pst
->texthigh
= best_highpc
+ baseaddr
;
3135 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3136 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3137 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3138 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3139 sort_pst_symbols (pst
);
3141 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3142 + cu
.header
.initial_length_size
);
3144 if (this_cu
->from_debug_types
)
3146 /* It's not clear we want to do anything with stmt lists here.
3147 Waiting to see what gcc ultimately does. */
3151 /* Get the list of files included in the current compilation unit,
3152 and build a psymtab for each of them. */
3153 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3156 do_cleanups (back_to_inner
);
3161 /* Traversal function for htab_traverse_noresize.
3162 Process one .debug_types comp-unit. */
3165 process_type_comp_unit (void **slot
, void *info
)
3167 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3168 struct objfile
*objfile
= (struct objfile
*) info
;
3169 struct dwarf2_per_cu_data
*this_cu
;
3171 this_cu
= &entry
->per_cu
;
3173 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3174 process_psymtab_comp_unit (objfile
, this_cu
,
3175 dwarf2_per_objfile
->types
.buffer
,
3176 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3177 dwarf2_per_objfile
->types
.size
);
3182 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3183 Build partial symbol tables for the .debug_types comp-units. */
3186 build_type_psymtabs (struct objfile
*objfile
)
3188 if (! create_debug_types_hash_table (objfile
))
3191 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3192 process_type_comp_unit
, objfile
);
3195 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3198 psymtabs_addrmap_cleanup (void *o
)
3200 struct objfile
*objfile
= o
;
3202 objfile
->psymtabs_addrmap
= NULL
;
3205 /* Build the partial symbol table by doing a quick pass through the
3206 .debug_info and .debug_abbrev sections. */
3209 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3212 struct cleanup
*back_to
, *addrmap_cleanup
;
3213 struct obstack temp_obstack
;
3215 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3217 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3218 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3220 /* Any cached compilation units will be linked by the per-objfile
3221 read_in_chain. Make sure to free them when we're done. */
3222 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3224 build_type_psymtabs (objfile
);
3226 create_all_comp_units (objfile
);
3228 /* Create a temporary address map on a temporary obstack. We later
3229 copy this to the final obstack. */
3230 obstack_init (&temp_obstack
);
3231 make_cleanup_obstack_free (&temp_obstack
);
3232 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3233 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3235 /* Since the objects we're extracting from .debug_info vary in
3236 length, only the individual functions to extract them (like
3237 read_comp_unit_head and load_partial_die) can really know whether
3238 the buffer is large enough to hold another complete object.
3240 At the moment, they don't actually check that. If .debug_info
3241 holds just one extra byte after the last compilation unit's dies,
3242 then read_comp_unit_head will happily read off the end of the
3243 buffer. read_partial_die is similarly casual. Those functions
3246 For this loop condition, simply checking whether there's any data
3247 left at all should be sufficient. */
3249 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3250 + dwarf2_per_objfile
->info
.size
))
3252 struct dwarf2_per_cu_data
*this_cu
;
3254 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3257 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3258 dwarf2_per_objfile
->info
.buffer
,
3260 dwarf2_per_objfile
->info
.size
);
3263 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3264 &objfile
->objfile_obstack
);
3265 discard_cleanups (addrmap_cleanup
);
3267 do_cleanups (back_to
);
3270 /* Load the partial DIEs for a secondary CU into memory. */
3273 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3274 struct objfile
*objfile
)
3276 bfd
*abfd
= objfile
->obfd
;
3277 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3278 struct die_info
*comp_unit_die
;
3279 struct dwarf2_cu
*cu
;
3280 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3281 struct attribute
*attr
;
3283 struct die_reader_specs reader_specs
;
3286 gdb_assert (! this_cu
->from_debug_types
);
3288 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3289 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3290 beg_of_comp_unit
= info_ptr
;
3292 if (this_cu
->cu
== NULL
)
3294 cu
= alloc_one_comp_unit (objfile
);
3298 /* If an error occurs while loading, release our storage. */
3299 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3301 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3302 dwarf2_per_objfile
->info
.buffer
,
3303 dwarf2_per_objfile
->info
.size
,
3306 /* Complete the cu_header. */
3307 cu
->header
.offset
= this_cu
->offset
;
3308 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3310 /* Link this compilation unit into the compilation unit tree. */
3312 cu
->per_cu
= this_cu
;
3313 cu
->type_hash
= this_cu
->type_hash
;
3315 /* Link this CU into read_in_chain. */
3316 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3317 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3322 info_ptr
+= cu
->header
.first_die_offset
;
3325 /* Read the abbrevs for this compilation unit into a table. */
3326 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3327 dwarf2_read_abbrevs (abfd
, cu
);
3328 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3330 /* Read the compilation unit die. */
3331 init_cu_die_reader (&reader_specs
, cu
);
3332 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3335 /* Set the language we're debugging. */
3336 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3338 set_cu_language (DW_UNSND (attr
), cu
);
3340 set_cu_language (language_minimal
, cu
);
3342 /* Check if comp unit has_children.
3343 If so, read the rest of the partial symbols from this comp unit.
3344 If not, there's no more debug_info for this comp unit. */
3346 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3348 do_cleanups (free_abbrevs_cleanup
);
3352 /* We've successfully allocated this compilation unit. Let our
3353 caller clean it up when finished with it. */
3354 discard_cleanups (free_cu_cleanup
);
3358 /* Create a list of all compilation units in OBJFILE. We do this only
3359 if an inter-comp-unit reference is found; presumably if there is one,
3360 there will be many, and one will occur early in the .debug_info section.
3361 So there's no point in building this list incrementally. */
3364 create_all_comp_units (struct objfile
*objfile
)
3368 struct dwarf2_per_cu_data
**all_comp_units
;
3371 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3372 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3376 all_comp_units
= xmalloc (n_allocated
3377 * sizeof (struct dwarf2_per_cu_data
*));
3379 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3381 unsigned int length
, initial_length_size
;
3382 struct dwarf2_per_cu_data
*this_cu
;
3383 unsigned int offset
;
3385 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3387 /* Read just enough information to find out where the next
3388 compilation unit is. */
3389 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3390 &initial_length_size
);
3392 /* Save the compilation unit for later lookup. */
3393 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3394 sizeof (struct dwarf2_per_cu_data
));
3395 memset (this_cu
, 0, sizeof (*this_cu
));
3396 this_cu
->offset
= offset
;
3397 this_cu
->length
= length
+ initial_length_size
;
3398 this_cu
->objfile
= objfile
;
3400 if (n_comp_units
== n_allocated
)
3403 all_comp_units
= xrealloc (all_comp_units
,
3405 * sizeof (struct dwarf2_per_cu_data
*));
3407 all_comp_units
[n_comp_units
++] = this_cu
;
3409 info_ptr
= info_ptr
+ this_cu
->length
;
3412 dwarf2_per_objfile
->all_comp_units
3413 = obstack_alloc (&objfile
->objfile_obstack
,
3414 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3415 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3416 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3417 xfree (all_comp_units
);
3418 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3421 /* Process all loaded DIEs for compilation unit CU, starting at
3422 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3423 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3424 DW_AT_ranges). If NEED_PC is set, then this function will set
3425 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3426 and record the covered ranges in the addrmap. */
3429 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3430 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3432 struct partial_die_info
*pdi
;
3434 /* Now, march along the PDI's, descending into ones which have
3435 interesting children but skipping the children of the other ones,
3436 until we reach the end of the compilation unit. */
3442 fixup_partial_die (pdi
, cu
);
3444 /* Anonymous namespaces or modules have no name but have interesting
3445 children, so we need to look at them. Ditto for anonymous
3448 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3449 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3453 case DW_TAG_subprogram
:
3454 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3456 case DW_TAG_variable
:
3457 case DW_TAG_typedef
:
3458 case DW_TAG_union_type
:
3459 if (!pdi
->is_declaration
)
3461 add_partial_symbol (pdi
, cu
);
3464 case DW_TAG_class_type
:
3465 case DW_TAG_interface_type
:
3466 case DW_TAG_structure_type
:
3467 if (!pdi
->is_declaration
)
3469 add_partial_symbol (pdi
, cu
);
3472 case DW_TAG_enumeration_type
:
3473 if (!pdi
->is_declaration
)
3474 add_partial_enumeration (pdi
, cu
);
3476 case DW_TAG_base_type
:
3477 case DW_TAG_subrange_type
:
3478 /* File scope base type definitions are added to the partial
3480 add_partial_symbol (pdi
, cu
);
3482 case DW_TAG_namespace
:
3483 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3486 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3493 /* If the die has a sibling, skip to the sibling. */
3495 pdi
= pdi
->die_sibling
;
3499 /* Functions used to compute the fully scoped name of a partial DIE.
3501 Normally, this is simple. For C++, the parent DIE's fully scoped
3502 name is concatenated with "::" and the partial DIE's name. For
3503 Java, the same thing occurs except that "." is used instead of "::".
3504 Enumerators are an exception; they use the scope of their parent
3505 enumeration type, i.e. the name of the enumeration type is not
3506 prepended to the enumerator.
3508 There are two complexities. One is DW_AT_specification; in this
3509 case "parent" means the parent of the target of the specification,
3510 instead of the direct parent of the DIE. The other is compilers
3511 which do not emit DW_TAG_namespace; in this case we try to guess
3512 the fully qualified name of structure types from their members'
3513 linkage names. This must be done using the DIE's children rather
3514 than the children of any DW_AT_specification target. We only need
3515 to do this for structures at the top level, i.e. if the target of
3516 any DW_AT_specification (if any; otherwise the DIE itself) does not
3519 /* Compute the scope prefix associated with PDI's parent, in
3520 compilation unit CU. The result will be allocated on CU's
3521 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3522 field. NULL is returned if no prefix is necessary. */
3524 partial_die_parent_scope (struct partial_die_info
*pdi
,
3525 struct dwarf2_cu
*cu
)
3527 char *grandparent_scope
;
3528 struct partial_die_info
*parent
, *real_pdi
;
3530 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3531 then this means the parent of the specification DIE. */
3534 while (real_pdi
->has_specification
)
3535 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3537 parent
= real_pdi
->die_parent
;
3541 if (parent
->scope_set
)
3542 return parent
->scope
;
3544 fixup_partial_die (parent
, cu
);
3546 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3548 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3549 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3550 Work around this problem here. */
3551 if (cu
->language
== language_cplus
3552 && parent
->tag
== DW_TAG_namespace
3553 && strcmp (parent
->name
, "::") == 0
3554 && grandparent_scope
== NULL
)
3556 parent
->scope
= NULL
;
3557 parent
->scope_set
= 1;
3561 if (parent
->tag
== DW_TAG_namespace
3562 || parent
->tag
== DW_TAG_module
3563 || parent
->tag
== DW_TAG_structure_type
3564 || parent
->tag
== DW_TAG_class_type
3565 || parent
->tag
== DW_TAG_interface_type
3566 || parent
->tag
== DW_TAG_union_type
3567 || parent
->tag
== DW_TAG_enumeration_type
)
3569 if (grandparent_scope
== NULL
)
3570 parent
->scope
= parent
->name
;
3572 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3573 parent
->name
, 0, cu
);
3575 else if (parent
->tag
== DW_TAG_enumerator
)
3576 /* Enumerators should not get the name of the enumeration as a prefix. */
3577 parent
->scope
= grandparent_scope
;
3580 /* FIXME drow/2004-04-01: What should we be doing with
3581 function-local names? For partial symbols, we should probably be
3583 complaint (&symfile_complaints
,
3584 _("unhandled containing DIE tag %d for DIE at %d"),
3585 parent
->tag
, pdi
->offset
);
3586 parent
->scope
= grandparent_scope
;
3589 parent
->scope_set
= 1;
3590 return parent
->scope
;
3593 /* Return the fully scoped name associated with PDI, from compilation unit
3594 CU. The result will be allocated with malloc. */
3596 partial_die_full_name (struct partial_die_info
*pdi
,
3597 struct dwarf2_cu
*cu
)
3601 /* If this is a template instantiation, we can not work out the
3602 template arguments from partial DIEs. So, unfortunately, we have
3603 to go through the full DIEs. At least any work we do building
3604 types here will be reused if full symbols are loaded later. */
3605 if (pdi
->has_template_arguments
)
3607 fixup_partial_die (pdi
, cu
);
3609 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3611 struct die_info
*die
;
3612 struct attribute attr
;
3613 struct dwarf2_cu
*ref_cu
= cu
;
3616 attr
.form
= DW_FORM_ref_addr
;
3617 attr
.u
.addr
= pdi
->offset
;
3618 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3620 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3624 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3625 if (parent_scope
== NULL
)
3628 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3632 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3634 struct objfile
*objfile
= cu
->objfile
;
3636 char *actual_name
= NULL
;
3637 const struct partial_symbol
*psym
= NULL
;
3639 int built_actual_name
= 0;
3641 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3643 actual_name
= partial_die_full_name (pdi
, cu
);
3645 built_actual_name
= 1;
3647 if (actual_name
== NULL
)
3648 actual_name
= pdi
->name
;
3652 case DW_TAG_subprogram
:
3653 if (pdi
->is_external
|| cu
->language
== language_ada
)
3655 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3656 of the global scope. But in Ada, we want to be able to access
3657 nested procedures globally. So all Ada subprograms are stored
3658 in the global scope. */
3659 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3660 mst_text, objfile); */
3661 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3663 VAR_DOMAIN
, LOC_BLOCK
,
3664 &objfile
->global_psymbols
,
3665 0, pdi
->lowpc
+ baseaddr
,
3666 cu
->language
, objfile
);
3670 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3671 mst_file_text, objfile); */
3672 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3674 VAR_DOMAIN
, LOC_BLOCK
,
3675 &objfile
->static_psymbols
,
3676 0, pdi
->lowpc
+ baseaddr
,
3677 cu
->language
, objfile
);
3680 case DW_TAG_variable
:
3682 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3686 && !dwarf2_per_objfile
->has_section_at_zero
)
3688 /* A global or static variable may also have been stripped
3689 out by the linker if unused, in which case its address
3690 will be nullified; do not add such variables into partial
3691 symbol table then. */
3693 else if (pdi
->is_external
)
3696 Don't enter into the minimal symbol tables as there is
3697 a minimal symbol table entry from the ELF symbols already.
3698 Enter into partial symbol table if it has a location
3699 descriptor or a type.
3700 If the location descriptor is missing, new_symbol will create
3701 a LOC_UNRESOLVED symbol, the address of the variable will then
3702 be determined from the minimal symbol table whenever the variable
3704 The address for the partial symbol table entry is not
3705 used by GDB, but it comes in handy for debugging partial symbol
3708 if (pdi
->locdesc
|| pdi
->has_type
)
3709 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3711 VAR_DOMAIN
, LOC_STATIC
,
3712 &objfile
->global_psymbols
,
3714 cu
->language
, objfile
);
3718 /* Static Variable. Skip symbols without location descriptors. */
3719 if (pdi
->locdesc
== NULL
)
3721 if (built_actual_name
)
3722 xfree (actual_name
);
3725 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3726 mst_file_data, objfile); */
3727 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3729 VAR_DOMAIN
, LOC_STATIC
,
3730 &objfile
->static_psymbols
,
3732 cu
->language
, objfile
);
3735 case DW_TAG_typedef
:
3736 case DW_TAG_base_type
:
3737 case DW_TAG_subrange_type
:
3738 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3740 VAR_DOMAIN
, LOC_TYPEDEF
,
3741 &objfile
->static_psymbols
,
3742 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3744 case DW_TAG_namespace
:
3745 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3747 VAR_DOMAIN
, LOC_TYPEDEF
,
3748 &objfile
->global_psymbols
,
3749 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3751 case DW_TAG_class_type
:
3752 case DW_TAG_interface_type
:
3753 case DW_TAG_structure_type
:
3754 case DW_TAG_union_type
:
3755 case DW_TAG_enumeration_type
:
3756 /* Skip external references. The DWARF standard says in the section
3757 about "Structure, Union, and Class Type Entries": "An incomplete
3758 structure, union or class type is represented by a structure,
3759 union or class entry that does not have a byte size attribute
3760 and that has a DW_AT_declaration attribute." */
3761 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3763 if (built_actual_name
)
3764 xfree (actual_name
);
3768 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3769 static vs. global. */
3770 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3772 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3773 (cu
->language
== language_cplus
3774 || cu
->language
== language_java
)
3775 ? &objfile
->global_psymbols
3776 : &objfile
->static_psymbols
,
3777 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3780 case DW_TAG_enumerator
:
3781 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3783 VAR_DOMAIN
, LOC_CONST
,
3784 (cu
->language
== language_cplus
3785 || cu
->language
== language_java
)
3786 ? &objfile
->global_psymbols
3787 : &objfile
->static_psymbols
,
3788 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3794 if (built_actual_name
)
3795 xfree (actual_name
);
3798 /* Read a partial die corresponding to a namespace; also, add a symbol
3799 corresponding to that namespace to the symbol table. NAMESPACE is
3800 the name of the enclosing namespace. */
3803 add_partial_namespace (struct partial_die_info
*pdi
,
3804 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3805 int need_pc
, struct dwarf2_cu
*cu
)
3807 /* Add a symbol for the namespace. */
3809 add_partial_symbol (pdi
, cu
);
3811 /* Now scan partial symbols in that namespace. */
3813 if (pdi
->has_children
)
3814 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3817 /* Read a partial die corresponding to a Fortran module. */
3820 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3821 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3823 /* Now scan partial symbols in that module. */
3825 if (pdi
->has_children
)
3826 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3829 /* Read a partial die corresponding to a subprogram and create a partial
3830 symbol for that subprogram. When the CU language allows it, this
3831 routine also defines a partial symbol for each nested subprogram
3832 that this subprogram contains.
3834 DIE my also be a lexical block, in which case we simply search
3835 recursively for suprograms defined inside that lexical block.
3836 Again, this is only performed when the CU language allows this
3837 type of definitions. */
3840 add_partial_subprogram (struct partial_die_info
*pdi
,
3841 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3842 int need_pc
, struct dwarf2_cu
*cu
)
3844 if (pdi
->tag
== DW_TAG_subprogram
)
3846 if (pdi
->has_pc_info
)
3848 if (pdi
->lowpc
< *lowpc
)
3849 *lowpc
= pdi
->lowpc
;
3850 if (pdi
->highpc
> *highpc
)
3851 *highpc
= pdi
->highpc
;
3855 struct objfile
*objfile
= cu
->objfile
;
3857 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3858 SECT_OFF_TEXT (objfile
));
3859 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3860 pdi
->lowpc
+ baseaddr
,
3861 pdi
->highpc
- 1 + baseaddr
,
3862 cu
->per_cu
->v
.psymtab
);
3864 if (!pdi
->is_declaration
)
3865 /* Ignore subprogram DIEs that do not have a name, they are
3866 illegal. Do not emit a complaint at this point, we will
3867 do so when we convert this psymtab into a symtab. */
3869 add_partial_symbol (pdi
, cu
);
3873 if (! pdi
->has_children
)
3876 if (cu
->language
== language_ada
)
3878 pdi
= pdi
->die_child
;
3881 fixup_partial_die (pdi
, cu
);
3882 if (pdi
->tag
== DW_TAG_subprogram
3883 || pdi
->tag
== DW_TAG_lexical_block
)
3884 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3885 pdi
= pdi
->die_sibling
;
3890 /* See if we can figure out if the class lives in a namespace. We do
3891 this by looking for a member function; its demangled name will
3892 contain namespace info, if there is any. */
3895 guess_structure_name (struct partial_die_info
*struct_pdi
,
3896 struct dwarf2_cu
*cu
)
3898 if ((cu
->language
== language_cplus
3899 || cu
->language
== language_java
)
3900 && cu
->has_namespace_info
== 0
3901 && struct_pdi
->has_children
)
3903 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3904 what template types look like, because the demangler
3905 frequently doesn't give the same name as the debug info. We
3906 could fix this by only using the demangled name to get the
3907 prefix (but see comment in read_structure_type). */
3909 struct partial_die_info
*real_pdi
;
3911 /* If this DIE (this DIE's specification, if any) has a parent, then
3912 we should not do this. We'll prepend the parent's fully qualified
3913 name when we create the partial symbol. */
3915 real_pdi
= struct_pdi
;
3916 while (real_pdi
->has_specification
)
3917 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3919 if (real_pdi
->die_parent
!= NULL
)
3924 /* Read a partial die corresponding to an enumeration type. */
3927 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3928 struct dwarf2_cu
*cu
)
3930 struct partial_die_info
*pdi
;
3932 if (enum_pdi
->name
!= NULL
)
3933 add_partial_symbol (enum_pdi
, cu
);
3935 pdi
= enum_pdi
->die_child
;
3938 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3939 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3941 add_partial_symbol (pdi
, cu
);
3942 pdi
= pdi
->die_sibling
;
3946 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3947 Return the corresponding abbrev, or NULL if the number is zero (indicating
3948 an empty DIE). In either case *BYTES_READ will be set to the length of
3949 the initial number. */
3951 static struct abbrev_info
*
3952 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3953 struct dwarf2_cu
*cu
)
3955 bfd
*abfd
= cu
->objfile
->obfd
;
3956 unsigned int abbrev_number
;
3957 struct abbrev_info
*abbrev
;
3959 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3961 if (abbrev_number
== 0)
3964 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3967 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3968 bfd_get_filename (abfd
));
3974 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3975 Returns a pointer to the end of a series of DIEs, terminated by an empty
3976 DIE. Any children of the skipped DIEs will also be skipped. */
3979 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3981 struct abbrev_info
*abbrev
;
3982 unsigned int bytes_read
;
3986 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3988 return info_ptr
+ bytes_read
;
3990 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3994 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3995 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3996 abbrev corresponding to that skipped uleb128 should be passed in
3997 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4001 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4002 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4004 unsigned int bytes_read
;
4005 struct attribute attr
;
4006 bfd
*abfd
= cu
->objfile
->obfd
;
4007 unsigned int form
, i
;
4009 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4011 /* The only abbrev we care about is DW_AT_sibling. */
4012 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4014 read_attribute (&attr
, &abbrev
->attrs
[i
],
4015 abfd
, info_ptr
, cu
);
4016 if (attr
.form
== DW_FORM_ref_addr
)
4017 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4019 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4022 /* If it isn't DW_AT_sibling, skip this attribute. */
4023 form
= abbrev
->attrs
[i
].form
;
4027 case DW_FORM_ref_addr
:
4028 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4029 and later it is offset sized. */
4030 if (cu
->header
.version
== 2)
4031 info_ptr
+= cu
->header
.addr_size
;
4033 info_ptr
+= cu
->header
.offset_size
;
4036 info_ptr
+= cu
->header
.addr_size
;
4043 case DW_FORM_flag_present
:
4058 case DW_FORM_string
:
4059 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4060 info_ptr
+= bytes_read
;
4062 case DW_FORM_sec_offset
:
4064 info_ptr
+= cu
->header
.offset_size
;
4066 case DW_FORM_exprloc
:
4068 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4069 info_ptr
+= bytes_read
;
4071 case DW_FORM_block1
:
4072 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4074 case DW_FORM_block2
:
4075 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4077 case DW_FORM_block4
:
4078 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4082 case DW_FORM_ref_udata
:
4083 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4085 case DW_FORM_indirect
:
4086 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4087 info_ptr
+= bytes_read
;
4088 /* We need to continue parsing from here, so just go back to
4090 goto skip_attribute
;
4093 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4094 dwarf_form_name (form
),
4095 bfd_get_filename (abfd
));
4099 if (abbrev
->has_children
)
4100 return skip_children (buffer
, info_ptr
, cu
);
4105 /* Locate ORIG_PDI's sibling.
4106 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4110 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4111 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4112 bfd
*abfd
, struct dwarf2_cu
*cu
)
4114 /* Do we know the sibling already? */
4116 if (orig_pdi
->sibling
)
4117 return orig_pdi
->sibling
;
4119 /* Are there any children to deal with? */
4121 if (!orig_pdi
->has_children
)
4124 /* Skip the children the long way. */
4126 return skip_children (buffer
, info_ptr
, cu
);
4129 /* Expand this partial symbol table into a full symbol table. */
4132 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4138 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4144 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4145 gdb_flush (gdb_stdout
);
4148 /* Restore our global data. */
4149 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4150 dwarf2_objfile_data_key
);
4152 /* If this psymtab is constructed from a debug-only objfile, the
4153 has_section_at_zero flag will not necessarily be correct. We
4154 can get the correct value for this flag by looking at the data
4155 associated with the (presumably stripped) associated objfile. */
4156 if (pst
->objfile
->separate_debug_objfile_backlink
)
4158 struct dwarf2_per_objfile
*dpo_backlink
4159 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4160 dwarf2_objfile_data_key
);
4162 dwarf2_per_objfile
->has_section_at_zero
4163 = dpo_backlink
->has_section_at_zero
;
4166 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4168 psymtab_to_symtab_1 (pst
);
4170 /* Finish up the debug error message. */
4172 printf_filtered (_("done.\n"));
4177 /* Add PER_CU to the queue. */
4180 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4182 struct dwarf2_queue_item
*item
;
4185 item
= xmalloc (sizeof (*item
));
4186 item
->per_cu
= per_cu
;
4189 if (dwarf2_queue
== NULL
)
4190 dwarf2_queue
= item
;
4192 dwarf2_queue_tail
->next
= item
;
4194 dwarf2_queue_tail
= item
;
4197 /* Process the queue. */
4200 process_queue (struct objfile
*objfile
)
4202 struct dwarf2_queue_item
*item
, *next_item
;
4204 /* The queue starts out with one item, but following a DIE reference
4205 may load a new CU, adding it to the end of the queue. */
4206 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4208 if (dwarf2_per_objfile
->using_index
4209 ? !item
->per_cu
->v
.quick
->symtab
4210 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4211 process_full_comp_unit (item
->per_cu
);
4213 item
->per_cu
->queued
= 0;
4214 next_item
= item
->next
;
4218 dwarf2_queue_tail
= NULL
;
4221 /* Free all allocated queue entries. This function only releases anything if
4222 an error was thrown; if the queue was processed then it would have been
4223 freed as we went along. */
4226 dwarf2_release_queue (void *dummy
)
4228 struct dwarf2_queue_item
*item
, *last
;
4230 item
= dwarf2_queue
;
4233 /* Anything still marked queued is likely to be in an
4234 inconsistent state, so discard it. */
4235 if (item
->per_cu
->queued
)
4237 if (item
->per_cu
->cu
!= NULL
)
4238 free_one_cached_comp_unit (item
->per_cu
->cu
);
4239 item
->per_cu
->queued
= 0;
4247 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4250 /* Read in full symbols for PST, and anything it depends on. */
4253 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4255 struct dwarf2_per_cu_data
*per_cu
;
4256 struct cleanup
*back_to
;
4259 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4260 if (!pst
->dependencies
[i
]->readin
)
4262 /* Inform about additional files that need to be read in. */
4265 /* FIXME: i18n: Need to make this a single string. */
4266 fputs_filtered (" ", gdb_stdout
);
4268 fputs_filtered ("and ", gdb_stdout
);
4270 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4271 wrap_here (""); /* Flush output */
4272 gdb_flush (gdb_stdout
);
4274 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4277 per_cu
= pst
->read_symtab_private
;
4281 /* It's an include file, no symbols to read for it.
4282 Everything is in the parent symtab. */
4287 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4290 /* Load the DIEs associated with PER_CU into memory. */
4293 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4295 bfd
*abfd
= objfile
->obfd
;
4296 struct dwarf2_cu
*cu
;
4297 unsigned int offset
;
4298 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4299 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4300 struct attribute
*attr
;
4303 gdb_assert (! per_cu
->from_debug_types
);
4305 /* Set local variables from the partial symbol table info. */
4306 offset
= per_cu
->offset
;
4308 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4309 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4310 beg_of_comp_unit
= info_ptr
;
4312 if (per_cu
->cu
== NULL
)
4314 cu
= alloc_one_comp_unit (objfile
);
4318 /* If an error occurs while loading, release our storage. */
4319 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4321 /* Read in the comp_unit header. */
4322 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4324 /* Complete the cu_header. */
4325 cu
->header
.offset
= offset
;
4326 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4328 /* Read the abbrevs for this compilation unit. */
4329 dwarf2_read_abbrevs (abfd
, cu
);
4330 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4332 /* Link this compilation unit into the compilation unit tree. */
4334 cu
->per_cu
= per_cu
;
4335 cu
->type_hash
= per_cu
->type_hash
;
4337 /* Link this CU into read_in_chain. */
4338 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4339 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4344 info_ptr
+= cu
->header
.first_die_offset
;
4347 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4349 /* We try not to read any attributes in this function, because not
4350 all objfiles needed for references have been loaded yet, and symbol
4351 table processing isn't initialized. But we have to set the CU language,
4352 or we won't be able to build types correctly. */
4353 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4355 set_cu_language (DW_UNSND (attr
), cu
);
4357 set_cu_language (language_minimal
, cu
);
4359 /* Similarly, if we do not read the producer, we can not apply
4360 producer-specific interpretation. */
4361 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4363 cu
->producer
= DW_STRING (attr
);
4367 do_cleanups (free_abbrevs_cleanup
);
4369 /* We've successfully allocated this compilation unit. Let our
4370 caller clean it up when finished with it. */
4371 discard_cleanups (free_cu_cleanup
);
4375 /* Add a DIE to the delayed physname list. */
4378 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4379 const char *name
, struct die_info
*die
,
4380 struct dwarf2_cu
*cu
)
4382 struct delayed_method_info mi
;
4384 mi
.fnfield_index
= fnfield_index
;
4388 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4391 /* A cleanup for freeing the delayed method list. */
4394 free_delayed_list (void *ptr
)
4396 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4397 if (cu
->method_list
!= NULL
)
4399 VEC_free (delayed_method_info
, cu
->method_list
);
4400 cu
->method_list
= NULL
;
4404 /* Compute the physnames of any methods on the CU's method list.
4406 The computation of method physnames is delayed in order to avoid the
4407 (bad) condition that one of the method's formal parameters is of an as yet
4411 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4414 struct delayed_method_info
*mi
;
4415 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4418 struct fn_fieldlist
*fn_flp
4419 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4420 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4421 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4425 /* Generate full symbol information for PST and CU, whose DIEs have
4426 already been loaded into memory. */
4429 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4431 struct dwarf2_cu
*cu
= per_cu
->cu
;
4432 struct objfile
*objfile
= per_cu
->objfile
;
4433 CORE_ADDR lowpc
, highpc
;
4434 struct symtab
*symtab
;
4435 struct cleanup
*back_to
, *delayed_list_cleanup
;
4438 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4441 back_to
= make_cleanup (really_free_pendings
, NULL
);
4442 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4444 cu
->list_in_scope
= &file_symbols
;
4446 dwarf2_find_base_address (cu
->dies
, cu
);
4448 /* Do line number decoding in read_file_scope () */
4449 process_die (cu
->dies
, cu
);
4451 /* Now that we have processed all the DIEs in the CU, all the types
4452 should be complete, and it should now be safe to compute all of the
4454 compute_delayed_physnames (cu
);
4455 do_cleanups (delayed_list_cleanup
);
4457 /* Some compilers don't define a DW_AT_high_pc attribute for the
4458 compilation unit. If the DW_AT_high_pc is missing, synthesize
4459 it, by scanning the DIE's below the compilation unit. */
4460 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4462 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4464 /* Set symtab language to language from DW_AT_language.
4465 If the compilation is from a C file generated by language preprocessors,
4466 do not set the language if it was already deduced by start_subfile. */
4468 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4470 symtab
->language
= cu
->language
;
4473 if (dwarf2_per_objfile
->using_index
)
4474 per_cu
->v
.quick
->symtab
= symtab
;
4477 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4478 pst
->symtab
= symtab
;
4482 do_cleanups (back_to
);
4485 /* Process a die and its children. */
4488 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4492 case DW_TAG_padding
:
4494 case DW_TAG_compile_unit
:
4495 read_file_scope (die
, cu
);
4497 case DW_TAG_type_unit
:
4498 read_type_unit_scope (die
, cu
);
4500 case DW_TAG_subprogram
:
4501 case DW_TAG_inlined_subroutine
:
4502 read_func_scope (die
, cu
);
4504 case DW_TAG_lexical_block
:
4505 case DW_TAG_try_block
:
4506 case DW_TAG_catch_block
:
4507 read_lexical_block_scope (die
, cu
);
4509 case DW_TAG_class_type
:
4510 case DW_TAG_interface_type
:
4511 case DW_TAG_structure_type
:
4512 case DW_TAG_union_type
:
4513 process_structure_scope (die
, cu
);
4515 case DW_TAG_enumeration_type
:
4516 process_enumeration_scope (die
, cu
);
4519 /* These dies have a type, but processing them does not create
4520 a symbol or recurse to process the children. Therefore we can
4521 read them on-demand through read_type_die. */
4522 case DW_TAG_subroutine_type
:
4523 case DW_TAG_set_type
:
4524 case DW_TAG_array_type
:
4525 case DW_TAG_pointer_type
:
4526 case DW_TAG_ptr_to_member_type
:
4527 case DW_TAG_reference_type
:
4528 case DW_TAG_string_type
:
4531 case DW_TAG_base_type
:
4532 case DW_TAG_subrange_type
:
4533 case DW_TAG_typedef
:
4534 /* Add a typedef symbol for the type definition, if it has a
4536 new_symbol (die
, read_type_die (die
, cu
), cu
);
4538 case DW_TAG_common_block
:
4539 read_common_block (die
, cu
);
4541 case DW_TAG_common_inclusion
:
4543 case DW_TAG_namespace
:
4544 processing_has_namespace_info
= 1;
4545 read_namespace (die
, cu
);
4548 processing_has_namespace_info
= 1;
4549 read_module (die
, cu
);
4551 case DW_TAG_imported_declaration
:
4552 case DW_TAG_imported_module
:
4553 processing_has_namespace_info
= 1;
4554 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4555 || cu
->language
!= language_fortran
))
4556 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4557 dwarf_tag_name (die
->tag
));
4558 read_import_statement (die
, cu
);
4561 new_symbol (die
, NULL
, cu
);
4566 /* A helper function for dwarf2_compute_name which determines whether DIE
4567 needs to have the name of the scope prepended to the name listed in the
4571 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4573 struct attribute
*attr
;
4577 case DW_TAG_namespace
:
4578 case DW_TAG_typedef
:
4579 case DW_TAG_class_type
:
4580 case DW_TAG_interface_type
:
4581 case DW_TAG_structure_type
:
4582 case DW_TAG_union_type
:
4583 case DW_TAG_enumeration_type
:
4584 case DW_TAG_enumerator
:
4585 case DW_TAG_subprogram
:
4589 case DW_TAG_variable
:
4590 /* We only need to prefix "globally" visible variables. These include
4591 any variable marked with DW_AT_external or any variable that
4592 lives in a namespace. [Variables in anonymous namespaces
4593 require prefixing, but they are not DW_AT_external.] */
4595 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4597 struct dwarf2_cu
*spec_cu
= cu
;
4599 return die_needs_namespace (die_specification (die
, &spec_cu
),
4603 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4604 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4605 && die
->parent
->tag
!= DW_TAG_module
)
4607 /* A variable in a lexical block of some kind does not need a
4608 namespace, even though in C++ such variables may be external
4609 and have a mangled name. */
4610 if (die
->parent
->tag
== DW_TAG_lexical_block
4611 || die
->parent
->tag
== DW_TAG_try_block
4612 || die
->parent
->tag
== DW_TAG_catch_block
4613 || die
->parent
->tag
== DW_TAG_subprogram
)
4622 /* Retrieve the last character from a mem_file. */
4625 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4627 char *last_char_p
= (char *) object
;
4630 *last_char_p
= buffer
[length
- 1];
4633 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4634 compute the physname for the object, which include a method's
4635 formal parameters (C++/Java) and return type (Java).
4637 For Ada, return the DIE's linkage name rather than the fully qualified
4638 name. PHYSNAME is ignored..
4640 The result is allocated on the objfile_obstack and canonicalized. */
4643 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4647 name
= dwarf2_name (die
, cu
);
4649 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4650 compute it by typename_concat inside GDB. */
4651 if (cu
->language
== language_ada
4652 || (cu
->language
== language_fortran
&& physname
))
4654 /* For Ada unit, we prefer the linkage name over the name, as
4655 the former contains the exported name, which the user expects
4656 to be able to reference. Ideally, we want the user to be able
4657 to reference this entity using either natural or linkage name,
4658 but we haven't started looking at this enhancement yet. */
4659 struct attribute
*attr
;
4661 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4663 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4664 if (attr
&& DW_STRING (attr
))
4665 return DW_STRING (attr
);
4668 /* These are the only languages we know how to qualify names in. */
4670 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4671 || cu
->language
== language_fortran
))
4673 if (die_needs_namespace (die
, cu
))
4677 struct ui_file
*buf
;
4679 prefix
= determine_prefix (die
, cu
);
4680 buf
= mem_fileopen ();
4681 if (*prefix
!= '\0')
4683 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4686 fputs_unfiltered (prefixed_name
, buf
);
4687 xfree (prefixed_name
);
4690 fputs_unfiltered (name
? name
: "", buf
);
4692 /* Template parameters may be specified in the DIE's DW_AT_name, or
4693 as children with DW_TAG_template_type_param or
4694 DW_TAG_value_type_param. If the latter, add them to the name
4695 here. If the name already has template parameters, then
4696 skip this step; some versions of GCC emit both, and
4697 it is more efficient to use the pre-computed name.
4699 Something to keep in mind about this process: it is very
4700 unlikely, or in some cases downright impossible, to produce
4701 something that will match the mangled name of a function.
4702 If the definition of the function has the same debug info,
4703 we should be able to match up with it anyway. But fallbacks
4704 using the minimal symbol, for instance to find a method
4705 implemented in a stripped copy of libstdc++, will not work.
4706 If we do not have debug info for the definition, we will have to
4707 match them up some other way.
4709 When we do name matching there is a related problem with function
4710 templates; two instantiated function templates are allowed to
4711 differ only by their return types, which we do not add here. */
4713 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4715 struct attribute
*attr
;
4716 struct die_info
*child
;
4719 die
->building_fullname
= 1;
4721 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4726 struct dwarf2_locexpr_baton
*baton
;
4729 if (child
->tag
!= DW_TAG_template_type_param
4730 && child
->tag
!= DW_TAG_template_value_param
)
4735 fputs_unfiltered ("<", buf
);
4739 fputs_unfiltered (", ", buf
);
4741 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4744 complaint (&symfile_complaints
,
4745 _("template parameter missing DW_AT_type"));
4746 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4749 type
= die_type (child
, cu
);
4751 if (child
->tag
== DW_TAG_template_type_param
)
4753 c_print_type (type
, "", buf
, -1, 0);
4757 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4760 complaint (&symfile_complaints
,
4761 _("template parameter missing DW_AT_const_value"));
4762 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4766 dwarf2_const_value_attr (attr
, type
, name
,
4767 &cu
->comp_unit_obstack
, cu
,
4768 &value
, &bytes
, &baton
);
4770 if (TYPE_NOSIGN (type
))
4771 /* GDB prints characters as NUMBER 'CHAR'. If that's
4772 changed, this can use value_print instead. */
4773 c_printchar (value
, type
, buf
);
4776 struct value_print_options opts
;
4779 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4783 else if (bytes
!= NULL
)
4785 v
= allocate_value (type
);
4786 memcpy (value_contents_writeable (v
), bytes
,
4787 TYPE_LENGTH (type
));
4790 v
= value_from_longest (type
, value
);
4792 /* Specify decimal so that we do not depend on the radix. */
4793 get_formatted_print_options (&opts
, 'd');
4795 value_print (v
, buf
, &opts
);
4801 die
->building_fullname
= 0;
4805 /* Close the argument list, with a space if necessary
4806 (nested templates). */
4807 char last_char
= '\0';
4808 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4809 if (last_char
== '>')
4810 fputs_unfiltered (" >", buf
);
4812 fputs_unfiltered (">", buf
);
4816 /* For Java and C++ methods, append formal parameter type
4817 information, if PHYSNAME. */
4819 if (physname
&& die
->tag
== DW_TAG_subprogram
4820 && (cu
->language
== language_cplus
4821 || cu
->language
== language_java
))
4823 struct type
*type
= read_type_die (die
, cu
);
4825 c_type_print_args (type
, buf
, 0, cu
->language
);
4827 if (cu
->language
== language_java
)
4829 /* For java, we must append the return type to method
4831 if (die
->tag
== DW_TAG_subprogram
)
4832 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4835 else if (cu
->language
== language_cplus
)
4837 if (TYPE_NFIELDS (type
) > 0
4838 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4839 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4840 fputs_unfiltered (" const", buf
);
4844 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4846 ui_file_delete (buf
);
4848 if (cu
->language
== language_cplus
)
4851 = dwarf2_canonicalize_name (name
, cu
,
4852 &cu
->objfile
->objfile_obstack
);
4863 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4864 If scope qualifiers are appropriate they will be added. The result
4865 will be allocated on the objfile_obstack, or NULL if the DIE does
4866 not have a name. NAME may either be from a previous call to
4867 dwarf2_name or NULL.
4869 The output string will be canonicalized (if C++/Java). */
4872 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4874 return dwarf2_compute_name (name
, die
, cu
, 0);
4877 /* Construct a physname for the given DIE in CU. NAME may either be
4878 from a previous call to dwarf2_name or NULL. The result will be
4879 allocated on the objfile_objstack or NULL if the DIE does not have a
4882 The output string will be canonicalized (if C++/Java). */
4885 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4887 return dwarf2_compute_name (name
, die
, cu
, 1);
4890 /* Read the import statement specified by the given die and record it. */
4893 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4895 struct attribute
*import_attr
;
4896 struct die_info
*imported_die
;
4897 struct dwarf2_cu
*imported_cu
;
4898 const char *imported_name
;
4899 const char *imported_name_prefix
;
4900 const char *canonical_name
;
4901 const char *import_alias
;
4902 const char *imported_declaration
= NULL
;
4903 const char *import_prefix
;
4907 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4908 if (import_attr
== NULL
)
4910 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4911 dwarf_tag_name (die
->tag
));
4916 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4917 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4918 if (imported_name
== NULL
)
4920 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4922 The import in the following code:
4936 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4937 <52> DW_AT_decl_file : 1
4938 <53> DW_AT_decl_line : 6
4939 <54> DW_AT_import : <0x75>
4940 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4942 <5b> DW_AT_decl_file : 1
4943 <5c> DW_AT_decl_line : 2
4944 <5d> DW_AT_type : <0x6e>
4946 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4947 <76> DW_AT_byte_size : 4
4948 <77> DW_AT_encoding : 5 (signed)
4950 imports the wrong die ( 0x75 instead of 0x58 ).
4951 This case will be ignored until the gcc bug is fixed. */
4955 /* Figure out the local name after import. */
4956 import_alias
= dwarf2_name (die
, cu
);
4958 /* Figure out where the statement is being imported to. */
4959 import_prefix
= determine_prefix (die
, cu
);
4961 /* Figure out what the scope of the imported die is and prepend it
4962 to the name of the imported die. */
4963 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4965 if (imported_die
->tag
!= DW_TAG_namespace
4966 && imported_die
->tag
!= DW_TAG_module
)
4968 imported_declaration
= imported_name
;
4969 canonical_name
= imported_name_prefix
;
4971 else if (strlen (imported_name_prefix
) > 0)
4973 temp
= alloca (strlen (imported_name_prefix
)
4974 + 2 + strlen (imported_name
) + 1);
4975 strcpy (temp
, imported_name_prefix
);
4976 strcat (temp
, "::");
4977 strcat (temp
, imported_name
);
4978 canonical_name
= temp
;
4981 canonical_name
= imported_name
;
4983 cp_add_using_directive (import_prefix
,
4986 imported_declaration
,
4987 &cu
->objfile
->objfile_obstack
);
4991 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4993 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4997 free_cu_line_header (void *arg
)
4999 struct dwarf2_cu
*cu
= arg
;
5001 free_line_header (cu
->line_header
);
5002 cu
->line_header
= NULL
;
5006 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5007 char **name
, char **comp_dir
)
5009 struct attribute
*attr
;
5014 /* Find the filename. Do not use dwarf2_name here, since the filename
5015 is not a source language identifier. */
5016 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5019 *name
= DW_STRING (attr
);
5022 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5024 *comp_dir
= DW_STRING (attr
);
5025 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5027 *comp_dir
= ldirname (*name
);
5028 if (*comp_dir
!= NULL
)
5029 make_cleanup (xfree
, *comp_dir
);
5031 if (*comp_dir
!= NULL
)
5033 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5034 directory, get rid of it. */
5035 char *cp
= strchr (*comp_dir
, ':');
5037 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5042 *name
= "<unknown>";
5046 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5048 struct objfile
*objfile
= cu
->objfile
;
5049 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5050 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5051 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5052 struct attribute
*attr
;
5054 char *comp_dir
= NULL
;
5055 struct die_info
*child_die
;
5056 bfd
*abfd
= objfile
->obfd
;
5057 struct line_header
*line_header
= 0;
5060 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5062 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5064 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5065 from finish_block. */
5066 if (lowpc
== ((CORE_ADDR
) -1))
5071 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5073 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5076 set_cu_language (DW_UNSND (attr
), cu
);
5079 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5081 cu
->producer
= DW_STRING (attr
);
5083 /* We assume that we're processing GCC output. */
5084 processing_gcc_compilation
= 2;
5086 processing_has_namespace_info
= 0;
5088 start_symtab (name
, comp_dir
, lowpc
);
5089 record_debugformat ("DWARF 2");
5090 record_producer (cu
->producer
);
5092 initialize_cu_func_list (cu
);
5094 /* Decode line number information if present. We do this before
5095 processing child DIEs, so that the line header table is available
5096 for DW_AT_decl_file. */
5097 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5100 unsigned int line_offset
= DW_UNSND (attr
);
5101 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5104 cu
->line_header
= line_header
;
5105 make_cleanup (free_cu_line_header
, cu
);
5106 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5110 /* Process all dies in compilation unit. */
5111 if (die
->child
!= NULL
)
5113 child_die
= die
->child
;
5114 while (child_die
&& child_die
->tag
)
5116 process_die (child_die
, cu
);
5117 child_die
= sibling_die (child_die
);
5121 /* Decode macro information, if present. Dwarf 2 macro information
5122 refers to information in the line number info statement program
5123 header, so we can only read it if we've read the header
5125 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5126 if (attr
&& line_header
)
5128 unsigned int macro_offset
= DW_UNSND (attr
);
5130 dwarf_decode_macros (line_header
, macro_offset
,
5131 comp_dir
, abfd
, cu
);
5133 do_cleanups (back_to
);
5136 /* For TUs we want to skip the first top level sibling if it's not the
5137 actual type being defined by this TU. In this case the first top
5138 level sibling is there to provide context only. */
5141 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5143 struct objfile
*objfile
= cu
->objfile
;
5144 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5146 struct attribute
*attr
;
5148 char *comp_dir
= NULL
;
5149 struct die_info
*child_die
;
5150 bfd
*abfd
= objfile
->obfd
;
5152 /* start_symtab needs a low pc, but we don't really have one.
5153 Do what read_file_scope would do in the absence of such info. */
5154 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5156 /* Find the filename. Do not use dwarf2_name here, since the filename
5157 is not a source language identifier. */
5158 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5160 name
= DW_STRING (attr
);
5162 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5164 comp_dir
= DW_STRING (attr
);
5165 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5167 comp_dir
= ldirname (name
);
5168 if (comp_dir
!= NULL
)
5169 make_cleanup (xfree
, comp_dir
);
5175 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5177 set_cu_language (DW_UNSND (attr
), cu
);
5179 /* This isn't technically needed today. It is done for symmetry
5180 with read_file_scope. */
5181 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5183 cu
->producer
= DW_STRING (attr
);
5185 /* We assume that we're processing GCC output. */
5186 processing_gcc_compilation
= 2;
5188 processing_has_namespace_info
= 0;
5190 start_symtab (name
, comp_dir
, lowpc
);
5191 record_debugformat ("DWARF 2");
5192 record_producer (cu
->producer
);
5194 /* Process the dies in the type unit. */
5195 if (die
->child
== NULL
)
5197 dump_die_for_error (die
);
5198 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5199 bfd_get_filename (abfd
));
5202 child_die
= die
->child
;
5204 while (child_die
&& child_die
->tag
)
5206 process_die (child_die
, cu
);
5208 child_die
= sibling_die (child_die
);
5211 do_cleanups (back_to
);
5215 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5216 struct dwarf2_cu
*cu
)
5218 struct function_range
*thisfn
;
5220 thisfn
= (struct function_range
*)
5221 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5222 thisfn
->name
= name
;
5223 thisfn
->lowpc
= lowpc
;
5224 thisfn
->highpc
= highpc
;
5225 thisfn
->seen_line
= 0;
5226 thisfn
->next
= NULL
;
5228 if (cu
->last_fn
== NULL
)
5229 cu
->first_fn
= thisfn
;
5231 cu
->last_fn
->next
= thisfn
;
5233 cu
->last_fn
= thisfn
;
5236 /* qsort helper for inherit_abstract_dies. */
5239 unsigned_int_compar (const void *ap
, const void *bp
)
5241 unsigned int a
= *(unsigned int *) ap
;
5242 unsigned int b
= *(unsigned int *) bp
;
5244 return (a
> b
) - (b
> a
);
5247 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5248 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5249 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5252 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5254 struct die_info
*child_die
;
5255 unsigned die_children_count
;
5256 /* CU offsets which were referenced by children of the current DIE. */
5258 unsigned *offsets_end
, *offsetp
;
5259 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5260 struct die_info
*origin_die
;
5261 /* Iterator of the ORIGIN_DIE children. */
5262 struct die_info
*origin_child_die
;
5263 struct cleanup
*cleanups
;
5264 struct attribute
*attr
;
5266 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5270 origin_die
= follow_die_ref (die
, attr
, &cu
);
5271 if (die
->tag
!= origin_die
->tag
5272 && !(die
->tag
== DW_TAG_inlined_subroutine
5273 && origin_die
->tag
== DW_TAG_subprogram
))
5274 complaint (&symfile_complaints
,
5275 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5276 die
->offset
, origin_die
->offset
);
5278 child_die
= die
->child
;
5279 die_children_count
= 0;
5280 while (child_die
&& child_die
->tag
)
5282 child_die
= sibling_die (child_die
);
5283 die_children_count
++;
5285 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5286 cleanups
= make_cleanup (xfree
, offsets
);
5288 offsets_end
= offsets
;
5289 child_die
= die
->child
;
5290 while (child_die
&& child_die
->tag
)
5292 /* For each CHILD_DIE, find the corresponding child of
5293 ORIGIN_DIE. If there is more than one layer of
5294 DW_AT_abstract_origin, follow them all; there shouldn't be,
5295 but GCC versions at least through 4.4 generate this (GCC PR
5297 struct die_info
*child_origin_die
= child_die
;
5301 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
5304 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
5307 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5308 counterpart may exist. */
5309 if (child_origin_die
!= child_die
)
5311 if (child_die
->tag
!= child_origin_die
->tag
5312 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5313 && child_origin_die
->tag
== DW_TAG_subprogram
))
5314 complaint (&symfile_complaints
,
5315 _("Child DIE 0x%x and its abstract origin 0x%x have "
5316 "different tags"), child_die
->offset
,
5317 child_origin_die
->offset
);
5318 if (child_origin_die
->parent
!= origin_die
)
5319 complaint (&symfile_complaints
,
5320 _("Child DIE 0x%x and its abstract origin 0x%x have "
5321 "different parents"), child_die
->offset
,
5322 child_origin_die
->offset
);
5324 *offsets_end
++ = child_origin_die
->offset
;
5326 child_die
= sibling_die (child_die
);
5328 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5329 unsigned_int_compar
);
5330 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5331 if (offsetp
[-1] == *offsetp
)
5332 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5333 "to DIE 0x%x as their abstract origin"),
5334 die
->offset
, *offsetp
);
5337 origin_child_die
= origin_die
->child
;
5338 while (origin_child_die
&& origin_child_die
->tag
)
5340 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5341 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5343 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5345 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5346 process_die (origin_child_die
, cu
);
5348 origin_child_die
= sibling_die (origin_child_die
);
5351 do_cleanups (cleanups
);
5355 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5357 struct objfile
*objfile
= cu
->objfile
;
5358 struct context_stack
*new;
5361 struct die_info
*child_die
;
5362 struct attribute
*attr
, *call_line
, *call_file
;
5365 struct block
*block
;
5366 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5367 VEC (symbolp
) *template_args
= NULL
;
5368 struct template_symbol
*templ_func
= NULL
;
5372 /* If we do not have call site information, we can't show the
5373 caller of this inlined function. That's too confusing, so
5374 only use the scope for local variables. */
5375 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5376 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5377 if (call_line
== NULL
|| call_file
== NULL
)
5379 read_lexical_block_scope (die
, cu
);
5384 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5386 name
= dwarf2_name (die
, cu
);
5388 /* Ignore functions with missing or empty names. These are actually
5389 illegal according to the DWARF standard. */
5392 complaint (&symfile_complaints
,
5393 _("missing name for subprogram DIE at %d"), die
->offset
);
5397 /* Ignore functions with missing or invalid low and high pc attributes. */
5398 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5400 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5401 if (!attr
|| !DW_UNSND (attr
))
5402 complaint (&symfile_complaints
,
5403 _("cannot get low and high bounds for subprogram DIE at %d"),
5411 /* Record the function range for dwarf_decode_lines. */
5412 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5414 /* If we have any template arguments, then we must allocate a
5415 different sort of symbol. */
5416 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5418 if (child_die
->tag
== DW_TAG_template_type_param
5419 || child_die
->tag
== DW_TAG_template_value_param
)
5421 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5422 struct template_symbol
);
5423 templ_func
->base
.is_cplus_template_function
= 1;
5428 new = push_context (0, lowpc
);
5429 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5430 (struct symbol
*) templ_func
);
5432 /* If there is a location expression for DW_AT_frame_base, record
5434 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5436 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5437 expression is being recorded directly in the function's symbol
5438 and not in a separate frame-base object. I guess this hack is
5439 to avoid adding some sort of frame-base adjunct/annex to the
5440 function's symbol :-(. The problem with doing this is that it
5441 results in a function symbol with a location expression that
5442 has nothing to do with the location of the function, ouch! The
5443 relationship should be: a function's symbol has-a frame base; a
5444 frame-base has-a location expression. */
5445 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5447 cu
->list_in_scope
= &local_symbols
;
5449 if (die
->child
!= NULL
)
5451 child_die
= die
->child
;
5452 while (child_die
&& child_die
->tag
)
5454 if (child_die
->tag
== DW_TAG_template_type_param
5455 || child_die
->tag
== DW_TAG_template_value_param
)
5457 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5459 VEC_safe_push (symbolp
, template_args
, arg
);
5462 process_die (child_die
, cu
);
5463 child_die
= sibling_die (child_die
);
5467 inherit_abstract_dies (die
, cu
);
5469 /* If we have a DW_AT_specification, we might need to import using
5470 directives from the context of the specification DIE. See the
5471 comment in determine_prefix. */
5472 if (cu
->language
== language_cplus
5473 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5475 struct dwarf2_cu
*spec_cu
= cu
;
5476 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5480 child_die
= spec_die
->child
;
5481 while (child_die
&& child_die
->tag
)
5483 if (child_die
->tag
== DW_TAG_imported_module
)
5484 process_die (child_die
, spec_cu
);
5485 child_die
= sibling_die (child_die
);
5488 /* In some cases, GCC generates specification DIEs that
5489 themselves contain DW_AT_specification attributes. */
5490 spec_die
= die_specification (spec_die
, &spec_cu
);
5494 new = pop_context ();
5495 /* Make a block for the local symbols within. */
5496 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5497 lowpc
, highpc
, objfile
);
5499 /* For C++, set the block's scope. */
5500 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5501 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5502 determine_prefix (die
, cu
),
5503 processing_has_namespace_info
);
5505 /* If we have address ranges, record them. */
5506 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5508 /* Attach template arguments to function. */
5509 if (! VEC_empty (symbolp
, template_args
))
5511 gdb_assert (templ_func
!= NULL
);
5513 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5514 templ_func
->template_arguments
5515 = obstack_alloc (&objfile
->objfile_obstack
,
5516 (templ_func
->n_template_arguments
5517 * sizeof (struct symbol
*)));
5518 memcpy (templ_func
->template_arguments
,
5519 VEC_address (symbolp
, template_args
),
5520 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5521 VEC_free (symbolp
, template_args
);
5524 /* In C++, we can have functions nested inside functions (e.g., when
5525 a function declares a class that has methods). This means that
5526 when we finish processing a function scope, we may need to go
5527 back to building a containing block's symbol lists. */
5528 local_symbols
= new->locals
;
5529 param_symbols
= new->params
;
5530 using_directives
= new->using_directives
;
5532 /* If we've finished processing a top-level function, subsequent
5533 symbols go in the file symbol list. */
5534 if (outermost_context_p ())
5535 cu
->list_in_scope
= &file_symbols
;
5538 /* Process all the DIES contained within a lexical block scope. Start
5539 a new scope, process the dies, and then close the scope. */
5542 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5544 struct objfile
*objfile
= cu
->objfile
;
5545 struct context_stack
*new;
5546 CORE_ADDR lowpc
, highpc
;
5547 struct die_info
*child_die
;
5550 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5552 /* Ignore blocks with missing or invalid low and high pc attributes. */
5553 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5554 as multiple lexical blocks? Handling children in a sane way would
5555 be nasty. Might be easier to properly extend generic blocks to
5557 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5562 push_context (0, lowpc
);
5563 if (die
->child
!= NULL
)
5565 child_die
= die
->child
;
5566 while (child_die
&& child_die
->tag
)
5568 process_die (child_die
, cu
);
5569 child_die
= sibling_die (child_die
);
5572 new = pop_context ();
5574 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5577 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5580 /* Note that recording ranges after traversing children, as we
5581 do here, means that recording a parent's ranges entails
5582 walking across all its children's ranges as they appear in
5583 the address map, which is quadratic behavior.
5585 It would be nicer to record the parent's ranges before
5586 traversing its children, simply overriding whatever you find
5587 there. But since we don't even decide whether to create a
5588 block until after we've traversed its children, that's hard
5590 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5592 local_symbols
= new->locals
;
5593 using_directives
= new->using_directives
;
5596 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5597 Return 1 if the attributes are present and valid, otherwise, return 0.
5598 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5601 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5602 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5603 struct partial_symtab
*ranges_pst
)
5605 struct objfile
*objfile
= cu
->objfile
;
5606 struct comp_unit_head
*cu_header
= &cu
->header
;
5607 bfd
*obfd
= objfile
->obfd
;
5608 unsigned int addr_size
= cu_header
->addr_size
;
5609 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5610 /* Base address selection entry. */
5621 found_base
= cu
->base_known
;
5622 base
= cu
->base_address
;
5624 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5625 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5627 complaint (&symfile_complaints
,
5628 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5632 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5634 /* Read in the largest possible address. */
5635 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5636 if ((marker
& mask
) == mask
)
5638 /* If we found the largest possible address, then
5639 read the base address. */
5640 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5641 buffer
+= 2 * addr_size
;
5642 offset
+= 2 * addr_size
;
5648 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5652 CORE_ADDR range_beginning
, range_end
;
5654 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5655 buffer
+= addr_size
;
5656 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5657 buffer
+= addr_size
;
5658 offset
+= 2 * addr_size
;
5660 /* An end of list marker is a pair of zero addresses. */
5661 if (range_beginning
== 0 && range_end
== 0)
5662 /* Found the end of list entry. */
5665 /* Each base address selection entry is a pair of 2 values.
5666 The first is the largest possible address, the second is
5667 the base address. Check for a base address here. */
5668 if ((range_beginning
& mask
) == mask
)
5670 /* If we found the largest possible address, then
5671 read the base address. */
5672 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5679 /* We have no valid base address for the ranges
5681 complaint (&symfile_complaints
,
5682 _("Invalid .debug_ranges data (no base address)"));
5686 range_beginning
+= base
;
5689 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5690 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5691 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5694 /* FIXME: This is recording everything as a low-high
5695 segment of consecutive addresses. We should have a
5696 data structure for discontiguous block ranges
5700 low
= range_beginning
;
5706 if (range_beginning
< low
)
5707 low
= range_beginning
;
5708 if (range_end
> high
)
5714 /* If the first entry is an end-of-list marker, the range
5715 describes an empty scope, i.e. no instructions. */
5721 *high_return
= high
;
5725 /* Get low and high pc attributes from a die. Return 1 if the attributes
5726 are present and valid, otherwise, return 0. Return -1 if the range is
5727 discontinuous, i.e. derived from DW_AT_ranges information. */
5729 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5730 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5731 struct partial_symtab
*pst
)
5733 struct attribute
*attr
;
5738 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5741 high
= DW_ADDR (attr
);
5742 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5744 low
= DW_ADDR (attr
);
5746 /* Found high w/o low attribute. */
5749 /* Found consecutive range of addresses. */
5754 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5757 /* Value of the DW_AT_ranges attribute is the offset in the
5758 .debug_ranges section. */
5759 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5761 /* Found discontinuous range of addresses. */
5769 /* When using the GNU linker, .gnu.linkonce. sections are used to
5770 eliminate duplicate copies of functions and vtables and such.
5771 The linker will arbitrarily choose one and discard the others.
5772 The AT_*_pc values for such functions refer to local labels in
5773 these sections. If the section from that file was discarded, the
5774 labels are not in the output, so the relocs get a value of 0.
5775 If this is a discarded function, mark the pc bounds as invalid,
5776 so that GDB will ignore it. */
5777 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5785 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5786 its low and high PC addresses. Do nothing if these addresses could not
5787 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5788 and HIGHPC to the high address if greater than HIGHPC. */
5791 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5792 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5793 struct dwarf2_cu
*cu
)
5795 CORE_ADDR low
, high
;
5796 struct die_info
*child
= die
->child
;
5798 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5800 *lowpc
= min (*lowpc
, low
);
5801 *highpc
= max (*highpc
, high
);
5804 /* If the language does not allow nested subprograms (either inside
5805 subprograms or lexical blocks), we're done. */
5806 if (cu
->language
!= language_ada
)
5809 /* Check all the children of the given DIE. If it contains nested
5810 subprograms, then check their pc bounds. Likewise, we need to
5811 check lexical blocks as well, as they may also contain subprogram
5813 while (child
&& child
->tag
)
5815 if (child
->tag
== DW_TAG_subprogram
5816 || child
->tag
== DW_TAG_lexical_block
)
5817 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5818 child
= sibling_die (child
);
5822 /* Get the low and high pc's represented by the scope DIE, and store
5823 them in *LOWPC and *HIGHPC. If the correct values can't be
5824 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5827 get_scope_pc_bounds (struct die_info
*die
,
5828 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5829 struct dwarf2_cu
*cu
)
5831 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5832 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5833 CORE_ADDR current_low
, current_high
;
5835 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5837 best_low
= current_low
;
5838 best_high
= current_high
;
5842 struct die_info
*child
= die
->child
;
5844 while (child
&& child
->tag
)
5846 switch (child
->tag
) {
5847 case DW_TAG_subprogram
:
5848 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5850 case DW_TAG_namespace
:
5852 /* FIXME: carlton/2004-01-16: Should we do this for
5853 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5854 that current GCC's always emit the DIEs corresponding
5855 to definitions of methods of classes as children of a
5856 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5857 the DIEs giving the declarations, which could be
5858 anywhere). But I don't see any reason why the
5859 standards says that they have to be there. */
5860 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5862 if (current_low
!= ((CORE_ADDR
) -1))
5864 best_low
= min (best_low
, current_low
);
5865 best_high
= max (best_high
, current_high
);
5873 child
= sibling_die (child
);
5878 *highpc
= best_high
;
5881 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5884 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5885 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5887 struct attribute
*attr
;
5889 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5892 CORE_ADDR high
= DW_ADDR (attr
);
5894 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5897 CORE_ADDR low
= DW_ADDR (attr
);
5899 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5903 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5906 bfd
*obfd
= cu
->objfile
->obfd
;
5908 /* The value of the DW_AT_ranges attribute is the offset of the
5909 address range list in the .debug_ranges section. */
5910 unsigned long offset
= DW_UNSND (attr
);
5911 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5913 /* For some target architectures, but not others, the
5914 read_address function sign-extends the addresses it returns.
5915 To recognize base address selection entries, we need a
5917 unsigned int addr_size
= cu
->header
.addr_size
;
5918 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5920 /* The base address, to which the next pair is relative. Note
5921 that this 'base' is a DWARF concept: most entries in a range
5922 list are relative, to reduce the number of relocs against the
5923 debugging information. This is separate from this function's
5924 'baseaddr' argument, which GDB uses to relocate debugging
5925 information from a shared library based on the address at
5926 which the library was loaded. */
5927 CORE_ADDR base
= cu
->base_address
;
5928 int base_known
= cu
->base_known
;
5930 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5931 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5933 complaint (&symfile_complaints
,
5934 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5941 unsigned int bytes_read
;
5942 CORE_ADDR start
, end
;
5944 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5945 buffer
+= bytes_read
;
5946 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5947 buffer
+= bytes_read
;
5949 /* Did we find the end of the range list? */
5950 if (start
== 0 && end
== 0)
5953 /* Did we find a base address selection entry? */
5954 else if ((start
& base_select_mask
) == base_select_mask
)
5960 /* We found an ordinary address range. */
5965 complaint (&symfile_complaints
,
5966 _("Invalid .debug_ranges data (no base address)"));
5970 record_block_range (block
,
5971 baseaddr
+ base
+ start
,
5972 baseaddr
+ base
+ end
- 1);
5978 /* Add an aggregate field to the field list. */
5981 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
5982 struct dwarf2_cu
*cu
)
5984 struct objfile
*objfile
= cu
->objfile
;
5985 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5986 struct nextfield
*new_field
;
5987 struct attribute
*attr
;
5989 char *fieldname
= "";
5991 /* Allocate a new field list entry and link it in. */
5992 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
5993 make_cleanup (xfree
, new_field
);
5994 memset (new_field
, 0, sizeof (struct nextfield
));
5996 if (die
->tag
== DW_TAG_inheritance
)
5998 new_field
->next
= fip
->baseclasses
;
5999 fip
->baseclasses
= new_field
;
6003 new_field
->next
= fip
->fields
;
6004 fip
->fields
= new_field
;
6008 /* Handle accessibility and virtuality of field.
6009 The default accessibility for members is public, the default
6010 accessibility for inheritance is private. */
6011 if (die
->tag
!= DW_TAG_inheritance
)
6012 new_field
->accessibility
= DW_ACCESS_public
;
6014 new_field
->accessibility
= DW_ACCESS_private
;
6015 new_field
->virtuality
= DW_VIRTUALITY_none
;
6017 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6019 new_field
->accessibility
= DW_UNSND (attr
);
6020 if (new_field
->accessibility
!= DW_ACCESS_public
)
6021 fip
->non_public_fields
= 1;
6022 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6024 new_field
->virtuality
= DW_UNSND (attr
);
6026 fp
= &new_field
->field
;
6028 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6030 /* Data member other than a C++ static data member. */
6032 /* Get type of field. */
6033 fp
->type
= die_type (die
, cu
);
6035 SET_FIELD_BITPOS (*fp
, 0);
6037 /* Get bit size of field (zero if none). */
6038 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6041 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6045 FIELD_BITSIZE (*fp
) = 0;
6048 /* Get bit offset of field. */
6049 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6052 int byte_offset
= 0;
6054 if (attr_form_is_section_offset (attr
))
6055 dwarf2_complex_location_expr_complaint ();
6056 else if (attr_form_is_constant (attr
))
6057 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6058 else if (attr_form_is_block (attr
))
6059 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6061 dwarf2_complex_location_expr_complaint ();
6063 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6065 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6068 if (gdbarch_bits_big_endian (gdbarch
))
6070 /* For big endian bits, the DW_AT_bit_offset gives the
6071 additional bit offset from the MSB of the containing
6072 anonymous object to the MSB of the field. We don't
6073 have to do anything special since we don't need to
6074 know the size of the anonymous object. */
6075 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6079 /* For little endian bits, compute the bit offset to the
6080 MSB of the anonymous object, subtract off the number of
6081 bits from the MSB of the field to the MSB of the
6082 object, and then subtract off the number of bits of
6083 the field itself. The result is the bit offset of
6084 the LSB of the field. */
6086 int bit_offset
= DW_UNSND (attr
);
6088 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6091 /* The size of the anonymous object containing
6092 the bit field is explicit, so use the
6093 indicated size (in bytes). */
6094 anonymous_size
= DW_UNSND (attr
);
6098 /* The size of the anonymous object containing
6099 the bit field must be inferred from the type
6100 attribute of the data member containing the
6102 anonymous_size
= TYPE_LENGTH (fp
->type
);
6104 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6105 - bit_offset
- FIELD_BITSIZE (*fp
);
6109 /* Get name of field. */
6110 fieldname
= dwarf2_name (die
, cu
);
6111 if (fieldname
== NULL
)
6114 /* The name is already allocated along with this objfile, so we don't
6115 need to duplicate it for the type. */
6116 fp
->name
= fieldname
;
6118 /* Change accessibility for artificial fields (e.g. virtual table
6119 pointer or virtual base class pointer) to private. */
6120 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6122 FIELD_ARTIFICIAL (*fp
) = 1;
6123 new_field
->accessibility
= DW_ACCESS_private
;
6124 fip
->non_public_fields
= 1;
6127 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6129 /* C++ static member. */
6131 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6132 is a declaration, but all versions of G++ as of this writing
6133 (so through at least 3.2.1) incorrectly generate
6134 DW_TAG_variable tags. */
6138 /* Get name of field. */
6139 fieldname
= dwarf2_name (die
, cu
);
6140 if (fieldname
== NULL
)
6143 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6145 /* Only create a symbol if this is an external value.
6146 new_symbol checks this and puts the value in the global symbol
6147 table, which we want. If it is not external, new_symbol
6148 will try to put the value in cu->list_in_scope which is wrong. */
6149 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6151 /* A static const member, not much different than an enum as far as
6152 we're concerned, except that we can support more types. */
6153 new_symbol (die
, NULL
, cu
);
6156 /* Get physical name. */
6157 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6159 /* The name is already allocated along with this objfile, so we don't
6160 need to duplicate it for the type. */
6161 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6162 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6163 FIELD_NAME (*fp
) = fieldname
;
6165 else if (die
->tag
== DW_TAG_inheritance
)
6167 /* C++ base class field. */
6168 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6171 int byte_offset
= 0;
6173 if (attr_form_is_section_offset (attr
))
6174 dwarf2_complex_location_expr_complaint ();
6175 else if (attr_form_is_constant (attr
))
6176 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6177 else if (attr_form_is_block (attr
))
6178 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6180 dwarf2_complex_location_expr_complaint ();
6182 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6184 FIELD_BITSIZE (*fp
) = 0;
6185 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6186 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6187 fip
->nbaseclasses
++;
6191 /* Add a typedef defined in the scope of the FIP's class. */
6194 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6195 struct dwarf2_cu
*cu
)
6197 struct objfile
*objfile
= cu
->objfile
;
6198 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6199 struct typedef_field_list
*new_field
;
6200 struct attribute
*attr
;
6201 struct typedef_field
*fp
;
6202 char *fieldname
= "";
6204 /* Allocate a new field list entry and link it in. */
6205 new_field
= xzalloc (sizeof (*new_field
));
6206 make_cleanup (xfree
, new_field
);
6208 gdb_assert (die
->tag
== DW_TAG_typedef
);
6210 fp
= &new_field
->field
;
6212 /* Get name of field. */
6213 fp
->name
= dwarf2_name (die
, cu
);
6214 if (fp
->name
== NULL
)
6217 fp
->type
= read_type_die (die
, cu
);
6219 new_field
->next
= fip
->typedef_field_list
;
6220 fip
->typedef_field_list
= new_field
;
6221 fip
->typedef_field_list_count
++;
6224 /* Create the vector of fields, and attach it to the type. */
6227 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6228 struct dwarf2_cu
*cu
)
6230 int nfields
= fip
->nfields
;
6232 /* Record the field count, allocate space for the array of fields,
6233 and create blank accessibility bitfields if necessary. */
6234 TYPE_NFIELDS (type
) = nfields
;
6235 TYPE_FIELDS (type
) = (struct field
*)
6236 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6237 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6239 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6241 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6243 TYPE_FIELD_PRIVATE_BITS (type
) =
6244 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6245 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6247 TYPE_FIELD_PROTECTED_BITS (type
) =
6248 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6249 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6251 TYPE_FIELD_IGNORE_BITS (type
) =
6252 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6253 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6256 /* If the type has baseclasses, allocate and clear a bit vector for
6257 TYPE_FIELD_VIRTUAL_BITS. */
6258 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6260 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6261 unsigned char *pointer
;
6263 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6264 pointer
= TYPE_ALLOC (type
, num_bytes
);
6265 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6266 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6267 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6270 /* Copy the saved-up fields into the field vector. Start from the head
6271 of the list, adding to the tail of the field array, so that they end
6272 up in the same order in the array in which they were added to the list. */
6273 while (nfields
-- > 0)
6275 struct nextfield
*fieldp
;
6279 fieldp
= fip
->fields
;
6280 fip
->fields
= fieldp
->next
;
6284 fieldp
= fip
->baseclasses
;
6285 fip
->baseclasses
= fieldp
->next
;
6288 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6289 switch (fieldp
->accessibility
)
6291 case DW_ACCESS_private
:
6292 if (cu
->language
!= language_ada
)
6293 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6296 case DW_ACCESS_protected
:
6297 if (cu
->language
!= language_ada
)
6298 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6301 case DW_ACCESS_public
:
6305 /* Unknown accessibility. Complain and treat it as public. */
6307 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6308 fieldp
->accessibility
);
6312 if (nfields
< fip
->nbaseclasses
)
6314 switch (fieldp
->virtuality
)
6316 case DW_VIRTUALITY_virtual
:
6317 case DW_VIRTUALITY_pure_virtual
:
6318 if (cu
->language
== language_ada
)
6319 error ("unexpected virtuality in component of Ada type");
6320 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6327 /* Add a member function to the proper fieldlist. */
6330 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6331 struct type
*type
, struct dwarf2_cu
*cu
)
6333 struct objfile
*objfile
= cu
->objfile
;
6334 struct attribute
*attr
;
6335 struct fnfieldlist
*flp
;
6337 struct fn_field
*fnp
;
6339 struct nextfnfield
*new_fnfield
;
6340 struct type
*this_type
;
6342 if (cu
->language
== language_ada
)
6343 error ("unexpected member function in Ada type");
6345 /* Get name of member function. */
6346 fieldname
= dwarf2_name (die
, cu
);
6347 if (fieldname
== NULL
)
6350 /* Look up member function name in fieldlist. */
6351 for (i
= 0; i
< fip
->nfnfields
; i
++)
6353 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6357 /* Create new list element if necessary. */
6358 if (i
< fip
->nfnfields
)
6359 flp
= &fip
->fnfieldlists
[i
];
6362 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6364 fip
->fnfieldlists
= (struct fnfieldlist
*)
6365 xrealloc (fip
->fnfieldlists
,
6366 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6367 * sizeof (struct fnfieldlist
));
6368 if (fip
->nfnfields
== 0)
6369 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6371 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6372 flp
->name
= fieldname
;
6375 i
= fip
->nfnfields
++;
6378 /* Create a new member function field and chain it to the field list
6380 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6381 make_cleanup (xfree
, new_fnfield
);
6382 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6383 new_fnfield
->next
= flp
->head
;
6384 flp
->head
= new_fnfield
;
6387 /* Fill in the member function field info. */
6388 fnp
= &new_fnfield
->fnfield
;
6390 /* Delay processing of the physname until later. */
6391 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6393 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6398 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6399 fnp
->physname
= physname
? physname
: "";
6402 fnp
->type
= alloc_type (objfile
);
6403 this_type
= read_type_die (die
, cu
);
6404 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6406 int nparams
= TYPE_NFIELDS (this_type
);
6408 /* TYPE is the domain of this method, and THIS_TYPE is the type
6409 of the method itself (TYPE_CODE_METHOD). */
6410 smash_to_method_type (fnp
->type
, type
,
6411 TYPE_TARGET_TYPE (this_type
),
6412 TYPE_FIELDS (this_type
),
6413 TYPE_NFIELDS (this_type
),
6414 TYPE_VARARGS (this_type
));
6416 /* Handle static member functions.
6417 Dwarf2 has no clean way to discern C++ static and non-static
6418 member functions. G++ helps GDB by marking the first
6419 parameter for non-static member functions (which is the
6420 this pointer) as artificial. We obtain this information
6421 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6422 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6423 fnp
->voffset
= VOFFSET_STATIC
;
6426 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6427 dwarf2_full_name (fieldname
, die
, cu
));
6429 /* Get fcontext from DW_AT_containing_type if present. */
6430 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6431 fnp
->fcontext
= die_containing_type (die
, cu
);
6433 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6434 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6436 /* Get accessibility. */
6437 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6440 switch (DW_UNSND (attr
))
6442 case DW_ACCESS_private
:
6443 fnp
->is_private
= 1;
6445 case DW_ACCESS_protected
:
6446 fnp
->is_protected
= 1;
6451 /* Check for artificial methods. */
6452 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6453 if (attr
&& DW_UNSND (attr
) != 0)
6454 fnp
->is_artificial
= 1;
6456 /* Get index in virtual function table if it is a virtual member
6457 function. For older versions of GCC, this is an offset in the
6458 appropriate virtual table, as specified by DW_AT_containing_type.
6459 For everyone else, it is an expression to be evaluated relative
6460 to the object address. */
6462 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6465 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6467 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6469 /* Old-style GCC. */
6470 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6472 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6473 || (DW_BLOCK (attr
)->size
> 1
6474 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6475 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6477 struct dwarf_block blk
;
6480 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6482 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6483 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6484 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6485 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6486 dwarf2_complex_location_expr_complaint ();
6488 fnp
->voffset
/= cu
->header
.addr_size
;
6492 dwarf2_complex_location_expr_complaint ();
6495 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6497 else if (attr_form_is_section_offset (attr
))
6499 dwarf2_complex_location_expr_complaint ();
6503 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6509 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6510 if (attr
&& DW_UNSND (attr
))
6512 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6513 complaint (&symfile_complaints
,
6514 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6515 fieldname
, die
->offset
);
6516 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6517 TYPE_CPLUS_DYNAMIC (type
) = 1;
6522 /* Create the vector of member function fields, and attach it to the type. */
6525 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6526 struct dwarf2_cu
*cu
)
6528 struct fnfieldlist
*flp
;
6529 int total_length
= 0;
6532 if (cu
->language
== language_ada
)
6533 error ("unexpected member functions in Ada type");
6535 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6536 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6537 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6539 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6541 struct nextfnfield
*nfp
= flp
->head
;
6542 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6545 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6546 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6547 fn_flp
->fn_fields
= (struct fn_field
*)
6548 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6549 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6550 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6552 total_length
+= flp
->length
;
6555 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6556 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6559 /* Returns non-zero if NAME is the name of a vtable member in CU's
6560 language, zero otherwise. */
6562 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6564 static const char vptr
[] = "_vptr";
6565 static const char vtable
[] = "vtable";
6567 /* Look for the C++ and Java forms of the vtable. */
6568 if ((cu
->language
== language_java
6569 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6570 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6571 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6577 /* GCC outputs unnamed structures that are really pointers to member
6578 functions, with the ABI-specified layout. If TYPE describes
6579 such a structure, smash it into a member function type.
6581 GCC shouldn't do this; it should just output pointer to member DIEs.
6582 This is GCC PR debug/28767. */
6585 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6587 struct type
*pfn_type
, *domain_type
, *new_type
;
6589 /* Check for a structure with no name and two children. */
6590 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6593 /* Check for __pfn and __delta members. */
6594 if (TYPE_FIELD_NAME (type
, 0) == NULL
6595 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6596 || TYPE_FIELD_NAME (type
, 1) == NULL
6597 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6600 /* Find the type of the method. */
6601 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6602 if (pfn_type
== NULL
6603 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6604 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6607 /* Look for the "this" argument. */
6608 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6609 if (TYPE_NFIELDS (pfn_type
) == 0
6610 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6611 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6614 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6615 new_type
= alloc_type (objfile
);
6616 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6617 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6618 TYPE_VARARGS (pfn_type
));
6619 smash_to_methodptr_type (type
, new_type
);
6622 /* Called when we find the DIE that starts a structure or union scope
6623 (definition) to process all dies that define the members of the
6626 NOTE: we need to call struct_type regardless of whether or not the
6627 DIE has an at_name attribute, since it might be an anonymous
6628 structure or union. This gets the type entered into our set of
6631 However, if the structure is incomplete (an opaque struct/union)
6632 then suppress creating a symbol table entry for it since gdb only
6633 wants to find the one with the complete definition. Note that if
6634 it is complete, we just call new_symbol, which does it's own
6635 checking about whether the struct/union is anonymous or not (and
6636 suppresses creating a symbol table entry itself). */
6638 static struct type
*
6639 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6641 struct objfile
*objfile
= cu
->objfile
;
6643 struct attribute
*attr
;
6645 struct cleanup
*back_to
;
6647 /* If the definition of this type lives in .debug_types, read that type.
6648 Don't follow DW_AT_specification though, that will take us back up
6649 the chain and we want to go down. */
6650 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6653 struct dwarf2_cu
*type_cu
= cu
;
6654 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6656 /* We could just recurse on read_structure_type, but we need to call
6657 get_die_type to ensure only one type for this DIE is created.
6658 This is important, for example, because for c++ classes we need
6659 TYPE_NAME set which is only done by new_symbol. Blech. */
6660 type
= read_type_die (type_die
, type_cu
);
6661 return set_die_type (die
, type
, cu
);
6664 back_to
= make_cleanup (null_cleanup
, 0);
6666 type
= alloc_type (objfile
);
6667 INIT_CPLUS_SPECIFIC (type
);
6669 name
= dwarf2_name (die
, cu
);
6672 if (cu
->language
== language_cplus
6673 || cu
->language
== language_java
)
6675 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6677 /* dwarf2_full_name might have already finished building the DIE's
6678 type. If so, there is no need to continue. */
6679 if (get_die_type (die
, cu
) != NULL
)
6680 return get_die_type (die
, cu
);
6682 TYPE_TAG_NAME (type
) = full_name
;
6683 if (die
->tag
== DW_TAG_structure_type
6684 || die
->tag
== DW_TAG_class_type
)
6685 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6689 /* The name is already allocated along with this objfile, so
6690 we don't need to duplicate it for the type. */
6691 TYPE_TAG_NAME (type
) = (char *) name
;
6692 if (die
->tag
== DW_TAG_class_type
)
6693 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6697 if (die
->tag
== DW_TAG_structure_type
)
6699 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6701 else if (die
->tag
== DW_TAG_union_type
)
6703 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6707 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6710 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6711 TYPE_DECLARED_CLASS (type
) = 1;
6713 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6716 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6720 TYPE_LENGTH (type
) = 0;
6723 TYPE_STUB_SUPPORTED (type
) = 1;
6724 if (die_is_declaration (die
, cu
))
6725 TYPE_STUB (type
) = 1;
6726 else if (attr
== NULL
&& die
->child
== NULL
6727 && producer_is_realview (cu
->producer
))
6728 /* RealView does not output the required DW_AT_declaration
6729 on incomplete types. */
6730 TYPE_STUB (type
) = 1;
6732 /* We need to add the type field to the die immediately so we don't
6733 infinitely recurse when dealing with pointers to the structure
6734 type within the structure itself. */
6735 set_die_type (die
, type
, cu
);
6737 /* set_die_type should be already done. */
6738 set_descriptive_type (type
, die
, cu
);
6740 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6742 struct field_info fi
;
6743 struct die_info
*child_die
;
6744 VEC (symbolp
) *template_args
= NULL
;
6746 memset (&fi
, 0, sizeof (struct field_info
));
6748 child_die
= die
->child
;
6750 while (child_die
&& child_die
->tag
)
6752 if (child_die
->tag
== DW_TAG_member
6753 || child_die
->tag
== DW_TAG_variable
)
6755 /* NOTE: carlton/2002-11-05: A C++ static data member
6756 should be a DW_TAG_member that is a declaration, but
6757 all versions of G++ as of this writing (so through at
6758 least 3.2.1) incorrectly generate DW_TAG_variable
6759 tags for them instead. */
6760 dwarf2_add_field (&fi
, child_die
, cu
);
6762 else if (child_die
->tag
== DW_TAG_subprogram
)
6764 /* C++ member function. */
6765 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6767 else if (child_die
->tag
== DW_TAG_inheritance
)
6769 /* C++ base class field. */
6770 dwarf2_add_field (&fi
, child_die
, cu
);
6772 else if (child_die
->tag
== DW_TAG_typedef
)
6773 dwarf2_add_typedef (&fi
, child_die
, cu
);
6774 else if (child_die
->tag
== DW_TAG_template_type_param
6775 || child_die
->tag
== DW_TAG_template_value_param
)
6777 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6779 VEC_safe_push (symbolp
, template_args
, arg
);
6782 child_die
= sibling_die (child_die
);
6785 /* Attach template arguments to type. */
6786 if (! VEC_empty (symbolp
, template_args
))
6788 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6789 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6790 = VEC_length (symbolp
, template_args
);
6791 TYPE_TEMPLATE_ARGUMENTS (type
)
6792 = obstack_alloc (&objfile
->objfile_obstack
,
6793 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6794 * sizeof (struct symbol
*)));
6795 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6796 VEC_address (symbolp
, template_args
),
6797 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6798 * sizeof (struct symbol
*)));
6799 VEC_free (symbolp
, template_args
);
6802 /* Attach fields and member functions to the type. */
6804 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6807 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6809 /* Get the type which refers to the base class (possibly this
6810 class itself) which contains the vtable pointer for the current
6811 class from the DW_AT_containing_type attribute. This use of
6812 DW_AT_containing_type is a GNU extension. */
6814 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6816 struct type
*t
= die_containing_type (die
, cu
);
6818 TYPE_VPTR_BASETYPE (type
) = t
;
6823 /* Our own class provides vtbl ptr. */
6824 for (i
= TYPE_NFIELDS (t
) - 1;
6825 i
>= TYPE_N_BASECLASSES (t
);
6828 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6830 if (is_vtable_name (fieldname
, cu
))
6832 TYPE_VPTR_FIELDNO (type
) = i
;
6837 /* Complain if virtual function table field not found. */
6838 if (i
< TYPE_N_BASECLASSES (t
))
6839 complaint (&symfile_complaints
,
6840 _("virtual function table pointer not found when defining class '%s'"),
6841 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6846 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6849 else if (cu
->producer
6850 && strncmp (cu
->producer
,
6851 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6853 /* The IBM XLC compiler does not provide direct indication
6854 of the containing type, but the vtable pointer is
6855 always named __vfp. */
6859 for (i
= TYPE_NFIELDS (type
) - 1;
6860 i
>= TYPE_N_BASECLASSES (type
);
6863 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6865 TYPE_VPTR_FIELDNO (type
) = i
;
6866 TYPE_VPTR_BASETYPE (type
) = type
;
6873 /* Copy fi.typedef_field_list linked list elements content into the
6874 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6875 if (fi
.typedef_field_list
)
6877 int i
= fi
.typedef_field_list_count
;
6879 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6880 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6881 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6882 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6884 /* Reverse the list order to keep the debug info elements order. */
6887 struct typedef_field
*dest
, *src
;
6889 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6890 src
= &fi
.typedef_field_list
->field
;
6891 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6897 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6899 do_cleanups (back_to
);
6904 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6906 struct die_info
*child_die
= die
->child
;
6907 struct type
*this_type
;
6909 this_type
= get_die_type (die
, cu
);
6910 if (this_type
== NULL
)
6911 this_type
= read_structure_type (die
, cu
);
6913 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6914 snapshots) has been known to create a die giving a declaration
6915 for a class that has, as a child, a die giving a definition for a
6916 nested class. So we have to process our children even if the
6917 current die is a declaration. Normally, of course, a declaration
6918 won't have any children at all. */
6920 while (child_die
!= NULL
&& child_die
->tag
)
6922 if (child_die
->tag
== DW_TAG_member
6923 || child_die
->tag
== DW_TAG_variable
6924 || child_die
->tag
== DW_TAG_inheritance
6925 || child_die
->tag
== DW_TAG_template_value_param
6926 || child_die
->tag
== DW_TAG_template_type_param
)
6931 process_die (child_die
, cu
);
6933 child_die
= sibling_die (child_die
);
6936 /* Do not consider external references. According to the DWARF standard,
6937 these DIEs are identified by the fact that they have no byte_size
6938 attribute, and a declaration attribute. */
6939 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6940 || !die_is_declaration (die
, cu
))
6941 new_symbol (die
, this_type
, cu
);
6944 /* Given a DW_AT_enumeration_type die, set its type. We do not
6945 complete the type's fields yet, or create any symbols. */
6947 static struct type
*
6948 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6950 struct objfile
*objfile
= cu
->objfile
;
6952 struct attribute
*attr
;
6955 /* If the definition of this type lives in .debug_types, read that type.
6956 Don't follow DW_AT_specification though, that will take us back up
6957 the chain and we want to go down. */
6958 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6961 struct dwarf2_cu
*type_cu
= cu
;
6962 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6964 type
= read_type_die (type_die
, type_cu
);
6965 return set_die_type (die
, type
, cu
);
6968 type
= alloc_type (objfile
);
6970 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
6971 name
= dwarf2_full_name (NULL
, die
, cu
);
6973 TYPE_TAG_NAME (type
) = (char *) name
;
6975 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6978 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6982 TYPE_LENGTH (type
) = 0;
6985 /* The enumeration DIE can be incomplete. In Ada, any type can be
6986 declared as private in the package spec, and then defined only
6987 inside the package body. Such types are known as Taft Amendment
6988 Types. When another package uses such a type, an incomplete DIE
6989 may be generated by the compiler. */
6990 if (die_is_declaration (die
, cu
))
6991 TYPE_STUB (type
) = 1;
6993 return set_die_type (die
, type
, cu
);
6996 /* Given a pointer to a die which begins an enumeration, process all
6997 the dies that define the members of the enumeration, and create the
6998 symbol for the enumeration type.
7000 NOTE: We reverse the order of the element list. */
7003 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7005 struct die_info
*child_die
;
7006 struct field
*fields
;
7009 int unsigned_enum
= 1;
7011 struct type
*this_type
;
7015 this_type
= get_die_type (die
, cu
);
7016 if (this_type
== NULL
)
7017 this_type
= read_enumeration_type (die
, cu
);
7018 if (die
->child
!= NULL
)
7020 child_die
= die
->child
;
7021 while (child_die
&& child_die
->tag
)
7023 if (child_die
->tag
!= DW_TAG_enumerator
)
7025 process_die (child_die
, cu
);
7029 name
= dwarf2_name (child_die
, cu
);
7032 sym
= new_symbol (child_die
, this_type
, cu
);
7033 if (SYMBOL_VALUE (sym
) < 0)
7036 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7038 fields
= (struct field
*)
7040 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7041 * sizeof (struct field
));
7044 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7045 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7046 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7047 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7053 child_die
= sibling_die (child_die
);
7058 TYPE_NFIELDS (this_type
) = num_fields
;
7059 TYPE_FIELDS (this_type
) = (struct field
*)
7060 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7061 memcpy (TYPE_FIELDS (this_type
), fields
,
7062 sizeof (struct field
) * num_fields
);
7066 TYPE_UNSIGNED (this_type
) = 1;
7069 new_symbol (die
, this_type
, cu
);
7072 /* Extract all information from a DW_TAG_array_type DIE and put it in
7073 the DIE's type field. For now, this only handles one dimensional
7076 static struct type
*
7077 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7079 struct objfile
*objfile
= cu
->objfile
;
7080 struct die_info
*child_die
;
7082 struct type
*element_type
, *range_type
, *index_type
;
7083 struct type
**range_types
= NULL
;
7084 struct attribute
*attr
;
7086 struct cleanup
*back_to
;
7089 element_type
= die_type (die
, cu
);
7091 /* The die_type call above may have already set the type for this DIE. */
7092 type
= get_die_type (die
, cu
);
7096 /* Irix 6.2 native cc creates array types without children for
7097 arrays with unspecified length. */
7098 if (die
->child
== NULL
)
7100 index_type
= objfile_type (objfile
)->builtin_int
;
7101 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7102 type
= create_array_type (NULL
, element_type
, range_type
);
7103 return set_die_type (die
, type
, cu
);
7106 back_to
= make_cleanup (null_cleanup
, NULL
);
7107 child_die
= die
->child
;
7108 while (child_die
&& child_die
->tag
)
7110 if (child_die
->tag
== DW_TAG_subrange_type
)
7112 struct type
*child_type
= read_type_die (child_die
, cu
);
7114 if (child_type
!= NULL
)
7116 /* The range type was succesfully read. Save it for
7117 the array type creation. */
7118 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7120 range_types
= (struct type
**)
7121 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7122 * sizeof (struct type
*));
7124 make_cleanup (free_current_contents
, &range_types
);
7126 range_types
[ndim
++] = child_type
;
7129 child_die
= sibling_die (child_die
);
7132 /* Dwarf2 dimensions are output from left to right, create the
7133 necessary array types in backwards order. */
7135 type
= element_type
;
7137 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7142 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7147 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7150 /* Understand Dwarf2 support for vector types (like they occur on
7151 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7152 array type. This is not part of the Dwarf2/3 standard yet, but a
7153 custom vendor extension. The main difference between a regular
7154 array and the vector variant is that vectors are passed by value
7156 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7158 make_vector_type (type
);
7160 name
= dwarf2_name (die
, cu
);
7162 TYPE_NAME (type
) = name
;
7164 /* Install the type in the die. */
7165 set_die_type (die
, type
, cu
);
7167 /* set_die_type should be already done. */
7168 set_descriptive_type (type
, die
, cu
);
7170 do_cleanups (back_to
);
7175 static enum dwarf_array_dim_ordering
7176 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7178 struct attribute
*attr
;
7180 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7182 if (attr
) return DW_SND (attr
);
7185 GNU F77 is a special case, as at 08/2004 array type info is the
7186 opposite order to the dwarf2 specification, but data is still
7187 laid out as per normal fortran.
7189 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7193 if (cu
->language
== language_fortran
7194 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7196 return DW_ORD_row_major
;
7199 switch (cu
->language_defn
->la_array_ordering
)
7201 case array_column_major
:
7202 return DW_ORD_col_major
;
7203 case array_row_major
:
7205 return DW_ORD_row_major
;
7209 /* Extract all information from a DW_TAG_set_type DIE and put it in
7210 the DIE's type field. */
7212 static struct type
*
7213 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7215 struct type
*domain_type
, *set_type
;
7216 struct attribute
*attr
;
7218 domain_type
= die_type (die
, cu
);
7220 /* The die_type call above may have already set the type for this DIE. */
7221 set_type
= get_die_type (die
, cu
);
7225 set_type
= create_set_type (NULL
, domain_type
);
7227 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7229 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7231 return set_die_type (die
, set_type
, cu
);
7234 /* First cut: install each common block member as a global variable. */
7237 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7239 struct die_info
*child_die
;
7240 struct attribute
*attr
;
7242 CORE_ADDR base
= (CORE_ADDR
) 0;
7244 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7247 /* Support the .debug_loc offsets */
7248 if (attr_form_is_block (attr
))
7250 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7252 else if (attr_form_is_section_offset (attr
))
7254 dwarf2_complex_location_expr_complaint ();
7258 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7259 "common block member");
7262 if (die
->child
!= NULL
)
7264 child_die
= die
->child
;
7265 while (child_die
&& child_die
->tag
)
7267 sym
= new_symbol (child_die
, NULL
, cu
);
7268 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7271 CORE_ADDR byte_offset
= 0;
7273 if (attr_form_is_section_offset (attr
))
7274 dwarf2_complex_location_expr_complaint ();
7275 else if (attr_form_is_constant (attr
))
7276 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7277 else if (attr_form_is_block (attr
))
7278 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7280 dwarf2_complex_location_expr_complaint ();
7282 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7283 add_symbol_to_list (sym
, &global_symbols
);
7285 child_die
= sibling_die (child_die
);
7290 /* Create a type for a C++ namespace. */
7292 static struct type
*
7293 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7295 struct objfile
*objfile
= cu
->objfile
;
7296 const char *previous_prefix
, *name
;
7300 /* For extensions, reuse the type of the original namespace. */
7301 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7303 struct die_info
*ext_die
;
7304 struct dwarf2_cu
*ext_cu
= cu
;
7306 ext_die
= dwarf2_extension (die
, &ext_cu
);
7307 type
= read_type_die (ext_die
, ext_cu
);
7308 return set_die_type (die
, type
, cu
);
7311 name
= namespace_name (die
, &is_anonymous
, cu
);
7313 /* Now build the name of the current namespace. */
7315 previous_prefix
= determine_prefix (die
, cu
);
7316 if (previous_prefix
[0] != '\0')
7317 name
= typename_concat (&objfile
->objfile_obstack
,
7318 previous_prefix
, name
, 0, cu
);
7320 /* Create the type. */
7321 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7323 TYPE_NAME (type
) = (char *) name
;
7324 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7326 return set_die_type (die
, type
, cu
);
7329 /* Read a C++ namespace. */
7332 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7334 struct objfile
*objfile
= cu
->objfile
;
7338 /* Add a symbol associated to this if we haven't seen the namespace
7339 before. Also, add a using directive if it's an anonymous
7342 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7346 type
= read_type_die (die
, cu
);
7347 new_symbol (die
, type
, cu
);
7349 name
= namespace_name (die
, &is_anonymous
, cu
);
7352 const char *previous_prefix
= determine_prefix (die
, cu
);
7354 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7355 NULL
, &objfile
->objfile_obstack
);
7359 if (die
->child
!= NULL
)
7361 struct die_info
*child_die
= die
->child
;
7363 while (child_die
&& child_die
->tag
)
7365 process_die (child_die
, cu
);
7366 child_die
= sibling_die (child_die
);
7371 /* Read a Fortran module as type. This DIE can be only a declaration used for
7372 imported module. Still we need that type as local Fortran "use ... only"
7373 declaration imports depend on the created type in determine_prefix. */
7375 static struct type
*
7376 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7378 struct objfile
*objfile
= cu
->objfile
;
7382 module_name
= dwarf2_name (die
, cu
);
7384 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7386 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7388 /* determine_prefix uses TYPE_TAG_NAME. */
7389 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7391 return set_die_type (die
, type
, cu
);
7394 /* Read a Fortran module. */
7397 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7399 struct die_info
*child_die
= die
->child
;
7401 while (child_die
&& child_die
->tag
)
7403 process_die (child_die
, cu
);
7404 child_die
= sibling_die (child_die
);
7408 /* Return the name of the namespace represented by DIE. Set
7409 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7413 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7415 struct die_info
*current_die
;
7416 const char *name
= NULL
;
7418 /* Loop through the extensions until we find a name. */
7420 for (current_die
= die
;
7421 current_die
!= NULL
;
7422 current_die
= dwarf2_extension (die
, &cu
))
7424 name
= dwarf2_name (current_die
, cu
);
7429 /* Is it an anonymous namespace? */
7431 *is_anonymous
= (name
== NULL
);
7433 name
= "(anonymous namespace)";
7438 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7439 the user defined type vector. */
7441 static struct type
*
7442 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7444 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7445 struct comp_unit_head
*cu_header
= &cu
->header
;
7447 struct attribute
*attr_byte_size
;
7448 struct attribute
*attr_address_class
;
7449 int byte_size
, addr_class
;
7450 struct type
*target_type
;
7452 target_type
= die_type (die
, cu
);
7454 /* The die_type call above may have already set the type for this DIE. */
7455 type
= get_die_type (die
, cu
);
7459 type
= lookup_pointer_type (target_type
);
7461 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7463 byte_size
= DW_UNSND (attr_byte_size
);
7465 byte_size
= cu_header
->addr_size
;
7467 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7468 if (attr_address_class
)
7469 addr_class
= DW_UNSND (attr_address_class
);
7471 addr_class
= DW_ADDR_none
;
7473 /* If the pointer size or address class is different than the
7474 default, create a type variant marked as such and set the
7475 length accordingly. */
7476 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7478 if (gdbarch_address_class_type_flags_p (gdbarch
))
7482 type_flags
= gdbarch_address_class_type_flags
7483 (gdbarch
, byte_size
, addr_class
);
7484 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7486 type
= make_type_with_address_space (type
, type_flags
);
7488 else if (TYPE_LENGTH (type
) != byte_size
)
7490 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7494 /* Should we also complain about unhandled address classes? */
7498 TYPE_LENGTH (type
) = byte_size
;
7499 return set_die_type (die
, type
, cu
);
7502 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7503 the user defined type vector. */
7505 static struct type
*
7506 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7509 struct type
*to_type
;
7510 struct type
*domain
;
7512 to_type
= die_type (die
, cu
);
7513 domain
= die_containing_type (die
, cu
);
7515 /* The calls above may have already set the type for this DIE. */
7516 type
= get_die_type (die
, cu
);
7520 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7521 type
= lookup_methodptr_type (to_type
);
7523 type
= lookup_memberptr_type (to_type
, domain
);
7525 return set_die_type (die
, type
, cu
);
7528 /* Extract all information from a DW_TAG_reference_type DIE and add to
7529 the user defined type vector. */
7531 static struct type
*
7532 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7534 struct comp_unit_head
*cu_header
= &cu
->header
;
7535 struct type
*type
, *target_type
;
7536 struct attribute
*attr
;
7538 target_type
= die_type (die
, cu
);
7540 /* The die_type call above may have already set the type for this DIE. */
7541 type
= get_die_type (die
, cu
);
7545 type
= lookup_reference_type (target_type
);
7546 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7549 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7553 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7555 return set_die_type (die
, type
, cu
);
7558 static struct type
*
7559 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7561 struct type
*base_type
, *cv_type
;
7563 base_type
= die_type (die
, cu
);
7565 /* The die_type call above may have already set the type for this DIE. */
7566 cv_type
= get_die_type (die
, cu
);
7570 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7571 return set_die_type (die
, cv_type
, cu
);
7574 static struct type
*
7575 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7577 struct type
*base_type
, *cv_type
;
7579 base_type
= die_type (die
, cu
);
7581 /* The die_type call above may have already set the type for this DIE. */
7582 cv_type
= get_die_type (die
, cu
);
7586 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7587 return set_die_type (die
, cv_type
, cu
);
7590 /* Extract all information from a DW_TAG_string_type DIE and add to
7591 the user defined type vector. It isn't really a user defined type,
7592 but it behaves like one, with other DIE's using an AT_user_def_type
7593 attribute to reference it. */
7595 static struct type
*
7596 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7598 struct objfile
*objfile
= cu
->objfile
;
7599 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7600 struct type
*type
, *range_type
, *index_type
, *char_type
;
7601 struct attribute
*attr
;
7602 unsigned int length
;
7604 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7607 length
= DW_UNSND (attr
);
7611 /* check for the DW_AT_byte_size attribute */
7612 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7615 length
= DW_UNSND (attr
);
7623 index_type
= objfile_type (objfile
)->builtin_int
;
7624 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7625 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7626 type
= create_string_type (NULL
, char_type
, range_type
);
7628 return set_die_type (die
, type
, cu
);
7631 /* Handle DIES due to C code like:
7635 int (*funcp)(int a, long l);
7639 ('funcp' generates a DW_TAG_subroutine_type DIE)
7642 static struct type
*
7643 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7645 struct type
*type
; /* Type that this function returns */
7646 struct type
*ftype
; /* Function that returns above type */
7647 struct attribute
*attr
;
7649 type
= die_type (die
, cu
);
7651 /* The die_type call above may have already set the type for this DIE. */
7652 ftype
= get_die_type (die
, cu
);
7656 ftype
= lookup_function_type (type
);
7658 /* All functions in C++, Pascal and Java have prototypes. */
7659 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7660 if ((attr
&& (DW_UNSND (attr
) != 0))
7661 || cu
->language
== language_cplus
7662 || cu
->language
== language_java
7663 || cu
->language
== language_pascal
)
7664 TYPE_PROTOTYPED (ftype
) = 1;
7665 else if (producer_is_realview (cu
->producer
))
7666 /* RealView does not emit DW_AT_prototyped. We can not
7667 distinguish prototyped and unprototyped functions; default to
7668 prototyped, since that is more common in modern code (and
7669 RealView warns about unprototyped functions). */
7670 TYPE_PROTOTYPED (ftype
) = 1;
7672 /* Store the calling convention in the type if it's available in
7673 the subroutine die. Otherwise set the calling convention to
7674 the default value DW_CC_normal. */
7675 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7676 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7678 /* We need to add the subroutine type to the die immediately so
7679 we don't infinitely recurse when dealing with parameters
7680 declared as the same subroutine type. */
7681 set_die_type (die
, ftype
, cu
);
7683 if (die
->child
!= NULL
)
7685 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7686 struct die_info
*child_die
;
7687 int nparams
, iparams
;
7689 /* Count the number of parameters.
7690 FIXME: GDB currently ignores vararg functions, but knows about
7691 vararg member functions. */
7693 child_die
= die
->child
;
7694 while (child_die
&& child_die
->tag
)
7696 if (child_die
->tag
== DW_TAG_formal_parameter
)
7698 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7699 TYPE_VARARGS (ftype
) = 1;
7700 child_die
= sibling_die (child_die
);
7703 /* Allocate storage for parameters and fill them in. */
7704 TYPE_NFIELDS (ftype
) = nparams
;
7705 TYPE_FIELDS (ftype
) = (struct field
*)
7706 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7708 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7709 even if we error out during the parameters reading below. */
7710 for (iparams
= 0; iparams
< nparams
; iparams
++)
7711 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7714 child_die
= die
->child
;
7715 while (child_die
&& child_die
->tag
)
7717 if (child_die
->tag
== DW_TAG_formal_parameter
)
7719 struct type
*arg_type
;
7721 /* DWARF version 2 has no clean way to discern C++
7722 static and non-static member functions. G++ helps
7723 GDB by marking the first parameter for non-static
7724 member functions (which is the this pointer) as
7725 artificial. We pass this information to
7726 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7728 DWARF version 3 added DW_AT_object_pointer, which GCC
7729 4.5 does not yet generate. */
7730 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7732 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7735 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7737 /* GCC/43521: In java, the formal parameter
7738 "this" is sometimes not marked with DW_AT_artificial. */
7739 if (cu
->language
== language_java
)
7741 const char *name
= dwarf2_name (child_die
, cu
);
7743 if (name
&& !strcmp (name
, "this"))
7744 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7747 arg_type
= die_type (child_die
, cu
);
7749 /* RealView does not mark THIS as const, which the testsuite
7750 expects. GCC marks THIS as const in method definitions,
7751 but not in the class specifications (GCC PR 43053). */
7752 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7753 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7756 struct dwarf2_cu
*arg_cu
= cu
;
7757 const char *name
= dwarf2_name (child_die
, cu
);
7759 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7762 /* If the compiler emits this, use it. */
7763 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7766 else if (name
&& strcmp (name
, "this") == 0)
7767 /* Function definitions will have the argument names. */
7769 else if (name
== NULL
&& iparams
== 0)
7770 /* Declarations may not have the names, so like
7771 elsewhere in GDB, assume an artificial first
7772 argument is "this". */
7776 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7780 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7783 child_die
= sibling_die (child_die
);
7790 static struct type
*
7791 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7793 struct objfile
*objfile
= cu
->objfile
;
7794 const char *name
= NULL
;
7795 struct type
*this_type
;
7797 name
= dwarf2_full_name (NULL
, die
, cu
);
7798 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7799 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7800 TYPE_NAME (this_type
) = (char *) name
;
7801 set_die_type (die
, this_type
, cu
);
7802 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7806 /* Find a representation of a given base type and install
7807 it in the TYPE field of the die. */
7809 static struct type
*
7810 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7812 struct objfile
*objfile
= cu
->objfile
;
7814 struct attribute
*attr
;
7815 int encoding
= 0, size
= 0;
7817 enum type_code code
= TYPE_CODE_INT
;
7819 struct type
*target_type
= NULL
;
7821 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7824 encoding
= DW_UNSND (attr
);
7826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7829 size
= DW_UNSND (attr
);
7831 name
= dwarf2_name (die
, cu
);
7834 complaint (&symfile_complaints
,
7835 _("DW_AT_name missing from DW_TAG_base_type"));
7840 case DW_ATE_address
:
7841 /* Turn DW_ATE_address into a void * pointer. */
7842 code
= TYPE_CODE_PTR
;
7843 type_flags
|= TYPE_FLAG_UNSIGNED
;
7844 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7846 case DW_ATE_boolean
:
7847 code
= TYPE_CODE_BOOL
;
7848 type_flags
|= TYPE_FLAG_UNSIGNED
;
7850 case DW_ATE_complex_float
:
7851 code
= TYPE_CODE_COMPLEX
;
7852 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7854 case DW_ATE_decimal_float
:
7855 code
= TYPE_CODE_DECFLOAT
;
7858 code
= TYPE_CODE_FLT
;
7862 case DW_ATE_unsigned
:
7863 type_flags
|= TYPE_FLAG_UNSIGNED
;
7865 case DW_ATE_signed_char
:
7866 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7867 || cu
->language
== language_pascal
)
7868 code
= TYPE_CODE_CHAR
;
7870 case DW_ATE_unsigned_char
:
7871 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7872 || cu
->language
== language_pascal
)
7873 code
= TYPE_CODE_CHAR
;
7874 type_flags
|= TYPE_FLAG_UNSIGNED
;
7877 /* We just treat this as an integer and then recognize the
7878 type by name elsewhere. */
7882 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7883 dwarf_type_encoding_name (encoding
));
7887 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7888 TYPE_NAME (type
) = name
;
7889 TYPE_TARGET_TYPE (type
) = target_type
;
7891 if (name
&& strcmp (name
, "char") == 0)
7892 TYPE_NOSIGN (type
) = 1;
7894 return set_die_type (die
, type
, cu
);
7897 /* Read the given DW_AT_subrange DIE. */
7899 static struct type
*
7900 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7902 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7903 struct type
*base_type
;
7904 struct type
*range_type
;
7905 struct attribute
*attr
;
7909 LONGEST negative_mask
;
7911 base_type
= die_type (die
, cu
);
7912 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7913 check_typedef (base_type
);
7915 /* The die_type call above may have already set the type for this DIE. */
7916 range_type
= get_die_type (die
, cu
);
7920 if (cu
->language
== language_fortran
)
7922 /* FORTRAN implies a lower bound of 1, if not given. */
7926 /* FIXME: For variable sized arrays either of these could be
7927 a variable rather than a constant value. We'll allow it,
7928 but we don't know how to handle it. */
7929 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7931 low
= dwarf2_get_attr_constant_value (attr
, 0);
7933 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7936 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7938 /* GCC encodes arrays with unspecified or dynamic length
7939 with a DW_FORM_block1 attribute or a reference attribute.
7940 FIXME: GDB does not yet know how to handle dynamic
7941 arrays properly, treat them as arrays with unspecified
7944 FIXME: jimb/2003-09-22: GDB does not really know
7945 how to handle arrays of unspecified length
7946 either; we just represent them as zero-length
7947 arrays. Choose an appropriate upper bound given
7948 the lower bound we've computed above. */
7952 high
= dwarf2_get_attr_constant_value (attr
, 1);
7956 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
7959 int count
= dwarf2_get_attr_constant_value (attr
, 1);
7960 high
= low
+ count
- 1;
7964 /* Dwarf-2 specifications explicitly allows to create subrange types
7965 without specifying a base type.
7966 In that case, the base type must be set to the type of
7967 the lower bound, upper bound or count, in that order, if any of these
7968 three attributes references an object that has a type.
7969 If no base type is found, the Dwarf-2 specifications say that
7970 a signed integer type of size equal to the size of an address should
7972 For the following C code: `extern char gdb_int [];'
7973 GCC produces an empty range DIE.
7974 FIXME: muller/2010-05-28: Possible references to object for low bound,
7975 high bound or count are not yet handled by this code.
7977 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
7979 struct objfile
*objfile
= cu
->objfile
;
7980 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7981 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
7982 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
7984 /* Test "int", "long int", and "long long int" objfile types,
7985 and select the first one having a size above or equal to the
7986 architecture address size. */
7987 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7988 base_type
= int_type
;
7991 int_type
= objfile_type (objfile
)->builtin_long
;
7992 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7993 base_type
= int_type
;
7996 int_type
= objfile_type (objfile
)->builtin_long_long
;
7997 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7998 base_type
= int_type
;
8004 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8005 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8006 low
|= negative_mask
;
8007 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8008 high
|= negative_mask
;
8010 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8012 /* Mark arrays with dynamic length at least as an array of unspecified
8013 length. GDB could check the boundary but before it gets implemented at
8014 least allow accessing the array elements. */
8015 if (attr
&& attr
->form
== DW_FORM_block1
)
8016 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8018 name
= dwarf2_name (die
, cu
);
8020 TYPE_NAME (range_type
) = name
;
8022 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8024 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8026 set_die_type (die
, range_type
, cu
);
8028 /* set_die_type should be already done. */
8029 set_descriptive_type (range_type
, die
, cu
);
8034 static struct type
*
8035 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8039 /* For now, we only support the C meaning of an unspecified type: void. */
8041 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8042 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8044 return set_die_type (die
, type
, cu
);
8047 /* Trivial hash function for die_info: the hash value of a DIE
8048 is its offset in .debug_info for this objfile. */
8051 die_hash (const void *item
)
8053 const struct die_info
*die
= item
;
8058 /* Trivial comparison function for die_info structures: two DIEs
8059 are equal if they have the same offset. */
8062 die_eq (const void *item_lhs
, const void *item_rhs
)
8064 const struct die_info
*die_lhs
= item_lhs
;
8065 const struct die_info
*die_rhs
= item_rhs
;
8067 return die_lhs
->offset
== die_rhs
->offset
;
8070 /* Read a whole compilation unit into a linked list of dies. */
8072 static struct die_info
*
8073 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8075 struct die_reader_specs reader_specs
;
8076 int read_abbrevs
= 0;
8077 struct cleanup
*back_to
= NULL
;
8078 struct die_info
*die
;
8080 if (cu
->dwarf2_abbrevs
== NULL
)
8082 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8083 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8087 gdb_assert (cu
->die_hash
== NULL
);
8089 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8093 &cu
->comp_unit_obstack
,
8094 hashtab_obstack_allocate
,
8095 dummy_obstack_deallocate
);
8097 init_cu_die_reader (&reader_specs
, cu
);
8099 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8102 do_cleanups (back_to
);
8107 /* Main entry point for reading a DIE and all children.
8108 Read the DIE and dump it if requested. */
8110 static struct die_info
*
8111 read_die_and_children (const struct die_reader_specs
*reader
,
8113 gdb_byte
**new_info_ptr
,
8114 struct die_info
*parent
)
8116 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8117 new_info_ptr
, parent
);
8119 if (dwarf2_die_debug
)
8121 fprintf_unfiltered (gdb_stdlog
,
8122 "\nRead die from %s of %s:\n",
8123 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8125 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8127 : "unknown section",
8128 reader
->abfd
->filename
);
8129 dump_die (result
, dwarf2_die_debug
);
8135 /* Read a single die and all its descendents. Set the die's sibling
8136 field to NULL; set other fields in the die correctly, and set all
8137 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8138 location of the info_ptr after reading all of those dies. PARENT
8139 is the parent of the die in question. */
8141 static struct die_info
*
8142 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8144 gdb_byte
**new_info_ptr
,
8145 struct die_info
*parent
)
8147 struct die_info
*die
;
8151 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8154 *new_info_ptr
= cur_ptr
;
8157 store_in_ref_table (die
, reader
->cu
);
8160 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8164 *new_info_ptr
= cur_ptr
;
8167 die
->sibling
= NULL
;
8168 die
->parent
= parent
;
8172 /* Read a die, all of its descendents, and all of its siblings; set
8173 all of the fields of all of the dies correctly. Arguments are as
8174 in read_die_and_children. */
8176 static struct die_info
*
8177 read_die_and_siblings (const struct die_reader_specs
*reader
,
8179 gdb_byte
**new_info_ptr
,
8180 struct die_info
*parent
)
8182 struct die_info
*first_die
, *last_sibling
;
8186 first_die
= last_sibling
= NULL
;
8190 struct die_info
*die
8191 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8195 *new_info_ptr
= cur_ptr
;
8202 last_sibling
->sibling
= die
;
8208 /* Read the die from the .debug_info section buffer. Set DIEP to
8209 point to a newly allocated die with its information, except for its
8210 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8211 whether the die has children or not. */
8214 read_full_die (const struct die_reader_specs
*reader
,
8215 struct die_info
**diep
, gdb_byte
*info_ptr
,
8218 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8219 struct abbrev_info
*abbrev
;
8220 struct die_info
*die
;
8221 struct dwarf2_cu
*cu
= reader
->cu
;
8222 bfd
*abfd
= reader
->abfd
;
8224 offset
= info_ptr
- reader
->buffer
;
8225 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8226 info_ptr
+= bytes_read
;
8234 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8236 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8238 bfd_get_filename (abfd
));
8240 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8241 die
->offset
= offset
;
8242 die
->tag
= abbrev
->tag
;
8243 die
->abbrev
= abbrev_number
;
8245 die
->num_attrs
= abbrev
->num_attrs
;
8247 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8248 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8249 abfd
, info_ptr
, cu
);
8252 *has_children
= abbrev
->has_children
;
8256 /* In DWARF version 2, the description of the debugging information is
8257 stored in a separate .debug_abbrev section. Before we read any
8258 dies from a section we read in all abbreviations and install them
8259 in a hash table. This function also sets flags in CU describing
8260 the data found in the abbrev table. */
8263 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8265 struct comp_unit_head
*cu_header
= &cu
->header
;
8266 gdb_byte
*abbrev_ptr
;
8267 struct abbrev_info
*cur_abbrev
;
8268 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8269 unsigned int abbrev_form
, hash_number
;
8270 struct attr_abbrev
*cur_attrs
;
8271 unsigned int allocated_attrs
;
8273 /* Initialize dwarf2 abbrevs */
8274 obstack_init (&cu
->abbrev_obstack
);
8275 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8277 * sizeof (struct abbrev_info
*)));
8278 memset (cu
->dwarf2_abbrevs
, 0,
8279 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8281 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8282 &dwarf2_per_objfile
->abbrev
);
8283 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8284 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8285 abbrev_ptr
+= bytes_read
;
8287 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8288 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8290 /* loop until we reach an abbrev number of 0 */
8291 while (abbrev_number
)
8293 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8295 /* read in abbrev header */
8296 cur_abbrev
->number
= abbrev_number
;
8297 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8298 abbrev_ptr
+= bytes_read
;
8299 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8302 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8303 cu
->has_namespace_info
= 1;
8305 /* now read in declarations */
8306 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8307 abbrev_ptr
+= bytes_read
;
8308 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8309 abbrev_ptr
+= bytes_read
;
8312 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8314 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8316 = xrealloc (cur_attrs
, (allocated_attrs
8317 * sizeof (struct attr_abbrev
)));
8320 /* Record whether this compilation unit might have
8321 inter-compilation-unit references. If we don't know what form
8322 this attribute will have, then it might potentially be a
8323 DW_FORM_ref_addr, so we conservatively expect inter-CU
8326 if (abbrev_form
== DW_FORM_ref_addr
8327 || abbrev_form
== DW_FORM_indirect
)
8328 cu
->has_form_ref_addr
= 1;
8330 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8331 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8332 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8333 abbrev_ptr
+= bytes_read
;
8334 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8335 abbrev_ptr
+= bytes_read
;
8338 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8339 (cur_abbrev
->num_attrs
8340 * sizeof (struct attr_abbrev
)));
8341 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8342 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8344 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8345 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8346 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8348 /* Get next abbreviation.
8349 Under Irix6 the abbreviations for a compilation unit are not
8350 always properly terminated with an abbrev number of 0.
8351 Exit loop if we encounter an abbreviation which we have
8352 already read (which means we are about to read the abbreviations
8353 for the next compile unit) or if the end of the abbreviation
8354 table is reached. */
8355 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8356 >= dwarf2_per_objfile
->abbrev
.size
)
8358 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8359 abbrev_ptr
+= bytes_read
;
8360 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8367 /* Release the memory used by the abbrev table for a compilation unit. */
8370 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8372 struct dwarf2_cu
*cu
= ptr_to_cu
;
8374 obstack_free (&cu
->abbrev_obstack
, NULL
);
8375 cu
->dwarf2_abbrevs
= NULL
;
8378 /* Lookup an abbrev_info structure in the abbrev hash table. */
8380 static struct abbrev_info
*
8381 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8383 unsigned int hash_number
;
8384 struct abbrev_info
*abbrev
;
8386 hash_number
= number
% ABBREV_HASH_SIZE
;
8387 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8391 if (abbrev
->number
== number
)
8394 abbrev
= abbrev
->next
;
8399 /* Returns nonzero if TAG represents a type that we might generate a partial
8403 is_type_tag_for_partial (int tag
)
8408 /* Some types that would be reasonable to generate partial symbols for,
8409 that we don't at present. */
8410 case DW_TAG_array_type
:
8411 case DW_TAG_file_type
:
8412 case DW_TAG_ptr_to_member_type
:
8413 case DW_TAG_set_type
:
8414 case DW_TAG_string_type
:
8415 case DW_TAG_subroutine_type
:
8417 case DW_TAG_base_type
:
8418 case DW_TAG_class_type
:
8419 case DW_TAG_interface_type
:
8420 case DW_TAG_enumeration_type
:
8421 case DW_TAG_structure_type
:
8422 case DW_TAG_subrange_type
:
8423 case DW_TAG_typedef
:
8424 case DW_TAG_union_type
:
8431 /* Load all DIEs that are interesting for partial symbols into memory. */
8433 static struct partial_die_info
*
8434 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8435 int building_psymtab
, struct dwarf2_cu
*cu
)
8437 struct partial_die_info
*part_die
;
8438 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8439 struct abbrev_info
*abbrev
;
8440 unsigned int bytes_read
;
8441 unsigned int load_all
= 0;
8443 int nesting_level
= 1;
8448 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8452 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8456 &cu
->comp_unit_obstack
,
8457 hashtab_obstack_allocate
,
8458 dummy_obstack_deallocate
);
8460 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8461 sizeof (struct partial_die_info
));
8465 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8467 /* A NULL abbrev means the end of a series of children. */
8470 if (--nesting_level
== 0)
8472 /* PART_DIE was probably the last thing allocated on the
8473 comp_unit_obstack, so we could call obstack_free
8474 here. We don't do that because the waste is small,
8475 and will be cleaned up when we're done with this
8476 compilation unit. This way, we're also more robust
8477 against other users of the comp_unit_obstack. */
8480 info_ptr
+= bytes_read
;
8481 last_die
= parent_die
;
8482 parent_die
= parent_die
->die_parent
;
8486 /* Check for template arguments. We never save these; if
8487 they're seen, we just mark the parent, and go on our way. */
8488 if (parent_die
!= NULL
8489 && cu
->language
== language_cplus
8490 && (abbrev
->tag
== DW_TAG_template_type_param
8491 || abbrev
->tag
== DW_TAG_template_value_param
))
8493 parent_die
->has_template_arguments
= 1;
8497 /* We don't need a partial DIE for the template argument. */
8498 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8504 /* We only recurse into subprograms looking for template arguments.
8505 Skip their other children. */
8507 && cu
->language
== language_cplus
8508 && parent_die
!= NULL
8509 && parent_die
->tag
== DW_TAG_subprogram
)
8511 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8515 /* Check whether this DIE is interesting enough to save. Normally
8516 we would not be interested in members here, but there may be
8517 later variables referencing them via DW_AT_specification (for
8520 && !is_type_tag_for_partial (abbrev
->tag
)
8521 && abbrev
->tag
!= DW_TAG_enumerator
8522 && abbrev
->tag
!= DW_TAG_subprogram
8523 && abbrev
->tag
!= DW_TAG_lexical_block
8524 && abbrev
->tag
!= DW_TAG_variable
8525 && abbrev
->tag
!= DW_TAG_namespace
8526 && abbrev
->tag
!= DW_TAG_module
8527 && abbrev
->tag
!= DW_TAG_member
)
8529 /* Otherwise we skip to the next sibling, if any. */
8530 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8534 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8535 buffer
, info_ptr
, cu
);
8537 /* This two-pass algorithm for processing partial symbols has a
8538 high cost in cache pressure. Thus, handle some simple cases
8539 here which cover the majority of C partial symbols. DIEs
8540 which neither have specification tags in them, nor could have
8541 specification tags elsewhere pointing at them, can simply be
8542 processed and discarded.
8544 This segment is also optional; scan_partial_symbols and
8545 add_partial_symbol will handle these DIEs if we chain
8546 them in normally. When compilers which do not emit large
8547 quantities of duplicate debug information are more common,
8548 this code can probably be removed. */
8550 /* Any complete simple types at the top level (pretty much all
8551 of them, for a language without namespaces), can be processed
8553 if (parent_die
== NULL
8554 && part_die
->has_specification
== 0
8555 && part_die
->is_declaration
== 0
8556 && (part_die
->tag
== DW_TAG_typedef
8557 || part_die
->tag
== DW_TAG_base_type
8558 || part_die
->tag
== DW_TAG_subrange_type
))
8560 if (building_psymtab
&& part_die
->name
!= NULL
)
8561 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8562 VAR_DOMAIN
, LOC_TYPEDEF
,
8563 &cu
->objfile
->static_psymbols
,
8564 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8565 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8569 /* If we're at the second level, and we're an enumerator, and
8570 our parent has no specification (meaning possibly lives in a
8571 namespace elsewhere), then we can add the partial symbol now
8572 instead of queueing it. */
8573 if (part_die
->tag
== DW_TAG_enumerator
8574 && parent_die
!= NULL
8575 && parent_die
->die_parent
== NULL
8576 && parent_die
->tag
== DW_TAG_enumeration_type
8577 && parent_die
->has_specification
== 0)
8579 if (part_die
->name
== NULL
)
8580 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8581 else if (building_psymtab
)
8582 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8583 VAR_DOMAIN
, LOC_CONST
,
8584 (cu
->language
== language_cplus
8585 || cu
->language
== language_java
)
8586 ? &cu
->objfile
->global_psymbols
8587 : &cu
->objfile
->static_psymbols
,
8588 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8590 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8594 /* We'll save this DIE so link it in. */
8595 part_die
->die_parent
= parent_die
;
8596 part_die
->die_sibling
= NULL
;
8597 part_die
->die_child
= NULL
;
8599 if (last_die
&& last_die
== parent_die
)
8600 last_die
->die_child
= part_die
;
8602 last_die
->die_sibling
= part_die
;
8604 last_die
= part_die
;
8606 if (first_die
== NULL
)
8607 first_die
= part_die
;
8609 /* Maybe add the DIE to the hash table. Not all DIEs that we
8610 find interesting need to be in the hash table, because we
8611 also have the parent/sibling/child chains; only those that we
8612 might refer to by offset later during partial symbol reading.
8614 For now this means things that might have be the target of a
8615 DW_AT_specification, DW_AT_abstract_origin, or
8616 DW_AT_extension. DW_AT_extension will refer only to
8617 namespaces; DW_AT_abstract_origin refers to functions (and
8618 many things under the function DIE, but we do not recurse
8619 into function DIEs during partial symbol reading) and
8620 possibly variables as well; DW_AT_specification refers to
8621 declarations. Declarations ought to have the DW_AT_declaration
8622 flag. It happens that GCC forgets to put it in sometimes, but
8623 only for functions, not for types.
8625 Adding more things than necessary to the hash table is harmless
8626 except for the performance cost. Adding too few will result in
8627 wasted time in find_partial_die, when we reread the compilation
8628 unit with load_all_dies set. */
8631 || abbrev
->tag
== DW_TAG_subprogram
8632 || abbrev
->tag
== DW_TAG_variable
8633 || abbrev
->tag
== DW_TAG_namespace
8634 || part_die
->is_declaration
)
8638 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8639 part_die
->offset
, INSERT
);
8643 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8644 sizeof (struct partial_die_info
));
8646 /* For some DIEs we want to follow their children (if any). For C
8647 we have no reason to follow the children of structures; for other
8648 languages we have to, so that we can get at method physnames
8649 to infer fully qualified class names, for DW_AT_specification,
8650 and for C++ template arguments. For C++, we also look one level
8651 inside functions to find template arguments (if the name of the
8652 function does not already contain the template arguments).
8654 For Ada, we need to scan the children of subprograms and lexical
8655 blocks as well because Ada allows the definition of nested
8656 entities that could be interesting for the debugger, such as
8657 nested subprograms for instance. */
8658 if (last_die
->has_children
8660 || last_die
->tag
== DW_TAG_namespace
8661 || last_die
->tag
== DW_TAG_module
8662 || last_die
->tag
== DW_TAG_enumeration_type
8663 || (cu
->language
== language_cplus
8664 && last_die
->tag
== DW_TAG_subprogram
8665 && (last_die
->name
== NULL
8666 || strchr (last_die
->name
, '<') == NULL
))
8667 || (cu
->language
!= language_c
8668 && (last_die
->tag
== DW_TAG_class_type
8669 || last_die
->tag
== DW_TAG_interface_type
8670 || last_die
->tag
== DW_TAG_structure_type
8671 || last_die
->tag
== DW_TAG_union_type
))
8672 || (cu
->language
== language_ada
8673 && (last_die
->tag
== DW_TAG_subprogram
8674 || last_die
->tag
== DW_TAG_lexical_block
))))
8677 parent_die
= last_die
;
8681 /* Otherwise we skip to the next sibling, if any. */
8682 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8684 /* Back to the top, do it again. */
8688 /* Read a minimal amount of information into the minimal die structure. */
8691 read_partial_die (struct partial_die_info
*part_die
,
8692 struct abbrev_info
*abbrev
,
8693 unsigned int abbrev_len
, bfd
*abfd
,
8694 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8695 struct dwarf2_cu
*cu
)
8698 struct attribute attr
;
8699 int has_low_pc_attr
= 0;
8700 int has_high_pc_attr
= 0;
8702 memset (part_die
, 0, sizeof (struct partial_die_info
));
8704 part_die
->offset
= info_ptr
- buffer
;
8706 info_ptr
+= abbrev_len
;
8711 part_die
->tag
= abbrev
->tag
;
8712 part_die
->has_children
= abbrev
->has_children
;
8714 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8716 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8718 /* Store the data if it is of an attribute we want to keep in a
8719 partial symbol table. */
8723 switch (part_die
->tag
)
8725 case DW_TAG_compile_unit
:
8726 case DW_TAG_type_unit
:
8727 /* Compilation units have a DW_AT_name that is a filename, not
8728 a source language identifier. */
8729 case DW_TAG_enumeration_type
:
8730 case DW_TAG_enumerator
:
8731 /* These tags always have simple identifiers already; no need
8732 to canonicalize them. */
8733 part_die
->name
= DW_STRING (&attr
);
8737 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8738 &cu
->objfile
->objfile_obstack
);
8742 case DW_AT_linkage_name
:
8743 case DW_AT_MIPS_linkage_name
:
8744 /* Note that both forms of linkage name might appear. We
8745 assume they will be the same, and we only store the last
8747 if (cu
->language
== language_ada
)
8748 part_die
->name
= DW_STRING (&attr
);
8751 has_low_pc_attr
= 1;
8752 part_die
->lowpc
= DW_ADDR (&attr
);
8755 has_high_pc_attr
= 1;
8756 part_die
->highpc
= DW_ADDR (&attr
);
8758 case DW_AT_location
:
8759 /* Support the .debug_loc offsets */
8760 if (attr_form_is_block (&attr
))
8762 part_die
->locdesc
= DW_BLOCK (&attr
);
8764 else if (attr_form_is_section_offset (&attr
))
8766 dwarf2_complex_location_expr_complaint ();
8770 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8771 "partial symbol information");
8774 case DW_AT_external
:
8775 part_die
->is_external
= DW_UNSND (&attr
);
8777 case DW_AT_declaration
:
8778 part_die
->is_declaration
= DW_UNSND (&attr
);
8781 part_die
->has_type
= 1;
8783 case DW_AT_abstract_origin
:
8784 case DW_AT_specification
:
8785 case DW_AT_extension
:
8786 part_die
->has_specification
= 1;
8787 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8790 /* Ignore absolute siblings, they might point outside of
8791 the current compile unit. */
8792 if (attr
.form
== DW_FORM_ref_addr
)
8793 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8795 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8797 case DW_AT_byte_size
:
8798 part_die
->has_byte_size
= 1;
8800 case DW_AT_calling_convention
:
8801 /* DWARF doesn't provide a way to identify a program's source-level
8802 entry point. DW_AT_calling_convention attributes are only meant
8803 to describe functions' calling conventions.
8805 However, because it's a necessary piece of information in
8806 Fortran, and because DW_CC_program is the only piece of debugging
8807 information whose definition refers to a 'main program' at all,
8808 several compilers have begun marking Fortran main programs with
8809 DW_CC_program --- even when those functions use the standard
8810 calling conventions.
8812 So until DWARF specifies a way to provide this information and
8813 compilers pick up the new representation, we'll support this
8815 if (DW_UNSND (&attr
) == DW_CC_program
8816 && cu
->language
== language_fortran
)
8817 set_main_name (part_die
->name
);
8824 /* When using the GNU linker, .gnu.linkonce. sections are used to
8825 eliminate duplicate copies of functions and vtables and such.
8826 The linker will arbitrarily choose one and discard the others.
8827 The AT_*_pc values for such functions refer to local labels in
8828 these sections. If the section from that file was discarded, the
8829 labels are not in the output, so the relocs get a value of 0.
8830 If this is a discarded function, mark the pc bounds as invalid,
8831 so that GDB will ignore it. */
8832 if (has_low_pc_attr
&& has_high_pc_attr
8833 && part_die
->lowpc
< part_die
->highpc
8834 && (part_die
->lowpc
!= 0
8835 || dwarf2_per_objfile
->has_section_at_zero
))
8836 part_die
->has_pc_info
= 1;
8841 /* Find a cached partial DIE at OFFSET in CU. */
8843 static struct partial_die_info
*
8844 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8846 struct partial_die_info
*lookup_die
= NULL
;
8847 struct partial_die_info part_die
;
8849 part_die
.offset
= offset
;
8850 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8855 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8856 except in the case of .debug_types DIEs which do not reference
8857 outside their CU (they do however referencing other types via
8860 static struct partial_die_info
*
8861 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8863 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8864 struct partial_die_info
*pd
= NULL
;
8866 if (cu
->per_cu
->from_debug_types
)
8868 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8874 if (offset_in_cu_p (&cu
->header
, offset
))
8876 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8881 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8883 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8884 load_partial_comp_unit (per_cu
, cu
->objfile
);
8886 per_cu
->cu
->last_used
= 0;
8887 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8889 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8891 struct cleanup
*back_to
;
8892 struct partial_die_info comp_unit_die
;
8893 struct abbrev_info
*abbrev
;
8894 unsigned int bytes_read
;
8897 per_cu
->load_all_dies
= 1;
8899 /* Re-read the DIEs. */
8900 back_to
= make_cleanup (null_cleanup
, 0);
8901 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8903 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8904 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8906 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8907 + per_cu
->cu
->header
.offset
8908 + per_cu
->cu
->header
.first_die_offset
);
8909 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8910 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8911 per_cu
->cu
->objfile
->obfd
,
8912 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8914 if (comp_unit_die
.has_children
)
8915 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8916 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8918 do_cleanups (back_to
);
8920 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8926 internal_error (__FILE__
, __LINE__
,
8927 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8928 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8932 /* Adjust PART_DIE before generating a symbol for it. This function
8933 may set the is_external flag or change the DIE's name. */
8936 fixup_partial_die (struct partial_die_info
*part_die
,
8937 struct dwarf2_cu
*cu
)
8939 /* If we found a reference attribute and the DIE has no name, try
8940 to find a name in the referred to DIE. */
8942 if (part_die
->name
== NULL
&& part_die
->has_specification
)
8944 struct partial_die_info
*spec_die
;
8946 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
8948 fixup_partial_die (spec_die
, cu
);
8952 part_die
->name
= spec_die
->name
;
8954 /* Copy DW_AT_external attribute if it is set. */
8955 if (spec_die
->is_external
)
8956 part_die
->is_external
= spec_die
->is_external
;
8960 /* Set default names for some unnamed DIEs. */
8961 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
8962 || part_die
->tag
== DW_TAG_class_type
))
8963 part_die
->name
= "(anonymous class)";
8965 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
8966 part_die
->name
= "(anonymous namespace)";
8968 if (part_die
->tag
== DW_TAG_structure_type
8969 || part_die
->tag
== DW_TAG_class_type
8970 || part_die
->tag
== DW_TAG_union_type
)
8971 guess_structure_name (part_die
, cu
);
8974 /* Read an attribute value described by an attribute form. */
8977 read_attribute_value (struct attribute
*attr
, unsigned form
,
8978 bfd
*abfd
, gdb_byte
*info_ptr
,
8979 struct dwarf2_cu
*cu
)
8981 struct comp_unit_head
*cu_header
= &cu
->header
;
8982 unsigned int bytes_read
;
8983 struct dwarf_block
*blk
;
8988 case DW_FORM_ref_addr
:
8989 if (cu
->header
.version
== 2)
8990 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8992 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8993 info_ptr
+= bytes_read
;
8996 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8997 info_ptr
+= bytes_read
;
8999 case DW_FORM_block2
:
9000 blk
= dwarf_alloc_block (cu
);
9001 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9003 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9004 info_ptr
+= blk
->size
;
9005 DW_BLOCK (attr
) = blk
;
9007 case DW_FORM_block4
:
9008 blk
= dwarf_alloc_block (cu
);
9009 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9011 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9012 info_ptr
+= blk
->size
;
9013 DW_BLOCK (attr
) = blk
;
9016 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9020 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9024 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9027 case DW_FORM_sec_offset
:
9028 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9029 info_ptr
+= bytes_read
;
9031 case DW_FORM_string
:
9032 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9033 DW_STRING_IS_CANONICAL (attr
) = 0;
9034 info_ptr
+= bytes_read
;
9037 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9039 DW_STRING_IS_CANONICAL (attr
) = 0;
9040 info_ptr
+= bytes_read
;
9042 case DW_FORM_exprloc
:
9044 blk
= dwarf_alloc_block (cu
);
9045 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9046 info_ptr
+= bytes_read
;
9047 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9048 info_ptr
+= blk
->size
;
9049 DW_BLOCK (attr
) = blk
;
9051 case DW_FORM_block1
:
9052 blk
= dwarf_alloc_block (cu
);
9053 blk
->size
= read_1_byte (abfd
, info_ptr
);
9055 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9056 info_ptr
+= blk
->size
;
9057 DW_BLOCK (attr
) = blk
;
9060 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9064 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9067 case DW_FORM_flag_present
:
9068 DW_UNSND (attr
) = 1;
9071 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9072 info_ptr
+= bytes_read
;
9075 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9076 info_ptr
+= bytes_read
;
9079 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9083 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9087 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9091 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9095 /* Convert the signature to something we can record in DW_UNSND
9097 NOTE: This is NULL if the type wasn't found. */
9098 DW_SIGNATURED_TYPE (attr
) =
9099 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9102 case DW_FORM_ref_udata
:
9103 DW_ADDR (attr
) = (cu
->header
.offset
9104 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9105 info_ptr
+= bytes_read
;
9107 case DW_FORM_indirect
:
9108 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9109 info_ptr
+= bytes_read
;
9110 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9113 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9114 dwarf_form_name (form
),
9115 bfd_get_filename (abfd
));
9118 /* We have seen instances where the compiler tried to emit a byte
9119 size attribute of -1 which ended up being encoded as an unsigned
9120 0xffffffff. Although 0xffffffff is technically a valid size value,
9121 an object of this size seems pretty unlikely so we can relatively
9122 safely treat these cases as if the size attribute was invalid and
9123 treat them as zero by default. */
9124 if (attr
->name
== DW_AT_byte_size
9125 && form
== DW_FORM_data4
9126 && DW_UNSND (attr
) >= 0xffffffff)
9129 (&symfile_complaints
,
9130 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9131 hex_string (DW_UNSND (attr
)));
9132 DW_UNSND (attr
) = 0;
9138 /* Read an attribute described by an abbreviated attribute. */
9141 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9142 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9144 attr
->name
= abbrev
->name
;
9145 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9148 /* read dwarf information from a buffer */
9151 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9153 return bfd_get_8 (abfd
, buf
);
9157 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9159 return bfd_get_signed_8 (abfd
, buf
);
9163 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9165 return bfd_get_16 (abfd
, buf
);
9169 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9171 return bfd_get_signed_16 (abfd
, buf
);
9175 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9177 return bfd_get_32 (abfd
, buf
);
9181 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9183 return bfd_get_signed_32 (abfd
, buf
);
9187 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9189 return bfd_get_64 (abfd
, buf
);
9193 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9194 unsigned int *bytes_read
)
9196 struct comp_unit_head
*cu_header
= &cu
->header
;
9197 CORE_ADDR retval
= 0;
9199 if (cu_header
->signed_addr_p
)
9201 switch (cu_header
->addr_size
)
9204 retval
= bfd_get_signed_16 (abfd
, buf
);
9207 retval
= bfd_get_signed_32 (abfd
, buf
);
9210 retval
= bfd_get_signed_64 (abfd
, buf
);
9213 internal_error (__FILE__
, __LINE__
,
9214 _("read_address: bad switch, signed [in module %s]"),
9215 bfd_get_filename (abfd
));
9220 switch (cu_header
->addr_size
)
9223 retval
= bfd_get_16 (abfd
, buf
);
9226 retval
= bfd_get_32 (abfd
, buf
);
9229 retval
= bfd_get_64 (abfd
, buf
);
9232 internal_error (__FILE__
, __LINE__
,
9233 _("read_address: bad switch, unsigned [in module %s]"),
9234 bfd_get_filename (abfd
));
9238 *bytes_read
= cu_header
->addr_size
;
9242 /* Read the initial length from a section. The (draft) DWARF 3
9243 specification allows the initial length to take up either 4 bytes
9244 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9245 bytes describe the length and all offsets will be 8 bytes in length
9248 An older, non-standard 64-bit format is also handled by this
9249 function. The older format in question stores the initial length
9250 as an 8-byte quantity without an escape value. Lengths greater
9251 than 2^32 aren't very common which means that the initial 4 bytes
9252 is almost always zero. Since a length value of zero doesn't make
9253 sense for the 32-bit format, this initial zero can be considered to
9254 be an escape value which indicates the presence of the older 64-bit
9255 format. As written, the code can't detect (old format) lengths
9256 greater than 4GB. If it becomes necessary to handle lengths
9257 somewhat larger than 4GB, we could allow other small values (such
9258 as the non-sensical values of 1, 2, and 3) to also be used as
9259 escape values indicating the presence of the old format.
9261 The value returned via bytes_read should be used to increment the
9262 relevant pointer after calling read_initial_length().
9264 [ Note: read_initial_length() and read_offset() are based on the
9265 document entitled "DWARF Debugging Information Format", revision
9266 3, draft 8, dated November 19, 2001. This document was obtained
9269 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9271 This document is only a draft and is subject to change. (So beware.)
9273 Details regarding the older, non-standard 64-bit format were
9274 determined empirically by examining 64-bit ELF files produced by
9275 the SGI toolchain on an IRIX 6.5 machine.
9277 - Kevin, July 16, 2002
9281 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9283 LONGEST length
= bfd_get_32 (abfd
, buf
);
9285 if (length
== 0xffffffff)
9287 length
= bfd_get_64 (abfd
, buf
+ 4);
9290 else if (length
== 0)
9292 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9293 length
= bfd_get_64 (abfd
, buf
);
9304 /* Cover function for read_initial_length.
9305 Returns the length of the object at BUF, and stores the size of the
9306 initial length in *BYTES_READ and stores the size that offsets will be in
9308 If the initial length size is not equivalent to that specified in
9309 CU_HEADER then issue a complaint.
9310 This is useful when reading non-comp-unit headers. */
9313 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9314 const struct comp_unit_head
*cu_header
,
9315 unsigned int *bytes_read
,
9316 unsigned int *offset_size
)
9318 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9320 gdb_assert (cu_header
->initial_length_size
== 4
9321 || cu_header
->initial_length_size
== 8
9322 || cu_header
->initial_length_size
== 12);
9324 if (cu_header
->initial_length_size
!= *bytes_read
)
9325 complaint (&symfile_complaints
,
9326 _("intermixed 32-bit and 64-bit DWARF sections"));
9328 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9332 /* Read an offset from the data stream. The size of the offset is
9333 given by cu_header->offset_size. */
9336 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9337 unsigned int *bytes_read
)
9339 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9341 *bytes_read
= cu_header
->offset_size
;
9345 /* Read an offset from the data stream. */
9348 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9352 switch (offset_size
)
9355 retval
= bfd_get_32 (abfd
, buf
);
9358 retval
= bfd_get_64 (abfd
, buf
);
9361 internal_error (__FILE__
, __LINE__
,
9362 _("read_offset_1: bad switch [in module %s]"),
9363 bfd_get_filename (abfd
));
9370 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9372 /* If the size of a host char is 8 bits, we can return a pointer
9373 to the buffer, otherwise we have to copy the data to a buffer
9374 allocated on the temporary obstack. */
9375 gdb_assert (HOST_CHAR_BIT
== 8);
9380 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9382 /* If the size of a host char is 8 bits, we can return a pointer
9383 to the string, otherwise we have to copy the string to a buffer
9384 allocated on the temporary obstack. */
9385 gdb_assert (HOST_CHAR_BIT
== 8);
9388 *bytes_read_ptr
= 1;
9391 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9392 return (char *) buf
;
9396 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9397 const struct comp_unit_head
*cu_header
,
9398 unsigned int *bytes_read_ptr
)
9400 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9402 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9403 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9405 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9406 bfd_get_filename (abfd
));
9409 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9411 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9412 bfd_get_filename (abfd
));
9415 gdb_assert (HOST_CHAR_BIT
== 8);
9416 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9418 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9421 static unsigned long
9422 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9424 unsigned long result
;
9425 unsigned int num_read
;
9435 byte
= bfd_get_8 (abfd
, buf
);
9438 result
|= ((unsigned long)(byte
& 127) << shift
);
9439 if ((byte
& 128) == 0)
9445 *bytes_read_ptr
= num_read
;
9450 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9453 int i
, shift
, num_read
;
9462 byte
= bfd_get_8 (abfd
, buf
);
9465 result
|= ((long)(byte
& 127) << shift
);
9467 if ((byte
& 128) == 0)
9472 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9473 result
|= -(((long)1) << shift
);
9474 *bytes_read_ptr
= num_read
;
9478 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9481 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9487 byte
= bfd_get_8 (abfd
, buf
);
9489 if ((byte
& 128) == 0)
9495 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9502 cu
->language
= language_c
;
9504 case DW_LANG_C_plus_plus
:
9505 cu
->language
= language_cplus
;
9508 cu
->language
= language_d
;
9510 case DW_LANG_Fortran77
:
9511 case DW_LANG_Fortran90
:
9512 case DW_LANG_Fortran95
:
9513 cu
->language
= language_fortran
;
9515 case DW_LANG_Mips_Assembler
:
9516 cu
->language
= language_asm
;
9519 cu
->language
= language_java
;
9523 cu
->language
= language_ada
;
9525 case DW_LANG_Modula2
:
9526 cu
->language
= language_m2
;
9528 case DW_LANG_Pascal83
:
9529 cu
->language
= language_pascal
;
9532 cu
->language
= language_objc
;
9534 case DW_LANG_Cobol74
:
9535 case DW_LANG_Cobol85
:
9537 cu
->language
= language_minimal
;
9540 cu
->language_defn
= language_def (cu
->language
);
9543 /* Return the named attribute or NULL if not there. */
9545 static struct attribute
*
9546 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9549 struct attribute
*spec
= NULL
;
9551 for (i
= 0; i
< die
->num_attrs
; ++i
)
9553 if (die
->attrs
[i
].name
== name
)
9554 return &die
->attrs
[i
];
9555 if (die
->attrs
[i
].name
== DW_AT_specification
9556 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9557 spec
= &die
->attrs
[i
];
9562 die
= follow_die_ref (die
, spec
, &cu
);
9563 return dwarf2_attr (die
, name
, cu
);
9569 /* Return the named attribute or NULL if not there,
9570 but do not follow DW_AT_specification, etc.
9571 This is for use in contexts where we're reading .debug_types dies.
9572 Following DW_AT_specification, DW_AT_abstract_origin will take us
9573 back up the chain, and we want to go down. */
9575 static struct attribute
*
9576 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9577 struct dwarf2_cu
*cu
)
9581 for (i
= 0; i
< die
->num_attrs
; ++i
)
9582 if (die
->attrs
[i
].name
== name
)
9583 return &die
->attrs
[i
];
9588 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9589 and holds a non-zero value. This function should only be used for
9590 DW_FORM_flag or DW_FORM_flag_present attributes. */
9593 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9595 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9597 return (attr
&& DW_UNSND (attr
));
9601 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9603 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9604 which value is non-zero. However, we have to be careful with
9605 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9606 (via dwarf2_flag_true_p) follows this attribute. So we may
9607 end up accidently finding a declaration attribute that belongs
9608 to a different DIE referenced by the specification attribute,
9609 even though the given DIE does not have a declaration attribute. */
9610 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9611 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9614 /* Return the die giving the specification for DIE, if there is
9615 one. *SPEC_CU is the CU containing DIE on input, and the CU
9616 containing the return value on output. If there is no
9617 specification, but there is an abstract origin, that is
9620 static struct die_info
*
9621 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9623 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9626 if (spec_attr
== NULL
)
9627 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9629 if (spec_attr
== NULL
)
9632 return follow_die_ref (die
, spec_attr
, spec_cu
);
9635 /* Free the line_header structure *LH, and any arrays and strings it
9638 free_line_header (struct line_header
*lh
)
9640 if (lh
->standard_opcode_lengths
)
9641 xfree (lh
->standard_opcode_lengths
);
9643 /* Remember that all the lh->file_names[i].name pointers are
9644 pointers into debug_line_buffer, and don't need to be freed. */
9646 xfree (lh
->file_names
);
9648 /* Similarly for the include directory names. */
9649 if (lh
->include_dirs
)
9650 xfree (lh
->include_dirs
);
9656 /* Add an entry to LH's include directory table. */
9658 add_include_dir (struct line_header
*lh
, char *include_dir
)
9660 /* Grow the array if necessary. */
9661 if (lh
->include_dirs_size
== 0)
9663 lh
->include_dirs_size
= 1; /* for testing */
9664 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9665 * sizeof (*lh
->include_dirs
));
9667 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9669 lh
->include_dirs_size
*= 2;
9670 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9671 (lh
->include_dirs_size
9672 * sizeof (*lh
->include_dirs
)));
9675 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9679 /* Add an entry to LH's file name table. */
9681 add_file_name (struct line_header
*lh
,
9683 unsigned int dir_index
,
9684 unsigned int mod_time
,
9685 unsigned int length
)
9687 struct file_entry
*fe
;
9689 /* Grow the array if necessary. */
9690 if (lh
->file_names_size
== 0)
9692 lh
->file_names_size
= 1; /* for testing */
9693 lh
->file_names
= xmalloc (lh
->file_names_size
9694 * sizeof (*lh
->file_names
));
9696 else if (lh
->num_file_names
>= lh
->file_names_size
)
9698 lh
->file_names_size
*= 2;
9699 lh
->file_names
= xrealloc (lh
->file_names
,
9700 (lh
->file_names_size
9701 * sizeof (*lh
->file_names
)));
9704 fe
= &lh
->file_names
[lh
->num_file_names
++];
9706 fe
->dir_index
= dir_index
;
9707 fe
->mod_time
= mod_time
;
9708 fe
->length
= length
;
9714 /* Read the statement program header starting at OFFSET in
9715 .debug_line, according to the endianness of ABFD. Return a pointer
9716 to a struct line_header, allocated using xmalloc.
9718 NOTE: the strings in the include directory and file name tables of
9719 the returned object point into debug_line_buffer, and must not be
9721 static struct line_header
*
9722 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9723 struct dwarf2_cu
*cu
)
9725 struct cleanup
*back_to
;
9726 struct line_header
*lh
;
9728 unsigned int bytes_read
, offset_size
;
9730 char *cur_dir
, *cur_file
;
9732 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9733 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9735 complaint (&symfile_complaints
, _("missing .debug_line section"));
9739 /* Make sure that at least there's room for the total_length field.
9740 That could be 12 bytes long, but we're just going to fudge that. */
9741 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9743 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9747 lh
= xmalloc (sizeof (*lh
));
9748 memset (lh
, 0, sizeof (*lh
));
9749 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9752 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9754 /* Read in the header. */
9756 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9757 &bytes_read
, &offset_size
);
9758 line_ptr
+= bytes_read
;
9759 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9760 + dwarf2_per_objfile
->line
.size
))
9762 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9765 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9766 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9768 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9769 line_ptr
+= offset_size
;
9770 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9772 if (lh
->version
>= 4)
9774 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9778 lh
->maximum_ops_per_instruction
= 1;
9780 if (lh
->maximum_ops_per_instruction
== 0)
9782 lh
->maximum_ops_per_instruction
= 1;
9783 complaint (&symfile_complaints
,
9784 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9787 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9789 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9791 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9793 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9795 lh
->standard_opcode_lengths
9796 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9798 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9799 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9801 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9805 /* Read directory table. */
9806 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9808 line_ptr
+= bytes_read
;
9809 add_include_dir (lh
, cur_dir
);
9811 line_ptr
+= bytes_read
;
9813 /* Read file name table. */
9814 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9816 unsigned int dir_index
, mod_time
, length
;
9818 line_ptr
+= bytes_read
;
9819 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9820 line_ptr
+= bytes_read
;
9821 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9822 line_ptr
+= bytes_read
;
9823 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9824 line_ptr
+= bytes_read
;
9826 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9828 line_ptr
+= bytes_read
;
9829 lh
->statement_program_start
= line_ptr
;
9831 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9832 + dwarf2_per_objfile
->line
.size
))
9833 complaint (&symfile_complaints
,
9834 _("line number info header doesn't fit in `.debug_line' section"));
9836 discard_cleanups (back_to
);
9840 /* This function exists to work around a bug in certain compilers
9841 (particularly GCC 2.95), in which the first line number marker of a
9842 function does not show up until after the prologue, right before
9843 the second line number marker. This function shifts ADDRESS down
9844 to the beginning of the function if necessary, and is called on
9845 addresses passed to record_line. */
9848 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9850 struct function_range
*fn
;
9852 /* Find the function_range containing address. */
9857 cu
->cached_fn
= cu
->first_fn
;
9861 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9867 while (fn
&& fn
!= cu
->cached_fn
)
9868 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9878 if (address
!= fn
->lowpc
)
9879 complaint (&symfile_complaints
,
9880 _("misplaced first line number at 0x%lx for '%s'"),
9881 (unsigned long) address
, fn
->name
);
9886 /* Decode the Line Number Program (LNP) for the given line_header
9887 structure and CU. The actual information extracted and the type
9888 of structures created from the LNP depends on the value of PST.
9890 1. If PST is NULL, then this procedure uses the data from the program
9891 to create all necessary symbol tables, and their linetables.
9892 The compilation directory of the file is passed in COMP_DIR,
9893 and must not be NULL.
9895 2. If PST is not NULL, this procedure reads the program to determine
9896 the list of files included by the unit represented by PST, and
9897 builds all the associated partial symbol tables. In this case,
9898 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9899 is not used to compute the full name of the symtab, and therefore
9900 omitting it when building the partial symtab does not introduce
9901 the potential for inconsistency - a partial symtab and its associated
9902 symbtab having a different fullname -). */
9905 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
9906 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
9908 gdb_byte
*line_ptr
, *extended_end
;
9910 unsigned int bytes_read
, extended_len
;
9911 unsigned char op_code
, extended_op
, adj_opcode
;
9913 struct objfile
*objfile
= cu
->objfile
;
9914 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9915 const int decode_for_pst_p
= (pst
!= NULL
);
9916 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
9918 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9920 line_ptr
= lh
->statement_program_start
;
9921 line_end
= lh
->statement_program_end
;
9923 /* Read the statement sequences until there's nothing left. */
9924 while (line_ptr
< line_end
)
9926 /* state machine registers */
9927 CORE_ADDR address
= 0;
9928 unsigned int file
= 1;
9929 unsigned int line
= 1;
9930 unsigned int column
= 0;
9931 int is_stmt
= lh
->default_is_stmt
;
9932 int basic_block
= 0;
9933 int end_sequence
= 0;
9935 unsigned char op_index
= 0;
9937 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
9939 /* Start a subfile for the current file of the state machine. */
9940 /* lh->include_dirs and lh->file_names are 0-based, but the
9941 directory and file name numbers in the statement program
9943 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9947 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9949 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9952 /* Decode the table. */
9953 while (!end_sequence
)
9955 op_code
= read_1_byte (abfd
, line_ptr
);
9957 if (line_ptr
> line_end
)
9959 dwarf2_debug_line_missing_end_sequence_complaint ();
9963 if (op_code
>= lh
->opcode_base
)
9965 /* Special operand. */
9966 adj_opcode
= op_code
- lh
->opcode_base
;
9967 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
9968 / lh
->maximum_ops_per_instruction
)
9969 * lh
->minimum_instruction_length
);
9970 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
9971 % lh
->maximum_ops_per_instruction
);
9972 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
9973 if (lh
->num_file_names
< file
|| file
== 0)
9974 dwarf2_debug_line_missing_file_complaint ();
9975 /* For now we ignore lines not starting on an
9976 instruction boundary. */
9977 else if (op_index
== 0)
9979 lh
->file_names
[file
- 1].included_p
= 1;
9980 if (!decode_for_pst_p
&& is_stmt
)
9982 if (last_subfile
!= current_subfile
)
9984 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9986 record_line (last_subfile
, 0, addr
);
9987 last_subfile
= current_subfile
;
9989 /* Append row to matrix using current values. */
9990 addr
= check_cu_functions (address
, cu
);
9991 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9992 record_line (current_subfile
, line
, addr
);
9997 else switch (op_code
)
9999 case DW_LNS_extended_op
:
10000 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10001 line_ptr
+= bytes_read
;
10002 extended_end
= line_ptr
+ extended_len
;
10003 extended_op
= read_1_byte (abfd
, line_ptr
);
10005 switch (extended_op
)
10007 case DW_LNE_end_sequence
:
10010 case DW_LNE_set_address
:
10011 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10013 line_ptr
+= bytes_read
;
10014 address
+= baseaddr
;
10016 case DW_LNE_define_file
:
10019 unsigned int dir_index
, mod_time
, length
;
10021 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10022 line_ptr
+= bytes_read
;
10024 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10025 line_ptr
+= bytes_read
;
10027 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10028 line_ptr
+= bytes_read
;
10030 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10031 line_ptr
+= bytes_read
;
10032 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10035 case DW_LNE_set_discriminator
:
10036 /* The discriminator is not interesting to the debugger;
10038 line_ptr
= extended_end
;
10041 complaint (&symfile_complaints
,
10042 _("mangled .debug_line section"));
10045 /* Make sure that we parsed the extended op correctly. If e.g.
10046 we expected a different address size than the producer used,
10047 we may have read the wrong number of bytes. */
10048 if (line_ptr
!= extended_end
)
10050 complaint (&symfile_complaints
,
10051 _("mangled .debug_line section"));
10056 if (lh
->num_file_names
< file
|| file
== 0)
10057 dwarf2_debug_line_missing_file_complaint ();
10060 lh
->file_names
[file
- 1].included_p
= 1;
10061 if (!decode_for_pst_p
&& is_stmt
)
10063 if (last_subfile
!= current_subfile
)
10065 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10067 record_line (last_subfile
, 0, addr
);
10068 last_subfile
= current_subfile
;
10070 addr
= check_cu_functions (address
, cu
);
10071 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10072 record_line (current_subfile
, line
, addr
);
10077 case DW_LNS_advance_pc
:
10080 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10082 address
+= (((op_index
+ adjust
)
10083 / lh
->maximum_ops_per_instruction
)
10084 * lh
->minimum_instruction_length
);
10085 op_index
= ((op_index
+ adjust
)
10086 % lh
->maximum_ops_per_instruction
);
10087 line_ptr
+= bytes_read
;
10090 case DW_LNS_advance_line
:
10091 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10092 line_ptr
+= bytes_read
;
10094 case DW_LNS_set_file
:
10096 /* The arrays lh->include_dirs and lh->file_names are
10097 0-based, but the directory and file name numbers in
10098 the statement program are 1-based. */
10099 struct file_entry
*fe
;
10102 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10103 line_ptr
+= bytes_read
;
10104 if (lh
->num_file_names
< file
|| file
== 0)
10105 dwarf2_debug_line_missing_file_complaint ();
10108 fe
= &lh
->file_names
[file
- 1];
10110 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10111 if (!decode_for_pst_p
)
10113 last_subfile
= current_subfile
;
10114 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10119 case DW_LNS_set_column
:
10120 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10121 line_ptr
+= bytes_read
;
10123 case DW_LNS_negate_stmt
:
10124 is_stmt
= (!is_stmt
);
10126 case DW_LNS_set_basic_block
:
10129 /* Add to the address register of the state machine the
10130 address increment value corresponding to special opcode
10131 255. I.e., this value is scaled by the minimum
10132 instruction length since special opcode 255 would have
10133 scaled the the increment. */
10134 case DW_LNS_const_add_pc
:
10136 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10138 address
+= (((op_index
+ adjust
)
10139 / lh
->maximum_ops_per_instruction
)
10140 * lh
->minimum_instruction_length
);
10141 op_index
= ((op_index
+ adjust
)
10142 % lh
->maximum_ops_per_instruction
);
10145 case DW_LNS_fixed_advance_pc
:
10146 address
+= read_2_bytes (abfd
, line_ptr
);
10152 /* Unknown standard opcode, ignore it. */
10155 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10157 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10158 line_ptr
+= bytes_read
;
10163 if (lh
->num_file_names
< file
|| file
== 0)
10164 dwarf2_debug_line_missing_file_complaint ();
10167 lh
->file_names
[file
- 1].included_p
= 1;
10168 if (!decode_for_pst_p
)
10170 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10171 record_line (current_subfile
, 0, addr
);
10176 if (decode_for_pst_p
)
10180 /* Now that we're done scanning the Line Header Program, we can
10181 create the psymtab of each included file. */
10182 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10183 if (lh
->file_names
[file_index
].included_p
== 1)
10185 const struct file_entry fe
= lh
->file_names
[file_index
];
10186 char *include_name
= fe
.name
;
10187 char *dir_name
= NULL
;
10188 char *pst_filename
= pst
->filename
;
10191 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10193 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
10195 include_name
= concat (dir_name
, SLASH_STRING
,
10196 include_name
, (char *)NULL
);
10197 make_cleanup (xfree
, include_name
);
10200 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10202 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
10203 pst_filename
, (char *)NULL
);
10204 make_cleanup (xfree
, pst_filename
);
10207 if (strcmp (include_name
, pst_filename
) != 0)
10208 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10213 /* Make sure a symtab is created for every file, even files
10214 which contain only variables (i.e. no code with associated
10218 struct file_entry
*fe
;
10220 for (i
= 0; i
< lh
->num_file_names
; i
++)
10224 fe
= &lh
->file_names
[i
];
10226 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10227 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10229 /* Skip the main file; we don't need it, and it must be
10230 allocated last, so that it will show up before the
10231 non-primary symtabs in the objfile's symtab list. */
10232 if (current_subfile
== first_subfile
)
10235 if (current_subfile
->symtab
== NULL
)
10236 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10238 fe
->symtab
= current_subfile
->symtab
;
10243 /* Start a subfile for DWARF. FILENAME is the name of the file and
10244 DIRNAME the name of the source directory which contains FILENAME
10245 or NULL if not known. COMP_DIR is the compilation directory for the
10246 linetable's compilation unit or NULL if not known.
10247 This routine tries to keep line numbers from identical absolute and
10248 relative file names in a common subfile.
10250 Using the `list' example from the GDB testsuite, which resides in
10251 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10252 of /srcdir/list0.c yields the following debugging information for list0.c:
10254 DW_AT_name: /srcdir/list0.c
10255 DW_AT_comp_dir: /compdir
10256 files.files[0].name: list0.h
10257 files.files[0].dir: /srcdir
10258 files.files[1].name: list0.c
10259 files.files[1].dir: /srcdir
10261 The line number information for list0.c has to end up in a single
10262 subfile, so that `break /srcdir/list0.c:1' works as expected.
10263 start_subfile will ensure that this happens provided that we pass the
10264 concatenation of files.files[1].dir and files.files[1].name as the
10268 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
10272 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10273 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10274 second argument to start_subfile. To be consistent, we do the
10275 same here. In order not to lose the line information directory,
10276 we concatenate it to the filename when it makes sense.
10277 Note that the Dwarf3 standard says (speaking of filenames in line
10278 information): ``The directory index is ignored for file names
10279 that represent full path names''. Thus ignoring dirname in the
10280 `else' branch below isn't an issue. */
10282 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10283 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10285 fullname
= filename
;
10287 start_subfile (fullname
, comp_dir
);
10289 if (fullname
!= filename
)
10294 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10295 struct dwarf2_cu
*cu
)
10297 struct objfile
*objfile
= cu
->objfile
;
10298 struct comp_unit_head
*cu_header
= &cu
->header
;
10300 /* NOTE drow/2003-01-30: There used to be a comment and some special
10301 code here to turn a symbol with DW_AT_external and a
10302 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10303 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10304 with some versions of binutils) where shared libraries could have
10305 relocations against symbols in their debug information - the
10306 minimal symbol would have the right address, but the debug info
10307 would not. It's no longer necessary, because we will explicitly
10308 apply relocations when we read in the debug information now. */
10310 /* A DW_AT_location attribute with no contents indicates that a
10311 variable has been optimized away. */
10312 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10314 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10318 /* Handle one degenerate form of location expression specially, to
10319 preserve GDB's previous behavior when section offsets are
10320 specified. If this is just a DW_OP_addr then mark this symbol
10323 if (attr_form_is_block (attr
)
10324 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10325 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10327 unsigned int dummy
;
10329 SYMBOL_VALUE_ADDRESS (sym
) =
10330 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10331 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10332 fixup_symbol_section (sym
, objfile
);
10333 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10334 SYMBOL_SECTION (sym
));
10338 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10339 expression evaluator, and use LOC_COMPUTED only when necessary
10340 (i.e. when the value of a register or memory location is
10341 referenced, or a thread-local block, etc.). Then again, it might
10342 not be worthwhile. I'm assuming that it isn't unless performance
10343 or memory numbers show me otherwise. */
10345 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10346 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10349 /* Given a pointer to a DWARF information entry, figure out if we need
10350 to make a symbol table entry for it, and if so, create a new entry
10351 and return a pointer to it.
10352 If TYPE is NULL, determine symbol type from the die, otherwise
10353 used the passed type.
10354 If SPACE is not NULL, use it to hold the new symbol. If it is
10355 NULL, allocate a new symbol on the objfile's obstack. */
10357 static struct symbol
*
10358 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10359 struct symbol
*space
)
10361 struct objfile
*objfile
= cu
->objfile
;
10362 struct symbol
*sym
= NULL
;
10364 struct attribute
*attr
= NULL
;
10365 struct attribute
*attr2
= NULL
;
10366 CORE_ADDR baseaddr
;
10367 struct pending
**list_to_add
= NULL
;
10369 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10371 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10373 name
= dwarf2_name (die
, cu
);
10376 const char *linkagename
;
10377 int suppress_add
= 0;
10382 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10383 OBJSTAT (objfile
, n_syms
++);
10385 /* Cache this symbol's name and the name's demangled form (if any). */
10386 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10387 linkagename
= dwarf2_physname (name
, die
, cu
);
10388 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10390 /* Fortran does not have mangling standard and the mangling does differ
10391 between gfortran, iFort etc. */
10392 if (cu
->language
== language_fortran
10393 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10394 symbol_set_demangled_name (&(sym
->ginfo
),
10395 (char *) dwarf2_full_name (name
, die
, cu
),
10398 /* Default assumptions.
10399 Use the passed type or decode it from the die. */
10400 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10401 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10403 SYMBOL_TYPE (sym
) = type
;
10405 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10406 attr
= dwarf2_attr (die
,
10407 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10411 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10414 attr
= dwarf2_attr (die
,
10415 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10419 int file_index
= DW_UNSND (attr
);
10421 if (cu
->line_header
== NULL
10422 || file_index
> cu
->line_header
->num_file_names
)
10423 complaint (&symfile_complaints
,
10424 _("file index out of range"));
10425 else if (file_index
> 0)
10427 struct file_entry
*fe
;
10429 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10430 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10437 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10440 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10442 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10443 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10444 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10445 add_symbol_to_list (sym
, cu
->list_in_scope
);
10447 case DW_TAG_subprogram
:
10448 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10450 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10451 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10452 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10453 || cu
->language
== language_ada
)
10455 /* Subprograms marked external are stored as a global symbol.
10456 Ada subprograms, whether marked external or not, are always
10457 stored as a global symbol, because we want to be able to
10458 access them globally. For instance, we want to be able
10459 to break on a nested subprogram without having to
10460 specify the context. */
10461 list_to_add
= &global_symbols
;
10465 list_to_add
= cu
->list_in_scope
;
10468 case DW_TAG_inlined_subroutine
:
10469 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10471 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10472 SYMBOL_INLINED (sym
) = 1;
10473 /* Do not add the symbol to any lists. It will be found via
10474 BLOCK_FUNCTION from the blockvector. */
10476 case DW_TAG_template_value_param
:
10478 /* Fall through. */
10479 case DW_TAG_variable
:
10480 case DW_TAG_member
:
10481 /* Compilation with minimal debug info may result in variables
10482 with missing type entries. Change the misleading `void' type
10483 to something sensible. */
10484 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10486 = objfile_type (objfile
)->nodebug_data_symbol
;
10488 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10489 /* In the case of DW_TAG_member, we should only be called for
10490 static const members. */
10491 if (die
->tag
== DW_TAG_member
)
10493 /* dwarf2_add_field uses die_is_declaration,
10494 so we do the same. */
10495 gdb_assert (die_is_declaration (die
, cu
));
10500 dwarf2_const_value (attr
, sym
, cu
);
10501 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10504 if (attr2
&& (DW_UNSND (attr2
) != 0))
10505 list_to_add
= &global_symbols
;
10507 list_to_add
= cu
->list_in_scope
;
10511 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10514 var_decode_location (attr
, sym
, cu
);
10515 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10516 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10517 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10518 && !dwarf2_per_objfile
->has_section_at_zero
)
10520 /* When a static variable is eliminated by the linker,
10521 the corresponding debug information is not stripped
10522 out, but the variable address is set to null;
10523 do not add such variables into symbol table. */
10525 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10527 /* Workaround gfortran PR debug/40040 - it uses
10528 DW_AT_location for variables in -fPIC libraries which may
10529 get overriden by other libraries/executable and get
10530 a different address. Resolve it by the minimal symbol
10531 which may come from inferior's executable using copy
10532 relocation. Make this workaround only for gfortran as for
10533 other compilers GDB cannot guess the minimal symbol
10534 Fortran mangling kind. */
10535 if (cu
->language
== language_fortran
&& die
->parent
10536 && die
->parent
->tag
== DW_TAG_module
10538 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10539 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10541 /* A variable with DW_AT_external is never static,
10542 but it may be block-scoped. */
10543 list_to_add
= (cu
->list_in_scope
== &file_symbols
10544 ? &global_symbols
: cu
->list_in_scope
);
10547 list_to_add
= cu
->list_in_scope
;
10551 /* We do not know the address of this symbol.
10552 If it is an external symbol and we have type information
10553 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10554 The address of the variable will then be determined from
10555 the minimal symbol table whenever the variable is
10557 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10558 if (attr2
&& (DW_UNSND (attr2
) != 0)
10559 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10561 /* A variable with DW_AT_external is never static, but it
10562 may be block-scoped. */
10563 list_to_add
= (cu
->list_in_scope
== &file_symbols
10564 ? &global_symbols
: cu
->list_in_scope
);
10566 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10568 else if (!die_is_declaration (die
, cu
))
10570 /* Use the default LOC_OPTIMIZED_OUT class. */
10571 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10573 list_to_add
= cu
->list_in_scope
;
10577 case DW_TAG_formal_parameter
:
10578 /* If we are inside a function, mark this as an argument. If
10579 not, we might be looking at an argument to an inlined function
10580 when we do not have enough information to show inlined frames;
10581 pretend it's a local variable in that case so that the user can
10583 if (context_stack_depth
> 0
10584 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10585 SYMBOL_IS_ARGUMENT (sym
) = 1;
10586 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10589 var_decode_location (attr
, sym
, cu
);
10591 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10594 dwarf2_const_value (attr
, sym
, cu
);
10596 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10597 if (attr
&& DW_UNSND (attr
))
10599 struct type
*ref_type
;
10601 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10602 SYMBOL_TYPE (sym
) = ref_type
;
10605 list_to_add
= cu
->list_in_scope
;
10607 case DW_TAG_unspecified_parameters
:
10608 /* From varargs functions; gdb doesn't seem to have any
10609 interest in this information, so just ignore it for now.
10612 case DW_TAG_template_type_param
:
10614 /* Fall through. */
10615 case DW_TAG_class_type
:
10616 case DW_TAG_interface_type
:
10617 case DW_TAG_structure_type
:
10618 case DW_TAG_union_type
:
10619 case DW_TAG_set_type
:
10620 case DW_TAG_enumeration_type
:
10621 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10622 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10625 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10626 really ever be static objects: otherwise, if you try
10627 to, say, break of a class's method and you're in a file
10628 which doesn't mention that class, it won't work unless
10629 the check for all static symbols in lookup_symbol_aux
10630 saves you. See the OtherFileClass tests in
10631 gdb.c++/namespace.exp. */
10635 list_to_add
= (cu
->list_in_scope
== &file_symbols
10636 && (cu
->language
== language_cplus
10637 || cu
->language
== language_java
)
10638 ? &global_symbols
: cu
->list_in_scope
);
10641 /* The semantics of C++ state that "struct foo { ... }" also
10642 defines a typedef for "foo". A Java class declaration also
10643 defines a typedef for the class. */
10644 if (cu
->language
== language_cplus
10645 || cu
->language
== language_java
10646 || cu
->language
== language_ada
)
10648 /* The symbol's name is already allocated along with
10649 this objfile, so we don't need to duplicate it for
10651 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10652 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10656 case DW_TAG_typedef
:
10657 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10658 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10659 list_to_add
= cu
->list_in_scope
;
10661 case DW_TAG_base_type
:
10662 case DW_TAG_subrange_type
:
10663 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10664 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10665 list_to_add
= cu
->list_in_scope
;
10667 case DW_TAG_enumerator
:
10668 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10671 dwarf2_const_value (attr
, sym
, cu
);
10674 /* NOTE: carlton/2003-11-10: See comment above in the
10675 DW_TAG_class_type, etc. block. */
10677 list_to_add
= (cu
->list_in_scope
== &file_symbols
10678 && (cu
->language
== language_cplus
10679 || cu
->language
== language_java
)
10680 ? &global_symbols
: cu
->list_in_scope
);
10683 case DW_TAG_namespace
:
10684 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10685 list_to_add
= &global_symbols
;
10688 /* Not a tag we recognize. Hopefully we aren't processing
10689 trash data, but since we must specifically ignore things
10690 we don't recognize, there is nothing else we should do at
10692 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10693 dwarf_tag_name (die
->tag
));
10699 sym
->hash_next
= objfile
->template_symbols
;
10700 objfile
->template_symbols
= sym
;
10701 list_to_add
= NULL
;
10704 if (list_to_add
!= NULL
)
10705 add_symbol_to_list (sym
, list_to_add
);
10707 /* For the benefit of old versions of GCC, check for anonymous
10708 namespaces based on the demangled name. */
10709 if (!processing_has_namespace_info
10710 && cu
->language
== language_cplus
)
10711 cp_scan_for_anonymous_namespaces (sym
);
10716 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10718 static struct symbol
*
10719 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10721 return new_symbol_full (die
, type
, cu
, NULL
);
10724 /* Given an attr with a DW_FORM_dataN value in host byte order,
10725 zero-extend it as appropriate for the symbol's type. The DWARF
10726 standard (v4) is not entirely clear about the meaning of using
10727 DW_FORM_dataN for a constant with a signed type, where the type is
10728 wider than the data. The conclusion of a discussion on the DWARF
10729 list was that this is unspecified. We choose to always zero-extend
10730 because that is the interpretation long in use by GCC. */
10733 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10734 const char *name
, struct obstack
*obstack
,
10735 struct dwarf2_cu
*cu
, long *value
, int bits
)
10737 struct objfile
*objfile
= cu
->objfile
;
10738 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10739 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10740 LONGEST l
= DW_UNSND (attr
);
10742 if (bits
< sizeof (*value
) * 8)
10744 l
&= ((LONGEST
) 1 << bits
) - 1;
10747 else if (bits
== sizeof (*value
) * 8)
10751 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10752 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10759 /* Read a constant value from an attribute. Either set *VALUE, or if
10760 the value does not fit in *VALUE, set *BYTES - either already
10761 allocated on the objfile obstack, or newly allocated on OBSTACK,
10762 or, set *BATON, if we translated the constant to a location
10766 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10767 const char *name
, struct obstack
*obstack
,
10768 struct dwarf2_cu
*cu
,
10769 long *value
, gdb_byte
**bytes
,
10770 struct dwarf2_locexpr_baton
**baton
)
10772 struct objfile
*objfile
= cu
->objfile
;
10773 struct comp_unit_head
*cu_header
= &cu
->header
;
10774 struct dwarf_block
*blk
;
10775 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10776 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10782 switch (attr
->form
)
10788 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10789 dwarf2_const_value_length_mismatch_complaint (name
,
10790 cu_header
->addr_size
,
10791 TYPE_LENGTH (type
));
10792 /* Symbols of this form are reasonably rare, so we just
10793 piggyback on the existing location code rather than writing
10794 a new implementation of symbol_computed_ops. */
10795 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
10796 sizeof (struct dwarf2_locexpr_baton
));
10797 (*baton
)->per_cu
= cu
->per_cu
;
10798 gdb_assert ((*baton
)->per_cu
);
10800 (*baton
)->size
= 2 + cu_header
->addr_size
;
10801 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
10802 (*baton
)->data
= data
;
10804 data
[0] = DW_OP_addr
;
10805 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10806 byte_order
, DW_ADDR (attr
));
10807 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10810 case DW_FORM_string
:
10812 /* DW_STRING is already allocated on the objfile obstack, point
10814 *bytes
= (gdb_byte
*) DW_STRING (attr
);
10816 case DW_FORM_block1
:
10817 case DW_FORM_block2
:
10818 case DW_FORM_block4
:
10819 case DW_FORM_block
:
10820 case DW_FORM_exprloc
:
10821 blk
= DW_BLOCK (attr
);
10822 if (TYPE_LENGTH (type
) != blk
->size
)
10823 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
10824 TYPE_LENGTH (type
));
10825 *bytes
= blk
->data
;
10828 /* The DW_AT_const_value attributes are supposed to carry the
10829 symbol's value "represented as it would be on the target
10830 architecture." By the time we get here, it's already been
10831 converted to host endianness, so we just need to sign- or
10832 zero-extend it as appropriate. */
10833 case DW_FORM_data1
:
10834 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
10836 case DW_FORM_data2
:
10837 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
10839 case DW_FORM_data4
:
10840 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
10842 case DW_FORM_data8
:
10843 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
10846 case DW_FORM_sdata
:
10847 *value
= DW_SND (attr
);
10850 case DW_FORM_udata
:
10851 *value
= DW_UNSND (attr
);
10855 complaint (&symfile_complaints
,
10856 _("unsupported const value attribute form: '%s'"),
10857 dwarf_form_name (attr
->form
));
10864 /* Copy constant value from an attribute to a symbol. */
10867 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10868 struct dwarf2_cu
*cu
)
10870 struct objfile
*objfile
= cu
->objfile
;
10871 struct comp_unit_head
*cu_header
= &cu
->header
;
10874 struct dwarf2_locexpr_baton
*baton
;
10876 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
10877 SYMBOL_PRINT_NAME (sym
),
10878 &objfile
->objfile_obstack
, cu
,
10879 &value
, &bytes
, &baton
);
10883 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10884 SYMBOL_LOCATION_BATON (sym
) = baton
;
10885 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10887 else if (bytes
!= NULL
)
10889 SYMBOL_VALUE_BYTES (sym
) = bytes
;
10890 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10894 SYMBOL_VALUE (sym
) = value
;
10895 SYMBOL_CLASS (sym
) = LOC_CONST
;
10900 /* Return the type of the die in question using its DW_AT_type attribute. */
10902 static struct type
*
10903 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10905 struct attribute
*type_attr
;
10906 struct die_info
*type_die
;
10908 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10911 /* A missing DW_AT_type represents a void type. */
10912 return objfile_type (cu
->objfile
)->builtin_void
;
10915 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10917 return tag_type_to_type (type_die
, cu
);
10920 /* True iff CU's producer generates GNAT Ada auxiliary information
10921 that allows to find parallel types through that information instead
10922 of having to do expensive parallel lookups by type name. */
10925 need_gnat_info (struct dwarf2_cu
*cu
)
10927 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10928 of GNAT produces this auxiliary information, without any indication
10929 that it is produced. Part of enhancing the FSF version of GNAT
10930 to produce that information will be to put in place an indicator
10931 that we can use in order to determine whether the descriptive type
10932 info is available or not. One suggestion that has been made is
10933 to use a new attribute, attached to the CU die. For now, assume
10934 that the descriptive type info is not available. */
10939 /* Return the auxiliary type of the die in question using its
10940 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10941 attribute is not present. */
10943 static struct type
*
10944 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10946 struct attribute
*type_attr
;
10947 struct die_info
*type_die
;
10949 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
10953 type_die
= follow_die_ref (die
, type_attr
, &cu
);
10954 return tag_type_to_type (type_die
, cu
);
10957 /* If DIE has a descriptive_type attribute, then set the TYPE's
10958 descriptive type accordingly. */
10961 set_descriptive_type (struct type
*type
, struct die_info
*die
,
10962 struct dwarf2_cu
*cu
)
10964 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
10966 if (descriptive_type
)
10968 ALLOCATE_GNAT_AUX_TYPE (type
);
10969 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
10973 /* Return the containing type of the die in question using its
10974 DW_AT_containing_type attribute. */
10976 static struct type
*
10977 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10979 struct attribute
*type_attr
;
10980 struct die_info
*type_die
;
10982 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
10984 error (_("Dwarf Error: Problem turning containing type into gdb type "
10985 "[in module %s]"), cu
->objfile
->name
);
10987 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10988 return tag_type_to_type (type_die
, cu
);
10991 static struct type
*
10992 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10994 struct type
*this_type
;
10996 this_type
= read_type_die (die
, cu
);
10999 char *message
, *saved
;
11001 /* read_type_die already issued a complaint. */
11002 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11006 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11007 message
, strlen (message
));
11010 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11015 static struct type
*
11016 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11018 struct type
*this_type
;
11020 this_type
= get_die_type (die
, cu
);
11026 case DW_TAG_class_type
:
11027 case DW_TAG_interface_type
:
11028 case DW_TAG_structure_type
:
11029 case DW_TAG_union_type
:
11030 this_type
= read_structure_type (die
, cu
);
11032 case DW_TAG_enumeration_type
:
11033 this_type
= read_enumeration_type (die
, cu
);
11035 case DW_TAG_subprogram
:
11036 case DW_TAG_subroutine_type
:
11037 case DW_TAG_inlined_subroutine
:
11038 this_type
= read_subroutine_type (die
, cu
);
11040 case DW_TAG_array_type
:
11041 this_type
= read_array_type (die
, cu
);
11043 case DW_TAG_set_type
:
11044 this_type
= read_set_type (die
, cu
);
11046 case DW_TAG_pointer_type
:
11047 this_type
= read_tag_pointer_type (die
, cu
);
11049 case DW_TAG_ptr_to_member_type
:
11050 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11052 case DW_TAG_reference_type
:
11053 this_type
= read_tag_reference_type (die
, cu
);
11055 case DW_TAG_const_type
:
11056 this_type
= read_tag_const_type (die
, cu
);
11058 case DW_TAG_volatile_type
:
11059 this_type
= read_tag_volatile_type (die
, cu
);
11061 case DW_TAG_string_type
:
11062 this_type
= read_tag_string_type (die
, cu
);
11064 case DW_TAG_typedef
:
11065 this_type
= read_typedef (die
, cu
);
11067 case DW_TAG_subrange_type
:
11068 this_type
= read_subrange_type (die
, cu
);
11070 case DW_TAG_base_type
:
11071 this_type
= read_base_type (die
, cu
);
11073 case DW_TAG_unspecified_type
:
11074 this_type
= read_unspecified_type (die
, cu
);
11076 case DW_TAG_namespace
:
11077 this_type
= read_namespace_type (die
, cu
);
11079 case DW_TAG_module
:
11080 this_type
= read_module_type (die
, cu
);
11083 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11084 dwarf_tag_name (die
->tag
));
11091 /* Return the name of the namespace/class that DIE is defined within,
11092 or "" if we can't tell. The caller should not xfree the result.
11094 For example, if we're within the method foo() in the following
11104 then determine_prefix on foo's die will return "N::C". */
11107 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11109 struct die_info
*parent
, *spec_die
;
11110 struct dwarf2_cu
*spec_cu
;
11111 struct type
*parent_type
;
11113 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11114 && cu
->language
!= language_fortran
)
11117 /* We have to be careful in the presence of DW_AT_specification.
11118 For example, with GCC 3.4, given the code
11122 // Definition of N::foo.
11126 then we'll have a tree of DIEs like this:
11128 1: DW_TAG_compile_unit
11129 2: DW_TAG_namespace // N
11130 3: DW_TAG_subprogram // declaration of N::foo
11131 4: DW_TAG_subprogram // definition of N::foo
11132 DW_AT_specification // refers to die #3
11134 Thus, when processing die #4, we have to pretend that we're in
11135 the context of its DW_AT_specification, namely the contex of die
11138 spec_die
= die_specification (die
, &spec_cu
);
11139 if (spec_die
== NULL
)
11140 parent
= die
->parent
;
11143 parent
= spec_die
->parent
;
11147 if (parent
== NULL
)
11149 else if (parent
->building_fullname
)
11152 const char *parent_name
;
11154 /* It has been seen on RealView 2.2 built binaries,
11155 DW_TAG_template_type_param types actually _defined_ as
11156 children of the parent class:
11159 template class <class Enum> Class{};
11160 Class<enum E> class_e;
11162 1: DW_TAG_class_type (Class)
11163 2: DW_TAG_enumeration_type (E)
11164 3: DW_TAG_enumerator (enum1:0)
11165 3: DW_TAG_enumerator (enum2:1)
11167 2: DW_TAG_template_type_param
11168 DW_AT_type DW_FORM_ref_udata (E)
11170 Besides being broken debug info, it can put GDB into an
11171 infinite loop. Consider:
11173 When we're building the full name for Class<E>, we'll start
11174 at Class, and go look over its template type parameters,
11175 finding E. We'll then try to build the full name of E, and
11176 reach here. We're now trying to build the full name of E,
11177 and look over the parent DIE for containing scope. In the
11178 broken case, if we followed the parent DIE of E, we'd again
11179 find Class, and once again go look at its template type
11180 arguments, etc., etc. Simply don't consider such parent die
11181 as source-level parent of this die (it can't be, the language
11182 doesn't allow it), and break the loop here. */
11183 name
= dwarf2_name (die
, cu
);
11184 parent_name
= dwarf2_name (parent
, cu
);
11185 complaint (&symfile_complaints
,
11186 _("template param type '%s' defined within parent '%s'"),
11187 name
? name
: "<unknown>",
11188 parent_name
? parent_name
: "<unknown>");
11192 switch (parent
->tag
)
11194 case DW_TAG_namespace
:
11195 parent_type
= read_type_die (parent
, cu
);
11196 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11197 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11198 Work around this problem here. */
11199 if (cu
->language
== language_cplus
11200 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11202 /* We give a name to even anonymous namespaces. */
11203 return TYPE_TAG_NAME (parent_type
);
11204 case DW_TAG_class_type
:
11205 case DW_TAG_interface_type
:
11206 case DW_TAG_structure_type
:
11207 case DW_TAG_union_type
:
11208 case DW_TAG_module
:
11209 parent_type
= read_type_die (parent
, cu
);
11210 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11211 return TYPE_TAG_NAME (parent_type
);
11213 /* An anonymous structure is only allowed non-static data
11214 members; no typedefs, no member functions, et cetera.
11215 So it does not need a prefix. */
11218 return determine_prefix (parent
, cu
);
11222 /* Return a newly-allocated string formed by concatenating PREFIX and
11223 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11224 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11225 perform an obconcat, otherwise allocate storage for the result. The CU argument
11226 is used to determine the language and hence, the appropriate separator. */
11228 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11231 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11232 int physname
, struct dwarf2_cu
*cu
)
11234 const char *lead
= "";
11237 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11239 else if (cu
->language
== language_java
)
11241 else if (cu
->language
== language_fortran
&& physname
)
11243 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11244 DW_AT_MIPS_linkage_name is preferred and used instead. */
11252 if (prefix
== NULL
)
11254 if (suffix
== NULL
)
11259 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11261 strcpy (retval
, lead
);
11262 strcat (retval
, prefix
);
11263 strcat (retval
, sep
);
11264 strcat (retval
, suffix
);
11269 /* We have an obstack. */
11270 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11274 /* Return sibling of die, NULL if no sibling. */
11276 static struct die_info
*
11277 sibling_die (struct die_info
*die
)
11279 return die
->sibling
;
11282 /* Get name of a die, return NULL if not found. */
11285 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11286 struct obstack
*obstack
)
11288 if (name
&& cu
->language
== language_cplus
)
11290 char *canon_name
= cp_canonicalize_string (name
);
11292 if (canon_name
!= NULL
)
11294 if (strcmp (canon_name
, name
) != 0)
11295 name
= obsavestring (canon_name
, strlen (canon_name
),
11297 xfree (canon_name
);
11304 /* Get name of a die, return NULL if not found. */
11307 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11309 struct attribute
*attr
;
11311 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11312 if (!attr
|| !DW_STRING (attr
))
11317 case DW_TAG_compile_unit
:
11318 /* Compilation units have a DW_AT_name that is a filename, not
11319 a source language identifier. */
11320 case DW_TAG_enumeration_type
:
11321 case DW_TAG_enumerator
:
11322 /* These tags always have simple identifiers already; no need
11323 to canonicalize them. */
11324 return DW_STRING (attr
);
11326 case DW_TAG_subprogram
:
11327 /* Java constructors will all be named "<init>", so return
11328 the class name when we see this special case. */
11329 if (cu
->language
== language_java
11330 && DW_STRING (attr
) != NULL
11331 && strcmp (DW_STRING (attr
), "<init>") == 0)
11333 struct dwarf2_cu
*spec_cu
= cu
;
11334 struct die_info
*spec_die
;
11336 /* GCJ will output '<init>' for Java constructor names.
11337 For this special case, return the name of the parent class. */
11339 /* GCJ may output suprogram DIEs with AT_specification set.
11340 If so, use the name of the specified DIE. */
11341 spec_die
= die_specification (die
, &spec_cu
);
11342 if (spec_die
!= NULL
)
11343 return dwarf2_name (spec_die
, spec_cu
);
11348 if (die
->tag
== DW_TAG_class_type
)
11349 return dwarf2_name (die
, cu
);
11351 while (die
->tag
!= DW_TAG_compile_unit
);
11355 case DW_TAG_class_type
:
11356 case DW_TAG_interface_type
:
11357 case DW_TAG_structure_type
:
11358 case DW_TAG_union_type
:
11359 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11360 structures or unions. These were of the form "._%d" in GCC 4.1,
11361 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11362 and GCC 4.4. We work around this problem by ignoring these. */
11363 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11364 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11372 if (!DW_STRING_IS_CANONICAL (attr
))
11375 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11376 &cu
->objfile
->objfile_obstack
);
11377 DW_STRING_IS_CANONICAL (attr
) = 1;
11379 return DW_STRING (attr
);
11382 /* Return the die that this die in an extension of, or NULL if there
11383 is none. *EXT_CU is the CU containing DIE on input, and the CU
11384 containing the return value on output. */
11386 static struct die_info
*
11387 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11389 struct attribute
*attr
;
11391 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11395 return follow_die_ref (die
, attr
, ext_cu
);
11398 /* Convert a DIE tag into its string name. */
11401 dwarf_tag_name (unsigned tag
)
11405 case DW_TAG_padding
:
11406 return "DW_TAG_padding";
11407 case DW_TAG_array_type
:
11408 return "DW_TAG_array_type";
11409 case DW_TAG_class_type
:
11410 return "DW_TAG_class_type";
11411 case DW_TAG_entry_point
:
11412 return "DW_TAG_entry_point";
11413 case DW_TAG_enumeration_type
:
11414 return "DW_TAG_enumeration_type";
11415 case DW_TAG_formal_parameter
:
11416 return "DW_TAG_formal_parameter";
11417 case DW_TAG_imported_declaration
:
11418 return "DW_TAG_imported_declaration";
11420 return "DW_TAG_label";
11421 case DW_TAG_lexical_block
:
11422 return "DW_TAG_lexical_block";
11423 case DW_TAG_member
:
11424 return "DW_TAG_member";
11425 case DW_TAG_pointer_type
:
11426 return "DW_TAG_pointer_type";
11427 case DW_TAG_reference_type
:
11428 return "DW_TAG_reference_type";
11429 case DW_TAG_compile_unit
:
11430 return "DW_TAG_compile_unit";
11431 case DW_TAG_string_type
:
11432 return "DW_TAG_string_type";
11433 case DW_TAG_structure_type
:
11434 return "DW_TAG_structure_type";
11435 case DW_TAG_subroutine_type
:
11436 return "DW_TAG_subroutine_type";
11437 case DW_TAG_typedef
:
11438 return "DW_TAG_typedef";
11439 case DW_TAG_union_type
:
11440 return "DW_TAG_union_type";
11441 case DW_TAG_unspecified_parameters
:
11442 return "DW_TAG_unspecified_parameters";
11443 case DW_TAG_variant
:
11444 return "DW_TAG_variant";
11445 case DW_TAG_common_block
:
11446 return "DW_TAG_common_block";
11447 case DW_TAG_common_inclusion
:
11448 return "DW_TAG_common_inclusion";
11449 case DW_TAG_inheritance
:
11450 return "DW_TAG_inheritance";
11451 case DW_TAG_inlined_subroutine
:
11452 return "DW_TAG_inlined_subroutine";
11453 case DW_TAG_module
:
11454 return "DW_TAG_module";
11455 case DW_TAG_ptr_to_member_type
:
11456 return "DW_TAG_ptr_to_member_type";
11457 case DW_TAG_set_type
:
11458 return "DW_TAG_set_type";
11459 case DW_TAG_subrange_type
:
11460 return "DW_TAG_subrange_type";
11461 case DW_TAG_with_stmt
:
11462 return "DW_TAG_with_stmt";
11463 case DW_TAG_access_declaration
:
11464 return "DW_TAG_access_declaration";
11465 case DW_TAG_base_type
:
11466 return "DW_TAG_base_type";
11467 case DW_TAG_catch_block
:
11468 return "DW_TAG_catch_block";
11469 case DW_TAG_const_type
:
11470 return "DW_TAG_const_type";
11471 case DW_TAG_constant
:
11472 return "DW_TAG_constant";
11473 case DW_TAG_enumerator
:
11474 return "DW_TAG_enumerator";
11475 case DW_TAG_file_type
:
11476 return "DW_TAG_file_type";
11477 case DW_TAG_friend
:
11478 return "DW_TAG_friend";
11479 case DW_TAG_namelist
:
11480 return "DW_TAG_namelist";
11481 case DW_TAG_namelist_item
:
11482 return "DW_TAG_namelist_item";
11483 case DW_TAG_packed_type
:
11484 return "DW_TAG_packed_type";
11485 case DW_TAG_subprogram
:
11486 return "DW_TAG_subprogram";
11487 case DW_TAG_template_type_param
:
11488 return "DW_TAG_template_type_param";
11489 case DW_TAG_template_value_param
:
11490 return "DW_TAG_template_value_param";
11491 case DW_TAG_thrown_type
:
11492 return "DW_TAG_thrown_type";
11493 case DW_TAG_try_block
:
11494 return "DW_TAG_try_block";
11495 case DW_TAG_variant_part
:
11496 return "DW_TAG_variant_part";
11497 case DW_TAG_variable
:
11498 return "DW_TAG_variable";
11499 case DW_TAG_volatile_type
:
11500 return "DW_TAG_volatile_type";
11501 case DW_TAG_dwarf_procedure
:
11502 return "DW_TAG_dwarf_procedure";
11503 case DW_TAG_restrict_type
:
11504 return "DW_TAG_restrict_type";
11505 case DW_TAG_interface_type
:
11506 return "DW_TAG_interface_type";
11507 case DW_TAG_namespace
:
11508 return "DW_TAG_namespace";
11509 case DW_TAG_imported_module
:
11510 return "DW_TAG_imported_module";
11511 case DW_TAG_unspecified_type
:
11512 return "DW_TAG_unspecified_type";
11513 case DW_TAG_partial_unit
:
11514 return "DW_TAG_partial_unit";
11515 case DW_TAG_imported_unit
:
11516 return "DW_TAG_imported_unit";
11517 case DW_TAG_condition
:
11518 return "DW_TAG_condition";
11519 case DW_TAG_shared_type
:
11520 return "DW_TAG_shared_type";
11521 case DW_TAG_type_unit
:
11522 return "DW_TAG_type_unit";
11523 case DW_TAG_MIPS_loop
:
11524 return "DW_TAG_MIPS_loop";
11525 case DW_TAG_HP_array_descriptor
:
11526 return "DW_TAG_HP_array_descriptor";
11527 case DW_TAG_format_label
:
11528 return "DW_TAG_format_label";
11529 case DW_TAG_function_template
:
11530 return "DW_TAG_function_template";
11531 case DW_TAG_class_template
:
11532 return "DW_TAG_class_template";
11533 case DW_TAG_GNU_BINCL
:
11534 return "DW_TAG_GNU_BINCL";
11535 case DW_TAG_GNU_EINCL
:
11536 return "DW_TAG_GNU_EINCL";
11537 case DW_TAG_upc_shared_type
:
11538 return "DW_TAG_upc_shared_type";
11539 case DW_TAG_upc_strict_type
:
11540 return "DW_TAG_upc_strict_type";
11541 case DW_TAG_upc_relaxed_type
:
11542 return "DW_TAG_upc_relaxed_type";
11543 case DW_TAG_PGI_kanji_type
:
11544 return "DW_TAG_PGI_kanji_type";
11545 case DW_TAG_PGI_interface_block
:
11546 return "DW_TAG_PGI_interface_block";
11548 return "DW_TAG_<unknown>";
11552 /* Convert a DWARF attribute code into its string name. */
11555 dwarf_attr_name (unsigned attr
)
11559 case DW_AT_sibling
:
11560 return "DW_AT_sibling";
11561 case DW_AT_location
:
11562 return "DW_AT_location";
11564 return "DW_AT_name";
11565 case DW_AT_ordering
:
11566 return "DW_AT_ordering";
11567 case DW_AT_subscr_data
:
11568 return "DW_AT_subscr_data";
11569 case DW_AT_byte_size
:
11570 return "DW_AT_byte_size";
11571 case DW_AT_bit_offset
:
11572 return "DW_AT_bit_offset";
11573 case DW_AT_bit_size
:
11574 return "DW_AT_bit_size";
11575 case DW_AT_element_list
:
11576 return "DW_AT_element_list";
11577 case DW_AT_stmt_list
:
11578 return "DW_AT_stmt_list";
11580 return "DW_AT_low_pc";
11581 case DW_AT_high_pc
:
11582 return "DW_AT_high_pc";
11583 case DW_AT_language
:
11584 return "DW_AT_language";
11586 return "DW_AT_member";
11588 return "DW_AT_discr";
11589 case DW_AT_discr_value
:
11590 return "DW_AT_discr_value";
11591 case DW_AT_visibility
:
11592 return "DW_AT_visibility";
11594 return "DW_AT_import";
11595 case DW_AT_string_length
:
11596 return "DW_AT_string_length";
11597 case DW_AT_common_reference
:
11598 return "DW_AT_common_reference";
11599 case DW_AT_comp_dir
:
11600 return "DW_AT_comp_dir";
11601 case DW_AT_const_value
:
11602 return "DW_AT_const_value";
11603 case DW_AT_containing_type
:
11604 return "DW_AT_containing_type";
11605 case DW_AT_default_value
:
11606 return "DW_AT_default_value";
11608 return "DW_AT_inline";
11609 case DW_AT_is_optional
:
11610 return "DW_AT_is_optional";
11611 case DW_AT_lower_bound
:
11612 return "DW_AT_lower_bound";
11613 case DW_AT_producer
:
11614 return "DW_AT_producer";
11615 case DW_AT_prototyped
:
11616 return "DW_AT_prototyped";
11617 case DW_AT_return_addr
:
11618 return "DW_AT_return_addr";
11619 case DW_AT_start_scope
:
11620 return "DW_AT_start_scope";
11621 case DW_AT_bit_stride
:
11622 return "DW_AT_bit_stride";
11623 case DW_AT_upper_bound
:
11624 return "DW_AT_upper_bound";
11625 case DW_AT_abstract_origin
:
11626 return "DW_AT_abstract_origin";
11627 case DW_AT_accessibility
:
11628 return "DW_AT_accessibility";
11629 case DW_AT_address_class
:
11630 return "DW_AT_address_class";
11631 case DW_AT_artificial
:
11632 return "DW_AT_artificial";
11633 case DW_AT_base_types
:
11634 return "DW_AT_base_types";
11635 case DW_AT_calling_convention
:
11636 return "DW_AT_calling_convention";
11638 return "DW_AT_count";
11639 case DW_AT_data_member_location
:
11640 return "DW_AT_data_member_location";
11641 case DW_AT_decl_column
:
11642 return "DW_AT_decl_column";
11643 case DW_AT_decl_file
:
11644 return "DW_AT_decl_file";
11645 case DW_AT_decl_line
:
11646 return "DW_AT_decl_line";
11647 case DW_AT_declaration
:
11648 return "DW_AT_declaration";
11649 case DW_AT_discr_list
:
11650 return "DW_AT_discr_list";
11651 case DW_AT_encoding
:
11652 return "DW_AT_encoding";
11653 case DW_AT_external
:
11654 return "DW_AT_external";
11655 case DW_AT_frame_base
:
11656 return "DW_AT_frame_base";
11658 return "DW_AT_friend";
11659 case DW_AT_identifier_case
:
11660 return "DW_AT_identifier_case";
11661 case DW_AT_macro_info
:
11662 return "DW_AT_macro_info";
11663 case DW_AT_namelist_items
:
11664 return "DW_AT_namelist_items";
11665 case DW_AT_priority
:
11666 return "DW_AT_priority";
11667 case DW_AT_segment
:
11668 return "DW_AT_segment";
11669 case DW_AT_specification
:
11670 return "DW_AT_specification";
11671 case DW_AT_static_link
:
11672 return "DW_AT_static_link";
11674 return "DW_AT_type";
11675 case DW_AT_use_location
:
11676 return "DW_AT_use_location";
11677 case DW_AT_variable_parameter
:
11678 return "DW_AT_variable_parameter";
11679 case DW_AT_virtuality
:
11680 return "DW_AT_virtuality";
11681 case DW_AT_vtable_elem_location
:
11682 return "DW_AT_vtable_elem_location";
11683 /* DWARF 3 values. */
11684 case DW_AT_allocated
:
11685 return "DW_AT_allocated";
11686 case DW_AT_associated
:
11687 return "DW_AT_associated";
11688 case DW_AT_data_location
:
11689 return "DW_AT_data_location";
11690 case DW_AT_byte_stride
:
11691 return "DW_AT_byte_stride";
11692 case DW_AT_entry_pc
:
11693 return "DW_AT_entry_pc";
11694 case DW_AT_use_UTF8
:
11695 return "DW_AT_use_UTF8";
11696 case DW_AT_extension
:
11697 return "DW_AT_extension";
11699 return "DW_AT_ranges";
11700 case DW_AT_trampoline
:
11701 return "DW_AT_trampoline";
11702 case DW_AT_call_column
:
11703 return "DW_AT_call_column";
11704 case DW_AT_call_file
:
11705 return "DW_AT_call_file";
11706 case DW_AT_call_line
:
11707 return "DW_AT_call_line";
11708 case DW_AT_description
:
11709 return "DW_AT_description";
11710 case DW_AT_binary_scale
:
11711 return "DW_AT_binary_scale";
11712 case DW_AT_decimal_scale
:
11713 return "DW_AT_decimal_scale";
11715 return "DW_AT_small";
11716 case DW_AT_decimal_sign
:
11717 return "DW_AT_decimal_sign";
11718 case DW_AT_digit_count
:
11719 return "DW_AT_digit_count";
11720 case DW_AT_picture_string
:
11721 return "DW_AT_picture_string";
11722 case DW_AT_mutable
:
11723 return "DW_AT_mutable";
11724 case DW_AT_threads_scaled
:
11725 return "DW_AT_threads_scaled";
11726 case DW_AT_explicit
:
11727 return "DW_AT_explicit";
11728 case DW_AT_object_pointer
:
11729 return "DW_AT_object_pointer";
11730 case DW_AT_endianity
:
11731 return "DW_AT_endianity";
11732 case DW_AT_elemental
:
11733 return "DW_AT_elemental";
11735 return "DW_AT_pure";
11736 case DW_AT_recursive
:
11737 return "DW_AT_recursive";
11738 /* DWARF 4 values. */
11739 case DW_AT_signature
:
11740 return "DW_AT_signature";
11741 case DW_AT_linkage_name
:
11742 return "DW_AT_linkage_name";
11743 /* SGI/MIPS extensions. */
11744 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11745 case DW_AT_MIPS_fde
:
11746 return "DW_AT_MIPS_fde";
11748 case DW_AT_MIPS_loop_begin
:
11749 return "DW_AT_MIPS_loop_begin";
11750 case DW_AT_MIPS_tail_loop_begin
:
11751 return "DW_AT_MIPS_tail_loop_begin";
11752 case DW_AT_MIPS_epilog_begin
:
11753 return "DW_AT_MIPS_epilog_begin";
11754 case DW_AT_MIPS_loop_unroll_factor
:
11755 return "DW_AT_MIPS_loop_unroll_factor";
11756 case DW_AT_MIPS_software_pipeline_depth
:
11757 return "DW_AT_MIPS_software_pipeline_depth";
11758 case DW_AT_MIPS_linkage_name
:
11759 return "DW_AT_MIPS_linkage_name";
11760 case DW_AT_MIPS_stride
:
11761 return "DW_AT_MIPS_stride";
11762 case DW_AT_MIPS_abstract_name
:
11763 return "DW_AT_MIPS_abstract_name";
11764 case DW_AT_MIPS_clone_origin
:
11765 return "DW_AT_MIPS_clone_origin";
11766 case DW_AT_MIPS_has_inlines
:
11767 return "DW_AT_MIPS_has_inlines";
11768 /* HP extensions. */
11769 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11770 case DW_AT_HP_block_index
:
11771 return "DW_AT_HP_block_index";
11773 case DW_AT_HP_unmodifiable
:
11774 return "DW_AT_HP_unmodifiable";
11775 case DW_AT_HP_actuals_stmt_list
:
11776 return "DW_AT_HP_actuals_stmt_list";
11777 case DW_AT_HP_proc_per_section
:
11778 return "DW_AT_HP_proc_per_section";
11779 case DW_AT_HP_raw_data_ptr
:
11780 return "DW_AT_HP_raw_data_ptr";
11781 case DW_AT_HP_pass_by_reference
:
11782 return "DW_AT_HP_pass_by_reference";
11783 case DW_AT_HP_opt_level
:
11784 return "DW_AT_HP_opt_level";
11785 case DW_AT_HP_prof_version_id
:
11786 return "DW_AT_HP_prof_version_id";
11787 case DW_AT_HP_opt_flags
:
11788 return "DW_AT_HP_opt_flags";
11789 case DW_AT_HP_cold_region_low_pc
:
11790 return "DW_AT_HP_cold_region_low_pc";
11791 case DW_AT_HP_cold_region_high_pc
:
11792 return "DW_AT_HP_cold_region_high_pc";
11793 case DW_AT_HP_all_variables_modifiable
:
11794 return "DW_AT_HP_all_variables_modifiable";
11795 case DW_AT_HP_linkage_name
:
11796 return "DW_AT_HP_linkage_name";
11797 case DW_AT_HP_prof_flags
:
11798 return "DW_AT_HP_prof_flags";
11799 /* GNU extensions. */
11800 case DW_AT_sf_names
:
11801 return "DW_AT_sf_names";
11802 case DW_AT_src_info
:
11803 return "DW_AT_src_info";
11804 case DW_AT_mac_info
:
11805 return "DW_AT_mac_info";
11806 case DW_AT_src_coords
:
11807 return "DW_AT_src_coords";
11808 case DW_AT_body_begin
:
11809 return "DW_AT_body_begin";
11810 case DW_AT_body_end
:
11811 return "DW_AT_body_end";
11812 case DW_AT_GNU_vector
:
11813 return "DW_AT_GNU_vector";
11814 case DW_AT_GNU_odr_signature
:
11815 return "DW_AT_GNU_odr_signature";
11816 /* VMS extensions. */
11817 case DW_AT_VMS_rtnbeg_pd_address
:
11818 return "DW_AT_VMS_rtnbeg_pd_address";
11819 /* UPC extension. */
11820 case DW_AT_upc_threads_scaled
:
11821 return "DW_AT_upc_threads_scaled";
11822 /* PGI (STMicroelectronics) extensions. */
11823 case DW_AT_PGI_lbase
:
11824 return "DW_AT_PGI_lbase";
11825 case DW_AT_PGI_soffset
:
11826 return "DW_AT_PGI_soffset";
11827 case DW_AT_PGI_lstride
:
11828 return "DW_AT_PGI_lstride";
11830 return "DW_AT_<unknown>";
11834 /* Convert a DWARF value form code into its string name. */
11837 dwarf_form_name (unsigned form
)
11842 return "DW_FORM_addr";
11843 case DW_FORM_block2
:
11844 return "DW_FORM_block2";
11845 case DW_FORM_block4
:
11846 return "DW_FORM_block4";
11847 case DW_FORM_data2
:
11848 return "DW_FORM_data2";
11849 case DW_FORM_data4
:
11850 return "DW_FORM_data4";
11851 case DW_FORM_data8
:
11852 return "DW_FORM_data8";
11853 case DW_FORM_string
:
11854 return "DW_FORM_string";
11855 case DW_FORM_block
:
11856 return "DW_FORM_block";
11857 case DW_FORM_block1
:
11858 return "DW_FORM_block1";
11859 case DW_FORM_data1
:
11860 return "DW_FORM_data1";
11862 return "DW_FORM_flag";
11863 case DW_FORM_sdata
:
11864 return "DW_FORM_sdata";
11866 return "DW_FORM_strp";
11867 case DW_FORM_udata
:
11868 return "DW_FORM_udata";
11869 case DW_FORM_ref_addr
:
11870 return "DW_FORM_ref_addr";
11872 return "DW_FORM_ref1";
11874 return "DW_FORM_ref2";
11876 return "DW_FORM_ref4";
11878 return "DW_FORM_ref8";
11879 case DW_FORM_ref_udata
:
11880 return "DW_FORM_ref_udata";
11881 case DW_FORM_indirect
:
11882 return "DW_FORM_indirect";
11883 case DW_FORM_sec_offset
:
11884 return "DW_FORM_sec_offset";
11885 case DW_FORM_exprloc
:
11886 return "DW_FORM_exprloc";
11887 case DW_FORM_flag_present
:
11888 return "DW_FORM_flag_present";
11890 return "DW_FORM_sig8";
11892 return "DW_FORM_<unknown>";
11896 /* Convert a DWARF stack opcode into its string name. */
11899 dwarf_stack_op_name (unsigned op
, int def
)
11904 return "DW_OP_addr";
11906 return "DW_OP_deref";
11907 case DW_OP_const1u
:
11908 return "DW_OP_const1u";
11909 case DW_OP_const1s
:
11910 return "DW_OP_const1s";
11911 case DW_OP_const2u
:
11912 return "DW_OP_const2u";
11913 case DW_OP_const2s
:
11914 return "DW_OP_const2s";
11915 case DW_OP_const4u
:
11916 return "DW_OP_const4u";
11917 case DW_OP_const4s
:
11918 return "DW_OP_const4s";
11919 case DW_OP_const8u
:
11920 return "DW_OP_const8u";
11921 case DW_OP_const8s
:
11922 return "DW_OP_const8s";
11924 return "DW_OP_constu";
11926 return "DW_OP_consts";
11928 return "DW_OP_dup";
11930 return "DW_OP_drop";
11932 return "DW_OP_over";
11934 return "DW_OP_pick";
11936 return "DW_OP_swap";
11938 return "DW_OP_rot";
11940 return "DW_OP_xderef";
11942 return "DW_OP_abs";
11944 return "DW_OP_and";
11946 return "DW_OP_div";
11948 return "DW_OP_minus";
11950 return "DW_OP_mod";
11952 return "DW_OP_mul";
11954 return "DW_OP_neg";
11956 return "DW_OP_not";
11960 return "DW_OP_plus";
11961 case DW_OP_plus_uconst
:
11962 return "DW_OP_plus_uconst";
11964 return "DW_OP_shl";
11966 return "DW_OP_shr";
11968 return "DW_OP_shra";
11970 return "DW_OP_xor";
11972 return "DW_OP_bra";
11986 return "DW_OP_skip";
11988 return "DW_OP_lit0";
11990 return "DW_OP_lit1";
11992 return "DW_OP_lit2";
11994 return "DW_OP_lit3";
11996 return "DW_OP_lit4";
11998 return "DW_OP_lit5";
12000 return "DW_OP_lit6";
12002 return "DW_OP_lit7";
12004 return "DW_OP_lit8";
12006 return "DW_OP_lit9";
12008 return "DW_OP_lit10";
12010 return "DW_OP_lit11";
12012 return "DW_OP_lit12";
12014 return "DW_OP_lit13";
12016 return "DW_OP_lit14";
12018 return "DW_OP_lit15";
12020 return "DW_OP_lit16";
12022 return "DW_OP_lit17";
12024 return "DW_OP_lit18";
12026 return "DW_OP_lit19";
12028 return "DW_OP_lit20";
12030 return "DW_OP_lit21";
12032 return "DW_OP_lit22";
12034 return "DW_OP_lit23";
12036 return "DW_OP_lit24";
12038 return "DW_OP_lit25";
12040 return "DW_OP_lit26";
12042 return "DW_OP_lit27";
12044 return "DW_OP_lit28";
12046 return "DW_OP_lit29";
12048 return "DW_OP_lit30";
12050 return "DW_OP_lit31";
12052 return "DW_OP_reg0";
12054 return "DW_OP_reg1";
12056 return "DW_OP_reg2";
12058 return "DW_OP_reg3";
12060 return "DW_OP_reg4";
12062 return "DW_OP_reg5";
12064 return "DW_OP_reg6";
12066 return "DW_OP_reg7";
12068 return "DW_OP_reg8";
12070 return "DW_OP_reg9";
12072 return "DW_OP_reg10";
12074 return "DW_OP_reg11";
12076 return "DW_OP_reg12";
12078 return "DW_OP_reg13";
12080 return "DW_OP_reg14";
12082 return "DW_OP_reg15";
12084 return "DW_OP_reg16";
12086 return "DW_OP_reg17";
12088 return "DW_OP_reg18";
12090 return "DW_OP_reg19";
12092 return "DW_OP_reg20";
12094 return "DW_OP_reg21";
12096 return "DW_OP_reg22";
12098 return "DW_OP_reg23";
12100 return "DW_OP_reg24";
12102 return "DW_OP_reg25";
12104 return "DW_OP_reg26";
12106 return "DW_OP_reg27";
12108 return "DW_OP_reg28";
12110 return "DW_OP_reg29";
12112 return "DW_OP_reg30";
12114 return "DW_OP_reg31";
12116 return "DW_OP_breg0";
12118 return "DW_OP_breg1";
12120 return "DW_OP_breg2";
12122 return "DW_OP_breg3";
12124 return "DW_OP_breg4";
12126 return "DW_OP_breg5";
12128 return "DW_OP_breg6";
12130 return "DW_OP_breg7";
12132 return "DW_OP_breg8";
12134 return "DW_OP_breg9";
12136 return "DW_OP_breg10";
12138 return "DW_OP_breg11";
12140 return "DW_OP_breg12";
12142 return "DW_OP_breg13";
12144 return "DW_OP_breg14";
12146 return "DW_OP_breg15";
12148 return "DW_OP_breg16";
12150 return "DW_OP_breg17";
12152 return "DW_OP_breg18";
12154 return "DW_OP_breg19";
12156 return "DW_OP_breg20";
12158 return "DW_OP_breg21";
12160 return "DW_OP_breg22";
12162 return "DW_OP_breg23";
12164 return "DW_OP_breg24";
12166 return "DW_OP_breg25";
12168 return "DW_OP_breg26";
12170 return "DW_OP_breg27";
12172 return "DW_OP_breg28";
12174 return "DW_OP_breg29";
12176 return "DW_OP_breg30";
12178 return "DW_OP_breg31";
12180 return "DW_OP_regx";
12182 return "DW_OP_fbreg";
12184 return "DW_OP_bregx";
12186 return "DW_OP_piece";
12187 case DW_OP_deref_size
:
12188 return "DW_OP_deref_size";
12189 case DW_OP_xderef_size
:
12190 return "DW_OP_xderef_size";
12192 return "DW_OP_nop";
12193 /* DWARF 3 extensions. */
12194 case DW_OP_push_object_address
:
12195 return "DW_OP_push_object_address";
12197 return "DW_OP_call2";
12199 return "DW_OP_call4";
12200 case DW_OP_call_ref
:
12201 return "DW_OP_call_ref";
12202 case DW_OP_form_tls_address
:
12203 return "DW_OP_form_tls_address";
12204 case DW_OP_call_frame_cfa
:
12205 return "DW_OP_call_frame_cfa";
12206 case DW_OP_bit_piece
:
12207 return "DW_OP_bit_piece";
12208 /* DWARF 4 extensions. */
12209 case DW_OP_implicit_value
:
12210 return "DW_OP_implicit_value";
12211 case DW_OP_stack_value
:
12212 return "DW_OP_stack_value";
12213 /* GNU extensions. */
12214 case DW_OP_GNU_push_tls_address
:
12215 return "DW_OP_GNU_push_tls_address";
12216 case DW_OP_GNU_uninit
:
12217 return "DW_OP_GNU_uninit";
12219 return def
? "OP_<unknown>" : NULL
;
12224 dwarf_bool_name (unsigned mybool
)
12232 /* Convert a DWARF type code into its string name. */
12235 dwarf_type_encoding_name (unsigned enc
)
12240 return "DW_ATE_void";
12241 case DW_ATE_address
:
12242 return "DW_ATE_address";
12243 case DW_ATE_boolean
:
12244 return "DW_ATE_boolean";
12245 case DW_ATE_complex_float
:
12246 return "DW_ATE_complex_float";
12248 return "DW_ATE_float";
12249 case DW_ATE_signed
:
12250 return "DW_ATE_signed";
12251 case DW_ATE_signed_char
:
12252 return "DW_ATE_signed_char";
12253 case DW_ATE_unsigned
:
12254 return "DW_ATE_unsigned";
12255 case DW_ATE_unsigned_char
:
12256 return "DW_ATE_unsigned_char";
12258 case DW_ATE_imaginary_float
:
12259 return "DW_ATE_imaginary_float";
12260 case DW_ATE_packed_decimal
:
12261 return "DW_ATE_packed_decimal";
12262 case DW_ATE_numeric_string
:
12263 return "DW_ATE_numeric_string";
12264 case DW_ATE_edited
:
12265 return "DW_ATE_edited";
12266 case DW_ATE_signed_fixed
:
12267 return "DW_ATE_signed_fixed";
12268 case DW_ATE_unsigned_fixed
:
12269 return "DW_ATE_unsigned_fixed";
12270 case DW_ATE_decimal_float
:
12271 return "DW_ATE_decimal_float";
12274 return "DW_ATE_UTF";
12275 /* HP extensions. */
12276 case DW_ATE_HP_float80
:
12277 return "DW_ATE_HP_float80";
12278 case DW_ATE_HP_complex_float80
:
12279 return "DW_ATE_HP_complex_float80";
12280 case DW_ATE_HP_float128
:
12281 return "DW_ATE_HP_float128";
12282 case DW_ATE_HP_complex_float128
:
12283 return "DW_ATE_HP_complex_float128";
12284 case DW_ATE_HP_floathpintel
:
12285 return "DW_ATE_HP_floathpintel";
12286 case DW_ATE_HP_imaginary_float80
:
12287 return "DW_ATE_HP_imaginary_float80";
12288 case DW_ATE_HP_imaginary_float128
:
12289 return "DW_ATE_HP_imaginary_float128";
12291 return "DW_ATE_<unknown>";
12295 /* Convert a DWARF call frame info operation to its string name. */
12299 dwarf_cfi_name (unsigned cfi_opc
)
12303 case DW_CFA_advance_loc
:
12304 return "DW_CFA_advance_loc";
12305 case DW_CFA_offset
:
12306 return "DW_CFA_offset";
12307 case DW_CFA_restore
:
12308 return "DW_CFA_restore";
12310 return "DW_CFA_nop";
12311 case DW_CFA_set_loc
:
12312 return "DW_CFA_set_loc";
12313 case DW_CFA_advance_loc1
:
12314 return "DW_CFA_advance_loc1";
12315 case DW_CFA_advance_loc2
:
12316 return "DW_CFA_advance_loc2";
12317 case DW_CFA_advance_loc4
:
12318 return "DW_CFA_advance_loc4";
12319 case DW_CFA_offset_extended
:
12320 return "DW_CFA_offset_extended";
12321 case DW_CFA_restore_extended
:
12322 return "DW_CFA_restore_extended";
12323 case DW_CFA_undefined
:
12324 return "DW_CFA_undefined";
12325 case DW_CFA_same_value
:
12326 return "DW_CFA_same_value";
12327 case DW_CFA_register
:
12328 return "DW_CFA_register";
12329 case DW_CFA_remember_state
:
12330 return "DW_CFA_remember_state";
12331 case DW_CFA_restore_state
:
12332 return "DW_CFA_restore_state";
12333 case DW_CFA_def_cfa
:
12334 return "DW_CFA_def_cfa";
12335 case DW_CFA_def_cfa_register
:
12336 return "DW_CFA_def_cfa_register";
12337 case DW_CFA_def_cfa_offset
:
12338 return "DW_CFA_def_cfa_offset";
12340 case DW_CFA_def_cfa_expression
:
12341 return "DW_CFA_def_cfa_expression";
12342 case DW_CFA_expression
:
12343 return "DW_CFA_expression";
12344 case DW_CFA_offset_extended_sf
:
12345 return "DW_CFA_offset_extended_sf";
12346 case DW_CFA_def_cfa_sf
:
12347 return "DW_CFA_def_cfa_sf";
12348 case DW_CFA_def_cfa_offset_sf
:
12349 return "DW_CFA_def_cfa_offset_sf";
12350 case DW_CFA_val_offset
:
12351 return "DW_CFA_val_offset";
12352 case DW_CFA_val_offset_sf
:
12353 return "DW_CFA_val_offset_sf";
12354 case DW_CFA_val_expression
:
12355 return "DW_CFA_val_expression";
12356 /* SGI/MIPS specific. */
12357 case DW_CFA_MIPS_advance_loc8
:
12358 return "DW_CFA_MIPS_advance_loc8";
12359 /* GNU extensions. */
12360 case DW_CFA_GNU_window_save
:
12361 return "DW_CFA_GNU_window_save";
12362 case DW_CFA_GNU_args_size
:
12363 return "DW_CFA_GNU_args_size";
12364 case DW_CFA_GNU_negative_offset_extended
:
12365 return "DW_CFA_GNU_negative_offset_extended";
12367 return "DW_CFA_<unknown>";
12373 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12377 print_spaces (indent
, f
);
12378 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12379 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12381 if (die
->parent
!= NULL
)
12383 print_spaces (indent
, f
);
12384 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12385 die
->parent
->offset
);
12388 print_spaces (indent
, f
);
12389 fprintf_unfiltered (f
, " has children: %s\n",
12390 dwarf_bool_name (die
->child
!= NULL
));
12392 print_spaces (indent
, f
);
12393 fprintf_unfiltered (f
, " attributes:\n");
12395 for (i
= 0; i
< die
->num_attrs
; ++i
)
12397 print_spaces (indent
, f
);
12398 fprintf_unfiltered (f
, " %s (%s) ",
12399 dwarf_attr_name (die
->attrs
[i
].name
),
12400 dwarf_form_name (die
->attrs
[i
].form
));
12402 switch (die
->attrs
[i
].form
)
12404 case DW_FORM_ref_addr
:
12406 fprintf_unfiltered (f
, "address: ");
12407 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12409 case DW_FORM_block2
:
12410 case DW_FORM_block4
:
12411 case DW_FORM_block
:
12412 case DW_FORM_block1
:
12413 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12415 case DW_FORM_exprloc
:
12416 fprintf_unfiltered (f
, "expression: size %u",
12417 DW_BLOCK (&die
->attrs
[i
])->size
);
12422 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12423 (long) (DW_ADDR (&die
->attrs
[i
])));
12425 case DW_FORM_data1
:
12426 case DW_FORM_data2
:
12427 case DW_FORM_data4
:
12428 case DW_FORM_data8
:
12429 case DW_FORM_udata
:
12430 case DW_FORM_sdata
:
12431 fprintf_unfiltered (f
, "constant: %s",
12432 pulongest (DW_UNSND (&die
->attrs
[i
])));
12434 case DW_FORM_sec_offset
:
12435 fprintf_unfiltered (f
, "section offset: %s",
12436 pulongest (DW_UNSND (&die
->attrs
[i
])));
12439 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12440 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12441 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12443 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12445 case DW_FORM_string
:
12447 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12448 DW_STRING (&die
->attrs
[i
])
12449 ? DW_STRING (&die
->attrs
[i
]) : "",
12450 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12453 if (DW_UNSND (&die
->attrs
[i
]))
12454 fprintf_unfiltered (f
, "flag: TRUE");
12456 fprintf_unfiltered (f
, "flag: FALSE");
12458 case DW_FORM_flag_present
:
12459 fprintf_unfiltered (f
, "flag: TRUE");
12461 case DW_FORM_indirect
:
12462 /* the reader will have reduced the indirect form to
12463 the "base form" so this form should not occur */
12464 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12467 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12468 die
->attrs
[i
].form
);
12471 fprintf_unfiltered (f
, "\n");
12476 dump_die_for_error (struct die_info
*die
)
12478 dump_die_shallow (gdb_stderr
, 0, die
);
12482 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12484 int indent
= level
* 4;
12486 gdb_assert (die
!= NULL
);
12488 if (level
>= max_level
)
12491 dump_die_shallow (f
, indent
, die
);
12493 if (die
->child
!= NULL
)
12495 print_spaces (indent
, f
);
12496 fprintf_unfiltered (f
, " Children:");
12497 if (level
+ 1 < max_level
)
12499 fprintf_unfiltered (f
, "\n");
12500 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12504 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12508 if (die
->sibling
!= NULL
&& level
> 0)
12510 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12514 /* This is called from the pdie macro in gdbinit.in.
12515 It's not static so gcc will keep a copy callable from gdb. */
12518 dump_die (struct die_info
*die
, int max_level
)
12520 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12524 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12528 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12534 is_ref_attr (struct attribute
*attr
)
12536 switch (attr
->form
)
12538 case DW_FORM_ref_addr
:
12543 case DW_FORM_ref_udata
:
12550 static unsigned int
12551 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12553 if (is_ref_attr (attr
))
12554 return DW_ADDR (attr
);
12556 complaint (&symfile_complaints
,
12557 _("unsupported die ref attribute form: '%s'"),
12558 dwarf_form_name (attr
->form
));
12562 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12563 * the value held by the attribute is not constant. */
12566 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12568 if (attr
->form
== DW_FORM_sdata
)
12569 return DW_SND (attr
);
12570 else if (attr
->form
== DW_FORM_udata
12571 || attr
->form
== DW_FORM_data1
12572 || attr
->form
== DW_FORM_data2
12573 || attr
->form
== DW_FORM_data4
12574 || attr
->form
== DW_FORM_data8
)
12575 return DW_UNSND (attr
);
12578 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12579 dwarf_form_name (attr
->form
));
12580 return default_value
;
12584 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12585 unit and add it to our queue.
12586 The result is non-zero if PER_CU was queued, otherwise the result is zero
12587 meaning either PER_CU is already queued or it is already loaded. */
12590 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12591 struct dwarf2_per_cu_data
*per_cu
)
12593 /* We may arrive here during partial symbol reading, if we need full
12594 DIEs to process an unusual case (e.g. template arguments). Do
12595 not queue PER_CU, just tell our caller to load its DIEs. */
12596 if (dwarf2_per_objfile
->reading_partial_symbols
)
12598 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12603 /* Mark the dependence relation so that we don't flush PER_CU
12605 dwarf2_add_dependence (this_cu
, per_cu
);
12607 /* If it's already on the queue, we have nothing to do. */
12608 if (per_cu
->queued
)
12611 /* If the compilation unit is already loaded, just mark it as
12613 if (per_cu
->cu
!= NULL
)
12615 per_cu
->cu
->last_used
= 0;
12619 /* Add it to the queue. */
12620 queue_comp_unit (per_cu
, this_cu
->objfile
);
12625 /* Follow reference or signature attribute ATTR of SRC_DIE.
12626 On entry *REF_CU is the CU of SRC_DIE.
12627 On exit *REF_CU is the CU of the result. */
12629 static struct die_info
*
12630 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12631 struct dwarf2_cu
**ref_cu
)
12633 struct die_info
*die
;
12635 if (is_ref_attr (attr
))
12636 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12637 else if (attr
->form
== DW_FORM_sig8
)
12638 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12641 dump_die_for_error (src_die
);
12642 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12643 (*ref_cu
)->objfile
->name
);
12649 /* Follow reference OFFSET.
12650 On entry *REF_CU is the CU of source DIE referencing OFFSET.
12651 On exit *REF_CU is the CU of the result. */
12653 static struct die_info
*
12654 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
12656 struct die_info temp_die
;
12657 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
12659 gdb_assert (cu
->per_cu
!= NULL
);
12663 if (cu
->per_cu
->from_debug_types
)
12665 /* .debug_types CUs cannot reference anything outside their CU.
12666 If they need to, they have to reference a signatured type via
12668 if (! offset_in_cu_p (&cu
->header
, offset
))
12671 else if (! offset_in_cu_p (&cu
->header
, offset
))
12673 struct dwarf2_per_cu_data
*per_cu
;
12675 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
12677 /* If necessary, add it to the queue and load its DIEs. */
12678 if (maybe_queue_comp_unit (cu
, per_cu
))
12679 load_full_comp_unit (per_cu
, cu
->objfile
);
12681 target_cu
= per_cu
->cu
;
12683 else if (cu
->dies
== NULL
)
12685 /* We're loading full DIEs during partial symbol reading. */
12686 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
12687 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
12690 *ref_cu
= target_cu
;
12691 temp_die
.offset
= offset
;
12692 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
12695 /* Follow reference attribute ATTR of SRC_DIE.
12696 On entry *REF_CU is the CU of SRC_DIE.
12697 On exit *REF_CU is the CU of the result. */
12699 static struct die_info
*
12700 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
12701 struct dwarf2_cu
**ref_cu
)
12703 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12704 struct dwarf2_cu
*cu
= *ref_cu
;
12705 struct die_info
*die
;
12707 die
= follow_die_offset (offset
, ref_cu
);
12709 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12710 "at 0x%x [in module %s]"),
12711 offset
, src_die
->offset
, cu
->objfile
->name
);
12716 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12717 value is intended for DW_OP_call*. */
12719 struct dwarf2_locexpr_baton
12720 dwarf2_fetch_die_location_block (unsigned int offset
,
12721 struct dwarf2_per_cu_data
*per_cu
)
12723 struct dwarf2_cu
*cu
= per_cu
->cu
;
12724 struct die_info
*die
;
12725 struct attribute
*attr
;
12726 struct dwarf2_locexpr_baton retval
;
12728 die
= follow_die_offset (offset
, &cu
);
12730 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12731 offset
, per_cu
->cu
->objfile
->name
);
12733 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12736 /* DWARF: "If there is no such attribute, then there is no effect.". */
12738 retval
.data
= NULL
;
12743 if (!attr_form_is_block (attr
))
12744 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12745 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12746 offset
, per_cu
->cu
->objfile
->name
);
12748 retval
.data
= DW_BLOCK (attr
)->data
;
12749 retval
.size
= DW_BLOCK (attr
)->size
;
12751 retval
.per_cu
= cu
->per_cu
;
12755 /* Follow the signature attribute ATTR in SRC_DIE.
12756 On entry *REF_CU is the CU of SRC_DIE.
12757 On exit *REF_CU is the CU of the result. */
12759 static struct die_info
*
12760 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
12761 struct dwarf2_cu
**ref_cu
)
12763 struct objfile
*objfile
= (*ref_cu
)->objfile
;
12764 struct die_info temp_die
;
12765 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12766 struct dwarf2_cu
*sig_cu
;
12767 struct die_info
*die
;
12769 /* sig_type will be NULL if the signatured type is missing from
12771 if (sig_type
== NULL
)
12772 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12773 "at 0x%x [in module %s]"),
12774 src_die
->offset
, objfile
->name
);
12776 /* If necessary, add it to the queue and load its DIEs. */
12778 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12779 read_signatured_type (objfile
, sig_type
);
12781 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12783 sig_cu
= sig_type
->per_cu
.cu
;
12784 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12785 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12792 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12793 "at 0x%x [in module %s]"),
12794 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12797 /* Given an offset of a signatured type, return its signatured_type. */
12799 static struct signatured_type
*
12800 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12802 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12803 unsigned int length
, initial_length_size
;
12804 unsigned int sig_offset
;
12805 struct signatured_type find_entry
, *type_sig
;
12807 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12808 sig_offset
= (initial_length_size
12810 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
12811 + 1 /*address_size*/);
12812 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
12813 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
12815 /* This is only used to lookup previously recorded types.
12816 If we didn't find it, it's our bug. */
12817 gdb_assert (type_sig
!= NULL
);
12818 gdb_assert (offset
== type_sig
->offset
);
12823 /* Read in signatured type at OFFSET and build its CU and die(s). */
12826 read_signatured_type_at_offset (struct objfile
*objfile
,
12827 unsigned int offset
)
12829 struct signatured_type
*type_sig
;
12831 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12833 /* We have the section offset, but we need the signature to do the
12834 hash table lookup. */
12835 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
12837 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12839 read_signatured_type (objfile
, type_sig
);
12841 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
12844 /* Read in a signatured type and build its CU and DIEs. */
12847 read_signatured_type (struct objfile
*objfile
,
12848 struct signatured_type
*type_sig
)
12850 gdb_byte
*types_ptr
;
12851 struct die_reader_specs reader_specs
;
12852 struct dwarf2_cu
*cu
;
12853 ULONGEST signature
;
12854 struct cleanup
*back_to
, *free_cu_cleanup
;
12855 struct attribute
*attr
;
12857 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12858 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
12860 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12862 cu
= xmalloc (sizeof (struct dwarf2_cu
));
12863 memset (cu
, 0, sizeof (struct dwarf2_cu
));
12864 obstack_init (&cu
->comp_unit_obstack
);
12865 cu
->objfile
= objfile
;
12866 type_sig
->per_cu
.cu
= cu
;
12867 cu
->per_cu
= &type_sig
->per_cu
;
12869 /* If an error occurs while loading, release our storage. */
12870 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
12872 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
12873 types_ptr
, objfile
->obfd
);
12874 gdb_assert (signature
== type_sig
->signature
);
12877 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12881 &cu
->comp_unit_obstack
,
12882 hashtab_obstack_allocate
,
12883 dummy_obstack_deallocate
);
12885 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
12886 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
12888 init_cu_die_reader (&reader_specs
, cu
);
12890 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
12893 /* We try not to read any attributes in this function, because not
12894 all objfiles needed for references have been loaded yet, and symbol
12895 table processing isn't initialized. But we have to set the CU language,
12896 or we won't be able to build types correctly. */
12897 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
12899 set_cu_language (DW_UNSND (attr
), cu
);
12901 set_cu_language (language_minimal
, cu
);
12903 do_cleanups (back_to
);
12905 /* We've successfully allocated this compilation unit. Let our caller
12906 clean it up when finished with it. */
12907 discard_cleanups (free_cu_cleanup
);
12909 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
12910 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
12913 /* Decode simple location descriptions.
12914 Given a pointer to a dwarf block that defines a location, compute
12915 the location and return the value.
12917 NOTE drow/2003-11-18: This function is called in two situations
12918 now: for the address of static or global variables (partial symbols
12919 only) and for offsets into structures which are expected to be
12920 (more or less) constant. The partial symbol case should go away,
12921 and only the constant case should remain. That will let this
12922 function complain more accurately. A few special modes are allowed
12923 without complaint for global variables (for instance, global
12924 register values and thread-local values).
12926 A location description containing no operations indicates that the
12927 object is optimized out. The return value is 0 for that case.
12928 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12929 callers will only want a very basic result and this can become a
12932 Note that stack[0] is unused except as a default error return.
12933 Note that stack overflow is not yet handled. */
12936 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
12938 struct objfile
*objfile
= cu
->objfile
;
12940 int size
= blk
->size
;
12941 gdb_byte
*data
= blk
->data
;
12942 CORE_ADDR stack
[64];
12944 unsigned int bytes_read
, unsnd
;
12988 stack
[++stacki
] = op
- DW_OP_lit0
;
13023 stack
[++stacki
] = op
- DW_OP_reg0
;
13025 dwarf2_complex_location_expr_complaint ();
13029 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13031 stack
[++stacki
] = unsnd
;
13033 dwarf2_complex_location_expr_complaint ();
13037 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13042 case DW_OP_const1u
:
13043 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13047 case DW_OP_const1s
:
13048 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13052 case DW_OP_const2u
:
13053 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13057 case DW_OP_const2s
:
13058 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13062 case DW_OP_const4u
:
13063 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13067 case DW_OP_const4s
:
13068 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13073 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13079 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13084 stack
[stacki
+ 1] = stack
[stacki
];
13089 stack
[stacki
- 1] += stack
[stacki
];
13093 case DW_OP_plus_uconst
:
13094 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13099 stack
[stacki
- 1] -= stack
[stacki
];
13104 /* If we're not the last op, then we definitely can't encode
13105 this using GDB's address_class enum. This is valid for partial
13106 global symbols, although the variable's address will be bogus
13109 dwarf2_complex_location_expr_complaint ();
13112 case DW_OP_GNU_push_tls_address
:
13113 /* The top of the stack has the offset from the beginning
13114 of the thread control block at which the variable is located. */
13115 /* Nothing should follow this operator, so the top of stack would
13117 /* This is valid for partial global symbols, but the variable's
13118 address will be bogus in the psymtab. */
13120 dwarf2_complex_location_expr_complaint ();
13123 case DW_OP_GNU_uninit
:
13127 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13128 dwarf_stack_op_name (op
, 1));
13129 return (stack
[stacki
]);
13132 return (stack
[stacki
]);
13135 /* memory allocation interface */
13137 static struct dwarf_block
*
13138 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13140 struct dwarf_block
*blk
;
13142 blk
= (struct dwarf_block
*)
13143 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13147 static struct abbrev_info
*
13148 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13150 struct abbrev_info
*abbrev
;
13152 abbrev
= (struct abbrev_info
*)
13153 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13154 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13158 static struct die_info
*
13159 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13161 struct die_info
*die
;
13162 size_t size
= sizeof (struct die_info
);
13165 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13167 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13168 memset (die
, 0, sizeof (struct die_info
));
13173 /* Macro support. */
13176 /* Return the full name of file number I in *LH's file name table.
13177 Use COMP_DIR as the name of the current directory of the
13178 compilation. The result is allocated using xmalloc; the caller is
13179 responsible for freeing it. */
13181 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13183 /* Is the file number a valid index into the line header's file name
13184 table? Remember that file numbers start with one, not zero. */
13185 if (1 <= file
&& file
<= lh
->num_file_names
)
13187 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13189 if (IS_ABSOLUTE_PATH (fe
->name
))
13190 return xstrdup (fe
->name
);
13198 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13204 dir_len
= strlen (dir
);
13205 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13206 strcpy (full_name
, dir
);
13207 full_name
[dir_len
] = '/';
13208 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13212 return xstrdup (fe
->name
);
13217 /* The compiler produced a bogus file number. We can at least
13218 record the macro definitions made in the file, even if we
13219 won't be able to find the file by name. */
13220 char fake_name
[80];
13222 sprintf (fake_name
, "<bad macro file number %d>", file
);
13224 complaint (&symfile_complaints
,
13225 _("bad file number in macro information (%d)"),
13228 return xstrdup (fake_name
);
13233 static struct macro_source_file
*
13234 macro_start_file (int file
, int line
,
13235 struct macro_source_file
*current_file
,
13236 const char *comp_dir
,
13237 struct line_header
*lh
, struct objfile
*objfile
)
13239 /* The full name of this source file. */
13240 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13242 /* We don't create a macro table for this compilation unit
13243 at all until we actually get a filename. */
13244 if (! pending_macros
)
13245 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13246 objfile
->macro_cache
);
13248 if (! current_file
)
13249 /* If we have no current file, then this must be the start_file
13250 directive for the compilation unit's main source file. */
13251 current_file
= macro_set_main (pending_macros
, full_name
);
13253 current_file
= macro_include (current_file
, line
, full_name
);
13257 return current_file
;
13261 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13262 followed by a null byte. */
13264 copy_string (const char *buf
, int len
)
13266 char *s
= xmalloc (len
+ 1);
13268 memcpy (s
, buf
, len
);
13274 static const char *
13275 consume_improper_spaces (const char *p
, const char *body
)
13279 complaint (&symfile_complaints
,
13280 _("macro definition contains spaces in formal argument list:\n`%s'"),
13292 parse_macro_definition (struct macro_source_file
*file
, int line
,
13297 /* The body string takes one of two forms. For object-like macro
13298 definitions, it should be:
13300 <macro name> " " <definition>
13302 For function-like macro definitions, it should be:
13304 <macro name> "() " <definition>
13306 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13308 Spaces may appear only where explicitly indicated, and in the
13311 The Dwarf 2 spec says that an object-like macro's name is always
13312 followed by a space, but versions of GCC around March 2002 omit
13313 the space when the macro's definition is the empty string.
13315 The Dwarf 2 spec says that there should be no spaces between the
13316 formal arguments in a function-like macro's formal argument list,
13317 but versions of GCC around March 2002 include spaces after the
13321 /* Find the extent of the macro name. The macro name is terminated
13322 by either a space or null character (for an object-like macro) or
13323 an opening paren (for a function-like macro). */
13324 for (p
= body
; *p
; p
++)
13325 if (*p
== ' ' || *p
== '(')
13328 if (*p
== ' ' || *p
== '\0')
13330 /* It's an object-like macro. */
13331 int name_len
= p
- body
;
13332 char *name
= copy_string (body
, name_len
);
13333 const char *replacement
;
13336 replacement
= body
+ name_len
+ 1;
13339 dwarf2_macro_malformed_definition_complaint (body
);
13340 replacement
= body
+ name_len
;
13343 macro_define_object (file
, line
, name
, replacement
);
13347 else if (*p
== '(')
13349 /* It's a function-like macro. */
13350 char *name
= copy_string (body
, p
- body
);
13353 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13357 p
= consume_improper_spaces (p
, body
);
13359 /* Parse the formal argument list. */
13360 while (*p
&& *p
!= ')')
13362 /* Find the extent of the current argument name. */
13363 const char *arg_start
= p
;
13365 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13368 if (! *p
|| p
== arg_start
)
13369 dwarf2_macro_malformed_definition_complaint (body
);
13372 /* Make sure argv has room for the new argument. */
13373 if (argc
>= argv_size
)
13376 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13379 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13382 p
= consume_improper_spaces (p
, body
);
13384 /* Consume the comma, if present. */
13389 p
= consume_improper_spaces (p
, body
);
13398 /* Perfectly formed definition, no complaints. */
13399 macro_define_function (file
, line
, name
,
13400 argc
, (const char **) argv
,
13402 else if (*p
== '\0')
13404 /* Complain, but do define it. */
13405 dwarf2_macro_malformed_definition_complaint (body
);
13406 macro_define_function (file
, line
, name
,
13407 argc
, (const char **) argv
,
13411 /* Just complain. */
13412 dwarf2_macro_malformed_definition_complaint (body
);
13415 /* Just complain. */
13416 dwarf2_macro_malformed_definition_complaint (body
);
13422 for (i
= 0; i
< argc
; i
++)
13428 dwarf2_macro_malformed_definition_complaint (body
);
13433 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13434 char *comp_dir
, bfd
*abfd
,
13435 struct dwarf2_cu
*cu
)
13437 gdb_byte
*mac_ptr
, *mac_end
;
13438 struct macro_source_file
*current_file
= 0;
13439 enum dwarf_macinfo_record_type macinfo_type
;
13440 int at_commandline
;
13442 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13443 &dwarf2_per_objfile
->macinfo
);
13444 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13446 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13450 /* First pass: Find the name of the base filename.
13451 This filename is needed in order to process all macros whose definition
13452 (or undefinition) comes from the command line. These macros are defined
13453 before the first DW_MACINFO_start_file entry, and yet still need to be
13454 associated to the base file.
13456 To determine the base file name, we scan the macro definitions until we
13457 reach the first DW_MACINFO_start_file entry. We then initialize
13458 CURRENT_FILE accordingly so that any macro definition found before the
13459 first DW_MACINFO_start_file can still be associated to the base file. */
13461 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13462 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13463 + dwarf2_per_objfile
->macinfo
.size
;
13467 /* Do we at least have room for a macinfo type byte? */
13468 if (mac_ptr
>= mac_end
)
13470 /* Complaint is printed during the second pass as GDB will probably
13471 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13475 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13478 switch (macinfo_type
)
13480 /* A zero macinfo type indicates the end of the macro
13485 case DW_MACINFO_define
:
13486 case DW_MACINFO_undef
:
13487 /* Only skip the data by MAC_PTR. */
13489 unsigned int bytes_read
;
13491 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13492 mac_ptr
+= bytes_read
;
13493 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13494 mac_ptr
+= bytes_read
;
13498 case DW_MACINFO_start_file
:
13500 unsigned int bytes_read
;
13503 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13504 mac_ptr
+= bytes_read
;
13505 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13506 mac_ptr
+= bytes_read
;
13508 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13513 case DW_MACINFO_end_file
:
13514 /* No data to skip by MAC_PTR. */
13517 case DW_MACINFO_vendor_ext
:
13518 /* Only skip the data by MAC_PTR. */
13520 unsigned int bytes_read
;
13522 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13523 mac_ptr
+= bytes_read
;
13524 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13525 mac_ptr
+= bytes_read
;
13532 } while (macinfo_type
!= 0 && current_file
== NULL
);
13534 /* Second pass: Process all entries.
13536 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13537 command-line macro definitions/undefinitions. This flag is unset when we
13538 reach the first DW_MACINFO_start_file entry. */
13540 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13542 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13543 GDB is still reading the definitions from command line. First
13544 DW_MACINFO_start_file will need to be ignored as it was already executed
13545 to create CURRENT_FILE for the main source holding also the command line
13546 definitions. On first met DW_MACINFO_start_file this flag is reset to
13547 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13549 at_commandline
= 1;
13553 /* Do we at least have room for a macinfo type byte? */
13554 if (mac_ptr
>= mac_end
)
13556 dwarf2_macros_too_long_complaint ();
13560 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13563 switch (macinfo_type
)
13565 /* A zero macinfo type indicates the end of the macro
13570 case DW_MACINFO_define
:
13571 case DW_MACINFO_undef
:
13573 unsigned int bytes_read
;
13577 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13578 mac_ptr
+= bytes_read
;
13579 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13580 mac_ptr
+= bytes_read
;
13582 if (! current_file
)
13584 /* DWARF violation as no main source is present. */
13585 complaint (&symfile_complaints
,
13586 _("debug info with no main source gives macro %s "
13588 macinfo_type
== DW_MACINFO_define
?
13590 macinfo_type
== DW_MACINFO_undef
?
13591 _("undefinition") :
13592 _("something-or-other"), line
, body
);
13595 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13596 complaint (&symfile_complaints
,
13597 _("debug info gives %s macro %s with %s line %d: %s"),
13598 at_commandline
? _("command-line") : _("in-file"),
13599 macinfo_type
== DW_MACINFO_define
?
13601 macinfo_type
== DW_MACINFO_undef
?
13602 _("undefinition") :
13603 _("something-or-other"),
13604 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13606 if (macinfo_type
== DW_MACINFO_define
)
13607 parse_macro_definition (current_file
, line
, body
);
13608 else if (macinfo_type
== DW_MACINFO_undef
)
13609 macro_undef (current_file
, line
, body
);
13613 case DW_MACINFO_start_file
:
13615 unsigned int bytes_read
;
13618 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13619 mac_ptr
+= bytes_read
;
13620 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13621 mac_ptr
+= bytes_read
;
13623 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13624 complaint (&symfile_complaints
,
13625 _("debug info gives source %d included "
13626 "from %s at %s line %d"),
13627 file
, at_commandline
? _("command-line") : _("file"),
13628 line
== 0 ? _("zero") : _("non-zero"), line
);
13630 if (at_commandline
)
13632 /* This DW_MACINFO_start_file was executed in the pass one. */
13633 at_commandline
= 0;
13636 current_file
= macro_start_file (file
, line
,
13637 current_file
, comp_dir
,
13642 case DW_MACINFO_end_file
:
13643 if (! current_file
)
13644 complaint (&symfile_complaints
,
13645 _("macro debug info has an unmatched `close_file' directive"));
13648 current_file
= current_file
->included_by
;
13649 if (! current_file
)
13651 enum dwarf_macinfo_record_type next_type
;
13653 /* GCC circa March 2002 doesn't produce the zero
13654 type byte marking the end of the compilation
13655 unit. Complain if it's not there, but exit no
13658 /* Do we at least have room for a macinfo type byte? */
13659 if (mac_ptr
>= mac_end
)
13661 dwarf2_macros_too_long_complaint ();
13665 /* We don't increment mac_ptr here, so this is just
13667 next_type
= read_1_byte (abfd
, mac_ptr
);
13668 if (next_type
!= 0)
13669 complaint (&symfile_complaints
,
13670 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13677 case DW_MACINFO_vendor_ext
:
13679 unsigned int bytes_read
;
13683 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13684 mac_ptr
+= bytes_read
;
13685 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13686 mac_ptr
+= bytes_read
;
13688 /* We don't recognize any vendor extensions. */
13692 } while (macinfo_type
!= 0);
13695 /* Check if the attribute's form is a DW_FORM_block*
13696 if so return true else false. */
13698 attr_form_is_block (struct attribute
*attr
)
13700 return (attr
== NULL
? 0 :
13701 attr
->form
== DW_FORM_block1
13702 || attr
->form
== DW_FORM_block2
13703 || attr
->form
== DW_FORM_block4
13704 || attr
->form
== DW_FORM_block
13705 || attr
->form
== DW_FORM_exprloc
);
13708 /* Return non-zero if ATTR's value is a section offset --- classes
13709 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13710 You may use DW_UNSND (attr) to retrieve such offsets.
13712 Section 7.5.4, "Attribute Encodings", explains that no attribute
13713 may have a value that belongs to more than one of these classes; it
13714 would be ambiguous if we did, because we use the same forms for all
13717 attr_form_is_section_offset (struct attribute
*attr
)
13719 return (attr
->form
== DW_FORM_data4
13720 || attr
->form
== DW_FORM_data8
13721 || attr
->form
== DW_FORM_sec_offset
);
13725 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13726 zero otherwise. When this function returns true, you can apply
13727 dwarf2_get_attr_constant_value to it.
13729 However, note that for some attributes you must check
13730 attr_form_is_section_offset before using this test. DW_FORM_data4
13731 and DW_FORM_data8 are members of both the constant class, and of
13732 the classes that contain offsets into other debug sections
13733 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13734 that, if an attribute's can be either a constant or one of the
13735 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13736 taken as section offsets, not constants. */
13738 attr_form_is_constant (struct attribute
*attr
)
13740 switch (attr
->form
)
13742 case DW_FORM_sdata
:
13743 case DW_FORM_udata
:
13744 case DW_FORM_data1
:
13745 case DW_FORM_data2
:
13746 case DW_FORM_data4
:
13747 case DW_FORM_data8
:
13755 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
13756 struct dwarf2_cu
*cu
)
13758 if (attr_form_is_section_offset (attr
)
13759 /* ".debug_loc" may not exist at all, or the offset may be outside
13760 the section. If so, fall through to the complaint in the
13762 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
13764 struct dwarf2_loclist_baton
*baton
;
13766 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13767 sizeof (struct dwarf2_loclist_baton
));
13768 baton
->per_cu
= cu
->per_cu
;
13769 gdb_assert (baton
->per_cu
);
13771 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13772 &dwarf2_per_objfile
->loc
);
13774 /* We don't know how long the location list is, but make sure we
13775 don't run off the edge of the section. */
13776 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
13777 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
13778 baton
->base_address
= cu
->base_address
;
13779 if (cu
->base_known
== 0)
13780 complaint (&symfile_complaints
,
13781 _("Location list used without specifying the CU base address."));
13783 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13784 SYMBOL_LOCATION_BATON (sym
) = baton
;
13788 struct dwarf2_locexpr_baton
*baton
;
13790 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13791 sizeof (struct dwarf2_locexpr_baton
));
13792 baton
->per_cu
= cu
->per_cu
;
13793 gdb_assert (baton
->per_cu
);
13795 if (attr_form_is_block (attr
))
13797 /* Note that we're just copying the block's data pointer
13798 here, not the actual data. We're still pointing into the
13799 info_buffer for SYM's objfile; right now we never release
13800 that buffer, but when we do clean up properly this may
13802 baton
->size
= DW_BLOCK (attr
)->size
;
13803 baton
->data
= DW_BLOCK (attr
)->data
;
13807 dwarf2_invalid_attrib_class_complaint ("location description",
13808 SYMBOL_NATURAL_NAME (sym
));
13810 baton
->data
= NULL
;
13813 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13814 SYMBOL_LOCATION_BATON (sym
) = baton
;
13818 /* Return the OBJFILE associated with the compilation unit CU. If CU
13819 came from a separate debuginfo file, then the master objfile is
13823 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
13825 struct objfile
*objfile
= per_cu
->objfile
;
13827 /* Return the master objfile, so that we can report and look up the
13828 correct file containing this variable. */
13829 if (objfile
->separate_debug_objfile_backlink
)
13830 objfile
= objfile
->separate_debug_objfile_backlink
;
13835 /* Return the address size given in the compilation unit header for CU. */
13838 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
13841 return per_cu
->cu
->header
.addr_size
;
13844 /* If the CU is not currently read in, we re-read its header. */
13845 struct objfile
*objfile
= per_cu
->objfile
;
13846 struct dwarf2_per_objfile
*per_objfile
13847 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13848 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13849 struct comp_unit_head cu_header
;
13851 memset (&cu_header
, 0, sizeof cu_header
);
13852 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13853 return cu_header
.addr_size
;
13857 /* Return the offset size given in the compilation unit header for CU. */
13860 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
13863 return per_cu
->cu
->header
.offset_size
;
13866 /* If the CU is not currently read in, we re-read its header. */
13867 struct objfile
*objfile
= per_cu
->objfile
;
13868 struct dwarf2_per_objfile
*per_objfile
13869 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13870 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13871 struct comp_unit_head cu_header
;
13873 memset (&cu_header
, 0, sizeof cu_header
);
13874 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13875 return cu_header
.offset_size
;
13879 /* Return the text offset of the CU. The returned offset comes from
13880 this CU's objfile. If this objfile came from a separate debuginfo
13881 file, then the offset may be different from the corresponding
13882 offset in the parent objfile. */
13885 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
13887 struct objfile
*objfile
= per_cu
->objfile
;
13889 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13892 /* Locate the .debug_info compilation unit from CU's objfile which contains
13893 the DIE at OFFSET. Raises an error on failure. */
13895 static struct dwarf2_per_cu_data
*
13896 dwarf2_find_containing_comp_unit (unsigned int offset
,
13897 struct objfile
*objfile
)
13899 struct dwarf2_per_cu_data
*this_cu
;
13903 high
= dwarf2_per_objfile
->n_comp_units
- 1;
13906 int mid
= low
+ (high
- low
) / 2;
13908 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
13913 gdb_assert (low
== high
);
13914 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
13917 error (_("Dwarf Error: could not find partial DIE containing "
13918 "offset 0x%lx [in module %s]"),
13919 (long) offset
, bfd_get_filename (objfile
->obfd
));
13921 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
13922 return dwarf2_per_objfile
->all_comp_units
[low
-1];
13926 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
13927 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
13928 && offset
>= this_cu
->offset
+ this_cu
->length
)
13929 error (_("invalid dwarf2 offset %u"), offset
);
13930 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
13935 /* Locate the compilation unit from OBJFILE which is located at exactly
13936 OFFSET. Raises an error on failure. */
13938 static struct dwarf2_per_cu_data
*
13939 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
13941 struct dwarf2_per_cu_data
*this_cu
;
13943 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
13944 if (this_cu
->offset
!= offset
)
13945 error (_("no compilation unit with offset %u."), offset
);
13949 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13951 static struct dwarf2_cu
*
13952 alloc_one_comp_unit (struct objfile
*objfile
)
13954 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
13955 cu
->objfile
= objfile
;
13956 obstack_init (&cu
->comp_unit_obstack
);
13960 /* Release one cached compilation unit, CU. We unlink it from the tree
13961 of compilation units, but we don't remove it from the read_in_chain;
13962 the caller is responsible for that.
13963 NOTE: DATA is a void * because this function is also used as a
13964 cleanup routine. */
13967 free_one_comp_unit (void *data
)
13969 struct dwarf2_cu
*cu
= data
;
13971 if (cu
->per_cu
!= NULL
)
13972 cu
->per_cu
->cu
= NULL
;
13975 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13980 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13981 when we're finished with it. We can't free the pointer itself, but be
13982 sure to unlink it from the cache. Also release any associated storage
13983 and perform cache maintenance.
13985 Only used during partial symbol parsing. */
13988 free_stack_comp_unit (void *data
)
13990 struct dwarf2_cu
*cu
= data
;
13992 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13993 cu
->partial_dies
= NULL
;
13995 if (cu
->per_cu
!= NULL
)
13997 /* This compilation unit is on the stack in our caller, so we
13998 should not xfree it. Just unlink it. */
13999 cu
->per_cu
->cu
= NULL
;
14002 /* If we had a per-cu pointer, then we may have other compilation
14003 units loaded, so age them now. */
14004 age_cached_comp_units ();
14008 /* Free all cached compilation units. */
14011 free_cached_comp_units (void *data
)
14013 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14015 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14016 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14017 while (per_cu
!= NULL
)
14019 struct dwarf2_per_cu_data
*next_cu
;
14021 next_cu
= per_cu
->cu
->read_in_chain
;
14023 free_one_comp_unit (per_cu
->cu
);
14024 *last_chain
= next_cu
;
14030 /* Increase the age counter on each cached compilation unit, and free
14031 any that are too old. */
14034 age_cached_comp_units (void)
14036 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14038 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14039 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14040 while (per_cu
!= NULL
)
14042 per_cu
->cu
->last_used
++;
14043 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14044 dwarf2_mark (per_cu
->cu
);
14045 per_cu
= per_cu
->cu
->read_in_chain
;
14048 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14049 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14050 while (per_cu
!= NULL
)
14052 struct dwarf2_per_cu_data
*next_cu
;
14054 next_cu
= per_cu
->cu
->read_in_chain
;
14056 if (!per_cu
->cu
->mark
)
14058 free_one_comp_unit (per_cu
->cu
);
14059 *last_chain
= next_cu
;
14062 last_chain
= &per_cu
->cu
->read_in_chain
;
14068 /* Remove a single compilation unit from the cache. */
14071 free_one_cached_comp_unit (void *target_cu
)
14073 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14075 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14076 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14077 while (per_cu
!= NULL
)
14079 struct dwarf2_per_cu_data
*next_cu
;
14081 next_cu
= per_cu
->cu
->read_in_chain
;
14083 if (per_cu
->cu
== target_cu
)
14085 free_one_comp_unit (per_cu
->cu
);
14086 *last_chain
= next_cu
;
14090 last_chain
= &per_cu
->cu
->read_in_chain
;
14096 /* Release all extra memory associated with OBJFILE. */
14099 dwarf2_free_objfile (struct objfile
*objfile
)
14101 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14103 if (dwarf2_per_objfile
== NULL
)
14106 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14107 free_cached_comp_units (NULL
);
14109 if (dwarf2_per_objfile
->using_index
)
14113 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14116 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14118 if (!cu
->v
.quick
->lines
)
14121 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
14123 if (cu
->v
.quick
->file_names
)
14124 xfree ((void *) cu
->v
.quick
->file_names
[j
]);
14125 if (cu
->v
.quick
->full_names
)
14126 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
14129 free_line_header (cu
->v
.quick
->lines
);
14133 /* Everything else should be on the objfile obstack. */
14136 /* A pair of DIE offset and GDB type pointer. We store these
14137 in a hash table separate from the DIEs, and preserve them
14138 when the DIEs are flushed out of cache. */
14140 struct dwarf2_offset_and_type
14142 unsigned int offset
;
14146 /* Hash function for a dwarf2_offset_and_type. */
14149 offset_and_type_hash (const void *item
)
14151 const struct dwarf2_offset_and_type
*ofs
= item
;
14153 return ofs
->offset
;
14156 /* Equality function for a dwarf2_offset_and_type. */
14159 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14161 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14162 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14164 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14167 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14168 table if necessary. For convenience, return TYPE.
14170 The DIEs reading must have careful ordering to:
14171 * Not cause infite loops trying to read in DIEs as a prerequisite for
14172 reading current DIE.
14173 * Not trying to dereference contents of still incompletely read in types
14174 while reading in other DIEs.
14175 * Enable referencing still incompletely read in types just by a pointer to
14176 the type without accessing its fields.
14178 Therefore caller should follow these rules:
14179 * Try to fetch any prerequisite types we may need to build this DIE type
14180 before building the type and calling set_die_type.
14181 * After building typer call set_die_type for current DIE as soon as
14182 possible before fetching more types to complete the current type.
14183 * Make the type as complete as possible before fetching more types. */
14185 static struct type
*
14186 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14188 struct dwarf2_offset_and_type
**slot
, ofs
;
14190 /* For Ada types, make sure that the gnat-specific data is always
14191 initialized (if not already set). There are a few types where
14192 we should not be doing so, because the type-specific area is
14193 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14194 where the type-specific area is used to store the floatformat).
14195 But this is not a problem, because the gnat-specific information
14196 is actually not needed for these types. */
14197 if (need_gnat_info (cu
)
14198 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14199 && TYPE_CODE (type
) != TYPE_CODE_FLT
14200 && !HAVE_GNAT_AUX_INFO (type
))
14201 INIT_GNAT_SPECIFIC (type
);
14203 if (cu
->type_hash
== NULL
)
14205 gdb_assert (cu
->per_cu
!= NULL
);
14206 cu
->per_cu
->type_hash
14207 = htab_create_alloc_ex (cu
->header
.length
/ 24,
14208 offset_and_type_hash
,
14209 offset_and_type_eq
,
14211 &cu
->objfile
->objfile_obstack
,
14212 hashtab_obstack_allocate
,
14213 dummy_obstack_deallocate
);
14214 cu
->type_hash
= cu
->per_cu
->type_hash
;
14217 ofs
.offset
= die
->offset
;
14219 slot
= (struct dwarf2_offset_and_type
**)
14220 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
14222 complaint (&symfile_complaints
,
14223 _("A problem internal to GDB: DIE 0x%x has type already set"),
14225 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
14230 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
14231 not have a saved type. */
14233 static struct type
*
14234 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14236 struct dwarf2_offset_and_type
*slot
, ofs
;
14237 htab_t type_hash
= cu
->type_hash
;
14239 if (type_hash
== NULL
)
14242 ofs
.offset
= die
->offset
;
14243 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14250 /* Add a dependence relationship from CU to REF_PER_CU. */
14253 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14254 struct dwarf2_per_cu_data
*ref_per_cu
)
14258 if (cu
->dependencies
== NULL
)
14260 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14261 NULL
, &cu
->comp_unit_obstack
,
14262 hashtab_obstack_allocate
,
14263 dummy_obstack_deallocate
);
14265 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14267 *slot
= ref_per_cu
;
14270 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14271 Set the mark field in every compilation unit in the
14272 cache that we must keep because we are keeping CU. */
14275 dwarf2_mark_helper (void **slot
, void *data
)
14277 struct dwarf2_per_cu_data
*per_cu
;
14279 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14280 if (per_cu
->cu
->mark
)
14282 per_cu
->cu
->mark
= 1;
14284 if (per_cu
->cu
->dependencies
!= NULL
)
14285 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14290 /* Set the mark field in CU and in every other compilation unit in the
14291 cache that we must keep because we are keeping CU. */
14294 dwarf2_mark (struct dwarf2_cu
*cu
)
14299 if (cu
->dependencies
!= NULL
)
14300 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14304 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14308 per_cu
->cu
->mark
= 0;
14309 per_cu
= per_cu
->cu
->read_in_chain
;
14313 /* Trivial hash function for partial_die_info: the hash value of a DIE
14314 is its offset in .debug_info for this objfile. */
14317 partial_die_hash (const void *item
)
14319 const struct partial_die_info
*part_die
= item
;
14321 return part_die
->offset
;
14324 /* Trivial comparison function for partial_die_info structures: two DIEs
14325 are equal if they have the same offset. */
14328 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14330 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14331 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14333 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14336 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14337 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14340 set_dwarf2_cmd (char *args
, int from_tty
)
14342 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14346 show_dwarf2_cmd (char *args
, int from_tty
)
14348 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14351 /* If section described by INFO was mmapped, munmap it now. */
14354 munmap_section_buffer (struct dwarf2_section_info
*info
)
14356 if (info
->was_mmapped
)
14359 intptr_t begin
= (intptr_t) info
->buffer
;
14360 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14361 size_t map_length
= info
->size
+ begin
- map_begin
;
14363 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14365 /* Without HAVE_MMAP, we should never be here to begin with. */
14366 gdb_assert_not_reached ("no mmap support");
14371 /* munmap debug sections for OBJFILE, if necessary. */
14374 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14376 struct dwarf2_per_objfile
*data
= d
;
14378 munmap_section_buffer (&data
->info
);
14379 munmap_section_buffer (&data
->abbrev
);
14380 munmap_section_buffer (&data
->line
);
14381 munmap_section_buffer (&data
->str
);
14382 munmap_section_buffer (&data
->macinfo
);
14383 munmap_section_buffer (&data
->ranges
);
14384 munmap_section_buffer (&data
->loc
);
14385 munmap_section_buffer (&data
->frame
);
14386 munmap_section_buffer (&data
->eh_frame
);
14387 munmap_section_buffer (&data
->gdb_index
);
14392 /* The contents of the hash table we create when building the string
14394 struct strtab_entry
14396 offset_type offset
;
14400 /* Hash function for a strtab_entry. */
14402 hash_strtab_entry (const void *e
)
14404 const struct strtab_entry
*entry
= e
;
14405 return mapped_index_string_hash (entry
->str
);
14408 /* Equality function for a strtab_entry. */
14410 eq_strtab_entry (const void *a
, const void *b
)
14412 const struct strtab_entry
*ea
= a
;
14413 const struct strtab_entry
*eb
= b
;
14414 return !strcmp (ea
->str
, eb
->str
);
14417 /* Create a strtab_entry hash table. */
14419 create_strtab (void)
14421 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14422 xfree
, xcalloc
, xfree
);
14425 /* Add a string to the constant pool. Return the string's offset in
14428 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14431 struct strtab_entry entry
;
14432 struct strtab_entry
*result
;
14435 slot
= htab_find_slot (table
, &entry
, INSERT
);
14440 result
= XNEW (struct strtab_entry
);
14441 result
->offset
= obstack_object_size (cpool
);
14443 obstack_grow_str0 (cpool
, str
);
14446 return result
->offset
;
14449 /* An entry in the symbol table. */
14450 struct symtab_index_entry
14452 /* The name of the symbol. */
14454 /* The offset of the name in the constant pool. */
14455 offset_type index_offset
;
14456 /* A sorted vector of the indices of all the CUs that hold an object
14458 VEC (offset_type
) *cu_indices
;
14461 /* The symbol table. This is a power-of-2-sized hash table. */
14462 struct mapped_symtab
14464 offset_type n_elements
;
14466 struct symtab_index_entry
**data
;
14469 /* Hash function for a symtab_index_entry. */
14471 hash_symtab_entry (const void *e
)
14473 const struct symtab_index_entry
*entry
= e
;
14474 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14475 sizeof (offset_type
) * VEC_length (offset_type
,
14476 entry
->cu_indices
),
14480 /* Equality function for a symtab_index_entry. */
14482 eq_symtab_entry (const void *a
, const void *b
)
14484 const struct symtab_index_entry
*ea
= a
;
14485 const struct symtab_index_entry
*eb
= b
;
14486 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14487 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14489 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14490 VEC_address (offset_type
, eb
->cu_indices
),
14491 sizeof (offset_type
) * len
);
14494 /* Destroy a symtab_index_entry. */
14496 delete_symtab_entry (void *p
)
14498 struct symtab_index_entry
*entry
= p
;
14499 VEC_free (offset_type
, entry
->cu_indices
);
14503 /* Create a hash table holding symtab_index_entry objects. */
14505 create_index_table (void)
14507 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14508 delete_symtab_entry
, xcalloc
, xfree
);
14511 /* Create a new mapped symtab object. */
14512 static struct mapped_symtab
*
14513 create_mapped_symtab (void)
14515 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14516 symtab
->n_elements
= 0;
14517 symtab
->size
= 1024;
14518 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14522 /* Destroy a mapped_symtab. */
14524 cleanup_mapped_symtab (void *p
)
14526 struct mapped_symtab
*symtab
= p
;
14527 /* The contents of the array are freed when the other hash table is
14529 xfree (symtab
->data
);
14533 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14535 static struct symtab_index_entry
**
14536 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14538 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14540 index
= hash
& (symtab
->size
- 1);
14541 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14545 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14546 return &symtab
->data
[index
];
14547 index
= (index
+ step
) & (symtab
->size
- 1);
14551 /* Expand SYMTAB's hash table. */
14553 hash_expand (struct mapped_symtab
*symtab
)
14555 offset_type old_size
= symtab
->size
;
14557 struct symtab_index_entry
**old_entries
= symtab
->data
;
14560 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14562 for (i
= 0; i
< old_size
; ++i
)
14564 if (old_entries
[i
])
14566 struct symtab_index_entry
**slot
= find_slot (symtab
,
14567 old_entries
[i
]->name
);
14568 *slot
= old_entries
[i
];
14572 xfree (old_entries
);
14575 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14576 is the index of the CU in which the symbol appears. */
14578 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
14579 offset_type cu_index
)
14581 struct symtab_index_entry
**slot
;
14583 ++symtab
->n_elements
;
14584 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
14585 hash_expand (symtab
);
14587 slot
= find_slot (symtab
, name
);
14590 *slot
= XNEW (struct symtab_index_entry
);
14591 (*slot
)->name
= name
;
14592 (*slot
)->cu_indices
= NULL
;
14594 /* Don't push an index twice. Due to how we add entries we only
14595 have to check the last one. */
14596 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
14597 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
14598 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
14601 /* Add a vector of indices to the constant pool. */
14603 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
14604 struct symtab_index_entry
*entry
)
14608 slot
= htab_find_slot (index_table
, entry
, INSERT
);
14611 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
14612 offset_type val
= MAYBE_SWAP (len
);
14617 entry
->index_offset
= obstack_object_size (cpool
);
14619 obstack_grow (cpool
, &val
, sizeof (val
));
14621 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
14624 val
= MAYBE_SWAP (iter
);
14625 obstack_grow (cpool
, &val
, sizeof (val
));
14630 struct symtab_index_entry
*old_entry
= *slot
;
14631 entry
->index_offset
= old_entry
->index_offset
;
14634 return entry
->index_offset
;
14637 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14638 constant pool entries going into the obstack CPOOL. */
14640 write_hash_table (struct mapped_symtab
*symtab
,
14641 struct obstack
*output
, struct obstack
*cpool
)
14644 htab_t index_table
;
14647 index_table
= create_index_table ();
14648 str_table
= create_strtab ();
14649 /* We add all the index vectors to the constant pool first, to
14650 ensure alignment is ok. */
14651 for (i
= 0; i
< symtab
->size
; ++i
)
14653 if (symtab
->data
[i
])
14654 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
14657 /* Now write out the hash table. */
14658 for (i
= 0; i
< symtab
->size
; ++i
)
14660 offset_type str_off
, vec_off
;
14662 if (symtab
->data
[i
])
14664 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
14665 vec_off
= symtab
->data
[i
]->index_offset
;
14669 /* While 0 is a valid constant pool index, it is not valid
14670 to have 0 for both offsets. */
14675 str_off
= MAYBE_SWAP (str_off
);
14676 vec_off
= MAYBE_SWAP (vec_off
);
14678 obstack_grow (output
, &str_off
, sizeof (str_off
));
14679 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
14682 htab_delete (str_table
);
14683 htab_delete (index_table
);
14686 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14687 from PST; CU_INDEX is the index of the CU in the vector of all
14690 add_address_entry (struct objfile
*objfile
,
14691 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
14692 unsigned int cu_index
)
14694 offset_type offset
;
14696 CORE_ADDR baseaddr
;
14698 /* Don't bother recording empty ranges. */
14699 if (pst
->textlow
== pst
->texthigh
)
14702 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14704 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
14705 obstack_grow (addr_obstack
, addr
, 8);
14706 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
14707 obstack_grow (addr_obstack
, addr
, 8);
14708 offset
= MAYBE_SWAP (cu_index
);
14709 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
14712 /* Add a list of partial symbols to SYMTAB. */
14714 write_psymbols (struct mapped_symtab
*symtab
,
14715 struct partial_symbol
**psymp
,
14717 offset_type cu_index
)
14719 for (; count
-- > 0; ++psymp
)
14721 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
14722 error (_("Ada is not currently supported by the index"));
14723 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
14727 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14728 exception if there is an error. */
14730 write_obstack (FILE *file
, struct obstack
*obstack
)
14732 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
14734 != obstack_object_size (obstack
))
14735 error (_("couldn't data write to file"));
14738 /* Unlink a file if the argument is not NULL. */
14740 unlink_if_set (void *p
)
14742 char **filename
= p
;
14744 unlink (*filename
);
14747 /* A helper struct used when iterating over debug_types. */
14748 struct signatured_type_index_data
14750 struct objfile
*objfile
;
14751 struct mapped_symtab
*symtab
;
14752 struct obstack
*types_list
;
14756 /* A helper function that writes a single signatured_type to an
14759 write_one_signatured_type (void **slot
, void *d
)
14761 struct signatured_type_index_data
*info
= d
;
14762 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
14763 struct dwarf2_per_cu_data
*cu
= &entry
->per_cu
;
14764 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14767 write_psymbols (info
->symtab
,
14768 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14769 psymtab
->n_global_syms
, info
->cu_index
);
14770 write_psymbols (info
->symtab
,
14771 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14772 psymtab
->n_static_syms
, info
->cu_index
);
14774 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
14775 obstack_grow (info
->types_list
, val
, 8);
14776 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
14777 obstack_grow (info
->types_list
, val
, 8);
14778 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
14779 obstack_grow (info
->types_list
, val
, 8);
14786 /* Create an index file for OBJFILE in the directory DIR. */
14788 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
14790 struct cleanup
*cleanup
;
14791 char *filename
, *cleanup_filename
;
14792 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
14793 struct obstack cu_list
, types_cu_list
;
14796 struct mapped_symtab
*symtab
;
14797 offset_type val
, size_of_contents
, total_len
;
14801 if (!objfile
->psymtabs
)
14803 if (dwarf2_per_objfile
->using_index
)
14804 error (_("Cannot use an index to create the index"));
14806 if (stat (objfile
->name
, &st
) < 0)
14807 perror_with_name (_("Could not stat"));
14809 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
14810 INDEX_SUFFIX
, (char *) NULL
);
14811 cleanup
= make_cleanup (xfree
, filename
);
14813 out_file
= fopen (filename
, "wb");
14815 error (_("Can't open `%s' for writing"), filename
);
14817 cleanup_filename
= filename
;
14818 make_cleanup (unlink_if_set
, &cleanup_filename
);
14820 symtab
= create_mapped_symtab ();
14821 make_cleanup (cleanup_mapped_symtab
, symtab
);
14823 obstack_init (&addr_obstack
);
14824 make_cleanup_obstack_free (&addr_obstack
);
14826 obstack_init (&cu_list
);
14827 make_cleanup_obstack_free (&cu_list
);
14829 obstack_init (&types_cu_list
);
14830 make_cleanup_obstack_free (&types_cu_list
);
14832 /* The list is already sorted, so we don't need to do additional
14833 work here. Also, the debug_types entries do not appear in
14834 all_comp_units, but only in their own hash table. */
14835 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14837 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14838 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14841 write_psymbols (symtab
,
14842 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14843 psymtab
->n_global_syms
, i
);
14844 write_psymbols (symtab
,
14845 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14846 psymtab
->n_static_syms
, i
);
14848 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
14850 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->offset
);
14851 obstack_grow (&cu_list
, val
, 8);
14852 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->length
);
14853 obstack_grow (&cu_list
, val
, 8);
14856 /* Write out the .debug_type entries, if any. */
14857 if (dwarf2_per_objfile
->signatured_types
)
14859 struct signatured_type_index_data sig_data
;
14861 sig_data
.objfile
= objfile
;
14862 sig_data
.symtab
= symtab
;
14863 sig_data
.types_list
= &types_cu_list
;
14864 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
14865 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
14866 write_one_signatured_type
, &sig_data
);
14869 obstack_init (&constant_pool
);
14870 make_cleanup_obstack_free (&constant_pool
);
14871 obstack_init (&symtab_obstack
);
14872 make_cleanup_obstack_free (&symtab_obstack
);
14873 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
14875 obstack_init (&contents
);
14876 make_cleanup_obstack_free (&contents
);
14877 size_of_contents
= 6 * sizeof (offset_type
);
14878 total_len
= size_of_contents
;
14880 /* The version number. */
14881 val
= MAYBE_SWAP (2);
14882 obstack_grow (&contents
, &val
, sizeof (val
));
14884 /* The offset of the CU list from the start of the file. */
14885 val
= MAYBE_SWAP (total_len
);
14886 obstack_grow (&contents
, &val
, sizeof (val
));
14887 total_len
+= obstack_object_size (&cu_list
);
14889 /* The offset of the types CU list from the start of the file. */
14890 val
= MAYBE_SWAP (total_len
);
14891 obstack_grow (&contents
, &val
, sizeof (val
));
14892 total_len
+= obstack_object_size (&types_cu_list
);
14894 /* The offset of the address table from the start of the file. */
14895 val
= MAYBE_SWAP (total_len
);
14896 obstack_grow (&contents
, &val
, sizeof (val
));
14897 total_len
+= obstack_object_size (&addr_obstack
);
14899 /* The offset of the symbol table from the start of the file. */
14900 val
= MAYBE_SWAP (total_len
);
14901 obstack_grow (&contents
, &val
, sizeof (val
));
14902 total_len
+= obstack_object_size (&symtab_obstack
);
14904 /* The offset of the constant pool from the start of the file. */
14905 val
= MAYBE_SWAP (total_len
);
14906 obstack_grow (&contents
, &val
, sizeof (val
));
14907 total_len
+= obstack_object_size (&constant_pool
);
14909 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
14911 write_obstack (out_file
, &contents
);
14912 write_obstack (out_file
, &cu_list
);
14913 write_obstack (out_file
, &types_cu_list
);
14914 write_obstack (out_file
, &addr_obstack
);
14915 write_obstack (out_file
, &symtab_obstack
);
14916 write_obstack (out_file
, &constant_pool
);
14920 /* We want to keep the file, so we set cleanup_filename to NULL
14921 here. See unlink_if_set. */
14922 cleanup_filename
= NULL
;
14924 do_cleanups (cleanup
);
14927 /* The mapped index file format is designed to be directly mmap()able
14928 on any architecture. In most cases, a datum is represented using a
14929 little-endian 32-bit integer value, called an offset_type. Big
14930 endian machines must byte-swap the values before using them.
14931 Exceptions to this rule are noted. The data is laid out such that
14932 alignment is always respected.
14934 A mapped index consists of several sections.
14936 1. The file header. This is a sequence of values, of offset_type
14937 unless otherwise noted:
14938 [0] The version number. Currently 1 or 2. The differences are
14939 noted below. Version 1 did not account for .debug_types sections;
14940 the presence of a .debug_types section invalidates any version 1
14941 index that may exist.
14942 [1] The offset, from the start of the file, of the CU list.
14943 [1.5] In version 2, the offset, from the start of the file, of the
14944 types CU list. This offset does not appear in version 1. Note
14945 that this can be empty, in which case this offset will be equal to
14947 [2] The offset, from the start of the file, of the address section.
14948 [3] The offset, from the start of the file, of the symbol table.
14949 [4] The offset, from the start of the file, of the constant pool.
14951 2. The CU list. This is a sequence of pairs of 64-bit
14952 little-endian values, sorted by the CU offset. The first element
14953 in each pair is the offset of a CU in the .debug_info section. The
14954 second element in each pair is the length of that CU. References
14955 to a CU elsewhere in the map are done using a CU index, which is
14956 just the 0-based index into this table. Note that if there are
14957 type CUs, then conceptually CUs and type CUs form a single list for
14958 the purposes of CU indices.
14960 2.5 The types CU list. This does not appear in a version 1 index.
14961 This is a sequence of triplets of 64-bit little-endian values. In
14962 a triplet, the first value is the CU offset, the second value is
14963 the type offset in the CU, and the third value is the type
14964 signature. The types CU list is not sorted.
14966 3. The address section. The address section consists of a sequence
14967 of address entries. Each address entry has three elements.
14968 [0] The low address. This is a 64-bit little-endian value.
14969 [1] The high address. This is a 64-bit little-endian value.
14970 [2] The CU index. This is an offset_type value.
14972 4. The symbol table. This is a hash table. The size of the hash
14973 table is always a power of 2. The initial hash and the step are
14974 currently defined by the `find_slot' function.
14976 Each slot in the hash table consists of a pair of offset_type
14977 values. The first value is the offset of the symbol's name in the
14978 constant pool. The second value is the offset of the CU vector in
14981 If both values are 0, then this slot in the hash table is empty.
14982 This is ok because while 0 is a valid constant pool index, it
14983 cannot be a valid index for both a string and a CU vector.
14985 A string in the constant pool is stored as a \0-terminated string,
14988 A CU vector in the constant pool is a sequence of offset_type
14989 values. The first value is the number of CU indices in the vector.
14990 Each subsequent value is the index of a CU in the CU list. This
14991 element in the hash table is used to indicate which CUs define the
14994 5. The constant pool. This is simply a bunch of bytes. It is
14995 organized so that alignment is correct: CU vectors are stored
14996 first, followed by strings. */
14998 save_gdb_index_command (char *arg
, int from_tty
)
15000 struct objfile
*objfile
;
15003 error (_("usage: save gdb-index DIRECTORY"));
15005 ALL_OBJFILES (objfile
)
15009 /* If the objfile does not correspond to an actual file, skip it. */
15010 if (stat (objfile
->name
, &st
) < 0)
15013 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15014 if (dwarf2_per_objfile
)
15016 volatile struct gdb_exception except
;
15018 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15020 write_psymtabs_to_index (objfile
, arg
);
15022 if (except
.reason
< 0)
15023 exception_fprintf (gdb_stderr
, except
,
15024 _("Error while writing index for `%s': "),
15032 int dwarf2_always_disassemble
;
15035 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15036 struct cmd_list_element
*c
, const char *value
)
15038 fprintf_filtered (file
, _("\
15039 Whether to always disassemble DWARF expressions is %s.\n"),
15043 void _initialize_dwarf2_read (void);
15046 _initialize_dwarf2_read (void)
15048 struct cmd_list_element
*c
;
15050 dwarf2_objfile_data_key
15051 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15053 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15054 Set DWARF 2 specific variables.\n\
15055 Configure DWARF 2 variables such as the cache size"),
15056 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15057 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15059 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15060 Show DWARF 2 specific variables\n\
15061 Show DWARF 2 variables such as the cache size"),
15062 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15063 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15065 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15066 &dwarf2_max_cache_age
, _("\
15067 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15068 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15069 A higher limit means that cached compilation units will be stored\n\
15070 in memory longer, and more total memory will be used. Zero disables\n\
15071 caching, which can slow down startup."),
15073 show_dwarf2_max_cache_age
,
15074 &set_dwarf2_cmdlist
,
15075 &show_dwarf2_cmdlist
);
15077 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15078 &dwarf2_always_disassemble
, _("\
15079 Set whether `info address' always disassembles DWARF expressions."), _("\
15080 Show whether `info address' always disassembles DWARF expressions."), _("\
15081 When enabled, DWARF expressions are always printed in an assembly-like\n\
15082 syntax. When disabled, expressions will be printed in a more\n\
15083 conversational style, when possible."),
15085 show_dwarf2_always_disassemble
,
15086 &set_dwarf2_cmdlist
,
15087 &show_dwarf2_cmdlist
);
15089 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15090 Set debugging of the dwarf2 DIE reader."), _("\
15091 Show debugging of the dwarf2 DIE reader."), _("\
15092 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15093 The value is the maximum depth to print."),
15096 &setdebuglist
, &showdebuglist
);
15098 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15099 _("Save a .gdb-index file"),
15101 set_cmd_completer (c
, filename_completer
);