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
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/>. */
34 #include "elf/dwarf2.h"
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"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
63 /* .debug_info header for a compilation unit
64 Because of alignment constraints, this structure has padding and cannot
65 be mapped directly onto the beginning of the .debug_info section. */
66 typedef struct comp_unit_header
68 unsigned int length
; /* length of the .debug_info
70 unsigned short version
; /* version number -- 2 for DWARF
72 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
73 unsigned char addr_size
; /* byte size of an address -- 4 */
76 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
79 /* .debug_pubnames header
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 pubnames_header
84 unsigned int length
; /* length of the .debug_pubnames
86 unsigned char version
; /* version number -- 2 for DWARF
88 unsigned int info_offset
; /* offset into .debug_info section */
89 unsigned int info_size
; /* byte size of .debug_info section
93 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
95 /* .debug_pubnames header
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 aranges_header
100 unsigned int length
; /* byte len of the .debug_aranges
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int info_offset
; /* offset into .debug_info section */
105 unsigned char addr_size
; /* byte size of an address */
106 unsigned char seg_size
; /* byte size of segment descriptor */
109 #define _ACTUAL_ARANGES_HEADER_SIZE 12
111 /* .debug_line statement program prologue
112 Because of alignment constraints, this structure has padding and cannot
113 be mapped directly onto the beginning of the .debug_info section. */
114 typedef struct statement_prologue
116 unsigned int total_length
; /* byte length of the statement
118 unsigned short version
; /* version number -- 2 for DWARF
120 unsigned int prologue_length
; /* # bytes between prologue &
122 unsigned char minimum_instruction_length
; /* byte size of
124 unsigned char default_is_stmt
; /* initial value of is_stmt
127 unsigned char line_range
;
128 unsigned char opcode_base
; /* number assigned to first special
130 unsigned char *standard_opcode_lengths
;
134 /* When non-zero, dump DIEs after they are read in. */
135 static int dwarf2_die_debug
= 0;
139 /* When set, the file that we're processing is known to have debugging
140 info for C++ namespaces. GCC 3.3.x did not produce this information,
141 but later versions do. */
143 static int processing_has_namespace_info
;
145 static const struct objfile_data
*dwarf2_objfile_data_key
;
147 struct dwarf2_section_info
155 struct dwarf2_per_objfile
157 struct dwarf2_section_info info
;
158 struct dwarf2_section_info abbrev
;
159 struct dwarf2_section_info line
;
160 struct dwarf2_section_info pubnames
;
161 struct dwarf2_section_info aranges
;
162 struct dwarf2_section_info loc
;
163 struct dwarf2_section_info macinfo
;
164 struct dwarf2_section_info str
;
165 struct dwarf2_section_info ranges
;
166 struct dwarf2_section_info frame
;
167 struct dwarf2_section_info eh_frame
;
169 /* A list of all the compilation units. This is used to locate
170 the target compilation unit of a particular reference. */
171 struct dwarf2_per_cu_data
**all_comp_units
;
173 /* The number of compilation units in ALL_COMP_UNITS. */
176 /* A chain of compilation units that are currently read in, so that
177 they can be freed later. */
178 struct dwarf2_per_cu_data
*read_in_chain
;
180 /* A flag indicating wether this objfile has a section loaded at a
182 int has_section_at_zero
;
185 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
187 /* names of the debugging sections */
189 /* Note that if the debugging section has been compressed, it might
190 have a name like .zdebug_info. */
192 #define INFO_SECTION "debug_info"
193 #define ABBREV_SECTION "debug_abbrev"
194 #define LINE_SECTION "debug_line"
195 #define PUBNAMES_SECTION "debug_pubnames"
196 #define ARANGES_SECTION "debug_aranges"
197 #define LOC_SECTION "debug_loc"
198 #define MACINFO_SECTION "debug_macinfo"
199 #define STR_SECTION "debug_str"
200 #define RANGES_SECTION "debug_ranges"
201 #define FRAME_SECTION "debug_frame"
202 #define EH_FRAME_SECTION "eh_frame"
204 /* local data types */
206 /* We hold several abbreviation tables in memory at the same time. */
207 #ifndef ABBREV_HASH_SIZE
208 #define ABBREV_HASH_SIZE 121
211 /* The data in a compilation unit header, after target2host
212 translation, looks like this. */
213 struct comp_unit_head
217 unsigned char addr_size
;
218 unsigned char signed_addr_p
;
219 unsigned int abbrev_offset
;
221 /* Size of file offsets; either 4 or 8. */
222 unsigned int offset_size
;
224 /* Size of the length field; either 4 or 12. */
225 unsigned int initial_length_size
;
227 /* Offset to the first byte of this compilation unit header in the
228 .debug_info section, for resolving relative reference dies. */
231 /* Offset to first die in this cu from the start of the cu.
232 This will be the first byte following the compilation unit header. */
233 unsigned int first_die_offset
;
236 /* Internal state when decoding a particular compilation unit. */
239 /* The objfile containing this compilation unit. */
240 struct objfile
*objfile
;
242 /* The header of the compilation unit. */
243 struct comp_unit_head header
;
245 /* Base address of this compilation unit. */
246 CORE_ADDR base_address
;
248 /* Non-zero if base_address has been set. */
251 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
253 /* The language we are debugging. */
254 enum language language
;
255 const struct language_defn
*language_defn
;
257 const char *producer
;
259 /* The generic symbol table building routines have separate lists for
260 file scope symbols and all all other scopes (local scopes). So
261 we need to select the right one to pass to add_symbol_to_list().
262 We do it by keeping a pointer to the correct list in list_in_scope.
264 FIXME: The original dwarf code just treated the file scope as the
265 first local scope, and all other local scopes as nested local
266 scopes, and worked fine. Check to see if we really need to
267 distinguish these in buildsym.c. */
268 struct pending
**list_in_scope
;
270 /* DWARF abbreviation table associated with this compilation unit. */
271 struct abbrev_info
**dwarf2_abbrevs
;
273 /* Storage for the abbrev table. */
274 struct obstack abbrev_obstack
;
276 /* Hash table holding all the loaded partial DIEs. */
279 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
280 unsigned int ranges_offset
;
282 /* Storage for things with the same lifetime as this read-in compilation
283 unit, including partial DIEs. */
284 struct obstack comp_unit_obstack
;
286 /* When multiple dwarf2_cu structures are living in memory, this field
287 chains them all together, so that they can be released efficiently.
288 We will probably also want a generation counter so that most-recently-used
289 compilation units are cached... */
290 struct dwarf2_per_cu_data
*read_in_chain
;
292 /* Backchain to our per_cu entry if the tree has been built. */
293 struct dwarf2_per_cu_data
*per_cu
;
295 /* Pointer to the die -> type map. Although it is stored
296 permanently in per_cu, we copy it here to avoid double
300 /* How many compilation units ago was this CU last referenced? */
303 /* A hash table of die offsets for following references. */
306 /* Full DIEs if read in. */
307 struct die_info
*dies
;
309 /* A set of pointers to dwarf2_per_cu_data objects for compilation
310 units referenced by this one. Only set during full symbol processing;
311 partial symbol tables do not have dependencies. */
314 /* Header data from the line table, during full symbol processing. */
315 struct line_header
*line_header
;
317 /* Mark used when releasing cached dies. */
318 unsigned int mark
: 1;
320 /* This flag will be set if this compilation unit might include
321 inter-compilation-unit references. */
322 unsigned int has_form_ref_addr
: 1;
324 /* This flag will be set if this compilation unit includes any
325 DW_TAG_namespace DIEs. If we know that there are explicit
326 DIEs for namespaces, we don't need to try to infer them
327 from mangled names. */
328 unsigned int has_namespace_info
: 1;
330 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
331 unsigned int has_ranges_offset
: 1;
334 /* Persistent data held for a compilation unit, even when not
335 processing it. We put a pointer to this structure in the
336 read_symtab_private field of the psymtab. If we encounter
337 inter-compilation-unit references, we also maintain a sorted
338 list of all compilation units. */
340 struct dwarf2_per_cu_data
342 /* The start offset and length of this compilation unit. 2**30-1
343 bytes should suffice to store the length of any compilation unit
344 - if it doesn't, GDB will fall over anyway.
345 NOTE: Unlike comp_unit_head.length, this length includes
346 initial_length_size. */
348 unsigned int length
: 30;
350 /* Flag indicating this compilation unit will be read in before
351 any of the current compilation units are processed. */
352 unsigned int queued
: 1;
354 /* This flag will be set if we need to load absolutely all DIEs
355 for this compilation unit, instead of just the ones we think
356 are interesting. It gets set if we look for a DIE in the
357 hash table and don't find it. */
358 unsigned int load_all_dies
: 1;
360 /* Set iff currently read in. */
361 struct dwarf2_cu
*cu
;
363 /* If full symbols for this CU have been read in, then this field
364 holds a map of DIE offsets to types. It isn't always possible
365 to reconstruct this information later, so we have to preserve
369 /* The partial symbol table associated with this compilation unit,
370 or NULL for partial units (which do not have an associated
372 struct partial_symtab
*psymtab
;
375 /* The line number information for a compilation unit (found in the
376 .debug_line section) begins with a "statement program header",
377 which contains the following information. */
380 unsigned int total_length
;
381 unsigned short version
;
382 unsigned int header_length
;
383 unsigned char minimum_instruction_length
;
384 unsigned char default_is_stmt
;
386 unsigned char line_range
;
387 unsigned char opcode_base
;
389 /* standard_opcode_lengths[i] is the number of operands for the
390 standard opcode whose value is i. This means that
391 standard_opcode_lengths[0] is unused, and the last meaningful
392 element is standard_opcode_lengths[opcode_base - 1]. */
393 unsigned char *standard_opcode_lengths
;
395 /* The include_directories table. NOTE! These strings are not
396 allocated with xmalloc; instead, they are pointers into
397 debug_line_buffer. If you try to free them, `free' will get
399 unsigned int num_include_dirs
, include_dirs_size
;
402 /* The file_names table. NOTE! These strings are not allocated
403 with xmalloc; instead, they are pointers into debug_line_buffer.
404 Don't try to free them directly. */
405 unsigned int num_file_names
, file_names_size
;
409 unsigned int dir_index
;
410 unsigned int mod_time
;
412 int included_p
; /* Non-zero if referenced by the Line Number Program. */
413 struct symtab
*symtab
; /* The associated symbol table, if any. */
416 /* The start and end of the statement program following this
417 header. These point into dwarf2_per_objfile->line_buffer. */
418 gdb_byte
*statement_program_start
, *statement_program_end
;
421 /* When we construct a partial symbol table entry we only
422 need this much information. */
423 struct partial_die_info
425 /* Offset of this DIE. */
428 /* DWARF-2 tag for this DIE. */
429 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
431 /* Language code associated with this DIE. This is only used
432 for the compilation unit DIE. */
433 unsigned int language
: 8;
435 /* Assorted flags describing the data found in this DIE. */
436 unsigned int has_children
: 1;
437 unsigned int is_external
: 1;
438 unsigned int is_declaration
: 1;
439 unsigned int has_type
: 1;
440 unsigned int has_specification
: 1;
441 unsigned int has_stmt_list
: 1;
442 unsigned int has_pc_info
: 1;
444 /* Flag set if the SCOPE field of this structure has been
446 unsigned int scope_set
: 1;
448 /* Flag set if the DIE has a byte_size attribute. */
449 unsigned int has_byte_size
: 1;
451 /* The name of this DIE. Normally the value of DW_AT_name, but
452 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
457 /* The scope to prepend to our children. This is generally
458 allocated on the comp_unit_obstack, so will disappear
459 when this compilation unit leaves the cache. */
462 /* The location description associated with this DIE, if any. */
463 struct dwarf_block
*locdesc
;
465 /* If HAS_PC_INFO, the PC range associated with this DIE. */
469 /* Pointer into the info_buffer pointing at the target of
470 DW_AT_sibling, if any. */
473 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
474 DW_AT_specification (or DW_AT_abstract_origin or
476 unsigned int spec_offset
;
478 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
479 unsigned int line_offset
;
481 /* Pointers to this DIE's parent, first child, and next sibling,
483 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
486 /* This data structure holds the information of an abbrev. */
489 unsigned int number
; /* number identifying abbrev */
490 enum dwarf_tag tag
; /* dwarf tag */
491 unsigned short has_children
; /* boolean */
492 unsigned short num_attrs
; /* number of attributes */
493 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
494 struct abbrev_info
*next
; /* next in chain */
499 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
500 ENUM_BITFIELD(dwarf_form
) form
: 16;
503 /* Additional GDB-specific attribute forms. */
506 /* A string which has been updated to GDB's internal
507 representation (e.g. converted to canonical form) and does not
508 need to be updated again. */
509 GDB_FORM_cached_string
= 0xff
512 /* Attributes have a name and a value */
515 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
516 ENUM_BITFIELD(dwarf_form
) form
: 16;
520 struct dwarf_block
*blk
;
528 /* This data structure holds a complete die structure. */
531 /* DWARF-2 tag for this DIE. */
532 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
534 /* Number of attributes */
535 unsigned short num_attrs
;
540 /* Offset in .debug_info section */
543 /* The dies in a compilation unit form an n-ary tree. PARENT
544 points to this die's parent; CHILD points to the first child of
545 this node; and all the children of a given node are chained
546 together via their SIBLING fields, terminated by a die whose
548 struct die_info
*child
; /* Its first child, if any. */
549 struct die_info
*sibling
; /* Its next sibling, if any. */
550 struct die_info
*parent
; /* Its parent, if any. */
552 /* An array of attributes, with NUM_ATTRS elements. There may be
553 zero, but it's not common and zero-sized arrays are not
554 sufficiently portable C. */
555 struct attribute attrs
[1];
558 struct function_range
561 CORE_ADDR lowpc
, highpc
;
563 struct function_range
*next
;
566 /* Get at parts of an attribute structure */
568 #define DW_STRING(attr) ((attr)->u.str)
569 #define DW_UNSND(attr) ((attr)->u.unsnd)
570 #define DW_BLOCK(attr) ((attr)->u.blk)
571 #define DW_SND(attr) ((attr)->u.snd)
572 #define DW_ADDR(attr) ((attr)->u.addr)
574 /* Blocks are a bunch of untyped bytes. */
581 #ifndef ATTR_ALLOC_CHUNK
582 #define ATTR_ALLOC_CHUNK 4
585 /* Allocate fields for structs, unions and enums in this size. */
586 #ifndef DW_FIELD_ALLOC_CHUNK
587 #define DW_FIELD_ALLOC_CHUNK 4
590 /* A zeroed version of a partial die for initialization purposes. */
591 static struct partial_die_info zeroed_partial_die
;
593 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
594 but this would require a corresponding change in unpack_field_as_long
596 static int bits_per_byte
= 8;
598 /* The routines that read and process dies for a C struct or C++ class
599 pass lists of data member fields and lists of member function fields
600 in an instance of a field_info structure, as defined below. */
603 /* List of data member and baseclasses fields. */
606 struct nextfield
*next
;
613 /* Number of fields. */
616 /* Number of baseclasses. */
619 /* Set if the accesibility of one of the fields is not public. */
620 int non_public_fields
;
622 /* Member function fields array, entries are allocated in the order they
623 are encountered in the object file. */
626 struct nextfnfield
*next
;
627 struct fn_field fnfield
;
631 /* Member function fieldlist array, contains name of possibly overloaded
632 member function, number of overloaded member functions and a pointer
633 to the head of the member function field chain. */
638 struct nextfnfield
*head
;
642 /* Number of entries in the fnfieldlists array. */
646 /* One item on the queue of compilation units to read in full symbols
648 struct dwarf2_queue_item
650 struct dwarf2_per_cu_data
*per_cu
;
651 struct dwarf2_queue_item
*next
;
654 /* The current queue. */
655 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
657 /* Loaded secondary compilation units are kept in memory until they
658 have not been referenced for the processing of this many
659 compilation units. Set this to zero to disable caching. Cache
660 sizes of up to at least twenty will improve startup time for
661 typical inter-CU-reference binaries, at an obvious memory cost. */
662 static int dwarf2_max_cache_age
= 5;
664 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
665 struct cmd_list_element
*c
, const char *value
)
667 fprintf_filtered (file
, _("\
668 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
673 /* Various complaints about symbol reading that don't abort the process */
676 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
678 complaint (&symfile_complaints
,
679 _("statement list doesn't fit in .debug_line section"));
683 dwarf2_debug_line_missing_file_complaint (void)
685 complaint (&symfile_complaints
,
686 _(".debug_line section has line data without a file"));
690 dwarf2_debug_line_missing_end_sequence_complaint (void)
692 complaint (&symfile_complaints
,
693 _(".debug_line section has line program sequence without an end"));
697 dwarf2_complex_location_expr_complaint (void)
699 complaint (&symfile_complaints
, _("location expression too complex"));
703 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
706 complaint (&symfile_complaints
,
707 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
712 dwarf2_macros_too_long_complaint (void)
714 complaint (&symfile_complaints
,
715 _("macro info runs off end of `.debug_macinfo' section"));
719 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
721 complaint (&symfile_complaints
,
722 _("macro debug info contains a malformed macro definition:\n`%s'"),
727 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
729 complaint (&symfile_complaints
,
730 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
733 /* local function prototypes */
735 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
738 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
741 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
744 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
745 struct partial_die_info
*,
746 struct partial_symtab
*);
748 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
750 static void scan_partial_symbols (struct partial_die_info
*,
751 CORE_ADDR
*, CORE_ADDR
*,
752 int, struct dwarf2_cu
*);
754 static void add_partial_symbol (struct partial_die_info
*,
757 static int pdi_needs_namespace (enum dwarf_tag tag
);
759 static void add_partial_namespace (struct partial_die_info
*pdi
,
760 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
761 int need_pc
, struct dwarf2_cu
*cu
);
763 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
764 CORE_ADDR
*highpc
, int need_pc
,
765 struct dwarf2_cu
*cu
);
767 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
768 struct dwarf2_cu
*cu
);
770 static void add_partial_subprogram (struct partial_die_info
*pdi
,
771 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
772 int need_pc
, struct dwarf2_cu
*cu
);
774 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
777 struct dwarf2_cu
*cu
);
779 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
781 static void psymtab_to_symtab_1 (struct partial_symtab
*);
783 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
785 static void dwarf2_free_abbrev_table (void *);
787 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
790 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
793 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
796 static gdb_byte
*read_partial_die (struct partial_die_info
*,
797 struct abbrev_info
*abbrev
, unsigned int,
798 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
800 static struct partial_die_info
*find_partial_die (unsigned int,
803 static void fixup_partial_die (struct partial_die_info
*,
806 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
807 struct dwarf2_cu
*, int *);
809 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
810 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
812 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
813 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
815 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
817 static int read_1_signed_byte (bfd
*, gdb_byte
*);
819 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
821 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
823 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
825 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
828 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
830 static LONGEST read_checked_initial_length_and_offset
831 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
832 unsigned int *, unsigned int *);
834 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
837 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
839 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
841 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
843 static char *read_indirect_string (bfd
*, gdb_byte
*,
844 const struct comp_unit_head
*,
847 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
849 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
851 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
853 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
855 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
858 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
859 struct dwarf2_cu
*cu
);
861 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
863 static struct die_info
*die_specification (struct die_info
*die
,
864 struct dwarf2_cu
**);
866 static void free_line_header (struct line_header
*lh
);
868 static void add_file_name (struct line_header
*, char *, unsigned int,
869 unsigned int, unsigned int);
871 static struct line_header
*(dwarf_decode_line_header
872 (unsigned int offset
,
873 bfd
*abfd
, struct dwarf2_cu
*cu
));
875 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
876 struct dwarf2_cu
*, struct partial_symtab
*);
878 static void dwarf2_start_subfile (char *, char *, char *);
880 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
883 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
886 static void dwarf2_const_value_data (struct attribute
*attr
,
890 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
892 static struct type
*die_containing_type (struct die_info
*,
895 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
897 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
899 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
901 static char *typename_concat (struct obstack
*,
906 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
908 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
910 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
912 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
913 struct dwarf2_cu
*, struct partial_symtab
*);
915 static int dwarf2_get_pc_bounds (struct die_info
*,
916 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
918 static void get_scope_pc_bounds (struct die_info
*,
919 CORE_ADDR
*, CORE_ADDR
*,
922 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
923 CORE_ADDR
, struct dwarf2_cu
*);
925 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
928 static void dwarf2_attach_fields_to_type (struct field_info
*,
929 struct type
*, struct dwarf2_cu
*);
931 static void dwarf2_add_member_fn (struct field_info
*,
932 struct die_info
*, struct type
*,
935 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
936 struct type
*, struct dwarf2_cu
*);
938 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
940 static const char *determine_class_name (struct die_info
*die
,
941 struct dwarf2_cu
*cu
);
943 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
945 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
947 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
949 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
951 static const char *namespace_name (struct die_info
*die
,
952 int *is_anonymous
, struct dwarf2_cu
*);
954 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
956 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
958 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
961 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
963 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
965 gdb_byte
**new_info_ptr
,
966 struct die_info
*parent
);
968 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
970 gdb_byte
**new_info_ptr
,
971 struct die_info
*parent
);
973 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
975 gdb_byte
**new_info_ptr
,
976 struct die_info
*parent
);
978 static void process_die (struct die_info
*, struct dwarf2_cu
*);
980 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
982 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
985 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
987 static struct die_info
*dwarf2_extension (struct die_info
*die
,
988 struct dwarf2_cu
**);
990 static char *dwarf_tag_name (unsigned int);
992 static char *dwarf_attr_name (unsigned int);
994 static char *dwarf_form_name (unsigned int);
996 static char *dwarf_stack_op_name (unsigned int);
998 static char *dwarf_bool_name (unsigned int);
1000 static char *dwarf_type_encoding_name (unsigned int);
1003 static char *dwarf_cfi_name (unsigned int);
1006 static struct die_info
*sibling_die (struct die_info
*);
1008 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1010 static void dump_die_for_error (struct die_info
*);
1012 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1015 /*static*/ void dump_die (struct die_info
*, int max_level
);
1017 static void store_in_ref_table (struct die_info
*,
1018 struct dwarf2_cu
*);
1020 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1022 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1024 static struct die_info
*follow_die_ref (struct die_info
*,
1026 struct dwarf2_cu
**);
1028 /* memory allocation interface */
1030 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1032 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1034 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1036 static void initialize_cu_func_list (struct dwarf2_cu
*);
1038 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1039 struct dwarf2_cu
*);
1041 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1042 char *, bfd
*, struct dwarf2_cu
*);
1044 static int attr_form_is_block (struct attribute
*);
1046 static int attr_form_is_section_offset (struct attribute
*);
1048 static int attr_form_is_constant (struct attribute
*);
1050 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1052 struct dwarf2_cu
*cu
);
1054 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1055 struct dwarf2_cu
*cu
);
1057 static void free_stack_comp_unit (void *);
1059 static hashval_t
partial_die_hash (const void *item
);
1061 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1063 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1064 (unsigned int offset
, struct objfile
*objfile
);
1066 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1067 (unsigned int offset
, struct objfile
*objfile
);
1069 static void free_one_comp_unit (void *);
1071 static void free_cached_comp_units (void *);
1073 static void age_cached_comp_units (void);
1075 static void free_one_cached_comp_unit (void *);
1077 static struct type
*set_die_type (struct die_info
*, struct type
*,
1078 struct dwarf2_cu
*);
1080 static void create_all_comp_units (struct objfile
*);
1082 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1085 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1087 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1088 struct dwarf2_per_cu_data
*);
1090 static void dwarf2_mark (struct dwarf2_cu
*);
1092 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1094 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1096 /* Try to locate the sections we need for DWARF 2 debugging
1097 information and return true if we have enough to do something. */
1100 dwarf2_has_info (struct objfile
*objfile
)
1102 struct dwarf2_per_objfile
*data
;
1104 /* Initialize per-objfile state. */
1105 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1106 memset (data
, 0, sizeof (*data
));
1107 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1108 dwarf2_per_objfile
= data
;
1110 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1111 return (data
->info
.asection
!= NULL
&& data
->abbrev
.asection
!= NULL
);
1114 /* When loading sections, we can either look for ".<name>", or for
1115 * ".z<name>", which indicates a compressed section. */
1118 section_is_p (const char *section_name
, const char *name
)
1120 return (section_name
[0] == '.'
1121 && (strcmp (section_name
+ 1, name
) == 0
1122 || (section_name
[1] == 'z'
1123 && strcmp (section_name
+ 2, name
) == 0)));
1126 /* This function is mapped across the sections and remembers the
1127 offset and size of each of the debugging sections we are interested
1131 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1133 if (section_is_p (sectp
->name
, INFO_SECTION
))
1135 dwarf2_per_objfile
->info
.asection
= sectp
;
1136 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1138 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1140 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1141 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1143 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1145 dwarf2_per_objfile
->line
.asection
= sectp
;
1146 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1148 else if (section_is_p (sectp
->name
, PUBNAMES_SECTION
))
1150 dwarf2_per_objfile
->pubnames
.asection
= sectp
;
1151 dwarf2_per_objfile
->pubnames
.size
= bfd_get_section_size (sectp
);
1153 else if (section_is_p (sectp
->name
, ARANGES_SECTION
))
1155 dwarf2_per_objfile
->aranges
.asection
= sectp
;
1156 dwarf2_per_objfile
->aranges
.size
= bfd_get_section_size (sectp
);
1158 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1160 dwarf2_per_objfile
->loc
.asection
= sectp
;
1161 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1163 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1165 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1166 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1168 else if (section_is_p (sectp
->name
, STR_SECTION
))
1170 dwarf2_per_objfile
->str
.asection
= sectp
;
1171 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1173 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1175 dwarf2_per_objfile
->frame
.asection
= sectp
;
1176 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1178 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1180 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1181 if (aflag
& SEC_HAS_CONTENTS
)
1183 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1184 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1187 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1189 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1190 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1193 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1194 && bfd_section_vma (abfd
, sectp
) == 0)
1195 dwarf2_per_objfile
->has_section_at_zero
= 1;
1198 /* Decompress a section that was compressed using zlib. Store the
1199 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1202 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1203 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1205 bfd
*abfd
= objfile
->obfd
;
1207 error (_("Support for zlib-compressed DWARF data (from '%s') "
1208 "is disabled in this copy of GDB"),
1209 bfd_get_filename (abfd
));
1211 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1212 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1213 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1214 bfd_size_type uncompressed_size
;
1215 gdb_byte
*uncompressed_buffer
;
1218 int header_size
= 12;
1220 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1221 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1222 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1223 bfd_get_filename (abfd
));
1225 /* Read the zlib header. In this case, it should be "ZLIB" followed
1226 by the uncompressed section size, 8 bytes in big-endian order. */
1227 if (compressed_size
< header_size
1228 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1229 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1230 bfd_get_filename (abfd
));
1231 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1232 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1233 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1234 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1235 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1236 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1237 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1238 uncompressed_size
+= compressed_buffer
[11];
1240 /* It is possible the section consists of several compressed
1241 buffers concatenated together, so we uncompress in a loop. */
1245 strm
.avail_in
= compressed_size
- header_size
;
1246 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1247 strm
.avail_out
= uncompressed_size
;
1248 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1250 rc
= inflateInit (&strm
);
1251 while (strm
.avail_in
> 0)
1254 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1255 bfd_get_filename (abfd
), rc
);
1256 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1257 + (uncompressed_size
- strm
.avail_out
));
1258 rc
= inflate (&strm
, Z_FINISH
);
1259 if (rc
!= Z_STREAM_END
)
1260 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1261 bfd_get_filename (abfd
), rc
);
1262 rc
= inflateReset (&strm
);
1264 rc
= inflateEnd (&strm
);
1266 || strm
.avail_out
!= 0)
1267 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1268 bfd_get_filename (abfd
), rc
);
1270 do_cleanups (cleanup
);
1271 *outbuf
= uncompressed_buffer
;
1272 *outsize
= uncompressed_size
;
1276 /* Read the contents of the section SECTP from object file specified by
1277 OBJFILE, store info about the section into INFO.
1278 If the section is compressed, uncompress it before returning. */
1281 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1283 bfd
*abfd
= objfile
->obfd
;
1284 asection
*sectp
= info
->asection
;
1285 gdb_byte
*buf
, *retbuf
;
1286 unsigned char header
[4];
1288 info
->buffer
= NULL
;
1289 info
->was_mmapped
= 0;
1291 if (info
->asection
== NULL
|| info
->size
== 0)
1294 /* Check if the file has a 4-byte header indicating compression. */
1295 if (info
->size
> sizeof (header
)
1296 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1297 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1299 /* Upon decompression, update the buffer and its size. */
1300 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1302 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1310 pagesize
= getpagesize ();
1312 /* Only try to mmap sections which are large enough: we don't want to
1313 waste space due to fragmentation. Also, only try mmap for sections
1314 without relocations. */
1316 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1318 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1319 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1320 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1321 MAP_PRIVATE
, pg_offset
);
1323 if (retbuf
!= MAP_FAILED
)
1325 info
->was_mmapped
= 1;
1326 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1332 /* If we get here, we are a normal, not-compressed section. */
1334 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1336 /* When debugging .o files, we may need to apply relocations; see
1337 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1338 We never compress sections in .o files, so we only need to
1339 try this when the section is not compressed. */
1340 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
1343 info
->buffer
= retbuf
;
1347 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1348 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1349 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1350 bfd_get_filename (abfd
));
1353 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1357 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1358 asection
**sectp
, gdb_byte
**bufp
,
1359 bfd_size_type
*sizep
)
1361 struct dwarf2_per_objfile
*data
1362 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1363 struct dwarf2_section_info
*info
;
1364 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1365 info
= &data
->eh_frame
;
1366 else if (section_is_p (section_name
, FRAME_SECTION
))
1367 info
= &data
->frame
;
1371 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1372 /* We haven't read this section in yet. Do it now. */
1373 dwarf2_read_section (objfile
, info
);
1375 *sectp
= info
->asection
;
1376 *bufp
= info
->buffer
;
1377 *sizep
= info
->size
;
1380 /* Build a partial symbol table. */
1383 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1385 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1386 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->abbrev
);
1387 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->line
);
1388 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->str
);
1389 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->macinfo
);
1390 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
1391 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->loc
);
1392 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->eh_frame
);
1393 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->frame
);
1396 || (objfile
->global_psymbols
.size
== 0
1397 && objfile
->static_psymbols
.size
== 0))
1399 init_psymbol_list (objfile
, 1024);
1403 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1405 /* Things are significantly easier if we have .debug_aranges and
1406 .debug_pubnames sections */
1408 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1412 /* only test this case for now */
1414 /* In this case we have to work a bit harder */
1415 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1420 /* Build the partial symbol table from the information in the
1421 .debug_pubnames and .debug_aranges sections. */
1424 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1426 bfd
*abfd
= objfile
->obfd
;
1427 char *aranges_buffer
, *pubnames_buffer
;
1428 char *aranges_ptr
, *pubnames_ptr
;
1429 unsigned int entry_length
, version
, info_offset
, info_size
;
1431 pubnames_buffer
= dwarf2_read_section (objfile
,
1432 dwarf_pubnames_section
);
1433 pubnames_ptr
= pubnames_buffer
;
1434 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames
.size
)
1436 unsigned int bytes_read
;
1438 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1439 pubnames_ptr
+= bytes_read
;
1440 version
= read_1_byte (abfd
, pubnames_ptr
);
1442 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1444 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1448 aranges_buffer
= dwarf2_read_section (objfile
,
1449 dwarf_aranges_section
);
1454 /* Return TRUE if OFFSET is within CU_HEADER. */
1457 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1459 unsigned int bottom
= cu_header
->offset
;
1460 unsigned int top
= (cu_header
->offset
1462 + cu_header
->initial_length_size
);
1463 return (offset
>= bottom
&& offset
< top
);
1466 /* Read in the comp unit header information from the debug_info at
1470 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1471 gdb_byte
*info_ptr
, bfd
*abfd
)
1474 unsigned int bytes_read
;
1476 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1477 cu_header
->initial_length_size
= bytes_read
;
1478 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1479 info_ptr
+= bytes_read
;
1480 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1482 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1484 info_ptr
+= bytes_read
;
1485 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1487 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1488 if (signed_addr
< 0)
1489 internal_error (__FILE__
, __LINE__
,
1490 _("read_comp_unit_head: dwarf from non elf file"));
1491 cu_header
->signed_addr_p
= signed_addr
;
1497 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1500 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1502 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1504 if (header
->version
!= 2 && header
->version
!= 3)
1505 error (_("Dwarf Error: wrong version in compilation unit header "
1506 "(is %d, should be %d) [in module %s]"), header
->version
,
1507 2, bfd_get_filename (abfd
));
1509 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1510 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1511 "(offset 0x%lx + 6) [in module %s]"),
1512 (long) header
->abbrev_offset
,
1513 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
),
1514 bfd_get_filename (abfd
));
1516 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1517 > dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
1518 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1519 "(offset 0x%lx + 0) [in module %s]"),
1520 (long) header
->length
,
1521 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
),
1522 bfd_get_filename (abfd
));
1527 /* Allocate a new partial symtab for file named NAME and mark this new
1528 partial symtab as being an include of PST. */
1531 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1532 struct objfile
*objfile
)
1534 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1536 subpst
->section_offsets
= pst
->section_offsets
;
1537 subpst
->textlow
= 0;
1538 subpst
->texthigh
= 0;
1540 subpst
->dependencies
= (struct partial_symtab
**)
1541 obstack_alloc (&objfile
->objfile_obstack
,
1542 sizeof (struct partial_symtab
*));
1543 subpst
->dependencies
[0] = pst
;
1544 subpst
->number_of_dependencies
= 1;
1546 subpst
->globals_offset
= 0;
1547 subpst
->n_global_syms
= 0;
1548 subpst
->statics_offset
= 0;
1549 subpst
->n_static_syms
= 0;
1550 subpst
->symtab
= NULL
;
1551 subpst
->read_symtab
= pst
->read_symtab
;
1554 /* No private part is necessary for include psymtabs. This property
1555 can be used to differentiate between such include psymtabs and
1556 the regular ones. */
1557 subpst
->read_symtab_private
= NULL
;
1560 /* Read the Line Number Program data and extract the list of files
1561 included by the source file represented by PST. Build an include
1562 partial symtab for each of these included files.
1564 This procedure assumes that there *is* a Line Number Program in
1565 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1566 before calling this procedure. */
1569 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1570 struct partial_die_info
*pdi
,
1571 struct partial_symtab
*pst
)
1573 struct objfile
*objfile
= cu
->objfile
;
1574 bfd
*abfd
= objfile
->obfd
;
1575 struct line_header
*lh
;
1577 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1579 return; /* No linetable, so no includes. */
1581 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1583 free_line_header (lh
);
1587 /* Build the partial symbol table by doing a quick pass through the
1588 .debug_info and .debug_abbrev sections. */
1591 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1593 /* Instead of reading this into a big buffer, we should probably use
1594 mmap() on architectures that support it. (FIXME) */
1595 bfd
*abfd
= objfile
->obfd
;
1597 gdb_byte
*beg_of_comp_unit
;
1598 struct partial_die_info comp_unit_die
;
1599 struct partial_symtab
*pst
;
1600 struct cleanup
*back_to
;
1603 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1605 /* Any cached compilation units will be linked by the per-objfile
1606 read_in_chain. Make sure to free them when we're done. */
1607 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1609 create_all_comp_units (objfile
);
1611 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1612 (&objfile
->objfile_obstack
);
1614 /* Since the objects we're extracting from .debug_info vary in
1615 length, only the individual functions to extract them (like
1616 read_comp_unit_head and load_partial_die) can really know whether
1617 the buffer is large enough to hold another complete object.
1619 At the moment, they don't actually check that. If .debug_info
1620 holds just one extra byte after the last compilation unit's dies,
1621 then read_comp_unit_head will happily read off the end of the
1622 buffer. read_partial_die is similarly casual. Those functions
1625 For this loop condition, simply checking whether there's any data
1626 left at all should be sufficient. */
1627 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
1628 + dwarf2_per_objfile
->info
.size
))
1630 struct cleanup
*back_to_inner
;
1631 struct dwarf2_cu cu
;
1632 struct abbrev_info
*abbrev
;
1633 unsigned int bytes_read
;
1634 struct dwarf2_per_cu_data
*this_cu
;
1636 beg_of_comp_unit
= info_ptr
;
1638 memset (&cu
, 0, sizeof (cu
));
1640 obstack_init (&cu
.comp_unit_obstack
);
1642 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1644 cu
.objfile
= objfile
;
1645 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1647 /* Complete the cu_header */
1648 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
;
1649 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1651 cu
.list_in_scope
= &file_symbols
;
1653 /* Read the abbrevs for this compilation unit into a table */
1654 dwarf2_read_abbrevs (abfd
, &cu
);
1655 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1657 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1659 /* Read the compilation unit die */
1660 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1661 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1662 abfd
, info_ptr
, &cu
);
1664 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1666 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1667 + cu
.header
.initial_length_size
);
1668 do_cleanups (back_to_inner
);
1672 /* Set the language we're debugging */
1673 set_cu_language (comp_unit_die
.language
, &cu
);
1675 /* Allocate a new partial symbol table structure */
1676 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1677 comp_unit_die
.name
? comp_unit_die
.name
: "",
1678 /* TEXTLOW and TEXTHIGH are set below. */
1680 objfile
->global_psymbols
.next
,
1681 objfile
->static_psymbols
.next
);
1683 if (comp_unit_die
.dirname
)
1684 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1685 strlen (comp_unit_die
.dirname
),
1686 &objfile
->objfile_obstack
);
1688 pst
->read_symtab_private
= (char *) this_cu
;
1690 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1692 /* Store the function that reads in the rest of the symbol table */
1693 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1695 /* If this compilation unit was already read in, free the
1696 cached copy in order to read it in again. This is
1697 necessary because we skipped some symbols when we first
1698 read in the compilation unit (see load_partial_dies).
1699 This problem could be avoided, but the benefit is
1701 if (this_cu
->cu
!= NULL
)
1702 free_one_cached_comp_unit (this_cu
->cu
);
1704 cu
.per_cu
= this_cu
;
1706 /* Note that this is a pointer to our stack frame, being
1707 added to a global data structure. It will be cleaned up
1708 in free_stack_comp_unit when we finish with this
1709 compilation unit. */
1712 this_cu
->psymtab
= pst
;
1714 /* Possibly set the default values of LOWPC and HIGHPC from
1716 if (cu
.has_ranges_offset
)
1718 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1719 &comp_unit_die
.highpc
, &cu
, pst
))
1720 comp_unit_die
.has_pc_info
= 1;
1722 else if (comp_unit_die
.has_pc_info
1723 && comp_unit_die
.lowpc
< comp_unit_die
.highpc
)
1724 /* Store the contiguous range if it is not empty; it can be empty for
1725 CUs with no code. */
1726 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1727 comp_unit_die
.lowpc
+ baseaddr
,
1728 comp_unit_die
.highpc
+ baseaddr
- 1, pst
);
1730 /* Check if comp unit has_children.
1731 If so, read the rest of the partial symbols from this comp unit.
1732 If not, there's no more debug_info for this comp unit. */
1733 if (comp_unit_die
.has_children
)
1735 struct partial_die_info
*first_die
;
1736 CORE_ADDR lowpc
, highpc
;
1738 lowpc
= ((CORE_ADDR
) -1);
1739 highpc
= ((CORE_ADDR
) 0);
1741 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1743 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1744 ! comp_unit_die
.has_pc_info
, &cu
);
1746 /* If we didn't find a lowpc, set it to highpc to avoid
1747 complaints from `maint check'. */
1748 if (lowpc
== ((CORE_ADDR
) -1))
1751 /* If the compilation unit didn't have an explicit address range,
1752 then use the information extracted from its child dies. */
1753 if (! comp_unit_die
.has_pc_info
)
1755 comp_unit_die
.lowpc
= lowpc
;
1756 comp_unit_die
.highpc
= highpc
;
1759 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1760 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1762 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1763 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1764 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1765 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1766 sort_pst_symbols (pst
);
1768 /* If there is already a psymtab or symtab for a file of this
1769 name, remove it. (If there is a symtab, more drastic things
1770 also happen.) This happens in VxWorks. */
1771 free_named_symtabs (pst
->filename
);
1773 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1774 + cu
.header
.initial_length_size
;
1776 if (comp_unit_die
.has_stmt_list
)
1778 /* Get the list of files included in the current compilation unit,
1779 and build a psymtab for each of them. */
1780 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1783 do_cleanups (back_to_inner
);
1786 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1787 &objfile
->objfile_obstack
);
1789 do_cleanups (back_to
);
1792 /* Load the DIEs for a secondary CU into memory. */
1795 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1797 bfd
*abfd
= objfile
->obfd
;
1798 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1799 struct partial_die_info comp_unit_die
;
1800 struct dwarf2_cu
*cu
;
1801 struct abbrev_info
*abbrev
;
1802 unsigned int bytes_read
;
1803 struct cleanup
*back_to
;
1805 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
1806 beg_of_comp_unit
= info_ptr
;
1808 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1809 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1811 obstack_init (&cu
->comp_unit_obstack
);
1813 cu
->objfile
= objfile
;
1814 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1816 /* Complete the cu_header. */
1817 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
;
1818 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1820 /* Read the abbrevs for this compilation unit into a table. */
1821 dwarf2_read_abbrevs (abfd
, cu
);
1822 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1824 /* Read the compilation unit die. */
1825 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1826 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1827 abfd
, info_ptr
, cu
);
1829 /* Set the language we're debugging. */
1830 set_cu_language (comp_unit_die
.language
, cu
);
1832 /* Link this compilation unit into the compilation unit tree. */
1834 cu
->per_cu
= this_cu
;
1835 cu
->type_hash
= cu
->per_cu
->type_hash
;
1837 /* Check if comp unit has_children.
1838 If so, read the rest of the partial symbols from this comp unit.
1839 If not, there's no more debug_info for this comp unit. */
1840 if (comp_unit_die
.has_children
)
1841 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1843 do_cleanups (back_to
);
1846 /* Create a list of all compilation units in OBJFILE. We do this only
1847 if an inter-comp-unit reference is found; presumably if there is one,
1848 there will be many, and one will occur early in the .debug_info section.
1849 So there's no point in building this list incrementally. */
1852 create_all_comp_units (struct objfile
*objfile
)
1856 struct dwarf2_per_cu_data
**all_comp_units
;
1857 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1861 all_comp_units
= xmalloc (n_allocated
1862 * sizeof (struct dwarf2_per_cu_data
*));
1864 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
1866 unsigned int length
, initial_length_size
;
1867 gdb_byte
*beg_of_comp_unit
;
1868 struct dwarf2_per_cu_data
*this_cu
;
1869 unsigned int offset
;
1871 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
1873 /* Read just enough information to find out where the next
1874 compilation unit is. */
1875 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1876 &initial_length_size
);
1878 /* Save the compilation unit for later lookup. */
1879 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1880 sizeof (struct dwarf2_per_cu_data
));
1881 memset (this_cu
, 0, sizeof (*this_cu
));
1882 this_cu
->offset
= offset
;
1883 this_cu
->length
= length
+ initial_length_size
;
1885 if (n_comp_units
== n_allocated
)
1888 all_comp_units
= xrealloc (all_comp_units
,
1890 * sizeof (struct dwarf2_per_cu_data
*));
1892 all_comp_units
[n_comp_units
++] = this_cu
;
1894 info_ptr
= info_ptr
+ this_cu
->length
;
1897 dwarf2_per_objfile
->all_comp_units
1898 = obstack_alloc (&objfile
->objfile_obstack
,
1899 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1900 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1901 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1902 xfree (all_comp_units
);
1903 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1906 /* Process all loaded DIEs for compilation unit CU, starting at
1907 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1908 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1909 DW_AT_ranges). If NEED_PC is set, then this function will set
1910 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1911 and record the covered ranges in the addrmap. */
1914 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1915 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
1917 struct objfile
*objfile
= cu
->objfile
;
1918 bfd
*abfd
= objfile
->obfd
;
1919 struct partial_die_info
*pdi
;
1921 /* Now, march along the PDI's, descending into ones which have
1922 interesting children but skipping the children of the other ones,
1923 until we reach the end of the compilation unit. */
1929 fixup_partial_die (pdi
, cu
);
1931 /* Anonymous namespaces have no name but have interesting
1932 children, so we need to look at them. Ditto for anonymous
1935 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1936 || pdi
->tag
== DW_TAG_enumeration_type
)
1940 case DW_TAG_subprogram
:
1941 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
1943 case DW_TAG_variable
:
1944 case DW_TAG_typedef
:
1945 case DW_TAG_union_type
:
1946 if (!pdi
->is_declaration
)
1948 add_partial_symbol (pdi
, cu
);
1951 case DW_TAG_class_type
:
1952 case DW_TAG_interface_type
:
1953 case DW_TAG_structure_type
:
1954 if (!pdi
->is_declaration
)
1956 add_partial_symbol (pdi
, cu
);
1959 case DW_TAG_enumeration_type
:
1960 if (!pdi
->is_declaration
)
1961 add_partial_enumeration (pdi
, cu
);
1963 case DW_TAG_base_type
:
1964 case DW_TAG_subrange_type
:
1965 /* File scope base type definitions are added to the partial
1967 add_partial_symbol (pdi
, cu
);
1969 case DW_TAG_namespace
:
1970 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
1973 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
1980 /* If the die has a sibling, skip to the sibling. */
1982 pdi
= pdi
->die_sibling
;
1986 /* Functions used to compute the fully scoped name of a partial DIE.
1988 Normally, this is simple. For C++, the parent DIE's fully scoped
1989 name is concatenated with "::" and the partial DIE's name. For
1990 Java, the same thing occurs except that "." is used instead of "::".
1991 Enumerators are an exception; they use the scope of their parent
1992 enumeration type, i.e. the name of the enumeration type is not
1993 prepended to the enumerator.
1995 There are two complexities. One is DW_AT_specification; in this
1996 case "parent" means the parent of the target of the specification,
1997 instead of the direct parent of the DIE. The other is compilers
1998 which do not emit DW_TAG_namespace; in this case we try to guess
1999 the fully qualified name of structure types from their members'
2000 linkage names. This must be done using the DIE's children rather
2001 than the children of any DW_AT_specification target. We only need
2002 to do this for structures at the top level, i.e. if the target of
2003 any DW_AT_specification (if any; otherwise the DIE itself) does not
2006 /* Compute the scope prefix associated with PDI's parent, in
2007 compilation unit CU. The result will be allocated on CU's
2008 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2009 field. NULL is returned if no prefix is necessary. */
2011 partial_die_parent_scope (struct partial_die_info
*pdi
,
2012 struct dwarf2_cu
*cu
)
2014 char *grandparent_scope
;
2015 struct partial_die_info
*parent
, *real_pdi
;
2017 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2018 then this means the parent of the specification DIE. */
2021 while (real_pdi
->has_specification
)
2022 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2024 parent
= real_pdi
->die_parent
;
2028 if (parent
->scope_set
)
2029 return parent
->scope
;
2031 fixup_partial_die (parent
, cu
);
2033 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2035 if (parent
->tag
== DW_TAG_namespace
2036 || parent
->tag
== DW_TAG_structure_type
2037 || parent
->tag
== DW_TAG_class_type
2038 || parent
->tag
== DW_TAG_interface_type
2039 || parent
->tag
== DW_TAG_union_type
)
2041 if (grandparent_scope
== NULL
)
2042 parent
->scope
= parent
->name
;
2044 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2047 else if (parent
->tag
== DW_TAG_enumeration_type
)
2048 /* Enumerators should not get the name of the enumeration as a prefix. */
2049 parent
->scope
= grandparent_scope
;
2052 /* FIXME drow/2004-04-01: What should we be doing with
2053 function-local names? For partial symbols, we should probably be
2055 complaint (&symfile_complaints
,
2056 _("unhandled containing DIE tag %d for DIE at %d"),
2057 parent
->tag
, pdi
->offset
);
2058 parent
->scope
= grandparent_scope
;
2061 parent
->scope_set
= 1;
2062 return parent
->scope
;
2065 /* Return the fully scoped name associated with PDI, from compilation unit
2066 CU. The result will be allocated with malloc. */
2068 partial_die_full_name (struct partial_die_info
*pdi
,
2069 struct dwarf2_cu
*cu
)
2073 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2074 if (parent_scope
== NULL
)
2077 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2081 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2083 struct objfile
*objfile
= cu
->objfile
;
2085 char *actual_name
= NULL
;
2086 const char *my_prefix
;
2087 const struct partial_symbol
*psym
= NULL
;
2089 int built_actual_name
= 0;
2091 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2093 if (pdi_needs_namespace (pdi
->tag
))
2095 actual_name
= partial_die_full_name (pdi
, cu
);
2097 built_actual_name
= 1;
2100 if (actual_name
== NULL
)
2101 actual_name
= pdi
->name
;
2105 case DW_TAG_subprogram
:
2106 if (pdi
->is_external
|| cu
->language
== language_ada
)
2108 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2109 of the global scope. But in Ada, we want to be able to access
2110 nested procedures globally. So all Ada subprograms are stored
2111 in the global scope. */
2112 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2113 mst_text, objfile); */
2114 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2115 VAR_DOMAIN
, LOC_BLOCK
,
2116 &objfile
->global_psymbols
,
2117 0, pdi
->lowpc
+ baseaddr
,
2118 cu
->language
, objfile
);
2122 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2123 mst_file_text, objfile); */
2124 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2125 VAR_DOMAIN
, LOC_BLOCK
,
2126 &objfile
->static_psymbols
,
2127 0, pdi
->lowpc
+ baseaddr
,
2128 cu
->language
, objfile
);
2131 case DW_TAG_variable
:
2132 if (pdi
->is_external
)
2135 Don't enter into the minimal symbol tables as there is
2136 a minimal symbol table entry from the ELF symbols already.
2137 Enter into partial symbol table if it has a location
2138 descriptor or a type.
2139 If the location descriptor is missing, new_symbol will create
2140 a LOC_UNRESOLVED symbol, the address of the variable will then
2141 be determined from the minimal symbol table whenever the variable
2143 The address for the partial symbol table entry is not
2144 used by GDB, but it comes in handy for debugging partial symbol
2148 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2149 if (pdi
->locdesc
|| pdi
->has_type
)
2150 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2151 VAR_DOMAIN
, LOC_STATIC
,
2152 &objfile
->global_psymbols
,
2154 cu
->language
, objfile
);
2158 /* Static Variable. Skip symbols without location descriptors. */
2159 if (pdi
->locdesc
== NULL
)
2161 if (built_actual_name
)
2162 xfree (actual_name
);
2165 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2166 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2167 mst_file_data, objfile); */
2168 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2169 VAR_DOMAIN
, LOC_STATIC
,
2170 &objfile
->static_psymbols
,
2172 cu
->language
, objfile
);
2175 case DW_TAG_typedef
:
2176 case DW_TAG_base_type
:
2177 case DW_TAG_subrange_type
:
2178 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2179 VAR_DOMAIN
, LOC_TYPEDEF
,
2180 &objfile
->static_psymbols
,
2181 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2183 case DW_TAG_namespace
:
2184 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2185 VAR_DOMAIN
, LOC_TYPEDEF
,
2186 &objfile
->global_psymbols
,
2187 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2189 case DW_TAG_class_type
:
2190 case DW_TAG_interface_type
:
2191 case DW_TAG_structure_type
:
2192 case DW_TAG_union_type
:
2193 case DW_TAG_enumeration_type
:
2194 /* Skip external references. The DWARF standard says in the section
2195 about "Structure, Union, and Class Type Entries": "An incomplete
2196 structure, union or class type is represented by a structure,
2197 union or class entry that does not have a byte size attribute
2198 and that has a DW_AT_declaration attribute." */
2199 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2201 if (built_actual_name
)
2202 xfree (actual_name
);
2206 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2207 static vs. global. */
2208 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2209 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2210 (cu
->language
== language_cplus
2211 || cu
->language
== language_java
)
2212 ? &objfile
->global_psymbols
2213 : &objfile
->static_psymbols
,
2214 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2217 case DW_TAG_enumerator
:
2218 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2219 VAR_DOMAIN
, LOC_CONST
,
2220 (cu
->language
== language_cplus
2221 || cu
->language
== language_java
)
2222 ? &objfile
->global_psymbols
2223 : &objfile
->static_psymbols
,
2224 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2230 /* Check to see if we should scan the name for possible namespace
2231 info. Only do this if this is C++, if we don't have namespace
2232 debugging info in the file, if the psym is of an appropriate type
2233 (otherwise we'll have psym == NULL), and if we actually had a
2234 mangled name to begin with. */
2236 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2237 cases which do not set PSYM above? */
2239 if (cu
->language
== language_cplus
2240 && cu
->has_namespace_info
== 0
2242 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2243 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2246 if (built_actual_name
)
2247 xfree (actual_name
);
2250 /* Determine whether a die of type TAG living in a C++ class or
2251 namespace needs to have the name of the scope prepended to the
2252 name listed in the die. */
2255 pdi_needs_namespace (enum dwarf_tag tag
)
2259 case DW_TAG_namespace
:
2260 case DW_TAG_typedef
:
2261 case DW_TAG_class_type
:
2262 case DW_TAG_interface_type
:
2263 case DW_TAG_structure_type
:
2264 case DW_TAG_union_type
:
2265 case DW_TAG_enumeration_type
:
2266 case DW_TAG_enumerator
:
2273 /* Read a partial die corresponding to a namespace; also, add a symbol
2274 corresponding to that namespace to the symbol table. NAMESPACE is
2275 the name of the enclosing namespace. */
2278 add_partial_namespace (struct partial_die_info
*pdi
,
2279 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2280 int need_pc
, struct dwarf2_cu
*cu
)
2282 struct objfile
*objfile
= cu
->objfile
;
2284 /* Add a symbol for the namespace. */
2286 add_partial_symbol (pdi
, cu
);
2288 /* Now scan partial symbols in that namespace. */
2290 if (pdi
->has_children
)
2291 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2294 /* Read a partial die corresponding to a Fortran module. */
2297 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2298 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2300 /* Now scan partial symbols in that module.
2302 FIXME: Support the separate Fortran module namespaces. */
2304 if (pdi
->has_children
)
2305 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2308 /* Read a partial die corresponding to a subprogram and create a partial
2309 symbol for that subprogram. When the CU language allows it, this
2310 routine also defines a partial symbol for each nested subprogram
2311 that this subprogram contains.
2313 DIE my also be a lexical block, in which case we simply search
2314 recursively for suprograms defined inside that lexical block.
2315 Again, this is only performed when the CU language allows this
2316 type of definitions. */
2319 add_partial_subprogram (struct partial_die_info
*pdi
,
2320 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2321 int need_pc
, struct dwarf2_cu
*cu
)
2323 if (pdi
->tag
== DW_TAG_subprogram
)
2325 if (pdi
->has_pc_info
)
2327 if (pdi
->lowpc
< *lowpc
)
2328 *lowpc
= pdi
->lowpc
;
2329 if (pdi
->highpc
> *highpc
)
2330 *highpc
= pdi
->highpc
;
2334 struct objfile
*objfile
= cu
->objfile
;
2336 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2337 SECT_OFF_TEXT (objfile
));
2338 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2339 pdi
->lowpc
, pdi
->highpc
- 1,
2340 cu
->per_cu
->psymtab
);
2342 if (!pdi
->is_declaration
)
2343 add_partial_symbol (pdi
, cu
);
2347 if (! pdi
->has_children
)
2350 if (cu
->language
== language_ada
)
2352 pdi
= pdi
->die_child
;
2355 fixup_partial_die (pdi
, cu
);
2356 if (pdi
->tag
== DW_TAG_subprogram
2357 || pdi
->tag
== DW_TAG_lexical_block
)
2358 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2359 pdi
= pdi
->die_sibling
;
2364 /* See if we can figure out if the class lives in a namespace. We do
2365 this by looking for a member function; its demangled name will
2366 contain namespace info, if there is any. */
2369 guess_structure_name (struct partial_die_info
*struct_pdi
,
2370 struct dwarf2_cu
*cu
)
2372 if ((cu
->language
== language_cplus
2373 || cu
->language
== language_java
)
2374 && cu
->has_namespace_info
== 0
2375 && struct_pdi
->has_children
)
2377 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2378 what template types look like, because the demangler
2379 frequently doesn't give the same name as the debug info. We
2380 could fix this by only using the demangled name to get the
2381 prefix (but see comment in read_structure_type). */
2383 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2384 struct partial_die_info
*real_pdi
;
2386 /* If this DIE (this DIE's specification, if any) has a parent, then
2387 we should not do this. We'll prepend the parent's fully qualified
2388 name when we create the partial symbol. */
2390 real_pdi
= struct_pdi
;
2391 while (real_pdi
->has_specification
)
2392 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2394 if (real_pdi
->die_parent
!= NULL
)
2397 while (child_pdi
!= NULL
)
2399 if (child_pdi
->tag
== DW_TAG_subprogram
)
2401 char *actual_class_name
2402 = language_class_name_from_physname (cu
->language_defn
,
2404 if (actual_class_name
!= NULL
)
2407 = obsavestring (actual_class_name
,
2408 strlen (actual_class_name
),
2409 &cu
->comp_unit_obstack
);
2410 xfree (actual_class_name
);
2415 child_pdi
= child_pdi
->die_sibling
;
2420 /* Read a partial die corresponding to an enumeration type. */
2423 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2424 struct dwarf2_cu
*cu
)
2426 struct objfile
*objfile
= cu
->objfile
;
2427 bfd
*abfd
= objfile
->obfd
;
2428 struct partial_die_info
*pdi
;
2430 if (enum_pdi
->name
!= NULL
)
2431 add_partial_symbol (enum_pdi
, cu
);
2433 pdi
= enum_pdi
->die_child
;
2436 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2437 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2439 add_partial_symbol (pdi
, cu
);
2440 pdi
= pdi
->die_sibling
;
2444 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2445 Return the corresponding abbrev, or NULL if the number is zero (indicating
2446 an empty DIE). In either case *BYTES_READ will be set to the length of
2447 the initial number. */
2449 static struct abbrev_info
*
2450 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2451 struct dwarf2_cu
*cu
)
2453 bfd
*abfd
= cu
->objfile
->obfd
;
2454 unsigned int abbrev_number
;
2455 struct abbrev_info
*abbrev
;
2457 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2459 if (abbrev_number
== 0)
2462 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2465 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2466 bfd_get_filename (abfd
));
2472 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2473 pointer to the end of a series of DIEs, terminated by an empty
2474 DIE. Any children of the skipped DIEs will also be skipped. */
2477 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2479 struct abbrev_info
*abbrev
;
2480 unsigned int bytes_read
;
2484 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2486 return info_ptr
+ bytes_read
;
2488 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2492 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2493 should point just after the initial uleb128 of a DIE, and the
2494 abbrev corresponding to that skipped uleb128 should be passed in
2495 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2499 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2500 struct dwarf2_cu
*cu
)
2502 unsigned int bytes_read
;
2503 struct attribute attr
;
2504 bfd
*abfd
= cu
->objfile
->obfd
;
2505 unsigned int form
, i
;
2507 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2509 /* The only abbrev we care about is DW_AT_sibling. */
2510 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2512 read_attribute (&attr
, &abbrev
->attrs
[i
],
2513 abfd
, info_ptr
, cu
);
2514 if (attr
.form
== DW_FORM_ref_addr
)
2515 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2517 return dwarf2_per_objfile
->info
.buffer
2518 + dwarf2_get_ref_die_offset (&attr
);
2521 /* If it isn't DW_AT_sibling, skip this attribute. */
2522 form
= abbrev
->attrs
[i
].form
;
2527 case DW_FORM_ref_addr
:
2528 info_ptr
+= cu
->header
.addr_size
;
2547 case DW_FORM_string
:
2548 read_string (abfd
, info_ptr
, &bytes_read
);
2549 info_ptr
+= bytes_read
;
2552 info_ptr
+= cu
->header
.offset_size
;
2555 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2556 info_ptr
+= bytes_read
;
2558 case DW_FORM_block1
:
2559 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2561 case DW_FORM_block2
:
2562 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2564 case DW_FORM_block4
:
2565 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2569 case DW_FORM_ref_udata
:
2570 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2572 case DW_FORM_indirect
:
2573 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2574 info_ptr
+= bytes_read
;
2575 /* We need to continue parsing from here, so just go back to
2577 goto skip_attribute
;
2580 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2581 dwarf_form_name (form
),
2582 bfd_get_filename (abfd
));
2586 if (abbrev
->has_children
)
2587 return skip_children (info_ptr
, cu
);
2592 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2593 the next DIE after ORIG_PDI. */
2596 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2597 bfd
*abfd
, struct dwarf2_cu
*cu
)
2599 /* Do we know the sibling already? */
2601 if (orig_pdi
->sibling
)
2602 return orig_pdi
->sibling
;
2604 /* Are there any children to deal with? */
2606 if (!orig_pdi
->has_children
)
2609 /* Skip the children the long way. */
2611 return skip_children (info_ptr
, cu
);
2614 /* Expand this partial symbol table into a full symbol table. */
2617 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2619 /* FIXME: This is barely more than a stub. */
2624 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2630 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2631 gdb_flush (gdb_stdout
);
2634 /* Restore our global data. */
2635 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2636 dwarf2_objfile_data_key
);
2638 /* If this psymtab is constructed from a debug-only objfile, the
2639 has_section_at_zero flag will not necessarily be correct. We
2640 can get the correct value for this flag by looking at the data
2641 associated with the (presumably stripped) associated objfile. */
2642 if (pst
->objfile
->separate_debug_objfile_backlink
)
2644 struct dwarf2_per_objfile
*dpo_backlink
2645 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2646 dwarf2_objfile_data_key
);
2647 dwarf2_per_objfile
->has_section_at_zero
2648 = dpo_backlink
->has_section_at_zero
;
2651 psymtab_to_symtab_1 (pst
);
2653 /* Finish up the debug error message. */
2655 printf_filtered (_("done.\n"));
2660 /* Add PER_CU to the queue. */
2663 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2665 struct dwarf2_queue_item
*item
;
2668 item
= xmalloc (sizeof (*item
));
2669 item
->per_cu
= per_cu
;
2672 if (dwarf2_queue
== NULL
)
2673 dwarf2_queue
= item
;
2675 dwarf2_queue_tail
->next
= item
;
2677 dwarf2_queue_tail
= item
;
2679 /* Either PER_CU is the CU we want to process, or we're following a reference
2680 pointing into PER_CU. Either way, we need its DIEs now. */
2681 load_full_comp_unit (item
->per_cu
, objfile
);
2682 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2683 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2686 /* Process the queue. */
2689 process_queue (struct objfile
*objfile
)
2691 struct dwarf2_queue_item
*item
, *next_item
;
2693 /* The queue starts out with one item, but following a DIE reference
2694 may load a new CU, adding it to the end of the queue. */
2695 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2697 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2698 process_full_comp_unit (item
->per_cu
);
2700 item
->per_cu
->queued
= 0;
2701 next_item
= item
->next
;
2705 dwarf2_queue_tail
= NULL
;
2708 /* Free all allocated queue entries. This function only releases anything if
2709 an error was thrown; if the queue was processed then it would have been
2710 freed as we went along. */
2713 dwarf2_release_queue (void *dummy
)
2715 struct dwarf2_queue_item
*item
, *last
;
2717 item
= dwarf2_queue
;
2720 /* Anything still marked queued is likely to be in an
2721 inconsistent state, so discard it. */
2722 if (item
->per_cu
->queued
)
2724 if (item
->per_cu
->cu
!= NULL
)
2725 free_one_cached_comp_unit (item
->per_cu
->cu
);
2726 item
->per_cu
->queued
= 0;
2734 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2737 /* Read in full symbols for PST, and anything it depends on. */
2740 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2742 struct dwarf2_per_cu_data
*per_cu
;
2743 struct cleanup
*back_to
;
2746 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2747 if (!pst
->dependencies
[i
]->readin
)
2749 /* Inform about additional files that need to be read in. */
2752 /* FIXME: i18n: Need to make this a single string. */
2753 fputs_filtered (" ", gdb_stdout
);
2755 fputs_filtered ("and ", gdb_stdout
);
2757 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2758 wrap_here (""); /* Flush output */
2759 gdb_flush (gdb_stdout
);
2761 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2764 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2768 /* It's an include file, no symbols to read for it.
2769 Everything is in the parent symtab. */
2774 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2776 queue_comp_unit (per_cu
, pst
->objfile
);
2778 process_queue (pst
->objfile
);
2780 /* Age the cache, releasing compilation units that have not
2781 been used recently. */
2782 age_cached_comp_units ();
2784 do_cleanups (back_to
);
2787 /* Load the DIEs associated with PST and PER_CU into memory. */
2789 static struct dwarf2_cu
*
2790 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2792 bfd
*abfd
= objfile
->obfd
;
2793 struct dwarf2_cu
*cu
;
2794 unsigned int offset
;
2796 struct cleanup
*back_to
, *free_cu_cleanup
;
2797 struct attribute
*attr
;
2800 /* Set local variables from the partial symbol table info. */
2801 offset
= per_cu
->offset
;
2803 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
2805 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2806 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2808 /* If an error occurs while loading, release our storage. */
2809 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2811 cu
->objfile
= objfile
;
2813 /* read in the comp_unit header */
2814 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2816 /* Read the abbrevs for this compilation unit */
2817 dwarf2_read_abbrevs (abfd
, cu
);
2818 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2820 cu
->header
.offset
= offset
;
2822 cu
->per_cu
= per_cu
;
2824 cu
->type_hash
= per_cu
->type_hash
;
2826 /* We use this obstack for block values in dwarf_alloc_block. */
2827 obstack_init (&cu
->comp_unit_obstack
);
2829 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2831 /* We try not to read any attributes in this function, because not
2832 all objfiles needed for references have been loaded yet, and symbol
2833 table processing isn't initialized. But we have to set the CU language,
2834 or we won't be able to build types correctly. */
2835 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2837 set_cu_language (DW_UNSND (attr
), cu
);
2839 set_cu_language (language_minimal
, cu
);
2841 do_cleanups (back_to
);
2843 /* We've successfully allocated this compilation unit. Let our caller
2844 clean it up when finished with it. */
2845 discard_cleanups (free_cu_cleanup
);
2850 /* Generate full symbol information for PST and CU, whose DIEs have
2851 already been loaded into memory. */
2854 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2856 struct partial_symtab
*pst
= per_cu
->psymtab
;
2857 struct dwarf2_cu
*cu
= per_cu
->cu
;
2858 struct objfile
*objfile
= pst
->objfile
;
2859 bfd
*abfd
= objfile
->obfd
;
2860 CORE_ADDR lowpc
, highpc
;
2861 struct symtab
*symtab
;
2862 struct cleanup
*back_to
;
2863 struct attribute
*attr
;
2866 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2869 back_to
= make_cleanup (really_free_pendings
, NULL
);
2871 cu
->list_in_scope
= &file_symbols
;
2873 /* Find the base address of the compilation unit for range lists and
2874 location lists. It will normally be specified by DW_AT_low_pc.
2875 In DWARF-3 draft 4, the base address could be overridden by
2876 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2877 compilation units with discontinuous ranges. */
2880 cu
->base_address
= 0;
2882 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2885 cu
->base_address
= DW_ADDR (attr
);
2890 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2893 cu
->base_address
= DW_ADDR (attr
);
2898 /* Do line number decoding in read_file_scope () */
2899 process_die (cu
->dies
, cu
);
2901 /* Some compilers don't define a DW_AT_high_pc attribute for the
2902 compilation unit. If the DW_AT_high_pc is missing, synthesize
2903 it, by scanning the DIE's below the compilation unit. */
2904 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2906 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2908 /* Set symtab language to language from DW_AT_language.
2909 If the compilation is from a C file generated by language preprocessors,
2910 do not set the language if it was already deduced by start_subfile. */
2912 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2914 symtab
->language
= cu
->language
;
2916 pst
->symtab
= symtab
;
2919 do_cleanups (back_to
);
2922 /* Process a die and its children. */
2925 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2929 case DW_TAG_padding
:
2931 case DW_TAG_compile_unit
:
2932 read_file_scope (die
, cu
);
2934 case DW_TAG_subprogram
:
2935 read_func_scope (die
, cu
);
2937 case DW_TAG_inlined_subroutine
:
2938 /* FIXME: These are ignored for now.
2939 They could be used to set breakpoints on all inlined instances
2940 of a function and make GDB `next' properly over inlined functions. */
2942 case DW_TAG_lexical_block
:
2943 case DW_TAG_try_block
:
2944 case DW_TAG_catch_block
:
2945 read_lexical_block_scope (die
, cu
);
2947 case DW_TAG_class_type
:
2948 case DW_TAG_interface_type
:
2949 case DW_TAG_structure_type
:
2950 case DW_TAG_union_type
:
2951 process_structure_scope (die
, cu
);
2953 case DW_TAG_enumeration_type
:
2954 process_enumeration_scope (die
, cu
);
2957 /* These dies have a type, but processing them does not create
2958 a symbol or recurse to process the children. Therefore we can
2959 read them on-demand through read_type_die. */
2960 case DW_TAG_subroutine_type
:
2961 case DW_TAG_set_type
:
2962 case DW_TAG_array_type
:
2963 case DW_TAG_pointer_type
:
2964 case DW_TAG_ptr_to_member_type
:
2965 case DW_TAG_reference_type
:
2966 case DW_TAG_string_type
:
2969 case DW_TAG_base_type
:
2970 case DW_TAG_subrange_type
:
2971 case DW_TAG_typedef
:
2972 /* Add a typedef symbol for the type definition, if it has a
2974 new_symbol (die
, read_type_die (die
, cu
), cu
);
2976 case DW_TAG_common_block
:
2977 read_common_block (die
, cu
);
2979 case DW_TAG_common_inclusion
:
2981 case DW_TAG_namespace
:
2982 processing_has_namespace_info
= 1;
2983 read_namespace (die
, cu
);
2986 read_module (die
, cu
);
2988 case DW_TAG_imported_declaration
:
2989 case DW_TAG_imported_module
:
2990 processing_has_namespace_info
= 1;
2991 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
2992 || cu
->language
!= language_fortran
))
2993 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
2994 dwarf_tag_name (die
->tag
));
2995 read_import_statement (die
, cu
);
2998 new_symbol (die
, NULL
, cu
);
3003 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3004 If scope qualifiers are appropriate they will be added. The result
3005 will be allocated on the objfile_obstack, or NULL if the DIE does
3009 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3011 struct attribute
*attr
;
3012 char *prefix
, *name
;
3013 struct ui_file
*buf
= NULL
;
3015 name
= dwarf2_name (die
, cu
);
3019 /* These are the only languages we know how to qualify names in. */
3020 if (cu
->language
!= language_cplus
3021 && cu
->language
!= language_java
)
3024 /* If no prefix is necessary for this type of DIE, return the
3025 unqualified name. The other three tags listed could be handled
3026 in pdi_needs_namespace, but that requires broader changes. */
3027 if (!pdi_needs_namespace (die
->tag
)
3028 && die
->tag
!= DW_TAG_subprogram
3029 && die
->tag
!= DW_TAG_variable
3030 && die
->tag
!= DW_TAG_member
)
3033 prefix
= determine_prefix (die
, cu
);
3034 if (*prefix
!= '\0')
3035 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
3041 /* Read the import statement specified by the given die and record it. */
3044 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3046 struct attribute
*import_attr
;
3047 struct die_info
*imported_die
;
3048 const char *imported_name
;
3050 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3051 if (import_attr
== NULL
)
3053 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3054 dwarf_tag_name (die
->tag
));
3058 imported_die
= follow_die_ref (die
, import_attr
, &cu
);
3059 imported_name
= dwarf2_name (imported_die
, cu
);
3060 if (imported_name
== NULL
)
3062 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3064 The import in the following code:
3078 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3079 <52> DW_AT_decl_file : 1
3080 <53> DW_AT_decl_line : 6
3081 <54> DW_AT_import : <0x75>
3082 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3084 <5b> DW_AT_decl_file : 1
3085 <5c> DW_AT_decl_line : 2
3086 <5d> DW_AT_type : <0x6e>
3088 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3089 <76> DW_AT_byte_size : 4
3090 <77> DW_AT_encoding : 5 (signed)
3092 imports the wrong die ( 0x75 instead of 0x58 ).
3093 This case will be ignored until the gcc bug is fixed. */
3097 /* FIXME: dwarf2_name (die); for the local name after import. */
3099 using_directives
= cp_add_using (imported_name
, strlen (imported_name
), 0,
3104 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3106 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3110 free_cu_line_header (void *arg
)
3112 struct dwarf2_cu
*cu
= arg
;
3114 free_line_header (cu
->line_header
);
3115 cu
->line_header
= NULL
;
3119 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3121 struct objfile
*objfile
= cu
->objfile
;
3122 struct comp_unit_head
*cu_header
= &cu
->header
;
3123 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3124 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3125 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3126 struct attribute
*attr
;
3128 char *comp_dir
= NULL
;
3129 struct die_info
*child_die
;
3130 bfd
*abfd
= objfile
->obfd
;
3131 struct line_header
*line_header
= 0;
3134 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3136 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3138 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3139 from finish_block. */
3140 if (lowpc
== ((CORE_ADDR
) -1))
3145 /* Find the filename. Do not use dwarf2_name here, since the filename
3146 is not a source language identifier. */
3147 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3150 name
= DW_STRING (attr
);
3153 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3155 comp_dir
= DW_STRING (attr
);
3156 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3158 comp_dir
= ldirname (name
);
3159 if (comp_dir
!= NULL
)
3160 make_cleanup (xfree
, comp_dir
);
3162 if (comp_dir
!= NULL
)
3164 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3165 directory, get rid of it. */
3166 char *cp
= strchr (comp_dir
, ':');
3168 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3175 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3178 set_cu_language (DW_UNSND (attr
), cu
);
3181 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3183 cu
->producer
= DW_STRING (attr
);
3185 /* We assume that we're processing GCC output. */
3186 processing_gcc_compilation
= 2;
3188 processing_has_namespace_info
= 0;
3190 start_symtab (name
, comp_dir
, lowpc
);
3191 record_debugformat ("DWARF 2");
3192 record_producer (cu
->producer
);
3194 initialize_cu_func_list (cu
);
3196 /* Decode line number information if present. We do this before
3197 processing child DIEs, so that the line header table is available
3198 for DW_AT_decl_file. */
3199 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3202 unsigned int line_offset
= DW_UNSND (attr
);
3203 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3206 cu
->line_header
= line_header
;
3207 make_cleanup (free_cu_line_header
, cu
);
3208 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3212 /* Process all dies in compilation unit. */
3213 if (die
->child
!= NULL
)
3215 child_die
= die
->child
;
3216 while (child_die
&& child_die
->tag
)
3218 process_die (child_die
, cu
);
3219 child_die
= sibling_die (child_die
);
3223 /* Decode macro information, if present. Dwarf 2 macro information
3224 refers to information in the line number info statement program
3225 header, so we can only read it if we've read the header
3227 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3228 if (attr
&& line_header
)
3230 unsigned int macro_offset
= DW_UNSND (attr
);
3231 dwarf_decode_macros (line_header
, macro_offset
,
3232 comp_dir
, abfd
, cu
);
3234 do_cleanups (back_to
);
3238 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3239 struct dwarf2_cu
*cu
)
3241 struct function_range
*thisfn
;
3243 thisfn
= (struct function_range
*)
3244 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3245 thisfn
->name
= name
;
3246 thisfn
->lowpc
= lowpc
;
3247 thisfn
->highpc
= highpc
;
3248 thisfn
->seen_line
= 0;
3249 thisfn
->next
= NULL
;
3251 if (cu
->last_fn
== NULL
)
3252 cu
->first_fn
= thisfn
;
3254 cu
->last_fn
->next
= thisfn
;
3256 cu
->last_fn
= thisfn
;
3259 /* qsort helper for inherit_abstract_dies. */
3262 unsigned_int_compar (const void *ap
, const void *bp
)
3264 unsigned int a
= *(unsigned int *) ap
;
3265 unsigned int b
= *(unsigned int *) bp
;
3267 return (a
> b
) - (b
> a
);
3270 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3271 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3272 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3275 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3277 struct die_info
*child_die
;
3278 unsigned die_children_count
;
3279 /* CU offsets which were referenced by children of the current DIE. */
3281 unsigned *offsets_end
, *offsetp
;
3282 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3283 struct die_info
*origin_die
;
3284 /* Iterator of the ORIGIN_DIE children. */
3285 struct die_info
*origin_child_die
;
3286 struct cleanup
*cleanups
;
3287 struct attribute
*attr
;
3289 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3293 origin_die
= follow_die_ref (die
, attr
, &cu
);
3294 if (die
->tag
!= origin_die
->tag
)
3295 complaint (&symfile_complaints
,
3296 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3297 die
->offset
, origin_die
->offset
);
3299 child_die
= die
->child
;
3300 die_children_count
= 0;
3301 while (child_die
&& child_die
->tag
)
3303 child_die
= sibling_die (child_die
);
3304 die_children_count
++;
3306 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3307 cleanups
= make_cleanup (xfree
, offsets
);
3309 offsets_end
= offsets
;
3310 child_die
= die
->child
;
3311 while (child_die
&& child_die
->tag
)
3313 attr
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
3314 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3315 counterpart may exist. */
3318 struct die_info
*child_origin_die
;
3320 child_origin_die
= follow_die_ref (child_die
, attr
, &cu
);
3321 if (child_die
->tag
!= child_origin_die
->tag
)
3322 complaint (&symfile_complaints
,
3323 _("Child DIE 0x%x and its abstract origin 0x%x have "
3324 "different tags"), child_die
->offset
,
3325 child_origin_die
->offset
);
3326 *offsets_end
++ = child_origin_die
->offset
;
3328 child_die
= sibling_die (child_die
);
3330 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3331 unsigned_int_compar
);
3332 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3333 if (offsetp
[-1] == *offsetp
)
3334 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3335 "to DIE 0x%x as their abstract origin"),
3336 die
->offset
, *offsetp
);
3339 origin_child_die
= origin_die
->child
;
3340 while (origin_child_die
&& origin_child_die
->tag
)
3342 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3343 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3345 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3347 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3348 process_die (origin_child_die
, cu
);
3350 origin_child_die
= sibling_die (origin_child_die
);
3353 do_cleanups (cleanups
);
3357 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3359 struct objfile
*objfile
= cu
->objfile
;
3360 struct context_stack
*new;
3363 struct die_info
*child_die
;
3364 struct attribute
*attr
;
3367 struct block
*block
;
3369 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3371 name
= dwarf2_linkage_name (die
, cu
);
3373 /* Ignore functions with missing or empty names and functions with
3374 missing or invalid low and high pc attributes. */
3375 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3381 /* Record the function range for dwarf_decode_lines. */
3382 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3384 new = push_context (0, lowpc
);
3385 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3387 /* If there is a location expression for DW_AT_frame_base, record
3389 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3391 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3392 expression is being recorded directly in the function's symbol
3393 and not in a separate frame-base object. I guess this hack is
3394 to avoid adding some sort of frame-base adjunct/annex to the
3395 function's symbol :-(. The problem with doing this is that it
3396 results in a function symbol with a location expression that
3397 has nothing to do with the location of the function, ouch! The
3398 relationship should be: a function's symbol has-a frame base; a
3399 frame-base has-a location expression. */
3400 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3402 cu
->list_in_scope
= &local_symbols
;
3404 if (die
->child
!= NULL
)
3406 child_die
= die
->child
;
3407 while (child_die
&& child_die
->tag
)
3409 process_die (child_die
, cu
);
3410 child_die
= sibling_die (child_die
);
3414 inherit_abstract_dies (die
, cu
);
3416 new = pop_context ();
3417 /* Make a block for the local symbols within. */
3418 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3419 lowpc
, highpc
, objfile
);
3421 /* For C++, set the block's scope. */
3422 if (cu
->language
== language_cplus
)
3423 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3424 determine_prefix (die
, cu
),
3425 processing_has_namespace_info
);
3427 /* If we have address ranges, record them. */
3428 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3430 /* In C++, we can have functions nested inside functions (e.g., when
3431 a function declares a class that has methods). This means that
3432 when we finish processing a function scope, we may need to go
3433 back to building a containing block's symbol lists. */
3434 local_symbols
= new->locals
;
3435 param_symbols
= new->params
;
3436 using_directives
= new->using_directives
;
3438 /* If we've finished processing a top-level function, subsequent
3439 symbols go in the file symbol list. */
3440 if (outermost_context_p ())
3441 cu
->list_in_scope
= &file_symbols
;
3444 /* Process all the DIES contained within a lexical block scope. Start
3445 a new scope, process the dies, and then close the scope. */
3448 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3450 struct objfile
*objfile
= cu
->objfile
;
3451 struct context_stack
*new;
3452 CORE_ADDR lowpc
, highpc
;
3453 struct die_info
*child_die
;
3456 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3458 /* Ignore blocks with missing or invalid low and high pc attributes. */
3459 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3460 as multiple lexical blocks? Handling children in a sane way would
3461 be nasty. Might be easier to properly extend generic blocks to
3463 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3468 push_context (0, lowpc
);
3469 if (die
->child
!= NULL
)
3471 child_die
= die
->child
;
3472 while (child_die
&& child_die
->tag
)
3474 process_die (child_die
, cu
);
3475 child_die
= sibling_die (child_die
);
3478 new = pop_context ();
3480 if (local_symbols
!= NULL
)
3483 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3486 /* Note that recording ranges after traversing children, as we
3487 do here, means that recording a parent's ranges entails
3488 walking across all its children's ranges as they appear in
3489 the address map, which is quadratic behavior.
3491 It would be nicer to record the parent's ranges before
3492 traversing its children, simply overriding whatever you find
3493 there. But since we don't even decide whether to create a
3494 block until after we've traversed its children, that's hard
3496 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3498 local_symbols
= new->locals
;
3499 using_directives
= new->using_directives
;
3502 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3503 Return 1 if the attributes are present and valid, otherwise, return 0.
3504 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3507 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3508 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3509 struct partial_symtab
*ranges_pst
)
3511 struct objfile
*objfile
= cu
->objfile
;
3512 struct comp_unit_head
*cu_header
= &cu
->header
;
3513 bfd
*obfd
= objfile
->obfd
;
3514 unsigned int addr_size
= cu_header
->addr_size
;
3515 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3516 /* Base address selection entry. */
3527 found_base
= cu
->base_known
;
3528 base
= cu
->base_address
;
3530 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
3532 complaint (&symfile_complaints
,
3533 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3537 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
3539 /* Read in the largest possible address. */
3540 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3541 if ((marker
& mask
) == mask
)
3543 /* If we found the largest possible address, then
3544 read the base address. */
3545 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3546 buffer
+= 2 * addr_size
;
3547 offset
+= 2 * addr_size
;
3553 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3557 CORE_ADDR range_beginning
, range_end
;
3559 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3560 buffer
+= addr_size
;
3561 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3562 buffer
+= addr_size
;
3563 offset
+= 2 * addr_size
;
3565 /* An end of list marker is a pair of zero addresses. */
3566 if (range_beginning
== 0 && range_end
== 0)
3567 /* Found the end of list entry. */
3570 /* Each base address selection entry is a pair of 2 values.
3571 The first is the largest possible address, the second is
3572 the base address. Check for a base address here. */
3573 if ((range_beginning
& mask
) == mask
)
3575 /* If we found the largest possible address, then
3576 read the base address. */
3577 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3584 /* We have no valid base address for the ranges
3586 complaint (&symfile_complaints
,
3587 _("Invalid .debug_ranges data (no base address)"));
3591 range_beginning
+= base
;
3594 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3595 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3596 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3599 /* FIXME: This is recording everything as a low-high
3600 segment of consecutive addresses. We should have a
3601 data structure for discontiguous block ranges
3605 low
= range_beginning
;
3611 if (range_beginning
< low
)
3612 low
= range_beginning
;
3613 if (range_end
> high
)
3619 /* If the first entry is an end-of-list marker, the range
3620 describes an empty scope, i.e. no instructions. */
3626 *high_return
= high
;
3630 /* Get low and high pc attributes from a die. Return 1 if the attributes
3631 are present and valid, otherwise, return 0. Return -1 if the range is
3632 discontinuous, i.e. derived from DW_AT_ranges information. */
3634 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3635 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3637 struct attribute
*attr
;
3642 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3645 high
= DW_ADDR (attr
);
3646 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3648 low
= DW_ADDR (attr
);
3650 /* Found high w/o low attribute. */
3653 /* Found consecutive range of addresses. */
3658 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3661 /* Value of the DW_AT_ranges attribute is the offset in the
3662 .debug_ranges section. */
3663 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3665 /* Found discontinuous range of addresses. */
3673 /* When using the GNU linker, .gnu.linkonce. sections are used to
3674 eliminate duplicate copies of functions and vtables and such.
3675 The linker will arbitrarily choose one and discard the others.
3676 The AT_*_pc values for such functions refer to local labels in
3677 these sections. If the section from that file was discarded, the
3678 labels are not in the output, so the relocs get a value of 0.
3679 If this is a discarded function, mark the pc bounds as invalid,
3680 so that GDB will ignore it. */
3681 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3689 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3690 its low and high PC addresses. Do nothing if these addresses could not
3691 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3692 and HIGHPC to the high address if greater than HIGHPC. */
3695 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3696 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3697 struct dwarf2_cu
*cu
)
3699 CORE_ADDR low
, high
;
3700 struct die_info
*child
= die
->child
;
3702 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3704 *lowpc
= min (*lowpc
, low
);
3705 *highpc
= max (*highpc
, high
);
3708 /* If the language does not allow nested subprograms (either inside
3709 subprograms or lexical blocks), we're done. */
3710 if (cu
->language
!= language_ada
)
3713 /* Check all the children of the given DIE. If it contains nested
3714 subprograms, then check their pc bounds. Likewise, we need to
3715 check lexical blocks as well, as they may also contain subprogram
3717 while (child
&& child
->tag
)
3719 if (child
->tag
== DW_TAG_subprogram
3720 || child
->tag
== DW_TAG_lexical_block
)
3721 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3722 child
= sibling_die (child
);
3726 /* Get the low and high pc's represented by the scope DIE, and store
3727 them in *LOWPC and *HIGHPC. If the correct values can't be
3728 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3731 get_scope_pc_bounds (struct die_info
*die
,
3732 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3733 struct dwarf2_cu
*cu
)
3735 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3736 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3737 CORE_ADDR current_low
, current_high
;
3739 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3741 best_low
= current_low
;
3742 best_high
= current_high
;
3746 struct die_info
*child
= die
->child
;
3748 while (child
&& child
->tag
)
3750 switch (child
->tag
) {
3751 case DW_TAG_subprogram
:
3752 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3754 case DW_TAG_namespace
:
3755 /* FIXME: carlton/2004-01-16: Should we do this for
3756 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3757 that current GCC's always emit the DIEs corresponding
3758 to definitions of methods of classes as children of a
3759 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3760 the DIEs giving the declarations, which could be
3761 anywhere). But I don't see any reason why the
3762 standards says that they have to be there. */
3763 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3765 if (current_low
!= ((CORE_ADDR
) -1))
3767 best_low
= min (best_low
, current_low
);
3768 best_high
= max (best_high
, current_high
);
3776 child
= sibling_die (child
);
3781 *highpc
= best_high
;
3784 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3787 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3788 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3790 struct attribute
*attr
;
3792 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3795 CORE_ADDR high
= DW_ADDR (attr
);
3796 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3799 CORE_ADDR low
= DW_ADDR (attr
);
3800 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3804 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3807 bfd
*obfd
= cu
->objfile
->obfd
;
3809 /* The value of the DW_AT_ranges attribute is the offset of the
3810 address range list in the .debug_ranges section. */
3811 unsigned long offset
= DW_UNSND (attr
);
3812 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
3814 /* For some target architectures, but not others, the
3815 read_address function sign-extends the addresses it returns.
3816 To recognize base address selection entries, we need a
3818 unsigned int addr_size
= cu
->header
.addr_size
;
3819 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3821 /* The base address, to which the next pair is relative. Note
3822 that this 'base' is a DWARF concept: most entries in a range
3823 list are relative, to reduce the number of relocs against the
3824 debugging information. This is separate from this function's
3825 'baseaddr' argument, which GDB uses to relocate debugging
3826 information from a shared library based on the address at
3827 which the library was loaded. */
3828 CORE_ADDR base
= cu
->base_address
;
3829 int base_known
= cu
->base_known
;
3831 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
3833 complaint (&symfile_complaints
,
3834 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3841 unsigned int bytes_read
;
3842 CORE_ADDR start
, end
;
3844 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3845 buffer
+= bytes_read
;
3846 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3847 buffer
+= bytes_read
;
3849 /* Did we find the end of the range list? */
3850 if (start
== 0 && end
== 0)
3853 /* Did we find a base address selection entry? */
3854 else if ((start
& base_select_mask
) == base_select_mask
)
3860 /* We found an ordinary address range. */
3865 complaint (&symfile_complaints
,
3866 _("Invalid .debug_ranges data (no base address)"));
3870 record_block_range (block
,
3871 baseaddr
+ base
+ start
,
3872 baseaddr
+ base
+ end
- 1);
3878 /* Add an aggregate field to the field list. */
3881 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3882 struct dwarf2_cu
*cu
)
3884 struct objfile
*objfile
= cu
->objfile
;
3885 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3886 struct nextfield
*new_field
;
3887 struct attribute
*attr
;
3889 char *fieldname
= "";
3891 /* Allocate a new field list entry and link it in. */
3892 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3893 make_cleanup (xfree
, new_field
);
3894 memset (new_field
, 0, sizeof (struct nextfield
));
3895 new_field
->next
= fip
->fields
;
3896 fip
->fields
= new_field
;
3899 /* Handle accessibility and virtuality of field.
3900 The default accessibility for members is public, the default
3901 accessibility for inheritance is private. */
3902 if (die
->tag
!= DW_TAG_inheritance
)
3903 new_field
->accessibility
= DW_ACCESS_public
;
3905 new_field
->accessibility
= DW_ACCESS_private
;
3906 new_field
->virtuality
= DW_VIRTUALITY_none
;
3908 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3910 new_field
->accessibility
= DW_UNSND (attr
);
3911 if (new_field
->accessibility
!= DW_ACCESS_public
)
3912 fip
->non_public_fields
= 1;
3913 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3915 new_field
->virtuality
= DW_UNSND (attr
);
3917 fp
= &new_field
->field
;
3919 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3921 /* Data member other than a C++ static data member. */
3923 /* Get type of field. */
3924 fp
->type
= die_type (die
, cu
);
3926 SET_FIELD_BITPOS (*fp
, 0);
3928 /* Get bit size of field (zero if none). */
3929 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3932 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3936 FIELD_BITSIZE (*fp
) = 0;
3939 /* Get bit offset of field. */
3940 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3945 if (attr_form_is_section_offset (attr
))
3947 dwarf2_complex_location_expr_complaint ();
3950 else if (attr_form_is_constant (attr
))
3951 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3953 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3955 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3957 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3960 if (gdbarch_bits_big_endian (gdbarch
))
3962 /* For big endian bits, the DW_AT_bit_offset gives the
3963 additional bit offset from the MSB of the containing
3964 anonymous object to the MSB of the field. We don't
3965 have to do anything special since we don't need to
3966 know the size of the anonymous object. */
3967 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3971 /* For little endian bits, compute the bit offset to the
3972 MSB of the anonymous object, subtract off the number of
3973 bits from the MSB of the field to the MSB of the
3974 object, and then subtract off the number of bits of
3975 the field itself. The result is the bit offset of
3976 the LSB of the field. */
3978 int bit_offset
= DW_UNSND (attr
);
3980 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3983 /* The size of the anonymous object containing
3984 the bit field is explicit, so use the
3985 indicated size (in bytes). */
3986 anonymous_size
= DW_UNSND (attr
);
3990 /* The size of the anonymous object containing
3991 the bit field must be inferred from the type
3992 attribute of the data member containing the
3994 anonymous_size
= TYPE_LENGTH (fp
->type
);
3996 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3997 - bit_offset
- FIELD_BITSIZE (*fp
);
4001 /* Get name of field. */
4002 fieldname
= dwarf2_name (die
, cu
);
4003 if (fieldname
== NULL
)
4006 /* The name is already allocated along with this objfile, so we don't
4007 need to duplicate it for the type. */
4008 fp
->name
= fieldname
;
4010 /* Change accessibility for artificial fields (e.g. virtual table
4011 pointer or virtual base class pointer) to private. */
4012 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4014 new_field
->accessibility
= DW_ACCESS_private
;
4015 fip
->non_public_fields
= 1;
4018 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4020 /* C++ static member. */
4022 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4023 is a declaration, but all versions of G++ as of this writing
4024 (so through at least 3.2.1) incorrectly generate
4025 DW_TAG_variable tags. */
4029 /* Get name of field. */
4030 fieldname
= dwarf2_name (die
, cu
);
4031 if (fieldname
== NULL
)
4034 /* Get physical name. */
4035 physname
= dwarf2_linkage_name (die
, cu
);
4037 /* The name is already allocated along with this objfile, so we don't
4038 need to duplicate it for the type. */
4039 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4040 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4041 FIELD_NAME (*fp
) = fieldname
;
4043 else if (die
->tag
== DW_TAG_inheritance
)
4045 /* C++ base class field. */
4046 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4048 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
4050 FIELD_BITSIZE (*fp
) = 0;
4051 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4052 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4053 fip
->nbaseclasses
++;
4057 /* Create the vector of fields, and attach it to the type. */
4060 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4061 struct dwarf2_cu
*cu
)
4063 int nfields
= fip
->nfields
;
4065 /* Record the field count, allocate space for the array of fields,
4066 and create blank accessibility bitfields if necessary. */
4067 TYPE_NFIELDS (type
) = nfields
;
4068 TYPE_FIELDS (type
) = (struct field
*)
4069 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4070 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4072 if (fip
->non_public_fields
)
4074 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4076 TYPE_FIELD_PRIVATE_BITS (type
) =
4077 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4078 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4080 TYPE_FIELD_PROTECTED_BITS (type
) =
4081 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4082 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4084 TYPE_FIELD_IGNORE_BITS (type
) =
4085 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4086 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4089 /* If the type has baseclasses, allocate and clear a bit vector for
4090 TYPE_FIELD_VIRTUAL_BITS. */
4091 if (fip
->nbaseclasses
)
4093 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4094 unsigned char *pointer
;
4096 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4097 pointer
= TYPE_ALLOC (type
, num_bytes
);
4098 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4099 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4100 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4103 /* Copy the saved-up fields into the field vector. Start from the head
4104 of the list, adding to the tail of the field array, so that they end
4105 up in the same order in the array in which they were added to the list. */
4106 while (nfields
-- > 0)
4108 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
4109 switch (fip
->fields
->accessibility
)
4111 case DW_ACCESS_private
:
4112 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4115 case DW_ACCESS_protected
:
4116 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4119 case DW_ACCESS_public
:
4123 /* Unknown accessibility. Complain and treat it as public. */
4125 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4126 fip
->fields
->accessibility
);
4130 if (nfields
< fip
->nbaseclasses
)
4132 switch (fip
->fields
->virtuality
)
4134 case DW_VIRTUALITY_virtual
:
4135 case DW_VIRTUALITY_pure_virtual
:
4136 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4140 fip
->fields
= fip
->fields
->next
;
4144 /* Add a member function to the proper fieldlist. */
4147 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4148 struct type
*type
, struct dwarf2_cu
*cu
)
4150 struct objfile
*objfile
= cu
->objfile
;
4151 struct attribute
*attr
;
4152 struct fnfieldlist
*flp
;
4154 struct fn_field
*fnp
;
4157 struct nextfnfield
*new_fnfield
;
4158 struct type
*this_type
;
4160 /* Get name of member function. */
4161 fieldname
= dwarf2_name (die
, cu
);
4162 if (fieldname
== NULL
)
4165 /* Get the mangled name. */
4166 physname
= dwarf2_linkage_name (die
, cu
);
4168 /* Look up member function name in fieldlist. */
4169 for (i
= 0; i
< fip
->nfnfields
; i
++)
4171 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4175 /* Create new list element if necessary. */
4176 if (i
< fip
->nfnfields
)
4177 flp
= &fip
->fnfieldlists
[i
];
4180 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4182 fip
->fnfieldlists
= (struct fnfieldlist
*)
4183 xrealloc (fip
->fnfieldlists
,
4184 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4185 * sizeof (struct fnfieldlist
));
4186 if (fip
->nfnfields
== 0)
4187 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4189 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4190 flp
->name
= fieldname
;
4196 /* Create a new member function field and chain it to the field list
4198 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4199 make_cleanup (xfree
, new_fnfield
);
4200 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4201 new_fnfield
->next
= flp
->head
;
4202 flp
->head
= new_fnfield
;
4205 /* Fill in the member function field info. */
4206 fnp
= &new_fnfield
->fnfield
;
4207 /* The name is already allocated along with this objfile, so we don't
4208 need to duplicate it for the type. */
4209 fnp
->physname
= physname
? physname
: "";
4210 fnp
->type
= alloc_type (objfile
);
4211 this_type
= read_type_die (die
, cu
);
4212 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4214 int nparams
= TYPE_NFIELDS (this_type
);
4216 /* TYPE is the domain of this method, and THIS_TYPE is the type
4217 of the method itself (TYPE_CODE_METHOD). */
4218 smash_to_method_type (fnp
->type
, type
,
4219 TYPE_TARGET_TYPE (this_type
),
4220 TYPE_FIELDS (this_type
),
4221 TYPE_NFIELDS (this_type
),
4222 TYPE_VARARGS (this_type
));
4224 /* Handle static member functions.
4225 Dwarf2 has no clean way to discern C++ static and non-static
4226 member functions. G++ helps GDB by marking the first
4227 parameter for non-static member functions (which is the
4228 this pointer) as artificial. We obtain this information
4229 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4230 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4231 fnp
->voffset
= VOFFSET_STATIC
;
4234 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4237 /* Get fcontext from DW_AT_containing_type if present. */
4238 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4239 fnp
->fcontext
= die_containing_type (die
, cu
);
4241 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4242 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4244 /* Get accessibility. */
4245 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4248 switch (DW_UNSND (attr
))
4250 case DW_ACCESS_private
:
4251 fnp
->is_private
= 1;
4253 case DW_ACCESS_protected
:
4254 fnp
->is_protected
= 1;
4259 /* Check for artificial methods. */
4260 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4261 if (attr
&& DW_UNSND (attr
) != 0)
4262 fnp
->is_artificial
= 1;
4264 /* Get index in virtual function table if it is a virtual member function. */
4265 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4268 /* Support the .debug_loc offsets */
4269 if (attr_form_is_block (attr
))
4271 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4273 else if (attr_form_is_section_offset (attr
))
4275 dwarf2_complex_location_expr_complaint ();
4279 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4285 /* Create the vector of member function fields, and attach it to the type. */
4288 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4289 struct dwarf2_cu
*cu
)
4291 struct fnfieldlist
*flp
;
4292 int total_length
= 0;
4295 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4296 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4297 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4299 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4301 struct nextfnfield
*nfp
= flp
->head
;
4302 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4305 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4306 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4307 fn_flp
->fn_fields
= (struct fn_field
*)
4308 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4309 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4310 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4312 total_length
+= flp
->length
;
4315 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4316 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4319 /* Returns non-zero if NAME is the name of a vtable member in CU's
4320 language, zero otherwise. */
4322 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4324 static const char vptr
[] = "_vptr";
4325 static const char vtable
[] = "vtable";
4327 /* Look for the C++ and Java forms of the vtable. */
4328 if ((cu
->language
== language_java
4329 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4330 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4331 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4337 /* GCC outputs unnamed structures that are really pointers to member
4338 functions, with the ABI-specified layout. If DIE (from CU) describes
4339 such a structure, set its type, and return nonzero. Otherwise return
4342 GCC shouldn't do this; it should just output pointer to member DIEs.
4343 This is GCC PR debug/28767. */
4345 static struct type
*
4346 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4348 struct objfile
*objfile
= cu
->objfile
;
4350 struct die_info
*pfn_die
, *delta_die
;
4351 struct attribute
*pfn_name
, *delta_name
;
4352 struct type
*pfn_type
, *domain_type
;
4354 /* Check for a structure with no name and two children. */
4355 if (die
->tag
!= DW_TAG_structure_type
4356 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4357 || die
->child
== NULL
4358 || die
->child
->sibling
== NULL
4359 || (die
->child
->sibling
->sibling
!= NULL
4360 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4363 /* Check for __pfn and __delta members. */
4364 pfn_die
= die
->child
;
4365 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4366 if (pfn_die
->tag
!= DW_TAG_member
4368 || DW_STRING (pfn_name
) == NULL
4369 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4372 delta_die
= pfn_die
->sibling
;
4373 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4374 if (delta_die
->tag
!= DW_TAG_member
4375 || delta_name
== NULL
4376 || DW_STRING (delta_name
) == NULL
4377 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4380 /* Find the type of the method. */
4381 pfn_type
= die_type (pfn_die
, cu
);
4382 if (pfn_type
== NULL
4383 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4384 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4387 /* Look for the "this" argument. */
4388 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4389 if (TYPE_NFIELDS (pfn_type
) == 0
4390 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4393 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4394 type
= alloc_type (objfile
);
4395 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4396 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4397 TYPE_VARARGS (pfn_type
));
4398 type
= lookup_methodptr_type (type
);
4399 return set_die_type (die
, type
, cu
);
4402 /* Called when we find the DIE that starts a structure or union scope
4403 (definition) to process all dies that define the members of the
4406 NOTE: we need to call struct_type regardless of whether or not the
4407 DIE has an at_name attribute, since it might be an anonymous
4408 structure or union. This gets the type entered into our set of
4411 However, if the structure is incomplete (an opaque struct/union)
4412 then suppress creating a symbol table entry for it since gdb only
4413 wants to find the one with the complete definition. Note that if
4414 it is complete, we just call new_symbol, which does it's own
4415 checking about whether the struct/union is anonymous or not (and
4416 suppresses creating a symbol table entry itself). */
4418 static struct type
*
4419 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4421 struct objfile
*objfile
= cu
->objfile
;
4423 struct attribute
*attr
;
4425 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4427 type
= quirk_gcc_member_function_pointer (die
, cu
);
4431 type
= alloc_type (objfile
);
4432 INIT_CPLUS_SPECIFIC (type
);
4433 name
= dwarf2_name (die
, cu
);
4436 if (cu
->language
== language_cplus
4437 || cu
->language
== language_java
)
4439 const char *new_prefix
= determine_class_name (die
, cu
);
4440 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4444 /* The name is already allocated along with this objfile, so
4445 we don't need to duplicate it for the type. */
4446 TYPE_TAG_NAME (type
) = name
;
4450 if (die
->tag
== DW_TAG_structure_type
)
4452 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4454 else if (die
->tag
== DW_TAG_union_type
)
4456 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4460 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4462 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4465 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4468 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4472 TYPE_LENGTH (type
) = 0;
4475 TYPE_STUB_SUPPORTED (type
) = 1;
4476 if (die_is_declaration (die
, cu
))
4477 TYPE_STUB (type
) = 1;
4479 /* We need to add the type field to the die immediately so we don't
4480 infinitely recurse when dealing with pointers to the structure
4481 type within the structure itself. */
4482 set_die_type (die
, type
, cu
);
4484 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4486 struct field_info fi
;
4487 struct die_info
*child_die
;
4489 memset (&fi
, 0, sizeof (struct field_info
));
4491 child_die
= die
->child
;
4493 while (child_die
&& child_die
->tag
)
4495 if (child_die
->tag
== DW_TAG_member
4496 || child_die
->tag
== DW_TAG_variable
)
4498 /* NOTE: carlton/2002-11-05: A C++ static data member
4499 should be a DW_TAG_member that is a declaration, but
4500 all versions of G++ as of this writing (so through at
4501 least 3.2.1) incorrectly generate DW_TAG_variable
4502 tags for them instead. */
4503 dwarf2_add_field (&fi
, child_die
, cu
);
4505 else if (child_die
->tag
== DW_TAG_subprogram
)
4507 /* C++ member function. */
4508 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4510 else if (child_die
->tag
== DW_TAG_inheritance
)
4512 /* C++ base class field. */
4513 dwarf2_add_field (&fi
, child_die
, cu
);
4515 child_die
= sibling_die (child_die
);
4518 /* Attach fields and member functions to the type. */
4520 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4523 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4525 /* Get the type which refers to the base class (possibly this
4526 class itself) which contains the vtable pointer for the current
4527 class from the DW_AT_containing_type attribute. */
4529 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4531 struct type
*t
= die_containing_type (die
, cu
);
4533 TYPE_VPTR_BASETYPE (type
) = t
;
4538 /* Our own class provides vtbl ptr. */
4539 for (i
= TYPE_NFIELDS (t
) - 1;
4540 i
>= TYPE_N_BASECLASSES (t
);
4543 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4545 if (is_vtable_name (fieldname
, cu
))
4547 TYPE_VPTR_FIELDNO (type
) = i
;
4552 /* Complain if virtual function table field not found. */
4553 if (i
< TYPE_N_BASECLASSES (t
))
4554 complaint (&symfile_complaints
,
4555 _("virtual function table pointer not found when defining class '%s'"),
4556 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4561 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4564 else if (cu
->producer
4565 && strncmp (cu
->producer
,
4566 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4568 /* The IBM XLC compiler does not provide direct indication
4569 of the containing type, but the vtable pointer is
4570 always named __vfp. */
4574 for (i
= TYPE_NFIELDS (type
) - 1;
4575 i
>= TYPE_N_BASECLASSES (type
);
4578 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4580 TYPE_VPTR_FIELDNO (type
) = i
;
4581 TYPE_VPTR_BASETYPE (type
) = type
;
4589 do_cleanups (back_to
);
4594 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4596 struct objfile
*objfile
= cu
->objfile
;
4597 struct die_info
*child_die
= die
->child
;
4598 struct type
*this_type
;
4600 this_type
= get_die_type (die
, cu
);
4601 if (this_type
== NULL
)
4602 this_type
= read_structure_type (die
, cu
);
4604 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4605 snapshots) has been known to create a die giving a declaration
4606 for a class that has, as a child, a die giving a definition for a
4607 nested class. So we have to process our children even if the
4608 current die is a declaration. Normally, of course, a declaration
4609 won't have any children at all. */
4611 while (child_die
!= NULL
&& child_die
->tag
)
4613 if (child_die
->tag
== DW_TAG_member
4614 || child_die
->tag
== DW_TAG_variable
4615 || child_die
->tag
== DW_TAG_inheritance
)
4620 process_die (child_die
, cu
);
4622 child_die
= sibling_die (child_die
);
4625 /* Do not consider external references. According to the DWARF standard,
4626 these DIEs are identified by the fact that they have no byte_size
4627 attribute, and a declaration attribute. */
4628 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4629 || !die_is_declaration (die
, cu
))
4630 new_symbol (die
, this_type
, cu
);
4633 /* Given a DW_AT_enumeration_type die, set its type. We do not
4634 complete the type's fields yet, or create any symbols. */
4636 static struct type
*
4637 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4639 struct objfile
*objfile
= cu
->objfile
;
4641 struct attribute
*attr
;
4644 type
= alloc_type (objfile
);
4646 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4647 name
= dwarf2_full_name (die
, cu
);
4649 TYPE_TAG_NAME (type
) = (char *) name
;
4651 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4654 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4658 TYPE_LENGTH (type
) = 0;
4661 /* The enumeration DIE can be incomplete. In Ada, any type can be
4662 declared as private in the package spec, and then defined only
4663 inside the package body. Such types are known as Taft Amendment
4664 Types. When another package uses such a type, an incomplete DIE
4665 may be generated by the compiler. */
4666 if (die_is_declaration (die
, cu
))
4667 TYPE_STUB (type
) = 1;
4669 return set_die_type (die
, type
, cu
);
4672 /* Determine the name of the type represented by DIE, which should be
4673 a named C++ or Java compound type. Return the name in question,
4674 allocated on the objfile obstack. */
4677 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4679 const char *new_prefix
= NULL
;
4681 /* If we don't have namespace debug info, guess the name by trying
4682 to demangle the names of members, just like we did in
4683 guess_structure_name. */
4684 if (!processing_has_namespace_info
)
4686 struct die_info
*child
;
4688 for (child
= die
->child
;
4689 child
!= NULL
&& child
->tag
!= 0;
4690 child
= sibling_die (child
))
4692 if (child
->tag
== DW_TAG_subprogram
)
4695 = language_class_name_from_physname (cu
->language_defn
,
4699 if (phys_prefix
!= NULL
)
4702 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4703 &cu
->objfile
->objfile_obstack
);
4704 xfree (phys_prefix
);
4711 if (new_prefix
== NULL
)
4712 new_prefix
= dwarf2_full_name (die
, cu
);
4717 /* Given a pointer to a die which begins an enumeration, process all
4718 the dies that define the members of the enumeration, and create the
4719 symbol for the enumeration type.
4721 NOTE: We reverse the order of the element list. */
4724 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4726 struct objfile
*objfile
= cu
->objfile
;
4727 struct die_info
*child_die
;
4728 struct field
*fields
;
4731 int unsigned_enum
= 1;
4733 struct type
*this_type
;
4737 this_type
= get_die_type (die
, cu
);
4738 if (this_type
== NULL
)
4739 this_type
= read_enumeration_type (die
, cu
);
4740 if (die
->child
!= NULL
)
4742 child_die
= die
->child
;
4743 while (child_die
&& child_die
->tag
)
4745 if (child_die
->tag
!= DW_TAG_enumerator
)
4747 process_die (child_die
, cu
);
4751 name
= dwarf2_name (child_die
, cu
);
4754 sym
= new_symbol (child_die
, this_type
, cu
);
4755 if (SYMBOL_VALUE (sym
) < 0)
4758 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4760 fields
= (struct field
*)
4762 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4763 * sizeof (struct field
));
4766 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4767 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4768 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4769 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4775 child_die
= sibling_die (child_die
);
4780 TYPE_NFIELDS (this_type
) = num_fields
;
4781 TYPE_FIELDS (this_type
) = (struct field
*)
4782 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4783 memcpy (TYPE_FIELDS (this_type
), fields
,
4784 sizeof (struct field
) * num_fields
);
4788 TYPE_UNSIGNED (this_type
) = 1;
4791 new_symbol (die
, this_type
, cu
);
4794 /* Extract all information from a DW_TAG_array_type DIE and put it in
4795 the DIE's type field. For now, this only handles one dimensional
4798 static struct type
*
4799 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4801 struct objfile
*objfile
= cu
->objfile
;
4802 struct die_info
*child_die
;
4803 struct type
*type
= NULL
;
4804 struct type
*element_type
, *range_type
, *index_type
;
4805 struct type
**range_types
= NULL
;
4806 struct attribute
*attr
;
4808 struct cleanup
*back_to
;
4811 element_type
= die_type (die
, cu
);
4813 /* Irix 6.2 native cc creates array types without children for
4814 arrays with unspecified length. */
4815 if (die
->child
== NULL
)
4817 index_type
= builtin_type_int32
;
4818 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4819 type
= create_array_type (NULL
, element_type
, range_type
);
4820 return set_die_type (die
, type
, cu
);
4823 back_to
= make_cleanup (null_cleanup
, NULL
);
4824 child_die
= die
->child
;
4825 while (child_die
&& child_die
->tag
)
4827 if (child_die
->tag
== DW_TAG_subrange_type
)
4829 struct type
*child_type
= read_type_die (child_die
, cu
);
4830 if (child_type
!= NULL
)
4832 /* The range type was succesfully read. Save it for
4833 the array type creation. */
4834 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4836 range_types
= (struct type
**)
4837 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4838 * sizeof (struct type
*));
4840 make_cleanup (free_current_contents
, &range_types
);
4842 range_types
[ndim
++] = child_type
;
4845 child_die
= sibling_die (child_die
);
4848 /* Dwarf2 dimensions are output from left to right, create the
4849 necessary array types in backwards order. */
4851 type
= element_type
;
4853 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4857 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4862 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4865 /* Understand Dwarf2 support for vector types (like they occur on
4866 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4867 array type. This is not part of the Dwarf2/3 standard yet, but a
4868 custom vendor extension. The main difference between a regular
4869 array and the vector variant is that vectors are passed by value
4871 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4873 make_vector_type (type
);
4875 name
= dwarf2_name (die
, cu
);
4877 TYPE_NAME (type
) = name
;
4879 do_cleanups (back_to
);
4881 /* Install the type in the die. */
4882 return set_die_type (die
, type
, cu
);
4885 static enum dwarf_array_dim_ordering
4886 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4888 struct attribute
*attr
;
4890 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4892 if (attr
) return DW_SND (attr
);
4895 GNU F77 is a special case, as at 08/2004 array type info is the
4896 opposite order to the dwarf2 specification, but data is still
4897 laid out as per normal fortran.
4899 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4903 if (cu
->language
== language_fortran
&&
4904 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4906 return DW_ORD_row_major
;
4909 switch (cu
->language_defn
->la_array_ordering
)
4911 case array_column_major
:
4912 return DW_ORD_col_major
;
4913 case array_row_major
:
4915 return DW_ORD_row_major
;
4919 /* Extract all information from a DW_TAG_set_type DIE and put it in
4920 the DIE's type field. */
4922 static struct type
*
4923 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4925 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4927 return set_die_type (die
, set_type
, cu
);
4930 /* First cut: install each common block member as a global variable. */
4933 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4935 struct die_info
*child_die
;
4936 struct attribute
*attr
;
4938 CORE_ADDR base
= (CORE_ADDR
) 0;
4940 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4943 /* Support the .debug_loc offsets */
4944 if (attr_form_is_block (attr
))
4946 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4948 else if (attr_form_is_section_offset (attr
))
4950 dwarf2_complex_location_expr_complaint ();
4954 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4955 "common block member");
4958 if (die
->child
!= NULL
)
4960 child_die
= die
->child
;
4961 while (child_die
&& child_die
->tag
)
4963 sym
= new_symbol (child_die
, NULL
, cu
);
4964 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4967 SYMBOL_VALUE_ADDRESS (sym
) =
4968 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4969 add_symbol_to_list (sym
, &global_symbols
);
4971 child_die
= sibling_die (child_die
);
4976 /* Create a type for a C++ namespace. */
4978 static struct type
*
4979 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4981 struct objfile
*objfile
= cu
->objfile
;
4982 const char *previous_prefix
, *name
;
4986 /* For extensions, reuse the type of the original namespace. */
4987 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
4989 struct die_info
*ext_die
;
4990 struct dwarf2_cu
*ext_cu
= cu
;
4991 ext_die
= dwarf2_extension (die
, &ext_cu
);
4992 type
= read_type_die (ext_die
, ext_cu
);
4993 return set_die_type (die
, type
, cu
);
4996 name
= namespace_name (die
, &is_anonymous
, cu
);
4998 /* Now build the name of the current namespace. */
5000 previous_prefix
= determine_prefix (die
, cu
);
5001 if (previous_prefix
[0] != '\0')
5002 name
= typename_concat (&objfile
->objfile_obstack
,
5003 previous_prefix
, name
, cu
);
5005 /* Create the type. */
5006 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5008 TYPE_NAME (type
) = (char *) name
;
5009 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5011 set_die_type (die
, type
, cu
);
5016 /* Read a C++ namespace. */
5019 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5021 struct objfile
*objfile
= cu
->objfile
;
5025 /* Add a symbol associated to this if we haven't seen the namespace
5026 before. Also, add a using directive if it's an anonymous
5029 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5033 type
= read_type_die (die
, cu
);
5034 new_symbol (die
, type
, cu
);
5036 name
= namespace_name (die
, &is_anonymous
, cu
);
5039 const char *previous_prefix
= determine_prefix (die
, cu
);
5040 cp_add_using_directive (TYPE_NAME (type
),
5041 strlen (previous_prefix
),
5042 strlen (TYPE_NAME (type
)));
5046 if (die
->child
!= NULL
)
5048 struct die_info
*child_die
= die
->child
;
5050 while (child_die
&& child_die
->tag
)
5052 process_die (child_die
, cu
);
5053 child_die
= sibling_die (child_die
);
5058 /* Read a Fortran module. */
5061 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5063 struct die_info
*child_die
= die
->child
;
5065 /* FIXME: Support the separate Fortran module namespaces. */
5067 while (child_die
&& child_die
->tag
)
5069 process_die (child_die
, cu
);
5070 child_die
= sibling_die (child_die
);
5074 /* Return the name of the namespace represented by DIE. Set
5075 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5079 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5081 struct die_info
*current_die
;
5082 const char *name
= NULL
;
5084 /* Loop through the extensions until we find a name. */
5086 for (current_die
= die
;
5087 current_die
!= NULL
;
5088 current_die
= dwarf2_extension (die
, &cu
))
5090 name
= dwarf2_name (current_die
, cu
);
5095 /* Is it an anonymous namespace? */
5097 *is_anonymous
= (name
== NULL
);
5099 name
= "(anonymous namespace)";
5104 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5105 the user defined type vector. */
5107 static struct type
*
5108 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5110 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5111 struct comp_unit_head
*cu_header
= &cu
->header
;
5113 struct attribute
*attr_byte_size
;
5114 struct attribute
*attr_address_class
;
5115 int byte_size
, addr_class
;
5117 type
= lookup_pointer_type (die_type (die
, cu
));
5119 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5121 byte_size
= DW_UNSND (attr_byte_size
);
5123 byte_size
= cu_header
->addr_size
;
5125 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5126 if (attr_address_class
)
5127 addr_class
= DW_UNSND (attr_address_class
);
5129 addr_class
= DW_ADDR_none
;
5131 /* If the pointer size or address class is different than the
5132 default, create a type variant marked as such and set the
5133 length accordingly. */
5134 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5136 if (gdbarch_address_class_type_flags_p (gdbarch
))
5140 type_flags
= gdbarch_address_class_type_flags
5141 (gdbarch
, byte_size
, addr_class
);
5142 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5144 type
= make_type_with_address_space (type
, type_flags
);
5146 else if (TYPE_LENGTH (type
) != byte_size
)
5148 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5151 /* Should we also complain about unhandled address classes? */
5155 TYPE_LENGTH (type
) = byte_size
;
5156 return set_die_type (die
, type
, cu
);
5159 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5160 the user defined type vector. */
5162 static struct type
*
5163 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5165 struct objfile
*objfile
= cu
->objfile
;
5167 struct type
*to_type
;
5168 struct type
*domain
;
5170 to_type
= die_type (die
, cu
);
5171 domain
= die_containing_type (die
, cu
);
5173 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5174 type
= lookup_methodptr_type (to_type
);
5176 type
= lookup_memberptr_type (to_type
, domain
);
5178 return set_die_type (die
, type
, cu
);
5181 /* Extract all information from a DW_TAG_reference_type DIE and add to
5182 the user defined type vector. */
5184 static struct type
*
5185 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5187 struct comp_unit_head
*cu_header
= &cu
->header
;
5189 struct attribute
*attr
;
5191 type
= lookup_reference_type (die_type (die
, cu
));
5192 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5195 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5199 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5201 return set_die_type (die
, type
, cu
);
5204 static struct type
*
5205 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5207 struct type
*base_type
, *cv_type
;
5209 base_type
= die_type (die
, cu
);
5210 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5211 return set_die_type (die
, cv_type
, cu
);
5214 static struct type
*
5215 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5217 struct type
*base_type
, *cv_type
;
5219 base_type
= die_type (die
, cu
);
5220 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5221 return set_die_type (die
, cv_type
, cu
);
5224 /* Extract all information from a DW_TAG_string_type DIE and add to
5225 the user defined type vector. It isn't really a user defined type,
5226 but it behaves like one, with other DIE's using an AT_user_def_type
5227 attribute to reference it. */
5229 static struct type
*
5230 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5232 struct objfile
*objfile
= cu
->objfile
;
5233 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5234 struct type
*type
, *range_type
, *index_type
, *char_type
;
5235 struct attribute
*attr
;
5236 unsigned int length
;
5238 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5241 length
= DW_UNSND (attr
);
5245 /* check for the DW_AT_byte_size attribute */
5246 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5249 length
= DW_UNSND (attr
);
5257 index_type
= builtin_type_int32
;
5258 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5259 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5260 type
= create_string_type (NULL
, char_type
, range_type
);
5262 return set_die_type (die
, type
, cu
);
5265 /* Handle DIES due to C code like:
5269 int (*funcp)(int a, long l);
5273 ('funcp' generates a DW_TAG_subroutine_type DIE)
5276 static struct type
*
5277 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5279 struct type
*type
; /* Type that this function returns */
5280 struct type
*ftype
; /* Function that returns above type */
5281 struct attribute
*attr
;
5283 type
= die_type (die
, cu
);
5284 ftype
= make_function_type (type
, (struct type
**) 0, cu
->objfile
);
5286 /* All functions in C++, Pascal and Java have prototypes. */
5287 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5288 if ((attr
&& (DW_UNSND (attr
) != 0))
5289 || cu
->language
== language_cplus
5290 || cu
->language
== language_java
5291 || cu
->language
== language_pascal
)
5292 TYPE_PROTOTYPED (ftype
) = 1;
5294 /* Store the calling convention in the type if it's available in
5295 the subroutine die. Otherwise set the calling convention to
5296 the default value DW_CC_normal. */
5297 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5298 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5300 if (die
->child
!= NULL
)
5302 struct die_info
*child_die
;
5306 /* Count the number of parameters.
5307 FIXME: GDB currently ignores vararg functions, but knows about
5308 vararg member functions. */
5309 child_die
= die
->child
;
5310 while (child_die
&& child_die
->tag
)
5312 if (child_die
->tag
== DW_TAG_formal_parameter
)
5314 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5315 TYPE_VARARGS (ftype
) = 1;
5316 child_die
= sibling_die (child_die
);
5319 /* Allocate storage for parameters and fill them in. */
5320 TYPE_NFIELDS (ftype
) = nparams
;
5321 TYPE_FIELDS (ftype
) = (struct field
*)
5322 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5324 child_die
= die
->child
;
5325 while (child_die
&& child_die
->tag
)
5327 if (child_die
->tag
== DW_TAG_formal_parameter
)
5329 /* Dwarf2 has no clean way to discern C++ static and non-static
5330 member functions. G++ helps GDB by marking the first
5331 parameter for non-static member functions (which is the
5332 this pointer) as artificial. We pass this information
5333 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5334 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5336 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5338 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5339 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5342 child_die
= sibling_die (child_die
);
5346 return set_die_type (die
, ftype
, cu
);
5349 static struct type
*
5350 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5352 struct objfile
*objfile
= cu
->objfile
;
5353 struct attribute
*attr
;
5354 const char *name
= NULL
;
5355 struct type
*this_type
;
5357 name
= dwarf2_full_name (die
, cu
);
5358 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5359 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5360 TYPE_NAME (this_type
) = (char *) name
;
5361 set_die_type (die
, this_type
, cu
);
5362 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5366 /* Find a representation of a given base type and install
5367 it in the TYPE field of the die. */
5369 static struct type
*
5370 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5372 struct objfile
*objfile
= cu
->objfile
;
5374 struct attribute
*attr
;
5375 int encoding
= 0, size
= 0;
5377 enum type_code code
= TYPE_CODE_INT
;
5379 struct type
*target_type
= NULL
;
5381 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5384 encoding
= DW_UNSND (attr
);
5386 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5389 size
= DW_UNSND (attr
);
5391 name
= dwarf2_name (die
, cu
);
5394 complaint (&symfile_complaints
,
5395 _("DW_AT_name missing from DW_TAG_base_type"));
5400 case DW_ATE_address
:
5401 /* Turn DW_ATE_address into a void * pointer. */
5402 code
= TYPE_CODE_PTR
;
5403 type_flags
|= TYPE_FLAG_UNSIGNED
;
5404 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5406 case DW_ATE_boolean
:
5407 code
= TYPE_CODE_BOOL
;
5408 type_flags
|= TYPE_FLAG_UNSIGNED
;
5410 case DW_ATE_complex_float
:
5411 code
= TYPE_CODE_COMPLEX
;
5412 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5414 case DW_ATE_decimal_float
:
5415 code
= TYPE_CODE_DECFLOAT
;
5418 code
= TYPE_CODE_FLT
;
5422 case DW_ATE_unsigned
:
5423 type_flags
|= TYPE_FLAG_UNSIGNED
;
5425 case DW_ATE_signed_char
:
5426 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5427 || cu
->language
== language_pascal
)
5428 code
= TYPE_CODE_CHAR
;
5430 case DW_ATE_unsigned_char
:
5431 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5432 || cu
->language
== language_pascal
)
5433 code
= TYPE_CODE_CHAR
;
5434 type_flags
|= TYPE_FLAG_UNSIGNED
;
5437 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5438 dwarf_type_encoding_name (encoding
));
5442 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5443 TYPE_NAME (type
) = name
;
5444 TYPE_TARGET_TYPE (type
) = target_type
;
5446 if (name
&& strcmp (name
, "char") == 0)
5447 TYPE_NOSIGN (type
) = 1;
5449 return set_die_type (die
, type
, cu
);
5452 /* Read the given DW_AT_subrange DIE. */
5454 static struct type
*
5455 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5457 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5458 struct type
*base_type
;
5459 struct type
*range_type
;
5460 struct attribute
*attr
;
5465 base_type
= die_type (die
, cu
);
5466 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5468 complaint (&symfile_complaints
,
5469 _("DW_AT_type missing from DW_TAG_subrange_type"));
5471 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5472 0, NULL
, cu
->objfile
);
5475 if (cu
->language
== language_fortran
)
5477 /* FORTRAN implies a lower bound of 1, if not given. */
5481 /* FIXME: For variable sized arrays either of these could be
5482 a variable rather than a constant value. We'll allow it,
5483 but we don't know how to handle it. */
5484 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5486 low
= dwarf2_get_attr_constant_value (attr
, 0);
5488 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5491 if (attr
->form
== DW_FORM_block1
)
5493 /* GCC encodes arrays with unspecified or dynamic length
5494 with a DW_FORM_block1 attribute.
5495 FIXME: GDB does not yet know how to handle dynamic
5496 arrays properly, treat them as arrays with unspecified
5499 FIXME: jimb/2003-09-22: GDB does not really know
5500 how to handle arrays of unspecified length
5501 either; we just represent them as zero-length
5502 arrays. Choose an appropriate upper bound given
5503 the lower bound we've computed above. */
5507 high
= dwarf2_get_attr_constant_value (attr
, 1);
5510 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5512 name
= dwarf2_name (die
, cu
);
5514 TYPE_NAME (range_type
) = name
;
5516 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5518 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5520 return set_die_type (die
, range_type
, cu
);
5523 static struct type
*
5524 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5528 /* For now, we only support the C meaning of an unspecified type: void. */
5530 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5531 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5533 return set_die_type (die
, type
, cu
);
5536 /* Trivial hash function for die_info: the hash value of a DIE
5537 is its offset in .debug_info for this objfile. */
5540 die_hash (const void *item
)
5542 const struct die_info
*die
= item
;
5546 /* Trivial comparison function for die_info structures: two DIEs
5547 are equal if they have the same offset. */
5550 die_eq (const void *item_lhs
, const void *item_rhs
)
5552 const struct die_info
*die_lhs
= item_lhs
;
5553 const struct die_info
*die_rhs
= item_rhs
;
5554 return die_lhs
->offset
== die_rhs
->offset
;
5557 /* Read a whole compilation unit into a linked list of dies. */
5559 static struct die_info
*
5560 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5563 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5567 &cu
->comp_unit_obstack
,
5568 hashtab_obstack_allocate
,
5569 dummy_obstack_deallocate
);
5571 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5574 /* Main entry point for reading a DIE and all children.
5575 Read the DIE and dump it if requested. */
5577 static struct die_info
*
5578 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5579 struct dwarf2_cu
*cu
,
5580 gdb_byte
**new_info_ptr
,
5581 struct die_info
*parent
)
5583 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5584 new_info_ptr
, parent
);
5586 if (dwarf2_die_debug
)
5588 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5589 dump_die (result
, dwarf2_die_debug
);
5595 /* Read a single die and all its descendents. Set the die's sibling
5596 field to NULL; set other fields in the die correctly, and set all
5597 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5598 location of the info_ptr after reading all of those dies. PARENT
5599 is the parent of the die in question. */
5601 static struct die_info
*
5602 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5603 struct dwarf2_cu
*cu
,
5604 gdb_byte
**new_info_ptr
,
5605 struct die_info
*parent
)
5607 struct die_info
*die
;
5611 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5614 *new_info_ptr
= cur_ptr
;
5617 store_in_ref_table (die
, cu
);
5621 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5627 *new_info_ptr
= cur_ptr
;
5630 die
->sibling
= NULL
;
5631 die
->parent
= parent
;
5635 /* Read a die, all of its descendents, and all of its siblings; set
5636 all of the fields of all of the dies correctly. Arguments are as
5637 in read_die_and_children. */
5639 static struct die_info
*
5640 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5641 struct dwarf2_cu
*cu
,
5642 gdb_byte
**new_info_ptr
,
5643 struct die_info
*parent
)
5645 struct die_info
*first_die
, *last_sibling
;
5649 first_die
= last_sibling
= NULL
;
5653 struct die_info
*die
5654 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5658 *new_info_ptr
= cur_ptr
;
5665 last_sibling
->sibling
= die
;
5671 /* In DWARF version 2, the description of the debugging information is
5672 stored in a separate .debug_abbrev section. Before we read any
5673 dies from a section we read in all abbreviations and install them
5674 in a hash table. This function also sets flags in CU describing
5675 the data found in the abbrev table. */
5678 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5680 struct comp_unit_head
*cu_header
= &cu
->header
;
5681 gdb_byte
*abbrev_ptr
;
5682 struct abbrev_info
*cur_abbrev
;
5683 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5684 unsigned int abbrev_form
, hash_number
;
5685 struct attr_abbrev
*cur_attrs
;
5686 unsigned int allocated_attrs
;
5688 /* Initialize dwarf2 abbrevs */
5689 obstack_init (&cu
->abbrev_obstack
);
5690 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5692 * sizeof (struct abbrev_info
*)));
5693 memset (cu
->dwarf2_abbrevs
, 0,
5694 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5696 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
5697 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5698 abbrev_ptr
+= bytes_read
;
5700 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5701 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5703 /* loop until we reach an abbrev number of 0 */
5704 while (abbrev_number
)
5706 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5708 /* read in abbrev header */
5709 cur_abbrev
->number
= abbrev_number
;
5710 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5711 abbrev_ptr
+= bytes_read
;
5712 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5715 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5716 cu
->has_namespace_info
= 1;
5718 /* now read in declarations */
5719 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5720 abbrev_ptr
+= bytes_read
;
5721 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5722 abbrev_ptr
+= bytes_read
;
5725 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5727 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5729 = xrealloc (cur_attrs
, (allocated_attrs
5730 * sizeof (struct attr_abbrev
)));
5733 /* Record whether this compilation unit might have
5734 inter-compilation-unit references. If we don't know what form
5735 this attribute will have, then it might potentially be a
5736 DW_FORM_ref_addr, so we conservatively expect inter-CU
5739 if (abbrev_form
== DW_FORM_ref_addr
5740 || abbrev_form
== DW_FORM_indirect
)
5741 cu
->has_form_ref_addr
= 1;
5743 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5744 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5745 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5746 abbrev_ptr
+= bytes_read
;
5747 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5748 abbrev_ptr
+= bytes_read
;
5751 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5752 (cur_abbrev
->num_attrs
5753 * sizeof (struct attr_abbrev
)));
5754 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5755 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5757 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5758 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5759 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5761 /* Get next abbreviation.
5762 Under Irix6 the abbreviations for a compilation unit are not
5763 always properly terminated with an abbrev number of 0.
5764 Exit loop if we encounter an abbreviation which we have
5765 already read (which means we are about to read the abbreviations
5766 for the next compile unit) or if the end of the abbreviation
5767 table is reached. */
5768 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
5769 >= dwarf2_per_objfile
->abbrev
.size
)
5771 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5772 abbrev_ptr
+= bytes_read
;
5773 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5780 /* Release the memory used by the abbrev table for a compilation unit. */
5783 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5785 struct dwarf2_cu
*cu
= ptr_to_cu
;
5787 obstack_free (&cu
->abbrev_obstack
, NULL
);
5788 cu
->dwarf2_abbrevs
= NULL
;
5791 /* Lookup an abbrev_info structure in the abbrev hash table. */
5793 static struct abbrev_info
*
5794 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5796 unsigned int hash_number
;
5797 struct abbrev_info
*abbrev
;
5799 hash_number
= number
% ABBREV_HASH_SIZE
;
5800 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5804 if (abbrev
->number
== number
)
5807 abbrev
= abbrev
->next
;
5812 /* Returns nonzero if TAG represents a type that we might generate a partial
5816 is_type_tag_for_partial (int tag
)
5821 /* Some types that would be reasonable to generate partial symbols for,
5822 that we don't at present. */
5823 case DW_TAG_array_type
:
5824 case DW_TAG_file_type
:
5825 case DW_TAG_ptr_to_member_type
:
5826 case DW_TAG_set_type
:
5827 case DW_TAG_string_type
:
5828 case DW_TAG_subroutine_type
:
5830 case DW_TAG_base_type
:
5831 case DW_TAG_class_type
:
5832 case DW_TAG_interface_type
:
5833 case DW_TAG_enumeration_type
:
5834 case DW_TAG_structure_type
:
5835 case DW_TAG_subrange_type
:
5836 case DW_TAG_typedef
:
5837 case DW_TAG_union_type
:
5844 /* Load all DIEs that are interesting for partial symbols into memory. */
5846 static struct partial_die_info
*
5847 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5848 struct dwarf2_cu
*cu
)
5850 struct partial_die_info
*part_die
;
5851 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5852 struct abbrev_info
*abbrev
;
5853 unsigned int bytes_read
;
5854 unsigned int load_all
= 0;
5856 int nesting_level
= 1;
5861 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5865 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5869 &cu
->comp_unit_obstack
,
5870 hashtab_obstack_allocate
,
5871 dummy_obstack_deallocate
);
5873 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5874 sizeof (struct partial_die_info
));
5878 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5880 /* A NULL abbrev means the end of a series of children. */
5883 if (--nesting_level
== 0)
5885 /* PART_DIE was probably the last thing allocated on the
5886 comp_unit_obstack, so we could call obstack_free
5887 here. We don't do that because the waste is small,
5888 and will be cleaned up when we're done with this
5889 compilation unit. This way, we're also more robust
5890 against other users of the comp_unit_obstack. */
5893 info_ptr
+= bytes_read
;
5894 last_die
= parent_die
;
5895 parent_die
= parent_die
->die_parent
;
5899 /* Check whether this DIE is interesting enough to save. Normally
5900 we would not be interested in members here, but there may be
5901 later variables referencing them via DW_AT_specification (for
5904 && !is_type_tag_for_partial (abbrev
->tag
)
5905 && abbrev
->tag
!= DW_TAG_enumerator
5906 && abbrev
->tag
!= DW_TAG_subprogram
5907 && abbrev
->tag
!= DW_TAG_lexical_block
5908 && abbrev
->tag
!= DW_TAG_variable
5909 && abbrev
->tag
!= DW_TAG_namespace
5910 && abbrev
->tag
!= DW_TAG_member
)
5912 /* Otherwise we skip to the next sibling, if any. */
5913 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5917 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5918 abfd
, info_ptr
, cu
);
5920 /* This two-pass algorithm for processing partial symbols has a
5921 high cost in cache pressure. Thus, handle some simple cases
5922 here which cover the majority of C partial symbols. DIEs
5923 which neither have specification tags in them, nor could have
5924 specification tags elsewhere pointing at them, can simply be
5925 processed and discarded.
5927 This segment is also optional; scan_partial_symbols and
5928 add_partial_symbol will handle these DIEs if we chain
5929 them in normally. When compilers which do not emit large
5930 quantities of duplicate debug information are more common,
5931 this code can probably be removed. */
5933 /* Any complete simple types at the top level (pretty much all
5934 of them, for a language without namespaces), can be processed
5936 if (parent_die
== NULL
5937 && part_die
->has_specification
== 0
5938 && part_die
->is_declaration
== 0
5939 && (part_die
->tag
== DW_TAG_typedef
5940 || part_die
->tag
== DW_TAG_base_type
5941 || part_die
->tag
== DW_TAG_subrange_type
))
5943 if (building_psymtab
&& part_die
->name
!= NULL
)
5944 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5945 VAR_DOMAIN
, LOC_TYPEDEF
,
5946 &cu
->objfile
->static_psymbols
,
5947 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5948 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5952 /* If we're at the second level, and we're an enumerator, and
5953 our parent has no specification (meaning possibly lives in a
5954 namespace elsewhere), then we can add the partial symbol now
5955 instead of queueing it. */
5956 if (part_die
->tag
== DW_TAG_enumerator
5957 && parent_die
!= NULL
5958 && parent_die
->die_parent
== NULL
5959 && parent_die
->tag
== DW_TAG_enumeration_type
5960 && parent_die
->has_specification
== 0)
5962 if (part_die
->name
== NULL
)
5963 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5964 else if (building_psymtab
)
5965 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5966 VAR_DOMAIN
, LOC_CONST
,
5967 (cu
->language
== language_cplus
5968 || cu
->language
== language_java
)
5969 ? &cu
->objfile
->global_psymbols
5970 : &cu
->objfile
->static_psymbols
,
5971 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5973 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5977 /* We'll save this DIE so link it in. */
5978 part_die
->die_parent
= parent_die
;
5979 part_die
->die_sibling
= NULL
;
5980 part_die
->die_child
= NULL
;
5982 if (last_die
&& last_die
== parent_die
)
5983 last_die
->die_child
= part_die
;
5985 last_die
->die_sibling
= part_die
;
5987 last_die
= part_die
;
5989 if (first_die
== NULL
)
5990 first_die
= part_die
;
5992 /* Maybe add the DIE to the hash table. Not all DIEs that we
5993 find interesting need to be in the hash table, because we
5994 also have the parent/sibling/child chains; only those that we
5995 might refer to by offset later during partial symbol reading.
5997 For now this means things that might have be the target of a
5998 DW_AT_specification, DW_AT_abstract_origin, or
5999 DW_AT_extension. DW_AT_extension will refer only to
6000 namespaces; DW_AT_abstract_origin refers to functions (and
6001 many things under the function DIE, but we do not recurse
6002 into function DIEs during partial symbol reading) and
6003 possibly variables as well; DW_AT_specification refers to
6004 declarations. Declarations ought to have the DW_AT_declaration
6005 flag. It happens that GCC forgets to put it in sometimes, but
6006 only for functions, not for types.
6008 Adding more things than necessary to the hash table is harmless
6009 except for the performance cost. Adding too few will result in
6010 wasted time in find_partial_die, when we reread the compilation
6011 unit with load_all_dies set. */
6014 || abbrev
->tag
== DW_TAG_subprogram
6015 || abbrev
->tag
== DW_TAG_variable
6016 || abbrev
->tag
== DW_TAG_namespace
6017 || part_die
->is_declaration
)
6021 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6022 part_die
->offset
, INSERT
);
6026 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6027 sizeof (struct partial_die_info
));
6029 /* For some DIEs we want to follow their children (if any). For C
6030 we have no reason to follow the children of structures; for other
6031 languages we have to, both so that we can get at method physnames
6032 to infer fully qualified class names, and for DW_AT_specification.
6034 For Ada, we need to scan the children of subprograms and lexical
6035 blocks as well because Ada allows the definition of nested
6036 entities that could be interesting for the debugger, such as
6037 nested subprograms for instance. */
6038 if (last_die
->has_children
6040 || last_die
->tag
== DW_TAG_namespace
6041 || last_die
->tag
== DW_TAG_enumeration_type
6042 || (cu
->language
!= language_c
6043 && (last_die
->tag
== DW_TAG_class_type
6044 || last_die
->tag
== DW_TAG_interface_type
6045 || last_die
->tag
== DW_TAG_structure_type
6046 || last_die
->tag
== DW_TAG_union_type
))
6047 || (cu
->language
== language_ada
6048 && (last_die
->tag
== DW_TAG_subprogram
6049 || last_die
->tag
== DW_TAG_lexical_block
))))
6052 parent_die
= last_die
;
6056 /* Otherwise we skip to the next sibling, if any. */
6057 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
6059 /* Back to the top, do it again. */
6063 /* Read a minimal amount of information into the minimal die structure. */
6066 read_partial_die (struct partial_die_info
*part_die
,
6067 struct abbrev_info
*abbrev
,
6068 unsigned int abbrev_len
, bfd
*abfd
,
6069 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6071 unsigned int bytes_read
, i
;
6072 struct attribute attr
;
6073 int has_low_pc_attr
= 0;
6074 int has_high_pc_attr
= 0;
6075 CORE_ADDR base_address
= 0;
6079 base_address_low_pc
,
6080 /* Overrides BASE_ADDRESS_LOW_PC. */
6081 base_address_entry_pc
6083 base_address_type
= base_address_none
;
6085 memset (part_die
, 0, sizeof (struct partial_die_info
));
6087 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
6089 info_ptr
+= abbrev_len
;
6094 part_die
->tag
= abbrev
->tag
;
6095 part_die
->has_children
= abbrev
->has_children
;
6097 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6099 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6101 /* Store the data if it is of an attribute we want to keep in a
6102 partial symbol table. */
6106 switch (part_die
->tag
)
6108 case DW_TAG_compile_unit
:
6109 /* Compilation units have a DW_AT_name that is a filename, not
6110 a source language identifier. */
6111 case DW_TAG_enumeration_type
:
6112 case DW_TAG_enumerator
:
6113 /* These tags always have simple identifiers already; no need
6114 to canonicalize them. */
6115 part_die
->name
= DW_STRING (&attr
);
6119 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6120 &cu
->comp_unit_obstack
);
6124 case DW_AT_comp_dir
:
6125 if (part_die
->dirname
== NULL
)
6126 part_die
->dirname
= DW_STRING (&attr
);
6128 case DW_AT_MIPS_linkage_name
:
6129 part_die
->name
= DW_STRING (&attr
);
6132 has_low_pc_attr
= 1;
6133 part_die
->lowpc
= DW_ADDR (&attr
);
6134 if (part_die
->tag
== DW_TAG_compile_unit
6135 && base_address_type
< base_address_low_pc
)
6137 base_address
= DW_ADDR (&attr
);
6138 base_address_type
= base_address_low_pc
;
6142 has_high_pc_attr
= 1;
6143 part_die
->highpc
= DW_ADDR (&attr
);
6145 case DW_AT_entry_pc
:
6146 if (part_die
->tag
== DW_TAG_compile_unit
6147 && base_address_type
< base_address_entry_pc
)
6149 base_address
= DW_ADDR (&attr
);
6150 base_address_type
= base_address_entry_pc
;
6154 if (part_die
->tag
== DW_TAG_compile_unit
)
6156 cu
->ranges_offset
= DW_UNSND (&attr
);
6157 cu
->has_ranges_offset
= 1;
6160 case DW_AT_location
:
6161 /* Support the .debug_loc offsets */
6162 if (attr_form_is_block (&attr
))
6164 part_die
->locdesc
= DW_BLOCK (&attr
);
6166 else if (attr_form_is_section_offset (&attr
))
6168 dwarf2_complex_location_expr_complaint ();
6172 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6173 "partial symbol information");
6176 case DW_AT_language
:
6177 part_die
->language
= DW_UNSND (&attr
);
6179 case DW_AT_external
:
6180 part_die
->is_external
= DW_UNSND (&attr
);
6182 case DW_AT_declaration
:
6183 part_die
->is_declaration
= DW_UNSND (&attr
);
6186 part_die
->has_type
= 1;
6188 case DW_AT_abstract_origin
:
6189 case DW_AT_specification
:
6190 case DW_AT_extension
:
6191 part_die
->has_specification
= 1;
6192 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6195 /* Ignore absolute siblings, they might point outside of
6196 the current compile unit. */
6197 if (attr
.form
== DW_FORM_ref_addr
)
6198 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6200 part_die
->sibling
= dwarf2_per_objfile
->info
.buffer
6201 + dwarf2_get_ref_die_offset (&attr
);
6203 case DW_AT_stmt_list
:
6204 part_die
->has_stmt_list
= 1;
6205 part_die
->line_offset
= DW_UNSND (&attr
);
6207 case DW_AT_byte_size
:
6208 part_die
->has_byte_size
= 1;
6210 case DW_AT_calling_convention
:
6211 /* DWARF doesn't provide a way to identify a program's source-level
6212 entry point. DW_AT_calling_convention attributes are only meant
6213 to describe functions' calling conventions.
6215 However, because it's a necessary piece of information in
6216 Fortran, and because DW_CC_program is the only piece of debugging
6217 information whose definition refers to a 'main program' at all,
6218 several compilers have begun marking Fortran main programs with
6219 DW_CC_program --- even when those functions use the standard
6220 calling conventions.
6222 So until DWARF specifies a way to provide this information and
6223 compilers pick up the new representation, we'll support this
6225 if (DW_UNSND (&attr
) == DW_CC_program
6226 && cu
->language
== language_fortran
)
6227 set_main_name (part_die
->name
);
6234 /* When using the GNU linker, .gnu.linkonce. sections are used to
6235 eliminate duplicate copies of functions and vtables and such.
6236 The linker will arbitrarily choose one and discard the others.
6237 The AT_*_pc values for such functions refer to local labels in
6238 these sections. If the section from that file was discarded, the
6239 labels are not in the output, so the relocs get a value of 0.
6240 If this is a discarded function, mark the pc bounds as invalid,
6241 so that GDB will ignore it. */
6242 if (has_low_pc_attr
&& has_high_pc_attr
6243 && part_die
->lowpc
< part_die
->highpc
6244 && (part_die
->lowpc
!= 0
6245 || dwarf2_per_objfile
->has_section_at_zero
))
6246 part_die
->has_pc_info
= 1;
6248 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6250 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6252 cu
->base_address
= base_address
;
6258 /* Find a cached partial DIE at OFFSET in CU. */
6260 static struct partial_die_info
*
6261 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6263 struct partial_die_info
*lookup_die
= NULL
;
6264 struct partial_die_info part_die
;
6266 part_die
.offset
= offset
;
6267 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6272 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6274 static struct partial_die_info
*
6275 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6277 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6278 struct partial_die_info
*pd
= NULL
;
6280 if (offset_in_cu_p (&cu
->header
, offset
))
6282 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6287 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6289 if (per_cu
->cu
== NULL
)
6291 load_comp_unit (per_cu
, cu
->objfile
);
6292 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6293 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6296 per_cu
->cu
->last_used
= 0;
6297 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6299 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6301 struct cleanup
*back_to
;
6302 struct partial_die_info comp_unit_die
;
6303 struct abbrev_info
*abbrev
;
6304 unsigned int bytes_read
;
6307 per_cu
->load_all_dies
= 1;
6309 /* Re-read the DIEs. */
6310 back_to
= make_cleanup (null_cleanup
, 0);
6311 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6313 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6314 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6316 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6317 + per_cu
->cu
->header
.offset
6318 + per_cu
->cu
->header
.first_die_offset
);
6319 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6320 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6321 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6323 if (comp_unit_die
.has_children
)
6324 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6325 do_cleanups (back_to
);
6327 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6331 internal_error (__FILE__
, __LINE__
,
6332 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6333 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6337 /* Adjust PART_DIE before generating a symbol for it. This function
6338 may set the is_external flag or change the DIE's name. */
6341 fixup_partial_die (struct partial_die_info
*part_die
,
6342 struct dwarf2_cu
*cu
)
6344 /* If we found a reference attribute and the DIE has no name, try
6345 to find a name in the referred to DIE. */
6347 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6349 struct partial_die_info
*spec_die
;
6351 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6353 fixup_partial_die (spec_die
, cu
);
6357 part_die
->name
= spec_die
->name
;
6359 /* Copy DW_AT_external attribute if it is set. */
6360 if (spec_die
->is_external
)
6361 part_die
->is_external
= spec_die
->is_external
;
6365 /* Set default names for some unnamed DIEs. */
6366 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6367 || part_die
->tag
== DW_TAG_class_type
))
6368 part_die
->name
= "(anonymous class)";
6370 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6371 part_die
->name
= "(anonymous namespace)";
6373 if (part_die
->tag
== DW_TAG_structure_type
6374 || part_die
->tag
== DW_TAG_class_type
6375 || part_die
->tag
== DW_TAG_union_type
)
6376 guess_structure_name (part_die
, cu
);
6379 /* Read the die from the .debug_info section buffer. Set DIEP to
6380 point to a newly allocated die with its information, except for its
6381 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6382 whether the die has children or not. */
6385 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6386 struct dwarf2_cu
*cu
, int *has_children
)
6388 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6389 struct abbrev_info
*abbrev
;
6390 struct die_info
*die
;
6392 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
6393 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6394 info_ptr
+= bytes_read
;
6402 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6405 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6407 bfd_get_filename (abfd
));
6409 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6410 die
->offset
= offset
;
6411 die
->tag
= abbrev
->tag
;
6412 die
->abbrev
= abbrev_number
;
6414 die
->num_attrs
= abbrev
->num_attrs
;
6416 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6417 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6418 abfd
, info_ptr
, cu
);
6421 *has_children
= abbrev
->has_children
;
6425 /* Read an attribute value described by an attribute form. */
6428 read_attribute_value (struct attribute
*attr
, unsigned form
,
6429 bfd
*abfd
, gdb_byte
*info_ptr
,
6430 struct dwarf2_cu
*cu
)
6432 struct comp_unit_head
*cu_header
= &cu
->header
;
6433 unsigned int bytes_read
;
6434 struct dwarf_block
*blk
;
6440 case DW_FORM_ref_addr
:
6441 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6442 info_ptr
+= bytes_read
;
6444 case DW_FORM_block2
:
6445 blk
= dwarf_alloc_block (cu
);
6446 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6449 info_ptr
+= blk
->size
;
6450 DW_BLOCK (attr
) = blk
;
6452 case DW_FORM_block4
:
6453 blk
= dwarf_alloc_block (cu
);
6454 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6456 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6457 info_ptr
+= blk
->size
;
6458 DW_BLOCK (attr
) = blk
;
6461 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6465 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6469 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6472 case DW_FORM_string
:
6473 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6474 info_ptr
+= bytes_read
;
6477 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6479 info_ptr
+= bytes_read
;
6482 blk
= dwarf_alloc_block (cu
);
6483 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6484 info_ptr
+= bytes_read
;
6485 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6486 info_ptr
+= blk
->size
;
6487 DW_BLOCK (attr
) = blk
;
6489 case DW_FORM_block1
:
6490 blk
= dwarf_alloc_block (cu
);
6491 blk
->size
= read_1_byte (abfd
, info_ptr
);
6493 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6494 info_ptr
+= blk
->size
;
6495 DW_BLOCK (attr
) = blk
;
6498 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6502 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6506 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6507 info_ptr
+= bytes_read
;
6510 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6511 info_ptr
+= bytes_read
;
6514 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6518 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6522 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6526 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6529 case DW_FORM_ref_udata
:
6530 DW_ADDR (attr
) = (cu
->header
.offset
6531 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6532 info_ptr
+= bytes_read
;
6534 case DW_FORM_indirect
:
6535 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6536 info_ptr
+= bytes_read
;
6537 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6540 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6541 dwarf_form_name (form
),
6542 bfd_get_filename (abfd
));
6545 /* We have seen instances where the compiler tried to emit a byte
6546 size attribute of -1 which ended up being encoded as an unsigned
6547 0xffffffff. Although 0xffffffff is technically a valid size value,
6548 an object of this size seems pretty unlikely so we can relatively
6549 safely treat these cases as if the size attribute was invalid and
6550 treat them as zero by default. */
6551 if (attr
->name
== DW_AT_byte_size
6552 && form
== DW_FORM_data4
6553 && DW_UNSND (attr
) >= 0xffffffff)
6556 (&symfile_complaints
,
6557 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6559 DW_UNSND (attr
) = 0;
6565 /* Read an attribute described by an abbreviated attribute. */
6568 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6569 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6571 attr
->name
= abbrev
->name
;
6572 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6575 /* read dwarf information from a buffer */
6578 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6580 return bfd_get_8 (abfd
, buf
);
6584 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6586 return bfd_get_signed_8 (abfd
, buf
);
6590 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6592 return bfd_get_16 (abfd
, buf
);
6596 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6598 return bfd_get_signed_16 (abfd
, buf
);
6602 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6604 return bfd_get_32 (abfd
, buf
);
6608 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6610 return bfd_get_signed_32 (abfd
, buf
);
6613 static unsigned long
6614 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6616 return bfd_get_64 (abfd
, buf
);
6620 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6621 unsigned int *bytes_read
)
6623 struct comp_unit_head
*cu_header
= &cu
->header
;
6624 CORE_ADDR retval
= 0;
6626 if (cu_header
->signed_addr_p
)
6628 switch (cu_header
->addr_size
)
6631 retval
= bfd_get_signed_16 (abfd
, buf
);
6634 retval
= bfd_get_signed_32 (abfd
, buf
);
6637 retval
= bfd_get_signed_64 (abfd
, buf
);
6640 internal_error (__FILE__
, __LINE__
,
6641 _("read_address: bad switch, signed [in module %s]"),
6642 bfd_get_filename (abfd
));
6647 switch (cu_header
->addr_size
)
6650 retval
= bfd_get_16 (abfd
, buf
);
6653 retval
= bfd_get_32 (abfd
, buf
);
6656 retval
= bfd_get_64 (abfd
, buf
);
6659 internal_error (__FILE__
, __LINE__
,
6660 _("read_address: bad switch, unsigned [in module %s]"),
6661 bfd_get_filename (abfd
));
6665 *bytes_read
= cu_header
->addr_size
;
6669 /* Read the initial length from a section. The (draft) DWARF 3
6670 specification allows the initial length to take up either 4 bytes
6671 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6672 bytes describe the length and all offsets will be 8 bytes in length
6675 An older, non-standard 64-bit format is also handled by this
6676 function. The older format in question stores the initial length
6677 as an 8-byte quantity without an escape value. Lengths greater
6678 than 2^32 aren't very common which means that the initial 4 bytes
6679 is almost always zero. Since a length value of zero doesn't make
6680 sense for the 32-bit format, this initial zero can be considered to
6681 be an escape value which indicates the presence of the older 64-bit
6682 format. As written, the code can't detect (old format) lengths
6683 greater than 4GB. If it becomes necessary to handle lengths
6684 somewhat larger than 4GB, we could allow other small values (such
6685 as the non-sensical values of 1, 2, and 3) to also be used as
6686 escape values indicating the presence of the old format.
6688 The value returned via bytes_read should be used to increment the
6689 relevant pointer after calling read_initial_length().
6691 [ Note: read_initial_length() and read_offset() are based on the
6692 document entitled "DWARF Debugging Information Format", revision
6693 3, draft 8, dated November 19, 2001. This document was obtained
6696 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6698 This document is only a draft and is subject to change. (So beware.)
6700 Details regarding the older, non-standard 64-bit format were
6701 determined empirically by examining 64-bit ELF files produced by
6702 the SGI toolchain on an IRIX 6.5 machine.
6704 - Kevin, July 16, 2002
6708 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6710 LONGEST length
= bfd_get_32 (abfd
, buf
);
6712 if (length
== 0xffffffff)
6714 length
= bfd_get_64 (abfd
, buf
+ 4);
6717 else if (length
== 0)
6719 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6720 length
= bfd_get_64 (abfd
, buf
);
6731 /* Cover function for read_initial_length.
6732 Returns the length of the object at BUF, and stores the size of the
6733 initial length in *BYTES_READ and stores the size that offsets will be in
6735 If the initial length size is not equivalent to that specified in
6736 CU_HEADER then issue a complaint.
6737 This is useful when reading non-comp-unit headers. */
6740 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6741 const struct comp_unit_head
*cu_header
,
6742 unsigned int *bytes_read
,
6743 unsigned int *offset_size
)
6745 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6747 gdb_assert (cu_header
->initial_length_size
== 4
6748 || cu_header
->initial_length_size
== 8
6749 || cu_header
->initial_length_size
== 12);
6751 if (cu_header
->initial_length_size
!= *bytes_read
)
6752 complaint (&symfile_complaints
,
6753 _("intermixed 32-bit and 64-bit DWARF sections"));
6755 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6759 /* Read an offset from the data stream. The size of the offset is
6760 given by cu_header->offset_size. */
6763 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6764 unsigned int *bytes_read
)
6766 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6767 *bytes_read
= cu_header
->offset_size
;
6771 /* Read an offset from the data stream. */
6774 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6778 switch (offset_size
)
6781 retval
= bfd_get_32 (abfd
, buf
);
6784 retval
= bfd_get_64 (abfd
, buf
);
6787 internal_error (__FILE__
, __LINE__
,
6788 _("read_offset_1: bad switch [in module %s]"),
6789 bfd_get_filename (abfd
));
6796 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6798 /* If the size of a host char is 8 bits, we can return a pointer
6799 to the buffer, otherwise we have to copy the data to a buffer
6800 allocated on the temporary obstack. */
6801 gdb_assert (HOST_CHAR_BIT
== 8);
6806 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6808 /* If the size of a host char is 8 bits, we can return a pointer
6809 to the string, otherwise we have to copy the string to a buffer
6810 allocated on the temporary obstack. */
6811 gdb_assert (HOST_CHAR_BIT
== 8);
6814 *bytes_read_ptr
= 1;
6817 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6818 return (char *) buf
;
6822 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6823 const struct comp_unit_head
*cu_header
,
6824 unsigned int *bytes_read_ptr
)
6826 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6828 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
6830 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6831 bfd_get_filename (abfd
));
6834 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
6836 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6837 bfd_get_filename (abfd
));
6840 gdb_assert (HOST_CHAR_BIT
== 8);
6841 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
6843 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
6846 static unsigned long
6847 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6849 unsigned long result
;
6850 unsigned int num_read
;
6860 byte
= bfd_get_8 (abfd
, buf
);
6863 result
|= ((unsigned long)(byte
& 127) << shift
);
6864 if ((byte
& 128) == 0)
6870 *bytes_read_ptr
= num_read
;
6875 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6878 int i
, shift
, num_read
;
6887 byte
= bfd_get_8 (abfd
, buf
);
6890 result
|= ((long)(byte
& 127) << shift
);
6892 if ((byte
& 128) == 0)
6897 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6898 result
|= -(((long)1) << shift
);
6899 *bytes_read_ptr
= num_read
;
6903 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6906 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6912 byte
= bfd_get_8 (abfd
, buf
);
6914 if ((byte
& 128) == 0)
6920 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6927 cu
->language
= language_c
;
6929 case DW_LANG_C_plus_plus
:
6930 cu
->language
= language_cplus
;
6932 case DW_LANG_Fortran77
:
6933 case DW_LANG_Fortran90
:
6934 case DW_LANG_Fortran95
:
6935 cu
->language
= language_fortran
;
6937 case DW_LANG_Mips_Assembler
:
6938 cu
->language
= language_asm
;
6941 cu
->language
= language_java
;
6945 cu
->language
= language_ada
;
6947 case DW_LANG_Modula2
:
6948 cu
->language
= language_m2
;
6950 case DW_LANG_Pascal83
:
6951 cu
->language
= language_pascal
;
6954 cu
->language
= language_objc
;
6956 case DW_LANG_Cobol74
:
6957 case DW_LANG_Cobol85
:
6959 cu
->language
= language_minimal
;
6962 cu
->language_defn
= language_def (cu
->language
);
6965 /* Return the named attribute or NULL if not there. */
6967 static struct attribute
*
6968 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6971 struct attribute
*spec
= NULL
;
6973 for (i
= 0; i
< die
->num_attrs
; ++i
)
6975 if (die
->attrs
[i
].name
== name
)
6976 return &die
->attrs
[i
];
6977 if (die
->attrs
[i
].name
== DW_AT_specification
6978 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6979 spec
= &die
->attrs
[i
];
6984 die
= follow_die_ref (die
, spec
, &cu
);
6985 return dwarf2_attr (die
, name
, cu
);
6991 /* Return non-zero iff the attribute NAME is defined for the given DIE,
6992 and holds a non-zero value. This function should only be used for
6993 DW_FORM_flag attributes. */
6996 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
6998 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7000 return (attr
&& DW_UNSND (attr
));
7004 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7006 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7007 which value is non-zero. However, we have to be careful with
7008 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7009 (via dwarf2_flag_true_p) follows this attribute. So we may
7010 end up accidently finding a declaration attribute that belongs
7011 to a different DIE referenced by the specification attribute,
7012 even though the given DIE does not have a declaration attribute. */
7013 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7014 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7017 /* Return the die giving the specification for DIE, if there is
7018 one. *SPEC_CU is the CU containing DIE on input, and the CU
7019 containing the return value on output. */
7021 static struct die_info
*
7022 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7024 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7027 if (spec_attr
== NULL
)
7030 return follow_die_ref (die
, spec_attr
, spec_cu
);
7033 /* Free the line_header structure *LH, and any arrays and strings it
7036 free_line_header (struct line_header
*lh
)
7038 if (lh
->standard_opcode_lengths
)
7039 xfree (lh
->standard_opcode_lengths
);
7041 /* Remember that all the lh->file_names[i].name pointers are
7042 pointers into debug_line_buffer, and don't need to be freed. */
7044 xfree (lh
->file_names
);
7046 /* Similarly for the include directory names. */
7047 if (lh
->include_dirs
)
7048 xfree (lh
->include_dirs
);
7054 /* Add an entry to LH's include directory table. */
7056 add_include_dir (struct line_header
*lh
, char *include_dir
)
7058 /* Grow the array if necessary. */
7059 if (lh
->include_dirs_size
== 0)
7061 lh
->include_dirs_size
= 1; /* for testing */
7062 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7063 * sizeof (*lh
->include_dirs
));
7065 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7067 lh
->include_dirs_size
*= 2;
7068 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7069 (lh
->include_dirs_size
7070 * sizeof (*lh
->include_dirs
)));
7073 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7077 /* Add an entry to LH's file name table. */
7079 add_file_name (struct line_header
*lh
,
7081 unsigned int dir_index
,
7082 unsigned int mod_time
,
7083 unsigned int length
)
7085 struct file_entry
*fe
;
7087 /* Grow the array if necessary. */
7088 if (lh
->file_names_size
== 0)
7090 lh
->file_names_size
= 1; /* for testing */
7091 lh
->file_names
= xmalloc (lh
->file_names_size
7092 * sizeof (*lh
->file_names
));
7094 else if (lh
->num_file_names
>= lh
->file_names_size
)
7096 lh
->file_names_size
*= 2;
7097 lh
->file_names
= xrealloc (lh
->file_names
,
7098 (lh
->file_names_size
7099 * sizeof (*lh
->file_names
)));
7102 fe
= &lh
->file_names
[lh
->num_file_names
++];
7104 fe
->dir_index
= dir_index
;
7105 fe
->mod_time
= mod_time
;
7106 fe
->length
= length
;
7112 /* Read the statement program header starting at OFFSET in
7113 .debug_line, according to the endianness of ABFD. Return a pointer
7114 to a struct line_header, allocated using xmalloc.
7116 NOTE: the strings in the include directory and file name tables of
7117 the returned object point into debug_line_buffer, and must not be
7119 static struct line_header
*
7120 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7121 struct dwarf2_cu
*cu
)
7123 struct cleanup
*back_to
;
7124 struct line_header
*lh
;
7126 unsigned int bytes_read
, offset_size
;
7128 char *cur_dir
, *cur_file
;
7130 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7132 complaint (&symfile_complaints
, _("missing .debug_line section"));
7136 /* Make sure that at least there's room for the total_length field.
7137 That could be 12 bytes long, but we're just going to fudge that. */
7138 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7140 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7144 lh
= xmalloc (sizeof (*lh
));
7145 memset (lh
, 0, sizeof (*lh
));
7146 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7149 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7151 /* Read in the header. */
7153 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7154 &bytes_read
, &offset_size
);
7155 line_ptr
+= bytes_read
;
7156 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7157 + dwarf2_per_objfile
->line
.size
))
7159 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7162 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7163 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7165 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7166 line_ptr
+= offset_size
;
7167 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7169 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7171 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7173 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7175 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7177 lh
->standard_opcode_lengths
7178 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7180 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7181 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7183 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7187 /* Read directory table. */
7188 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7190 line_ptr
+= bytes_read
;
7191 add_include_dir (lh
, cur_dir
);
7193 line_ptr
+= bytes_read
;
7195 /* Read file name table. */
7196 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7198 unsigned int dir_index
, mod_time
, length
;
7200 line_ptr
+= bytes_read
;
7201 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7202 line_ptr
+= bytes_read
;
7203 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7204 line_ptr
+= bytes_read
;
7205 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7206 line_ptr
+= bytes_read
;
7208 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7210 line_ptr
+= bytes_read
;
7211 lh
->statement_program_start
= line_ptr
;
7213 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7214 + dwarf2_per_objfile
->line
.size
))
7215 complaint (&symfile_complaints
,
7216 _("line number info header doesn't fit in `.debug_line' section"));
7218 discard_cleanups (back_to
);
7222 /* This function exists to work around a bug in certain compilers
7223 (particularly GCC 2.95), in which the first line number marker of a
7224 function does not show up until after the prologue, right before
7225 the second line number marker. This function shifts ADDRESS down
7226 to the beginning of the function if necessary, and is called on
7227 addresses passed to record_line. */
7230 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7232 struct function_range
*fn
;
7234 /* Find the function_range containing address. */
7239 cu
->cached_fn
= cu
->first_fn
;
7243 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7249 while (fn
&& fn
!= cu
->cached_fn
)
7250 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7260 if (address
!= fn
->lowpc
)
7261 complaint (&symfile_complaints
,
7262 _("misplaced first line number at 0x%lx for '%s'"),
7263 (unsigned long) address
, fn
->name
);
7268 /* Decode the Line Number Program (LNP) for the given line_header
7269 structure and CU. The actual information extracted and the type
7270 of structures created from the LNP depends on the value of PST.
7272 1. If PST is NULL, then this procedure uses the data from the program
7273 to create all necessary symbol tables, and their linetables.
7274 The compilation directory of the file is passed in COMP_DIR,
7275 and must not be NULL.
7277 2. If PST is not NULL, this procedure reads the program to determine
7278 the list of files included by the unit represented by PST, and
7279 builds all the associated partial symbol tables. In this case,
7280 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7281 is not used to compute the full name of the symtab, and therefore
7282 omitting it when building the partial symtab does not introduce
7283 the potential for inconsistency - a partial symtab and its associated
7284 symbtab having a different fullname -). */
7287 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7288 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7290 gdb_byte
*line_ptr
, *extended_end
;
7292 unsigned int bytes_read
, extended_len
;
7293 unsigned char op_code
, extended_op
, adj_opcode
;
7295 struct objfile
*objfile
= cu
->objfile
;
7296 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7297 const int decode_for_pst_p
= (pst
!= NULL
);
7298 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7300 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7302 line_ptr
= lh
->statement_program_start
;
7303 line_end
= lh
->statement_program_end
;
7305 /* Read the statement sequences until there's nothing left. */
7306 while (line_ptr
< line_end
)
7308 /* state machine registers */
7309 CORE_ADDR address
= 0;
7310 unsigned int file
= 1;
7311 unsigned int line
= 1;
7312 unsigned int column
= 0;
7313 int is_stmt
= lh
->default_is_stmt
;
7314 int basic_block
= 0;
7315 int end_sequence
= 0;
7318 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7320 /* Start a subfile for the current file of the state machine. */
7321 /* lh->include_dirs and lh->file_names are 0-based, but the
7322 directory and file name numbers in the statement program
7324 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7328 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7330 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7333 /* Decode the table. */
7334 while (!end_sequence
)
7336 op_code
= read_1_byte (abfd
, line_ptr
);
7338 if (line_ptr
> line_end
)
7340 dwarf2_debug_line_missing_end_sequence_complaint ();
7344 if (op_code
>= lh
->opcode_base
)
7346 /* Special operand. */
7347 adj_opcode
= op_code
- lh
->opcode_base
;
7348 address
+= (adj_opcode
/ lh
->line_range
)
7349 * lh
->minimum_instruction_length
;
7350 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7351 if (lh
->num_file_names
< file
|| file
== 0)
7352 dwarf2_debug_line_missing_file_complaint ();
7355 lh
->file_names
[file
- 1].included_p
= 1;
7356 if (!decode_for_pst_p
)
7358 if (last_subfile
!= current_subfile
)
7360 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7362 record_line (last_subfile
, 0, addr
);
7363 last_subfile
= current_subfile
;
7365 /* Append row to matrix using current values. */
7366 addr
= check_cu_functions (address
, cu
);
7367 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7368 record_line (current_subfile
, line
, addr
);
7373 else switch (op_code
)
7375 case DW_LNS_extended_op
:
7376 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7377 line_ptr
+= bytes_read
;
7378 extended_end
= line_ptr
+ extended_len
;
7379 extended_op
= read_1_byte (abfd
, line_ptr
);
7381 switch (extended_op
)
7383 case DW_LNE_end_sequence
:
7386 case DW_LNE_set_address
:
7387 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7388 line_ptr
+= bytes_read
;
7389 address
+= baseaddr
;
7391 case DW_LNE_define_file
:
7394 unsigned int dir_index
, mod_time
, length
;
7396 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7397 line_ptr
+= bytes_read
;
7399 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7400 line_ptr
+= bytes_read
;
7402 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7403 line_ptr
+= bytes_read
;
7405 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7406 line_ptr
+= bytes_read
;
7407 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7410 case DW_LNE_set_discriminator
:
7411 /* The discriminator is not interesting to the debugger;
7413 line_ptr
= extended_end
;
7416 complaint (&symfile_complaints
,
7417 _("mangled .debug_line section"));
7420 /* Make sure that we parsed the extended op correctly. If e.g.
7421 we expected a different address size than the producer used,
7422 we may have read the wrong number of bytes. */
7423 if (line_ptr
!= extended_end
)
7425 complaint (&symfile_complaints
,
7426 _("mangled .debug_line section"));
7431 if (lh
->num_file_names
< file
|| file
== 0)
7432 dwarf2_debug_line_missing_file_complaint ();
7435 lh
->file_names
[file
- 1].included_p
= 1;
7436 if (!decode_for_pst_p
)
7438 if (last_subfile
!= current_subfile
)
7440 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7442 record_line (last_subfile
, 0, addr
);
7443 last_subfile
= current_subfile
;
7445 addr
= check_cu_functions (address
, cu
);
7446 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7447 record_line (current_subfile
, line
, addr
);
7452 case DW_LNS_advance_pc
:
7453 address
+= lh
->minimum_instruction_length
7454 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7455 line_ptr
+= bytes_read
;
7457 case DW_LNS_advance_line
:
7458 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7459 line_ptr
+= bytes_read
;
7461 case DW_LNS_set_file
:
7463 /* The arrays lh->include_dirs and lh->file_names are
7464 0-based, but the directory and file name numbers in
7465 the statement program are 1-based. */
7466 struct file_entry
*fe
;
7469 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7470 line_ptr
+= bytes_read
;
7471 if (lh
->num_file_names
< file
|| file
== 0)
7472 dwarf2_debug_line_missing_file_complaint ();
7475 fe
= &lh
->file_names
[file
- 1];
7477 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7478 if (!decode_for_pst_p
)
7480 last_subfile
= current_subfile
;
7481 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7486 case DW_LNS_set_column
:
7487 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7488 line_ptr
+= bytes_read
;
7490 case DW_LNS_negate_stmt
:
7491 is_stmt
= (!is_stmt
);
7493 case DW_LNS_set_basic_block
:
7496 /* Add to the address register of the state machine the
7497 address increment value corresponding to special opcode
7498 255. I.e., this value is scaled by the minimum
7499 instruction length since special opcode 255 would have
7500 scaled the the increment. */
7501 case DW_LNS_const_add_pc
:
7502 address
+= (lh
->minimum_instruction_length
7503 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7505 case DW_LNS_fixed_advance_pc
:
7506 address
+= read_2_bytes (abfd
, line_ptr
);
7511 /* Unknown standard opcode, ignore it. */
7514 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7516 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7517 line_ptr
+= bytes_read
;
7522 if (lh
->num_file_names
< file
|| file
== 0)
7523 dwarf2_debug_line_missing_file_complaint ();
7526 lh
->file_names
[file
- 1].included_p
= 1;
7527 if (!decode_for_pst_p
)
7529 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7530 record_line (current_subfile
, 0, addr
);
7535 if (decode_for_pst_p
)
7539 /* Now that we're done scanning the Line Header Program, we can
7540 create the psymtab of each included file. */
7541 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7542 if (lh
->file_names
[file_index
].included_p
== 1)
7544 const struct file_entry fe
= lh
->file_names
[file_index
];
7545 char *include_name
= fe
.name
;
7546 char *dir_name
= NULL
;
7547 char *pst_filename
= pst
->filename
;
7550 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7552 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7554 include_name
= concat (dir_name
, SLASH_STRING
,
7555 include_name
, (char *)NULL
);
7556 make_cleanup (xfree
, include_name
);
7559 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7561 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7562 pst_filename
, (char *)NULL
);
7563 make_cleanup (xfree
, pst_filename
);
7566 if (strcmp (include_name
, pst_filename
) != 0)
7567 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7572 /* Make sure a symtab is created for every file, even files
7573 which contain only variables (i.e. no code with associated
7577 struct file_entry
*fe
;
7579 for (i
= 0; i
< lh
->num_file_names
; i
++)
7582 fe
= &lh
->file_names
[i
];
7584 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7585 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7587 /* Skip the main file; we don't need it, and it must be
7588 allocated last, so that it will show up before the
7589 non-primary symtabs in the objfile's symtab list. */
7590 if (current_subfile
== first_subfile
)
7593 if (current_subfile
->symtab
== NULL
)
7594 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7596 fe
->symtab
= current_subfile
->symtab
;
7601 /* Start a subfile for DWARF. FILENAME is the name of the file and
7602 DIRNAME the name of the source directory which contains FILENAME
7603 or NULL if not known. COMP_DIR is the compilation directory for the
7604 linetable's compilation unit or NULL if not known.
7605 This routine tries to keep line numbers from identical absolute and
7606 relative file names in a common subfile.
7608 Using the `list' example from the GDB testsuite, which resides in
7609 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7610 of /srcdir/list0.c yields the following debugging information for list0.c:
7612 DW_AT_name: /srcdir/list0.c
7613 DW_AT_comp_dir: /compdir
7614 files.files[0].name: list0.h
7615 files.files[0].dir: /srcdir
7616 files.files[1].name: list0.c
7617 files.files[1].dir: /srcdir
7619 The line number information for list0.c has to end up in a single
7620 subfile, so that `break /srcdir/list0.c:1' works as expected.
7621 start_subfile will ensure that this happens provided that we pass the
7622 concatenation of files.files[1].dir and files.files[1].name as the
7626 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7630 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7631 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7632 second argument to start_subfile. To be consistent, we do the
7633 same here. In order not to lose the line information directory,
7634 we concatenate it to the filename when it makes sense.
7635 Note that the Dwarf3 standard says (speaking of filenames in line
7636 information): ``The directory index is ignored for file names
7637 that represent full path names''. Thus ignoring dirname in the
7638 `else' branch below isn't an issue. */
7640 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7641 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7643 fullname
= filename
;
7645 start_subfile (fullname
, comp_dir
);
7647 if (fullname
!= filename
)
7652 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7653 struct dwarf2_cu
*cu
)
7655 struct objfile
*objfile
= cu
->objfile
;
7656 struct comp_unit_head
*cu_header
= &cu
->header
;
7658 /* NOTE drow/2003-01-30: There used to be a comment and some special
7659 code here to turn a symbol with DW_AT_external and a
7660 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7661 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7662 with some versions of binutils) where shared libraries could have
7663 relocations against symbols in their debug information - the
7664 minimal symbol would have the right address, but the debug info
7665 would not. It's no longer necessary, because we will explicitly
7666 apply relocations when we read in the debug information now. */
7668 /* A DW_AT_location attribute with no contents indicates that a
7669 variable has been optimized away. */
7670 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7672 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7676 /* Handle one degenerate form of location expression specially, to
7677 preserve GDB's previous behavior when section offsets are
7678 specified. If this is just a DW_OP_addr then mark this symbol
7681 if (attr_form_is_block (attr
)
7682 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7683 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7687 SYMBOL_VALUE_ADDRESS (sym
) =
7688 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7689 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7690 fixup_symbol_section (sym
, objfile
);
7691 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7692 SYMBOL_SECTION (sym
));
7696 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7697 expression evaluator, and use LOC_COMPUTED only when necessary
7698 (i.e. when the value of a register or memory location is
7699 referenced, or a thread-local block, etc.). Then again, it might
7700 not be worthwhile. I'm assuming that it isn't unless performance
7701 or memory numbers show me otherwise. */
7703 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7704 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7707 /* Given a pointer to a DWARF information entry, figure out if we need
7708 to make a symbol table entry for it, and if so, create a new entry
7709 and return a pointer to it.
7710 If TYPE is NULL, determine symbol type from the die, otherwise
7711 used the passed type. */
7713 static struct symbol
*
7714 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7716 struct objfile
*objfile
= cu
->objfile
;
7717 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7718 struct symbol
*sym
= NULL
;
7720 struct attribute
*attr
= NULL
;
7721 struct attribute
*attr2
= NULL
;
7724 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7726 if (die
->tag
!= DW_TAG_namespace
)
7727 name
= dwarf2_linkage_name (die
, cu
);
7729 name
= TYPE_NAME (type
);
7733 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7734 sizeof (struct symbol
));
7735 OBJSTAT (objfile
, n_syms
++);
7736 memset (sym
, 0, sizeof (struct symbol
));
7738 /* Cache this symbol's name and the name's demangled form (if any). */
7739 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7740 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7742 /* Default assumptions.
7743 Use the passed type or decode it from the die. */
7744 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7745 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7747 SYMBOL_TYPE (sym
) = type
;
7749 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7750 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7753 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7756 attr
= dwarf2_attr (die
, DW_AT_decl_file
, cu
);
7759 int file_index
= DW_UNSND (attr
);
7760 if (cu
->line_header
== NULL
7761 || file_index
> cu
->line_header
->num_file_names
)
7762 complaint (&symfile_complaints
,
7763 _("file index out of range"));
7764 else if (file_index
> 0)
7766 struct file_entry
*fe
;
7767 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7768 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7775 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7778 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7780 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7782 case DW_TAG_subprogram
:
7783 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7785 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7786 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7787 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7788 || cu
->language
== language_ada
)
7790 /* Subprograms marked external are stored as a global symbol.
7791 Ada subprograms, whether marked external or not, are always
7792 stored as a global symbol, because we want to be able to
7793 access them globally. For instance, we want to be able
7794 to break on a nested subprogram without having to
7795 specify the context. */
7796 add_symbol_to_list (sym
, &global_symbols
);
7800 add_symbol_to_list (sym
, cu
->list_in_scope
);
7803 case DW_TAG_variable
:
7804 /* Compilation with minimal debug info may result in variables
7805 with missing type entries. Change the misleading `void' type
7806 to something sensible. */
7807 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7809 = builtin_type (gdbarch
)->nodebug_data_symbol
;
7811 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7814 dwarf2_const_value (attr
, sym
, cu
);
7815 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7816 if (attr2
&& (DW_UNSND (attr2
) != 0))
7817 add_symbol_to_list (sym
, &global_symbols
);
7819 add_symbol_to_list (sym
, cu
->list_in_scope
);
7822 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7825 var_decode_location (attr
, sym
, cu
);
7826 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7827 if (attr2
&& (DW_UNSND (attr2
) != 0))
7828 add_symbol_to_list (sym
, &global_symbols
);
7830 add_symbol_to_list (sym
, cu
->list_in_scope
);
7834 /* We do not know the address of this symbol.
7835 If it is an external symbol and we have type information
7836 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7837 The address of the variable will then be determined from
7838 the minimal symbol table whenever the variable is
7840 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7841 if (attr2
&& (DW_UNSND (attr2
) != 0)
7842 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7844 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7845 add_symbol_to_list (sym
, cu
->list_in_scope
);
7847 else if (!die_is_declaration (die
, cu
))
7849 /* Use the default LOC_OPTIMIZED_OUT class. */
7850 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
7851 add_symbol_to_list (sym
, cu
->list_in_scope
);
7855 case DW_TAG_formal_parameter
:
7856 SYMBOL_IS_ARGUMENT (sym
) = 1;
7857 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7860 var_decode_location (attr
, sym
, cu
);
7862 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7865 dwarf2_const_value (attr
, sym
, cu
);
7867 add_symbol_to_list (sym
, cu
->list_in_scope
);
7869 case DW_TAG_unspecified_parameters
:
7870 /* From varargs functions; gdb doesn't seem to have any
7871 interest in this information, so just ignore it for now.
7874 case DW_TAG_class_type
:
7875 case DW_TAG_interface_type
:
7876 case DW_TAG_structure_type
:
7877 case DW_TAG_union_type
:
7878 case DW_TAG_set_type
:
7879 case DW_TAG_enumeration_type
:
7880 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7881 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7883 /* Make sure that the symbol includes appropriate enclosing
7884 classes/namespaces in its name. These are calculated in
7885 read_structure_type, and the correct name is saved in
7888 if (cu
->language
== language_cplus
7889 || cu
->language
== language_java
)
7891 struct type
*type
= SYMBOL_TYPE (sym
);
7893 if (TYPE_TAG_NAME (type
) != NULL
)
7895 /* FIXME: carlton/2003-11-10: Should this use
7896 SYMBOL_SET_NAMES instead? (The same problem also
7897 arises further down in this function.) */
7898 /* The type's name is already allocated along with
7899 this objfile, so we don't need to duplicate it
7901 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7906 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7907 really ever be static objects: otherwise, if you try
7908 to, say, break of a class's method and you're in a file
7909 which doesn't mention that class, it won't work unless
7910 the check for all static symbols in lookup_symbol_aux
7911 saves you. See the OtherFileClass tests in
7912 gdb.c++/namespace.exp. */
7914 struct pending
**list_to_add
;
7916 list_to_add
= (cu
->list_in_scope
== &file_symbols
7917 && (cu
->language
== language_cplus
7918 || cu
->language
== language_java
)
7919 ? &global_symbols
: cu
->list_in_scope
);
7921 add_symbol_to_list (sym
, list_to_add
);
7923 /* The semantics of C++ state that "struct foo { ... }" also
7924 defines a typedef for "foo". A Java class declaration also
7925 defines a typedef for the class. */
7926 if (cu
->language
== language_cplus
7927 || cu
->language
== language_java
7928 || cu
->language
== language_ada
)
7930 /* The symbol's name is already allocated along with
7931 this objfile, so we don't need to duplicate it for
7933 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7934 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7938 case DW_TAG_typedef
:
7939 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7940 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7941 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7942 add_symbol_to_list (sym
, cu
->list_in_scope
);
7944 case DW_TAG_base_type
:
7945 case DW_TAG_subrange_type
:
7946 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7947 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7948 add_symbol_to_list (sym
, cu
->list_in_scope
);
7950 case DW_TAG_enumerator
:
7951 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7952 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7955 dwarf2_const_value (attr
, sym
, cu
);
7958 /* NOTE: carlton/2003-11-10: See comment above in the
7959 DW_TAG_class_type, etc. block. */
7961 struct pending
**list_to_add
;
7963 list_to_add
= (cu
->list_in_scope
== &file_symbols
7964 && (cu
->language
== language_cplus
7965 || cu
->language
== language_java
)
7966 ? &global_symbols
: cu
->list_in_scope
);
7968 add_symbol_to_list (sym
, list_to_add
);
7971 case DW_TAG_namespace
:
7972 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7973 add_symbol_to_list (sym
, &global_symbols
);
7976 /* Not a tag we recognize. Hopefully we aren't processing
7977 trash data, but since we must specifically ignore things
7978 we don't recognize, there is nothing else we should do at
7980 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
7981 dwarf_tag_name (die
->tag
));
7985 /* For the benefit of old versions of GCC, check for anonymous
7986 namespaces based on the demangled name. */
7987 if (!processing_has_namespace_info
7988 && cu
->language
== language_cplus
7989 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
7990 cp_scan_for_anonymous_namespaces (sym
);
7995 /* Copy constant value from an attribute to a symbol. */
7998 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
7999 struct dwarf2_cu
*cu
)
8001 struct objfile
*objfile
= cu
->objfile
;
8002 struct comp_unit_head
*cu_header
= &cu
->header
;
8003 struct dwarf_block
*blk
;
8008 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8009 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8010 cu_header
->addr_size
,
8011 TYPE_LENGTH (SYMBOL_TYPE
8013 SYMBOL_VALUE_BYTES (sym
) =
8014 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8015 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8016 it's body - store_unsigned_integer. */
8017 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8019 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8021 case DW_FORM_string
:
8023 /* DW_STRING is already allocated on the obstack, point directly
8025 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8026 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8028 case DW_FORM_block1
:
8029 case DW_FORM_block2
:
8030 case DW_FORM_block4
:
8032 blk
= DW_BLOCK (attr
);
8033 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8034 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8036 TYPE_LENGTH (SYMBOL_TYPE
8038 SYMBOL_VALUE_BYTES (sym
) =
8039 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8040 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8041 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8044 /* The DW_AT_const_value attributes are supposed to carry the
8045 symbol's value "represented as it would be on the target
8046 architecture." By the time we get here, it's already been
8047 converted to host endianness, so we just need to sign- or
8048 zero-extend it as appropriate. */
8050 dwarf2_const_value_data (attr
, sym
, 8);
8053 dwarf2_const_value_data (attr
, sym
, 16);
8056 dwarf2_const_value_data (attr
, sym
, 32);
8059 dwarf2_const_value_data (attr
, sym
, 64);
8063 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8064 SYMBOL_CLASS (sym
) = LOC_CONST
;
8068 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8069 SYMBOL_CLASS (sym
) = LOC_CONST
;
8073 complaint (&symfile_complaints
,
8074 _("unsupported const value attribute form: '%s'"),
8075 dwarf_form_name (attr
->form
));
8076 SYMBOL_VALUE (sym
) = 0;
8077 SYMBOL_CLASS (sym
) = LOC_CONST
;
8083 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8084 or zero-extend it as appropriate for the symbol's type. */
8086 dwarf2_const_value_data (struct attribute
*attr
,
8090 LONGEST l
= DW_UNSND (attr
);
8092 if (bits
< sizeof (l
) * 8)
8094 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8095 l
&= ((LONGEST
) 1 << bits
) - 1;
8097 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8100 SYMBOL_VALUE (sym
) = l
;
8101 SYMBOL_CLASS (sym
) = LOC_CONST
;
8105 /* Return the type of the die in question using its DW_AT_type attribute. */
8107 static struct type
*
8108 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8110 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8112 struct attribute
*type_attr
;
8113 struct die_info
*type_die
;
8115 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8118 /* A missing DW_AT_type represents a void type. */
8119 return builtin_type (gdbarch
)->builtin_void
;
8122 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8124 type
= tag_type_to_type (type_die
, cu
);
8127 dump_die_for_error (type_die
);
8128 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8134 /* Return the containing type of the die in question using its
8135 DW_AT_containing_type attribute. */
8137 static struct type
*
8138 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8140 struct type
*type
= NULL
;
8141 struct attribute
*type_attr
;
8142 struct die_info
*type_die
= NULL
;
8144 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8147 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8148 type
= tag_type_to_type (type_die
, cu
);
8153 dump_die_for_error (type_die
);
8154 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8160 static struct type
*
8161 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8163 struct type
*this_type
;
8165 this_type
= read_type_die (die
, cu
);
8168 dump_die_for_error (die
);
8169 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8175 static struct type
*
8176 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8178 struct type
*this_type
;
8180 this_type
= get_die_type (die
, cu
);
8186 case DW_TAG_class_type
:
8187 case DW_TAG_interface_type
:
8188 case DW_TAG_structure_type
:
8189 case DW_TAG_union_type
:
8190 this_type
= read_structure_type (die
, cu
);
8192 case DW_TAG_enumeration_type
:
8193 this_type
= read_enumeration_type (die
, cu
);
8195 case DW_TAG_subprogram
:
8196 case DW_TAG_subroutine_type
:
8197 this_type
= read_subroutine_type (die
, cu
);
8199 case DW_TAG_array_type
:
8200 this_type
= read_array_type (die
, cu
);
8202 case DW_TAG_set_type
:
8203 this_type
= read_set_type (die
, cu
);
8205 case DW_TAG_pointer_type
:
8206 this_type
= read_tag_pointer_type (die
, cu
);
8208 case DW_TAG_ptr_to_member_type
:
8209 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8211 case DW_TAG_reference_type
:
8212 this_type
= read_tag_reference_type (die
, cu
);
8214 case DW_TAG_const_type
:
8215 this_type
= read_tag_const_type (die
, cu
);
8217 case DW_TAG_volatile_type
:
8218 this_type
= read_tag_volatile_type (die
, cu
);
8220 case DW_TAG_string_type
:
8221 this_type
= read_tag_string_type (die
, cu
);
8223 case DW_TAG_typedef
:
8224 this_type
= read_typedef (die
, cu
);
8226 case DW_TAG_subrange_type
:
8227 this_type
= read_subrange_type (die
, cu
);
8229 case DW_TAG_base_type
:
8230 this_type
= read_base_type (die
, cu
);
8232 case DW_TAG_unspecified_type
:
8233 this_type
= read_unspecified_type (die
, cu
);
8235 case DW_TAG_namespace
:
8236 this_type
= read_namespace_type (die
, cu
);
8239 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8240 dwarf_tag_name (die
->tag
));
8247 /* Return the name of the namespace/class that DIE is defined within,
8248 or "" if we can't tell. The caller should not xfree the result.
8250 For example, if we're within the method foo() in the following
8260 then determine_prefix on foo's die will return "N::C". */
8263 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8265 struct die_info
*parent
, *spec_die
;
8266 struct dwarf2_cu
*spec_cu
;
8267 struct type
*parent_type
;
8269 if (cu
->language
!= language_cplus
8270 && cu
->language
!= language_java
)
8273 /* We have to be careful in the presence of DW_AT_specification.
8274 For example, with GCC 3.4, given the code
8278 // Definition of N::foo.
8282 then we'll have a tree of DIEs like this:
8284 1: DW_TAG_compile_unit
8285 2: DW_TAG_namespace // N
8286 3: DW_TAG_subprogram // declaration of N::foo
8287 4: DW_TAG_subprogram // definition of N::foo
8288 DW_AT_specification // refers to die #3
8290 Thus, when processing die #4, we have to pretend that we're in
8291 the context of its DW_AT_specification, namely the contex of die
8294 spec_die
= die_specification (die
, &spec_cu
);
8295 if (spec_die
== NULL
)
8296 parent
= die
->parent
;
8299 parent
= spec_die
->parent
;
8306 switch (parent
->tag
)
8308 case DW_TAG_namespace
:
8309 parent_type
= read_type_die (parent
, cu
);
8310 /* We give a name to even anonymous namespaces. */
8311 return TYPE_TAG_NAME (parent_type
);
8312 case DW_TAG_class_type
:
8313 case DW_TAG_interface_type
:
8314 case DW_TAG_structure_type
:
8315 case DW_TAG_union_type
:
8316 parent_type
= read_type_die (parent
, cu
);
8317 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8318 return TYPE_TAG_NAME (parent_type
);
8320 /* An anonymous structure is only allowed non-static data
8321 members; no typedefs, no member functions, et cetera.
8322 So it does not need a prefix. */
8325 return determine_prefix (parent
, cu
);
8329 /* Return a newly-allocated string formed by concatenating PREFIX and
8330 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8331 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8332 perform an obconcat, otherwise allocate storage for the result. The CU argument
8333 is used to determine the language and hence, the appropriate separator. */
8335 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8338 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8339 struct dwarf2_cu
*cu
)
8343 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8345 else if (cu
->language
== language_java
)
8357 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8358 strcpy (retval
, prefix
);
8359 strcat (retval
, sep
);
8360 strcat (retval
, suffix
);
8365 /* We have an obstack. */
8366 return obconcat (obs
, prefix
, sep
, suffix
);
8370 /* Return sibling of die, NULL if no sibling. */
8372 static struct die_info
*
8373 sibling_die (struct die_info
*die
)
8375 return die
->sibling
;
8378 /* Get linkage name of a die, return NULL if not found. */
8381 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8383 struct attribute
*attr
;
8385 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8386 if (attr
&& DW_STRING (attr
))
8387 return DW_STRING (attr
);
8388 return dwarf2_name (die
, cu
);
8391 /* Get name of a die, return NULL if not found. */
8394 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
8395 struct obstack
*obstack
)
8397 if (name
&& cu
->language
== language_cplus
)
8399 char *canon_name
= cp_canonicalize_string (name
);
8401 if (canon_name
!= NULL
)
8403 if (strcmp (canon_name
, name
) != 0)
8404 name
= obsavestring (canon_name
, strlen (canon_name
),
8413 /* Get name of a die, return NULL if not found. */
8416 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8418 struct attribute
*attr
;
8420 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8421 if (!attr
|| !DW_STRING (attr
))
8426 case DW_TAG_compile_unit
:
8427 /* Compilation units have a DW_AT_name that is a filename, not
8428 a source language identifier. */
8429 case DW_TAG_enumeration_type
:
8430 case DW_TAG_enumerator
:
8431 /* These tags always have simple identifiers already; no need
8432 to canonicalize them. */
8433 return DW_STRING (attr
);
8435 if (attr
->form
!= GDB_FORM_cached_string
)
8438 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
8439 &cu
->objfile
->objfile_obstack
);
8440 attr
->form
= GDB_FORM_cached_string
;
8442 return DW_STRING (attr
);
8446 /* Return the die that this die in an extension of, or NULL if there
8447 is none. *EXT_CU is the CU containing DIE on input, and the CU
8448 containing the return value on output. */
8450 static struct die_info
*
8451 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8453 struct attribute
*attr
;
8455 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8459 return follow_die_ref (die
, attr
, ext_cu
);
8462 /* Convert a DIE tag into its string name. */
8465 dwarf_tag_name (unsigned tag
)
8469 case DW_TAG_padding
:
8470 return "DW_TAG_padding";
8471 case DW_TAG_array_type
:
8472 return "DW_TAG_array_type";
8473 case DW_TAG_class_type
:
8474 return "DW_TAG_class_type";
8475 case DW_TAG_entry_point
:
8476 return "DW_TAG_entry_point";
8477 case DW_TAG_enumeration_type
:
8478 return "DW_TAG_enumeration_type";
8479 case DW_TAG_formal_parameter
:
8480 return "DW_TAG_formal_parameter";
8481 case DW_TAG_imported_declaration
:
8482 return "DW_TAG_imported_declaration";
8484 return "DW_TAG_label";
8485 case DW_TAG_lexical_block
:
8486 return "DW_TAG_lexical_block";
8488 return "DW_TAG_member";
8489 case DW_TAG_pointer_type
:
8490 return "DW_TAG_pointer_type";
8491 case DW_TAG_reference_type
:
8492 return "DW_TAG_reference_type";
8493 case DW_TAG_compile_unit
:
8494 return "DW_TAG_compile_unit";
8495 case DW_TAG_string_type
:
8496 return "DW_TAG_string_type";
8497 case DW_TAG_structure_type
:
8498 return "DW_TAG_structure_type";
8499 case DW_TAG_subroutine_type
:
8500 return "DW_TAG_subroutine_type";
8501 case DW_TAG_typedef
:
8502 return "DW_TAG_typedef";
8503 case DW_TAG_union_type
:
8504 return "DW_TAG_union_type";
8505 case DW_TAG_unspecified_parameters
:
8506 return "DW_TAG_unspecified_parameters";
8507 case DW_TAG_variant
:
8508 return "DW_TAG_variant";
8509 case DW_TAG_common_block
:
8510 return "DW_TAG_common_block";
8511 case DW_TAG_common_inclusion
:
8512 return "DW_TAG_common_inclusion";
8513 case DW_TAG_inheritance
:
8514 return "DW_TAG_inheritance";
8515 case DW_TAG_inlined_subroutine
:
8516 return "DW_TAG_inlined_subroutine";
8518 return "DW_TAG_module";
8519 case DW_TAG_ptr_to_member_type
:
8520 return "DW_TAG_ptr_to_member_type";
8521 case DW_TAG_set_type
:
8522 return "DW_TAG_set_type";
8523 case DW_TAG_subrange_type
:
8524 return "DW_TAG_subrange_type";
8525 case DW_TAG_with_stmt
:
8526 return "DW_TAG_with_stmt";
8527 case DW_TAG_access_declaration
:
8528 return "DW_TAG_access_declaration";
8529 case DW_TAG_base_type
:
8530 return "DW_TAG_base_type";
8531 case DW_TAG_catch_block
:
8532 return "DW_TAG_catch_block";
8533 case DW_TAG_const_type
:
8534 return "DW_TAG_const_type";
8535 case DW_TAG_constant
:
8536 return "DW_TAG_constant";
8537 case DW_TAG_enumerator
:
8538 return "DW_TAG_enumerator";
8539 case DW_TAG_file_type
:
8540 return "DW_TAG_file_type";
8542 return "DW_TAG_friend";
8543 case DW_TAG_namelist
:
8544 return "DW_TAG_namelist";
8545 case DW_TAG_namelist_item
:
8546 return "DW_TAG_namelist_item";
8547 case DW_TAG_packed_type
:
8548 return "DW_TAG_packed_type";
8549 case DW_TAG_subprogram
:
8550 return "DW_TAG_subprogram";
8551 case DW_TAG_template_type_param
:
8552 return "DW_TAG_template_type_param";
8553 case DW_TAG_template_value_param
:
8554 return "DW_TAG_template_value_param";
8555 case DW_TAG_thrown_type
:
8556 return "DW_TAG_thrown_type";
8557 case DW_TAG_try_block
:
8558 return "DW_TAG_try_block";
8559 case DW_TAG_variant_part
:
8560 return "DW_TAG_variant_part";
8561 case DW_TAG_variable
:
8562 return "DW_TAG_variable";
8563 case DW_TAG_volatile_type
:
8564 return "DW_TAG_volatile_type";
8565 case DW_TAG_dwarf_procedure
:
8566 return "DW_TAG_dwarf_procedure";
8567 case DW_TAG_restrict_type
:
8568 return "DW_TAG_restrict_type";
8569 case DW_TAG_interface_type
:
8570 return "DW_TAG_interface_type";
8571 case DW_TAG_namespace
:
8572 return "DW_TAG_namespace";
8573 case DW_TAG_imported_module
:
8574 return "DW_TAG_imported_module";
8575 case DW_TAG_unspecified_type
:
8576 return "DW_TAG_unspecified_type";
8577 case DW_TAG_partial_unit
:
8578 return "DW_TAG_partial_unit";
8579 case DW_TAG_imported_unit
:
8580 return "DW_TAG_imported_unit";
8581 case DW_TAG_condition
:
8582 return "DW_TAG_condition";
8583 case DW_TAG_shared_type
:
8584 return "DW_TAG_shared_type";
8585 case DW_TAG_MIPS_loop
:
8586 return "DW_TAG_MIPS_loop";
8587 case DW_TAG_HP_array_descriptor
:
8588 return "DW_TAG_HP_array_descriptor";
8589 case DW_TAG_format_label
:
8590 return "DW_TAG_format_label";
8591 case DW_TAG_function_template
:
8592 return "DW_TAG_function_template";
8593 case DW_TAG_class_template
:
8594 return "DW_TAG_class_template";
8595 case DW_TAG_GNU_BINCL
:
8596 return "DW_TAG_GNU_BINCL";
8597 case DW_TAG_GNU_EINCL
:
8598 return "DW_TAG_GNU_EINCL";
8599 case DW_TAG_upc_shared_type
:
8600 return "DW_TAG_upc_shared_type";
8601 case DW_TAG_upc_strict_type
:
8602 return "DW_TAG_upc_strict_type";
8603 case DW_TAG_upc_relaxed_type
:
8604 return "DW_TAG_upc_relaxed_type";
8605 case DW_TAG_PGI_kanji_type
:
8606 return "DW_TAG_PGI_kanji_type";
8607 case DW_TAG_PGI_interface_block
:
8608 return "DW_TAG_PGI_interface_block";
8610 return "DW_TAG_<unknown>";
8614 /* Convert a DWARF attribute code into its string name. */
8617 dwarf_attr_name (unsigned attr
)
8622 return "DW_AT_sibling";
8623 case DW_AT_location
:
8624 return "DW_AT_location";
8626 return "DW_AT_name";
8627 case DW_AT_ordering
:
8628 return "DW_AT_ordering";
8629 case DW_AT_subscr_data
:
8630 return "DW_AT_subscr_data";
8631 case DW_AT_byte_size
:
8632 return "DW_AT_byte_size";
8633 case DW_AT_bit_offset
:
8634 return "DW_AT_bit_offset";
8635 case DW_AT_bit_size
:
8636 return "DW_AT_bit_size";
8637 case DW_AT_element_list
:
8638 return "DW_AT_element_list";
8639 case DW_AT_stmt_list
:
8640 return "DW_AT_stmt_list";
8642 return "DW_AT_low_pc";
8644 return "DW_AT_high_pc";
8645 case DW_AT_language
:
8646 return "DW_AT_language";
8648 return "DW_AT_member";
8650 return "DW_AT_discr";
8651 case DW_AT_discr_value
:
8652 return "DW_AT_discr_value";
8653 case DW_AT_visibility
:
8654 return "DW_AT_visibility";
8656 return "DW_AT_import";
8657 case DW_AT_string_length
:
8658 return "DW_AT_string_length";
8659 case DW_AT_common_reference
:
8660 return "DW_AT_common_reference";
8661 case DW_AT_comp_dir
:
8662 return "DW_AT_comp_dir";
8663 case DW_AT_const_value
:
8664 return "DW_AT_const_value";
8665 case DW_AT_containing_type
:
8666 return "DW_AT_containing_type";
8667 case DW_AT_default_value
:
8668 return "DW_AT_default_value";
8670 return "DW_AT_inline";
8671 case DW_AT_is_optional
:
8672 return "DW_AT_is_optional";
8673 case DW_AT_lower_bound
:
8674 return "DW_AT_lower_bound";
8675 case DW_AT_producer
:
8676 return "DW_AT_producer";
8677 case DW_AT_prototyped
:
8678 return "DW_AT_prototyped";
8679 case DW_AT_return_addr
:
8680 return "DW_AT_return_addr";
8681 case DW_AT_start_scope
:
8682 return "DW_AT_start_scope";
8683 case DW_AT_bit_stride
:
8684 return "DW_AT_bit_stride";
8685 case DW_AT_upper_bound
:
8686 return "DW_AT_upper_bound";
8687 case DW_AT_abstract_origin
:
8688 return "DW_AT_abstract_origin";
8689 case DW_AT_accessibility
:
8690 return "DW_AT_accessibility";
8691 case DW_AT_address_class
:
8692 return "DW_AT_address_class";
8693 case DW_AT_artificial
:
8694 return "DW_AT_artificial";
8695 case DW_AT_base_types
:
8696 return "DW_AT_base_types";
8697 case DW_AT_calling_convention
:
8698 return "DW_AT_calling_convention";
8700 return "DW_AT_count";
8701 case DW_AT_data_member_location
:
8702 return "DW_AT_data_member_location";
8703 case DW_AT_decl_column
:
8704 return "DW_AT_decl_column";
8705 case DW_AT_decl_file
:
8706 return "DW_AT_decl_file";
8707 case DW_AT_decl_line
:
8708 return "DW_AT_decl_line";
8709 case DW_AT_declaration
:
8710 return "DW_AT_declaration";
8711 case DW_AT_discr_list
:
8712 return "DW_AT_discr_list";
8713 case DW_AT_encoding
:
8714 return "DW_AT_encoding";
8715 case DW_AT_external
:
8716 return "DW_AT_external";
8717 case DW_AT_frame_base
:
8718 return "DW_AT_frame_base";
8720 return "DW_AT_friend";
8721 case DW_AT_identifier_case
:
8722 return "DW_AT_identifier_case";
8723 case DW_AT_macro_info
:
8724 return "DW_AT_macro_info";
8725 case DW_AT_namelist_items
:
8726 return "DW_AT_namelist_items";
8727 case DW_AT_priority
:
8728 return "DW_AT_priority";
8730 return "DW_AT_segment";
8731 case DW_AT_specification
:
8732 return "DW_AT_specification";
8733 case DW_AT_static_link
:
8734 return "DW_AT_static_link";
8736 return "DW_AT_type";
8737 case DW_AT_use_location
:
8738 return "DW_AT_use_location";
8739 case DW_AT_variable_parameter
:
8740 return "DW_AT_variable_parameter";
8741 case DW_AT_virtuality
:
8742 return "DW_AT_virtuality";
8743 case DW_AT_vtable_elem_location
:
8744 return "DW_AT_vtable_elem_location";
8745 /* DWARF 3 values. */
8746 case DW_AT_allocated
:
8747 return "DW_AT_allocated";
8748 case DW_AT_associated
:
8749 return "DW_AT_associated";
8750 case DW_AT_data_location
:
8751 return "DW_AT_data_location";
8752 case DW_AT_byte_stride
:
8753 return "DW_AT_byte_stride";
8754 case DW_AT_entry_pc
:
8755 return "DW_AT_entry_pc";
8756 case DW_AT_use_UTF8
:
8757 return "DW_AT_use_UTF8";
8758 case DW_AT_extension
:
8759 return "DW_AT_extension";
8761 return "DW_AT_ranges";
8762 case DW_AT_trampoline
:
8763 return "DW_AT_trampoline";
8764 case DW_AT_call_column
:
8765 return "DW_AT_call_column";
8766 case DW_AT_call_file
:
8767 return "DW_AT_call_file";
8768 case DW_AT_call_line
:
8769 return "DW_AT_call_line";
8770 case DW_AT_description
:
8771 return "DW_AT_description";
8772 case DW_AT_binary_scale
:
8773 return "DW_AT_binary_scale";
8774 case DW_AT_decimal_scale
:
8775 return "DW_AT_decimal_scale";
8777 return "DW_AT_small";
8778 case DW_AT_decimal_sign
:
8779 return "DW_AT_decimal_sign";
8780 case DW_AT_digit_count
:
8781 return "DW_AT_digit_count";
8782 case DW_AT_picture_string
:
8783 return "DW_AT_picture_string";
8785 return "DW_AT_mutable";
8786 case DW_AT_threads_scaled
:
8787 return "DW_AT_threads_scaled";
8788 case DW_AT_explicit
:
8789 return "DW_AT_explicit";
8790 case DW_AT_object_pointer
:
8791 return "DW_AT_object_pointer";
8792 case DW_AT_endianity
:
8793 return "DW_AT_endianity";
8794 case DW_AT_elemental
:
8795 return "DW_AT_elemental";
8797 return "DW_AT_pure";
8798 case DW_AT_recursive
:
8799 return "DW_AT_recursive";
8800 /* SGI/MIPS extensions. */
8801 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8802 case DW_AT_MIPS_fde
:
8803 return "DW_AT_MIPS_fde";
8805 case DW_AT_MIPS_loop_begin
:
8806 return "DW_AT_MIPS_loop_begin";
8807 case DW_AT_MIPS_tail_loop_begin
:
8808 return "DW_AT_MIPS_tail_loop_begin";
8809 case DW_AT_MIPS_epilog_begin
:
8810 return "DW_AT_MIPS_epilog_begin";
8811 case DW_AT_MIPS_loop_unroll_factor
:
8812 return "DW_AT_MIPS_loop_unroll_factor";
8813 case DW_AT_MIPS_software_pipeline_depth
:
8814 return "DW_AT_MIPS_software_pipeline_depth";
8815 case DW_AT_MIPS_linkage_name
:
8816 return "DW_AT_MIPS_linkage_name";
8817 case DW_AT_MIPS_stride
:
8818 return "DW_AT_MIPS_stride";
8819 case DW_AT_MIPS_abstract_name
:
8820 return "DW_AT_MIPS_abstract_name";
8821 case DW_AT_MIPS_clone_origin
:
8822 return "DW_AT_MIPS_clone_origin";
8823 case DW_AT_MIPS_has_inlines
:
8824 return "DW_AT_MIPS_has_inlines";
8825 /* HP extensions. */
8826 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8827 case DW_AT_HP_block_index
:
8828 return "DW_AT_HP_block_index";
8830 case DW_AT_HP_unmodifiable
:
8831 return "DW_AT_HP_unmodifiable";
8832 case DW_AT_HP_actuals_stmt_list
:
8833 return "DW_AT_HP_actuals_stmt_list";
8834 case DW_AT_HP_proc_per_section
:
8835 return "DW_AT_HP_proc_per_section";
8836 case DW_AT_HP_raw_data_ptr
:
8837 return "DW_AT_HP_raw_data_ptr";
8838 case DW_AT_HP_pass_by_reference
:
8839 return "DW_AT_HP_pass_by_reference";
8840 case DW_AT_HP_opt_level
:
8841 return "DW_AT_HP_opt_level";
8842 case DW_AT_HP_prof_version_id
:
8843 return "DW_AT_HP_prof_version_id";
8844 case DW_AT_HP_opt_flags
:
8845 return "DW_AT_HP_opt_flags";
8846 case DW_AT_HP_cold_region_low_pc
:
8847 return "DW_AT_HP_cold_region_low_pc";
8848 case DW_AT_HP_cold_region_high_pc
:
8849 return "DW_AT_HP_cold_region_high_pc";
8850 case DW_AT_HP_all_variables_modifiable
:
8851 return "DW_AT_HP_all_variables_modifiable";
8852 case DW_AT_HP_linkage_name
:
8853 return "DW_AT_HP_linkage_name";
8854 case DW_AT_HP_prof_flags
:
8855 return "DW_AT_HP_prof_flags";
8856 /* GNU extensions. */
8857 case DW_AT_sf_names
:
8858 return "DW_AT_sf_names";
8859 case DW_AT_src_info
:
8860 return "DW_AT_src_info";
8861 case DW_AT_mac_info
:
8862 return "DW_AT_mac_info";
8863 case DW_AT_src_coords
:
8864 return "DW_AT_src_coords";
8865 case DW_AT_body_begin
:
8866 return "DW_AT_body_begin";
8867 case DW_AT_body_end
:
8868 return "DW_AT_body_end";
8869 case DW_AT_GNU_vector
:
8870 return "DW_AT_GNU_vector";
8871 /* VMS extensions. */
8872 case DW_AT_VMS_rtnbeg_pd_address
:
8873 return "DW_AT_VMS_rtnbeg_pd_address";
8874 /* UPC extension. */
8875 case DW_AT_upc_threads_scaled
:
8876 return "DW_AT_upc_threads_scaled";
8877 /* PGI (STMicroelectronics) extensions. */
8878 case DW_AT_PGI_lbase
:
8879 return "DW_AT_PGI_lbase";
8880 case DW_AT_PGI_soffset
:
8881 return "DW_AT_PGI_soffset";
8882 case DW_AT_PGI_lstride
:
8883 return "DW_AT_PGI_lstride";
8885 return "DW_AT_<unknown>";
8889 /* Convert a DWARF value form code into its string name. */
8892 dwarf_form_name (unsigned form
)
8897 return "DW_FORM_addr";
8898 case DW_FORM_block2
:
8899 return "DW_FORM_block2";
8900 case DW_FORM_block4
:
8901 return "DW_FORM_block4";
8903 return "DW_FORM_data2";
8905 return "DW_FORM_data4";
8907 return "DW_FORM_data8";
8908 case DW_FORM_string
:
8909 return "DW_FORM_string";
8911 return "DW_FORM_block";
8912 case DW_FORM_block1
:
8913 return "DW_FORM_block1";
8915 return "DW_FORM_data1";
8917 return "DW_FORM_flag";
8919 return "DW_FORM_sdata";
8921 return "DW_FORM_strp";
8923 return "DW_FORM_udata";
8924 case DW_FORM_ref_addr
:
8925 return "DW_FORM_ref_addr";
8927 return "DW_FORM_ref1";
8929 return "DW_FORM_ref2";
8931 return "DW_FORM_ref4";
8933 return "DW_FORM_ref8";
8934 case DW_FORM_ref_udata
:
8935 return "DW_FORM_ref_udata";
8936 case DW_FORM_indirect
:
8937 return "DW_FORM_indirect";
8938 case GDB_FORM_cached_string
:
8939 return "GDB_FORM_cached_string";
8941 return "DW_FORM_<unknown>";
8945 /* Convert a DWARF stack opcode into its string name. */
8948 dwarf_stack_op_name (unsigned op
)
8953 return "DW_OP_addr";
8955 return "DW_OP_deref";
8957 return "DW_OP_const1u";
8959 return "DW_OP_const1s";
8961 return "DW_OP_const2u";
8963 return "DW_OP_const2s";
8965 return "DW_OP_const4u";
8967 return "DW_OP_const4s";
8969 return "DW_OP_const8u";
8971 return "DW_OP_const8s";
8973 return "DW_OP_constu";
8975 return "DW_OP_consts";
8979 return "DW_OP_drop";
8981 return "DW_OP_over";
8983 return "DW_OP_pick";
8985 return "DW_OP_swap";
8989 return "DW_OP_xderef";
8997 return "DW_OP_minus";
9009 return "DW_OP_plus";
9010 case DW_OP_plus_uconst
:
9011 return "DW_OP_plus_uconst";
9017 return "DW_OP_shra";
9035 return "DW_OP_skip";
9037 return "DW_OP_lit0";
9039 return "DW_OP_lit1";
9041 return "DW_OP_lit2";
9043 return "DW_OP_lit3";
9045 return "DW_OP_lit4";
9047 return "DW_OP_lit5";
9049 return "DW_OP_lit6";
9051 return "DW_OP_lit7";
9053 return "DW_OP_lit8";
9055 return "DW_OP_lit9";
9057 return "DW_OP_lit10";
9059 return "DW_OP_lit11";
9061 return "DW_OP_lit12";
9063 return "DW_OP_lit13";
9065 return "DW_OP_lit14";
9067 return "DW_OP_lit15";
9069 return "DW_OP_lit16";
9071 return "DW_OP_lit17";
9073 return "DW_OP_lit18";
9075 return "DW_OP_lit19";
9077 return "DW_OP_lit20";
9079 return "DW_OP_lit21";
9081 return "DW_OP_lit22";
9083 return "DW_OP_lit23";
9085 return "DW_OP_lit24";
9087 return "DW_OP_lit25";
9089 return "DW_OP_lit26";
9091 return "DW_OP_lit27";
9093 return "DW_OP_lit28";
9095 return "DW_OP_lit29";
9097 return "DW_OP_lit30";
9099 return "DW_OP_lit31";
9101 return "DW_OP_reg0";
9103 return "DW_OP_reg1";
9105 return "DW_OP_reg2";
9107 return "DW_OP_reg3";
9109 return "DW_OP_reg4";
9111 return "DW_OP_reg5";
9113 return "DW_OP_reg6";
9115 return "DW_OP_reg7";
9117 return "DW_OP_reg8";
9119 return "DW_OP_reg9";
9121 return "DW_OP_reg10";
9123 return "DW_OP_reg11";
9125 return "DW_OP_reg12";
9127 return "DW_OP_reg13";
9129 return "DW_OP_reg14";
9131 return "DW_OP_reg15";
9133 return "DW_OP_reg16";
9135 return "DW_OP_reg17";
9137 return "DW_OP_reg18";
9139 return "DW_OP_reg19";
9141 return "DW_OP_reg20";
9143 return "DW_OP_reg21";
9145 return "DW_OP_reg22";
9147 return "DW_OP_reg23";
9149 return "DW_OP_reg24";
9151 return "DW_OP_reg25";
9153 return "DW_OP_reg26";
9155 return "DW_OP_reg27";
9157 return "DW_OP_reg28";
9159 return "DW_OP_reg29";
9161 return "DW_OP_reg30";
9163 return "DW_OP_reg31";
9165 return "DW_OP_breg0";
9167 return "DW_OP_breg1";
9169 return "DW_OP_breg2";
9171 return "DW_OP_breg3";
9173 return "DW_OP_breg4";
9175 return "DW_OP_breg5";
9177 return "DW_OP_breg6";
9179 return "DW_OP_breg7";
9181 return "DW_OP_breg8";
9183 return "DW_OP_breg9";
9185 return "DW_OP_breg10";
9187 return "DW_OP_breg11";
9189 return "DW_OP_breg12";
9191 return "DW_OP_breg13";
9193 return "DW_OP_breg14";
9195 return "DW_OP_breg15";
9197 return "DW_OP_breg16";
9199 return "DW_OP_breg17";
9201 return "DW_OP_breg18";
9203 return "DW_OP_breg19";
9205 return "DW_OP_breg20";
9207 return "DW_OP_breg21";
9209 return "DW_OP_breg22";
9211 return "DW_OP_breg23";
9213 return "DW_OP_breg24";
9215 return "DW_OP_breg25";
9217 return "DW_OP_breg26";
9219 return "DW_OP_breg27";
9221 return "DW_OP_breg28";
9223 return "DW_OP_breg29";
9225 return "DW_OP_breg30";
9227 return "DW_OP_breg31";
9229 return "DW_OP_regx";
9231 return "DW_OP_fbreg";
9233 return "DW_OP_bregx";
9235 return "DW_OP_piece";
9236 case DW_OP_deref_size
:
9237 return "DW_OP_deref_size";
9238 case DW_OP_xderef_size
:
9239 return "DW_OP_xderef_size";
9242 /* DWARF 3 extensions. */
9243 case DW_OP_push_object_address
:
9244 return "DW_OP_push_object_address";
9246 return "DW_OP_call2";
9248 return "DW_OP_call4";
9249 case DW_OP_call_ref
:
9250 return "DW_OP_call_ref";
9251 /* GNU extensions. */
9252 case DW_OP_form_tls_address
:
9253 return "DW_OP_form_tls_address";
9254 case DW_OP_call_frame_cfa
:
9255 return "DW_OP_call_frame_cfa";
9256 case DW_OP_bit_piece
:
9257 return "DW_OP_bit_piece";
9258 case DW_OP_GNU_push_tls_address
:
9259 return "DW_OP_GNU_push_tls_address";
9260 case DW_OP_GNU_uninit
:
9261 return "DW_OP_GNU_uninit";
9262 /* HP extensions. */
9263 case DW_OP_HP_is_value
:
9264 return "DW_OP_HP_is_value";
9265 case DW_OP_HP_fltconst4
:
9266 return "DW_OP_HP_fltconst4";
9267 case DW_OP_HP_fltconst8
:
9268 return "DW_OP_HP_fltconst8";
9269 case DW_OP_HP_mod_range
:
9270 return "DW_OP_HP_mod_range";
9271 case DW_OP_HP_unmod_range
:
9272 return "DW_OP_HP_unmod_range";
9274 return "DW_OP_HP_tls";
9276 return "OP_<unknown>";
9281 dwarf_bool_name (unsigned mybool
)
9289 /* Convert a DWARF type code into its string name. */
9292 dwarf_type_encoding_name (unsigned enc
)
9297 return "DW_ATE_void";
9298 case DW_ATE_address
:
9299 return "DW_ATE_address";
9300 case DW_ATE_boolean
:
9301 return "DW_ATE_boolean";
9302 case DW_ATE_complex_float
:
9303 return "DW_ATE_complex_float";
9305 return "DW_ATE_float";
9307 return "DW_ATE_signed";
9308 case DW_ATE_signed_char
:
9309 return "DW_ATE_signed_char";
9310 case DW_ATE_unsigned
:
9311 return "DW_ATE_unsigned";
9312 case DW_ATE_unsigned_char
:
9313 return "DW_ATE_unsigned_char";
9315 case DW_ATE_imaginary_float
:
9316 return "DW_ATE_imaginary_float";
9317 case DW_ATE_packed_decimal
:
9318 return "DW_ATE_packed_decimal";
9319 case DW_ATE_numeric_string
:
9320 return "DW_ATE_numeric_string";
9322 return "DW_ATE_edited";
9323 case DW_ATE_signed_fixed
:
9324 return "DW_ATE_signed_fixed";
9325 case DW_ATE_unsigned_fixed
:
9326 return "DW_ATE_unsigned_fixed";
9327 case DW_ATE_decimal_float
:
9328 return "DW_ATE_decimal_float";
9329 /* HP extensions. */
9330 case DW_ATE_HP_float80
:
9331 return "DW_ATE_HP_float80";
9332 case DW_ATE_HP_complex_float80
:
9333 return "DW_ATE_HP_complex_float80";
9334 case DW_ATE_HP_float128
:
9335 return "DW_ATE_HP_float128";
9336 case DW_ATE_HP_complex_float128
:
9337 return "DW_ATE_HP_complex_float128";
9338 case DW_ATE_HP_floathpintel
:
9339 return "DW_ATE_HP_floathpintel";
9340 case DW_ATE_HP_imaginary_float80
:
9341 return "DW_ATE_HP_imaginary_float80";
9342 case DW_ATE_HP_imaginary_float128
:
9343 return "DW_ATE_HP_imaginary_float128";
9345 return "DW_ATE_<unknown>";
9349 /* Convert a DWARF call frame info operation to its string name. */
9353 dwarf_cfi_name (unsigned cfi_opc
)
9357 case DW_CFA_advance_loc
:
9358 return "DW_CFA_advance_loc";
9360 return "DW_CFA_offset";
9361 case DW_CFA_restore
:
9362 return "DW_CFA_restore";
9364 return "DW_CFA_nop";
9365 case DW_CFA_set_loc
:
9366 return "DW_CFA_set_loc";
9367 case DW_CFA_advance_loc1
:
9368 return "DW_CFA_advance_loc1";
9369 case DW_CFA_advance_loc2
:
9370 return "DW_CFA_advance_loc2";
9371 case DW_CFA_advance_loc4
:
9372 return "DW_CFA_advance_loc4";
9373 case DW_CFA_offset_extended
:
9374 return "DW_CFA_offset_extended";
9375 case DW_CFA_restore_extended
:
9376 return "DW_CFA_restore_extended";
9377 case DW_CFA_undefined
:
9378 return "DW_CFA_undefined";
9379 case DW_CFA_same_value
:
9380 return "DW_CFA_same_value";
9381 case DW_CFA_register
:
9382 return "DW_CFA_register";
9383 case DW_CFA_remember_state
:
9384 return "DW_CFA_remember_state";
9385 case DW_CFA_restore_state
:
9386 return "DW_CFA_restore_state";
9387 case DW_CFA_def_cfa
:
9388 return "DW_CFA_def_cfa";
9389 case DW_CFA_def_cfa_register
:
9390 return "DW_CFA_def_cfa_register";
9391 case DW_CFA_def_cfa_offset
:
9392 return "DW_CFA_def_cfa_offset";
9394 case DW_CFA_def_cfa_expression
:
9395 return "DW_CFA_def_cfa_expression";
9396 case DW_CFA_expression
:
9397 return "DW_CFA_expression";
9398 case DW_CFA_offset_extended_sf
:
9399 return "DW_CFA_offset_extended_sf";
9400 case DW_CFA_def_cfa_sf
:
9401 return "DW_CFA_def_cfa_sf";
9402 case DW_CFA_def_cfa_offset_sf
:
9403 return "DW_CFA_def_cfa_offset_sf";
9404 case DW_CFA_val_offset
:
9405 return "DW_CFA_val_offset";
9406 case DW_CFA_val_offset_sf
:
9407 return "DW_CFA_val_offset_sf";
9408 case DW_CFA_val_expression
:
9409 return "DW_CFA_val_expression";
9410 /* SGI/MIPS specific. */
9411 case DW_CFA_MIPS_advance_loc8
:
9412 return "DW_CFA_MIPS_advance_loc8";
9413 /* GNU extensions. */
9414 case DW_CFA_GNU_window_save
:
9415 return "DW_CFA_GNU_window_save";
9416 case DW_CFA_GNU_args_size
:
9417 return "DW_CFA_GNU_args_size";
9418 case DW_CFA_GNU_negative_offset_extended
:
9419 return "DW_CFA_GNU_negative_offset_extended";
9421 return "DW_CFA_<unknown>";
9427 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9431 print_spaces (indent
, f
);
9432 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9433 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9435 if (die
->parent
!= NULL
)
9437 print_spaces (indent
, f
);
9438 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9439 die
->parent
->offset
);
9442 print_spaces (indent
, f
);
9443 fprintf_unfiltered (f
, " has children: %s\n",
9444 dwarf_bool_name (die
->child
!= NULL
));
9446 print_spaces (indent
, f
);
9447 fprintf_unfiltered (f
, " attributes:\n");
9449 for (i
= 0; i
< die
->num_attrs
; ++i
)
9451 print_spaces (indent
, f
);
9452 fprintf_unfiltered (f
, " %s (%s) ",
9453 dwarf_attr_name (die
->attrs
[i
].name
),
9454 dwarf_form_name (die
->attrs
[i
].form
));
9456 switch (die
->attrs
[i
].form
)
9458 case DW_FORM_ref_addr
:
9460 fprintf_unfiltered (f
, "address: ");
9461 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9463 case DW_FORM_block2
:
9464 case DW_FORM_block4
:
9466 case DW_FORM_block1
:
9467 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9472 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9473 (long) (DW_ADDR (&die
->attrs
[i
])));
9481 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9483 case DW_FORM_string
:
9485 case GDB_FORM_cached_string
:
9486 fprintf_unfiltered (f
, "string: \"%s\"",
9487 DW_STRING (&die
->attrs
[i
])
9488 ? DW_STRING (&die
->attrs
[i
]) : "");
9491 if (DW_UNSND (&die
->attrs
[i
]))
9492 fprintf_unfiltered (f
, "flag: TRUE");
9494 fprintf_unfiltered (f
, "flag: FALSE");
9496 case DW_FORM_indirect
:
9497 /* the reader will have reduced the indirect form to
9498 the "base form" so this form should not occur */
9499 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9502 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9503 die
->attrs
[i
].form
);
9506 fprintf_unfiltered (f
, "\n");
9511 dump_die_for_error (struct die_info
*die
)
9513 dump_die_shallow (gdb_stderr
, 0, die
);
9517 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9519 int indent
= level
* 4;
9521 gdb_assert (die
!= NULL
);
9523 if (level
>= max_level
)
9526 dump_die_shallow (f
, indent
, die
);
9528 if (die
->child
!= NULL
)
9530 print_spaces (indent
, f
);
9531 fprintf_unfiltered (f
, " Children:");
9532 if (level
+ 1 < max_level
)
9534 fprintf_unfiltered (f
, "\n");
9535 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9539 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9543 if (die
->sibling
!= NULL
&& level
> 0)
9545 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9549 /* This is called from the pdie macro in gdbinit.in.
9550 It's not static so gcc will keep a copy callable from gdb. */
9553 dump_die (struct die_info
*die
, int max_level
)
9555 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9559 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9563 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9569 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9571 unsigned int result
= 0;
9575 case DW_FORM_ref_addr
:
9580 case DW_FORM_ref_udata
:
9581 result
= DW_ADDR (attr
);
9584 complaint (&symfile_complaints
,
9585 _("unsupported die ref attribute form: '%s'"),
9586 dwarf_form_name (attr
->form
));
9591 /* Return the constant value held by the given attribute. Return -1
9592 if the value held by the attribute is not constant. */
9595 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9597 if (attr
->form
== DW_FORM_sdata
)
9598 return DW_SND (attr
);
9599 else if (attr
->form
== DW_FORM_udata
9600 || attr
->form
== DW_FORM_data1
9601 || attr
->form
== DW_FORM_data2
9602 || attr
->form
== DW_FORM_data4
9603 || attr
->form
== DW_FORM_data8
)
9604 return DW_UNSND (attr
);
9607 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9608 dwarf_form_name (attr
->form
));
9609 return default_value
;
9613 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9614 unit and add it to our queue. */
9617 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9618 struct dwarf2_per_cu_data
*per_cu
)
9620 /* Mark the dependence relation so that we don't flush PER_CU
9622 dwarf2_add_dependence (this_cu
, per_cu
);
9624 /* If it's already on the queue, we have nothing to do. */
9628 /* If the compilation unit is already loaded, just mark it as
9630 if (per_cu
->cu
!= NULL
)
9632 per_cu
->cu
->last_used
= 0;
9636 /* Add it to the queue. */
9637 queue_comp_unit (per_cu
, this_cu
->objfile
);
9640 /* Follow reference attribute ATTR of SRC_DIE.
9641 On entry *REF_CU is the CU of SRC_DIE.
9642 On exit *REF_CU is the CU of the result. */
9644 static struct die_info
*
9645 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9646 struct dwarf2_cu
**ref_cu
)
9648 struct die_info
*die
;
9649 unsigned int offset
;
9650 struct die_info temp_die
;
9651 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9653 offset
= dwarf2_get_ref_die_offset (attr
);
9655 if (! offset_in_cu_p (&cu
->header
, offset
))
9657 struct dwarf2_per_cu_data
*per_cu
;
9658 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9660 /* If necessary, add it to the queue and load its DIEs. */
9661 maybe_queue_comp_unit (cu
, per_cu
);
9663 target_cu
= per_cu
->cu
;
9668 *ref_cu
= target_cu
;
9669 temp_die
.offset
= offset
;
9670 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9674 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9675 "at 0x%lx [in module %s]"),
9676 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9679 /* Decode simple location descriptions.
9680 Given a pointer to a dwarf block that defines a location, compute
9681 the location and return the value.
9683 NOTE drow/2003-11-18: This function is called in two situations
9684 now: for the address of static or global variables (partial symbols
9685 only) and for offsets into structures which are expected to be
9686 (more or less) constant. The partial symbol case should go away,
9687 and only the constant case should remain. That will let this
9688 function complain more accurately. A few special modes are allowed
9689 without complaint for global variables (for instance, global
9690 register values and thread-local values).
9692 A location description containing no operations indicates that the
9693 object is optimized out. The return value is 0 for that case.
9694 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9695 callers will only want a very basic result and this can become a
9698 Note that stack[0] is unused except as a default error return.
9699 Note that stack overflow is not yet handled. */
9702 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9704 struct objfile
*objfile
= cu
->objfile
;
9705 struct comp_unit_head
*cu_header
= &cu
->header
;
9707 int size
= blk
->size
;
9708 gdb_byte
*data
= blk
->data
;
9709 CORE_ADDR stack
[64];
9711 unsigned int bytes_read
, unsnd
;
9755 stack
[++stacki
] = op
- DW_OP_lit0
;
9790 stack
[++stacki
] = op
- DW_OP_reg0
;
9792 dwarf2_complex_location_expr_complaint ();
9796 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9798 stack
[++stacki
] = unsnd
;
9800 dwarf2_complex_location_expr_complaint ();
9804 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9810 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9815 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9820 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9825 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9830 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9835 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9840 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9846 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9851 stack
[stacki
+ 1] = stack
[stacki
];
9856 stack
[stacki
- 1] += stack
[stacki
];
9860 case DW_OP_plus_uconst
:
9861 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9866 stack
[stacki
- 1] -= stack
[stacki
];
9871 /* If we're not the last op, then we definitely can't encode
9872 this using GDB's address_class enum. This is valid for partial
9873 global symbols, although the variable's address will be bogus
9876 dwarf2_complex_location_expr_complaint ();
9879 case DW_OP_GNU_push_tls_address
:
9880 /* The top of the stack has the offset from the beginning
9881 of the thread control block at which the variable is located. */
9882 /* Nothing should follow this operator, so the top of stack would
9884 /* This is valid for partial global symbols, but the variable's
9885 address will be bogus in the psymtab. */
9887 dwarf2_complex_location_expr_complaint ();
9890 case DW_OP_GNU_uninit
:
9894 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9895 dwarf_stack_op_name (op
));
9896 return (stack
[stacki
]);
9899 return (stack
[stacki
]);
9902 /* memory allocation interface */
9904 static struct dwarf_block
*
9905 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9907 struct dwarf_block
*blk
;
9909 blk
= (struct dwarf_block
*)
9910 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9914 static struct abbrev_info
*
9915 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9917 struct abbrev_info
*abbrev
;
9919 abbrev
= (struct abbrev_info
*)
9920 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9921 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9925 static struct die_info
*
9926 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9928 struct die_info
*die
;
9929 size_t size
= sizeof (struct die_info
);
9932 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9934 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9935 memset (die
, 0, sizeof (struct die_info
));
9940 /* Macro support. */
9943 /* Return the full name of file number I in *LH's file name table.
9944 Use COMP_DIR as the name of the current directory of the
9945 compilation. The result is allocated using xmalloc; the caller is
9946 responsible for freeing it. */
9948 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9950 /* Is the file number a valid index into the line header's file name
9951 table? Remember that file numbers start with one, not zero. */
9952 if (1 <= file
&& file
<= lh
->num_file_names
)
9954 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9956 if (IS_ABSOLUTE_PATH (fe
->name
))
9957 return xstrdup (fe
->name
);
9965 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9971 dir_len
= strlen (dir
);
9972 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
9973 strcpy (full_name
, dir
);
9974 full_name
[dir_len
] = '/';
9975 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
9979 return xstrdup (fe
->name
);
9984 /* The compiler produced a bogus file number. We can at least
9985 record the macro definitions made in the file, even if we
9986 won't be able to find the file by name. */
9988 sprintf (fake_name
, "<bad macro file number %d>", file
);
9990 complaint (&symfile_complaints
,
9991 _("bad file number in macro information (%d)"),
9994 return xstrdup (fake_name
);
9999 static struct macro_source_file
*
10000 macro_start_file (int file
, int line
,
10001 struct macro_source_file
*current_file
,
10002 const char *comp_dir
,
10003 struct line_header
*lh
, struct objfile
*objfile
)
10005 /* The full name of this source file. */
10006 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10008 /* We don't create a macro table for this compilation unit
10009 at all until we actually get a filename. */
10010 if (! pending_macros
)
10011 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10012 objfile
->macro_cache
);
10014 if (! current_file
)
10015 /* If we have no current file, then this must be the start_file
10016 directive for the compilation unit's main source file. */
10017 current_file
= macro_set_main (pending_macros
, full_name
);
10019 current_file
= macro_include (current_file
, line
, full_name
);
10023 return current_file
;
10027 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10028 followed by a null byte. */
10030 copy_string (const char *buf
, int len
)
10032 char *s
= xmalloc (len
+ 1);
10033 memcpy (s
, buf
, len
);
10040 static const char *
10041 consume_improper_spaces (const char *p
, const char *body
)
10045 complaint (&symfile_complaints
,
10046 _("macro definition contains spaces in formal argument list:\n`%s'"),
10058 parse_macro_definition (struct macro_source_file
*file
, int line
,
10063 /* The body string takes one of two forms. For object-like macro
10064 definitions, it should be:
10066 <macro name> " " <definition>
10068 For function-like macro definitions, it should be:
10070 <macro name> "() " <definition>
10072 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10074 Spaces may appear only where explicitly indicated, and in the
10077 The Dwarf 2 spec says that an object-like macro's name is always
10078 followed by a space, but versions of GCC around March 2002 omit
10079 the space when the macro's definition is the empty string.
10081 The Dwarf 2 spec says that there should be no spaces between the
10082 formal arguments in a function-like macro's formal argument list,
10083 but versions of GCC around March 2002 include spaces after the
10087 /* Find the extent of the macro name. The macro name is terminated
10088 by either a space or null character (for an object-like macro) or
10089 an opening paren (for a function-like macro). */
10090 for (p
= body
; *p
; p
++)
10091 if (*p
== ' ' || *p
== '(')
10094 if (*p
== ' ' || *p
== '\0')
10096 /* It's an object-like macro. */
10097 int name_len
= p
- body
;
10098 char *name
= copy_string (body
, name_len
);
10099 const char *replacement
;
10102 replacement
= body
+ name_len
+ 1;
10105 dwarf2_macro_malformed_definition_complaint (body
);
10106 replacement
= body
+ name_len
;
10109 macro_define_object (file
, line
, name
, replacement
);
10113 else if (*p
== '(')
10115 /* It's a function-like macro. */
10116 char *name
= copy_string (body
, p
- body
);
10119 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
10123 p
= consume_improper_spaces (p
, body
);
10125 /* Parse the formal argument list. */
10126 while (*p
&& *p
!= ')')
10128 /* Find the extent of the current argument name. */
10129 const char *arg_start
= p
;
10131 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
10134 if (! *p
|| p
== arg_start
)
10135 dwarf2_macro_malformed_definition_complaint (body
);
10138 /* Make sure argv has room for the new argument. */
10139 if (argc
>= argv_size
)
10142 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
10145 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
10148 p
= consume_improper_spaces (p
, body
);
10150 /* Consume the comma, if present. */
10155 p
= consume_improper_spaces (p
, body
);
10164 /* Perfectly formed definition, no complaints. */
10165 macro_define_function (file
, line
, name
,
10166 argc
, (const char **) argv
,
10168 else if (*p
== '\0')
10170 /* Complain, but do define it. */
10171 dwarf2_macro_malformed_definition_complaint (body
);
10172 macro_define_function (file
, line
, name
,
10173 argc
, (const char **) argv
,
10177 /* Just complain. */
10178 dwarf2_macro_malformed_definition_complaint (body
);
10181 /* Just complain. */
10182 dwarf2_macro_malformed_definition_complaint (body
);
10188 for (i
= 0; i
< argc
; i
++)
10194 dwarf2_macro_malformed_definition_complaint (body
);
10199 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
10200 char *comp_dir
, bfd
*abfd
,
10201 struct dwarf2_cu
*cu
)
10203 gdb_byte
*mac_ptr
, *mac_end
;
10204 struct macro_source_file
*current_file
= 0;
10205 enum dwarf_macinfo_record_type macinfo_type
;
10206 int at_commandline
;
10208 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
10210 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
10214 /* First pass: Find the name of the base filename.
10215 This filename is needed in order to process all macros whose definition
10216 (or undefinition) comes from the command line. These macros are defined
10217 before the first DW_MACINFO_start_file entry, and yet still need to be
10218 associated to the base file.
10220 To determine the base file name, we scan the macro definitions until we
10221 reach the first DW_MACINFO_start_file entry. We then initialize
10222 CURRENT_FILE accordingly so that any macro definition found before the
10223 first DW_MACINFO_start_file can still be associated to the base file. */
10225 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
10226 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
10227 + dwarf2_per_objfile
->macinfo
.size
;
10231 /* Do we at least have room for a macinfo type byte? */
10232 if (mac_ptr
>= mac_end
)
10234 /* Complaint is printed during the second pass as GDB will probably
10235 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10239 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10242 switch (macinfo_type
)
10244 /* A zero macinfo type indicates the end of the macro
10249 case DW_MACINFO_define
:
10250 case DW_MACINFO_undef
:
10251 /* Only skip the data by MAC_PTR. */
10253 unsigned int bytes_read
;
10255 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10256 mac_ptr
+= bytes_read
;
10257 read_string (abfd
, mac_ptr
, &bytes_read
);
10258 mac_ptr
+= bytes_read
;
10262 case DW_MACINFO_start_file
:
10264 unsigned int bytes_read
;
10267 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10268 mac_ptr
+= bytes_read
;
10269 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10270 mac_ptr
+= bytes_read
;
10272 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
10277 case DW_MACINFO_end_file
:
10278 /* No data to skip by MAC_PTR. */
10281 case DW_MACINFO_vendor_ext
:
10282 /* Only skip the data by MAC_PTR. */
10284 unsigned int bytes_read
;
10286 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10287 mac_ptr
+= bytes_read
;
10288 read_string (abfd
, mac_ptr
, &bytes_read
);
10289 mac_ptr
+= bytes_read
;
10296 } while (macinfo_type
!= 0 && current_file
== NULL
);
10298 /* Second pass: Process all entries.
10300 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10301 command-line macro definitions/undefinitions. This flag is unset when we
10302 reach the first DW_MACINFO_start_file entry. */
10304 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
10306 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10307 GDB is still reading the definitions from command line. First
10308 DW_MACINFO_start_file will need to be ignored as it was already executed
10309 to create CURRENT_FILE for the main source holding also the command line
10310 definitions. On first met DW_MACINFO_start_file this flag is reset to
10311 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10313 at_commandline
= 1;
10317 /* Do we at least have room for a macinfo type byte? */
10318 if (mac_ptr
>= mac_end
)
10320 dwarf2_macros_too_long_complaint ();
10324 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10327 switch (macinfo_type
)
10329 /* A zero macinfo type indicates the end of the macro
10334 case DW_MACINFO_define
:
10335 case DW_MACINFO_undef
:
10337 unsigned int bytes_read
;
10341 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10342 mac_ptr
+= bytes_read
;
10343 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
10344 mac_ptr
+= bytes_read
;
10346 if (! current_file
)
10348 /* DWARF violation as no main source is present. */
10349 complaint (&symfile_complaints
,
10350 _("debug info with no main source gives macro %s "
10353 DW_MACINFO_define
? _("definition") : macinfo_type
==
10354 DW_MACINFO_undef
? _("undefinition") :
10355 "something-or-other", line
, body
);
10358 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10359 complaint (&symfile_complaints
,
10360 _("debug info gives %s macro %s with %s line %d: %s"),
10361 at_commandline
? _("command-line") : _("in-file"),
10363 DW_MACINFO_define
? _("definition") : macinfo_type
==
10364 DW_MACINFO_undef
? _("undefinition") :
10365 "something-or-other",
10366 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
10368 if (macinfo_type
== DW_MACINFO_define
)
10369 parse_macro_definition (current_file
, line
, body
);
10370 else if (macinfo_type
== DW_MACINFO_undef
)
10371 macro_undef (current_file
, line
, body
);
10375 case DW_MACINFO_start_file
:
10377 unsigned int bytes_read
;
10380 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10381 mac_ptr
+= bytes_read
;
10382 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10383 mac_ptr
+= bytes_read
;
10385 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10386 complaint (&symfile_complaints
,
10387 _("debug info gives source %d included "
10388 "from %s at %s line %d"),
10389 file
, at_commandline
? _("command-line") : _("file"),
10390 line
== 0 ? _("zero") : _("non-zero"), line
);
10392 if (at_commandline
)
10394 /* This DW_MACINFO_start_file was executed in the pass one. */
10395 at_commandline
= 0;
10398 current_file
= macro_start_file (file
, line
,
10399 current_file
, comp_dir
,
10404 case DW_MACINFO_end_file
:
10405 if (! current_file
)
10406 complaint (&symfile_complaints
,
10407 _("macro debug info has an unmatched `close_file' directive"));
10410 current_file
= current_file
->included_by
;
10411 if (! current_file
)
10413 enum dwarf_macinfo_record_type next_type
;
10415 /* GCC circa March 2002 doesn't produce the zero
10416 type byte marking the end of the compilation
10417 unit. Complain if it's not there, but exit no
10420 /* Do we at least have room for a macinfo type byte? */
10421 if (mac_ptr
>= mac_end
)
10423 dwarf2_macros_too_long_complaint ();
10427 /* We don't increment mac_ptr here, so this is just
10429 next_type
= read_1_byte (abfd
, mac_ptr
);
10430 if (next_type
!= 0)
10431 complaint (&symfile_complaints
,
10432 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10439 case DW_MACINFO_vendor_ext
:
10441 unsigned int bytes_read
;
10445 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10446 mac_ptr
+= bytes_read
;
10447 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10448 mac_ptr
+= bytes_read
;
10450 /* We don't recognize any vendor extensions. */
10454 } while (macinfo_type
!= 0);
10457 /* Check if the attribute's form is a DW_FORM_block*
10458 if so return true else false. */
10460 attr_form_is_block (struct attribute
*attr
)
10462 return (attr
== NULL
? 0 :
10463 attr
->form
== DW_FORM_block1
10464 || attr
->form
== DW_FORM_block2
10465 || attr
->form
== DW_FORM_block4
10466 || attr
->form
== DW_FORM_block
);
10469 /* Return non-zero if ATTR's value is a section offset --- classes
10470 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10471 You may use DW_UNSND (attr) to retrieve such offsets.
10473 Section 7.5.4, "Attribute Encodings", explains that no attribute
10474 may have a value that belongs to more than one of these classes; it
10475 would be ambiguous if we did, because we use the same forms for all
10478 attr_form_is_section_offset (struct attribute
*attr
)
10480 return (attr
->form
== DW_FORM_data4
10481 || attr
->form
== DW_FORM_data8
);
10485 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10486 zero otherwise. When this function returns true, you can apply
10487 dwarf2_get_attr_constant_value to it.
10489 However, note that for some attributes you must check
10490 attr_form_is_section_offset before using this test. DW_FORM_data4
10491 and DW_FORM_data8 are members of both the constant class, and of
10492 the classes that contain offsets into other debug sections
10493 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10494 that, if an attribute's can be either a constant or one of the
10495 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10496 taken as section offsets, not constants. */
10498 attr_form_is_constant (struct attribute
*attr
)
10500 switch (attr
->form
)
10502 case DW_FORM_sdata
:
10503 case DW_FORM_udata
:
10504 case DW_FORM_data1
:
10505 case DW_FORM_data2
:
10506 case DW_FORM_data4
:
10507 case DW_FORM_data8
:
10515 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10516 struct dwarf2_cu
*cu
)
10518 if (attr_form_is_section_offset (attr
)
10519 /* ".debug_loc" may not exist at all, or the offset may be outside
10520 the section. If so, fall through to the complaint in the
10522 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
10524 struct dwarf2_loclist_baton
*baton
;
10526 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10527 sizeof (struct dwarf2_loclist_baton
));
10528 baton
->per_cu
= cu
->per_cu
;
10529 gdb_assert (baton
->per_cu
);
10531 /* We don't know how long the location list is, but make sure we
10532 don't run off the edge of the section. */
10533 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
10534 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
10535 baton
->base_address
= cu
->base_address
;
10536 if (cu
->base_known
== 0)
10537 complaint (&symfile_complaints
,
10538 _("Location list used without specifying the CU base address."));
10540 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
10541 SYMBOL_LOCATION_BATON (sym
) = baton
;
10545 struct dwarf2_locexpr_baton
*baton
;
10547 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10548 sizeof (struct dwarf2_locexpr_baton
));
10549 baton
->per_cu
= cu
->per_cu
;
10550 gdb_assert (baton
->per_cu
);
10552 if (attr_form_is_block (attr
))
10554 /* Note that we're just copying the block's data pointer
10555 here, not the actual data. We're still pointing into the
10556 info_buffer for SYM's objfile; right now we never release
10557 that buffer, but when we do clean up properly this may
10559 baton
->size
= DW_BLOCK (attr
)->size
;
10560 baton
->data
= DW_BLOCK (attr
)->data
;
10564 dwarf2_invalid_attrib_class_complaint ("location description",
10565 SYMBOL_NATURAL_NAME (sym
));
10567 baton
->data
= NULL
;
10570 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10571 SYMBOL_LOCATION_BATON (sym
) = baton
;
10575 /* Return the OBJFILE associated with the compilation unit CU. */
10578 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10580 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10582 /* Return the master objfile, so that we can report and look up the
10583 correct file containing this variable. */
10584 if (objfile
->separate_debug_objfile_backlink
)
10585 objfile
= objfile
->separate_debug_objfile_backlink
;
10590 /* Return the address size given in the compilation unit header for CU. */
10593 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10596 return per_cu
->cu
->header
.addr_size
;
10599 /* If the CU is not currently read in, we re-read its header. */
10600 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10601 struct dwarf2_per_objfile
*per_objfile
10602 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10603 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
10605 struct comp_unit_head cu_header
;
10606 memset (&cu_header
, 0, sizeof cu_header
);
10607 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10608 return cu_header
.addr_size
;
10612 /* Locate the compilation unit from CU's objfile which contains the
10613 DIE at OFFSET. Raises an error on failure. */
10615 static struct dwarf2_per_cu_data
*
10616 dwarf2_find_containing_comp_unit (unsigned int offset
,
10617 struct objfile
*objfile
)
10619 struct dwarf2_per_cu_data
*this_cu
;
10623 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10626 int mid
= low
+ (high
- low
) / 2;
10627 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10632 gdb_assert (low
== high
);
10633 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10636 error (_("Dwarf Error: could not find partial DIE containing "
10637 "offset 0x%lx [in module %s]"),
10638 (long) offset
, bfd_get_filename (objfile
->obfd
));
10640 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10641 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10645 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10646 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10647 && offset
>= this_cu
->offset
+ this_cu
->length
)
10648 error (_("invalid dwarf2 offset %u"), offset
);
10649 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10654 /* Locate the compilation unit from OBJFILE which is located at exactly
10655 OFFSET. Raises an error on failure. */
10657 static struct dwarf2_per_cu_data
*
10658 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10660 struct dwarf2_per_cu_data
*this_cu
;
10661 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10662 if (this_cu
->offset
!= offset
)
10663 error (_("no compilation unit with offset %u."), offset
);
10667 /* Release one cached compilation unit, CU. We unlink it from the tree
10668 of compilation units, but we don't remove it from the read_in_chain;
10669 the caller is responsible for that. */
10672 free_one_comp_unit (void *data
)
10674 struct dwarf2_cu
*cu
= data
;
10676 if (cu
->per_cu
!= NULL
)
10677 cu
->per_cu
->cu
= NULL
;
10680 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10685 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10686 when we're finished with it. We can't free the pointer itself, but be
10687 sure to unlink it from the cache. Also release any associated storage
10688 and perform cache maintenance.
10690 Only used during partial symbol parsing. */
10693 free_stack_comp_unit (void *data
)
10695 struct dwarf2_cu
*cu
= data
;
10697 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10698 cu
->partial_dies
= NULL
;
10700 if (cu
->per_cu
!= NULL
)
10702 /* This compilation unit is on the stack in our caller, so we
10703 should not xfree it. Just unlink it. */
10704 cu
->per_cu
->cu
= NULL
;
10707 /* If we had a per-cu pointer, then we may have other compilation
10708 units loaded, so age them now. */
10709 age_cached_comp_units ();
10713 /* Free all cached compilation units. */
10716 free_cached_comp_units (void *data
)
10718 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10720 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10721 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10722 while (per_cu
!= NULL
)
10724 struct dwarf2_per_cu_data
*next_cu
;
10726 next_cu
= per_cu
->cu
->read_in_chain
;
10728 free_one_comp_unit (per_cu
->cu
);
10729 *last_chain
= next_cu
;
10735 /* Increase the age counter on each cached compilation unit, and free
10736 any that are too old. */
10739 age_cached_comp_units (void)
10741 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10743 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10744 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10745 while (per_cu
!= NULL
)
10747 per_cu
->cu
->last_used
++;
10748 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10749 dwarf2_mark (per_cu
->cu
);
10750 per_cu
= per_cu
->cu
->read_in_chain
;
10753 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10754 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10755 while (per_cu
!= NULL
)
10757 struct dwarf2_per_cu_data
*next_cu
;
10759 next_cu
= per_cu
->cu
->read_in_chain
;
10761 if (!per_cu
->cu
->mark
)
10763 free_one_comp_unit (per_cu
->cu
);
10764 *last_chain
= next_cu
;
10767 last_chain
= &per_cu
->cu
->read_in_chain
;
10773 /* Remove a single compilation unit from the cache. */
10776 free_one_cached_comp_unit (void *target_cu
)
10778 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10780 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10781 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10782 while (per_cu
!= NULL
)
10784 struct dwarf2_per_cu_data
*next_cu
;
10786 next_cu
= per_cu
->cu
->read_in_chain
;
10788 if (per_cu
->cu
== target_cu
)
10790 free_one_comp_unit (per_cu
->cu
);
10791 *last_chain
= next_cu
;
10795 last_chain
= &per_cu
->cu
->read_in_chain
;
10801 /* Release all extra memory associated with OBJFILE. */
10804 dwarf2_free_objfile (struct objfile
*objfile
)
10806 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10808 if (dwarf2_per_objfile
== NULL
)
10811 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10812 free_cached_comp_units (NULL
);
10814 /* Everything else should be on the objfile obstack. */
10817 /* A pair of DIE offset and GDB type pointer. We store these
10818 in a hash table separate from the DIEs, and preserve them
10819 when the DIEs are flushed out of cache. */
10821 struct dwarf2_offset_and_type
10823 unsigned int offset
;
10827 /* Hash function for a dwarf2_offset_and_type. */
10830 offset_and_type_hash (const void *item
)
10832 const struct dwarf2_offset_and_type
*ofs
= item
;
10833 return ofs
->offset
;
10836 /* Equality function for a dwarf2_offset_and_type. */
10839 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10841 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10842 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10843 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10846 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10847 table if necessary. For convenience, return TYPE. */
10849 static struct type
*
10850 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10852 struct dwarf2_offset_and_type
**slot
, ofs
;
10854 if (cu
->type_hash
== NULL
)
10856 gdb_assert (cu
->per_cu
!= NULL
);
10857 cu
->per_cu
->type_hash
10858 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10859 offset_and_type_hash
,
10860 offset_and_type_eq
,
10862 &cu
->objfile
->objfile_obstack
,
10863 hashtab_obstack_allocate
,
10864 dummy_obstack_deallocate
);
10865 cu
->type_hash
= cu
->per_cu
->type_hash
;
10868 ofs
.offset
= die
->offset
;
10870 slot
= (struct dwarf2_offset_and_type
**)
10871 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10872 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10877 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10878 not have a saved type. */
10880 static struct type
*
10881 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10883 struct dwarf2_offset_and_type
*slot
, ofs
;
10884 htab_t type_hash
= cu
->type_hash
;
10886 if (type_hash
== NULL
)
10889 ofs
.offset
= die
->offset
;
10890 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10897 /* Add a dependence relationship from CU to REF_PER_CU. */
10900 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10901 struct dwarf2_per_cu_data
*ref_per_cu
)
10905 if (cu
->dependencies
== NULL
)
10907 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10908 NULL
, &cu
->comp_unit_obstack
,
10909 hashtab_obstack_allocate
,
10910 dummy_obstack_deallocate
);
10912 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10914 *slot
= ref_per_cu
;
10917 /* Subroutine of dwarf2_mark to pass to htab_traverse.
10918 Set the mark field in every compilation unit in the
10919 cache that we must keep because we are keeping CU. */
10922 dwarf2_mark_helper (void **slot
, void *data
)
10924 struct dwarf2_per_cu_data
*per_cu
;
10926 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10927 if (per_cu
->cu
->mark
)
10929 per_cu
->cu
->mark
= 1;
10931 if (per_cu
->cu
->dependencies
!= NULL
)
10932 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10937 /* Set the mark field in CU and in every other compilation unit in the
10938 cache that we must keep because we are keeping CU. */
10941 dwarf2_mark (struct dwarf2_cu
*cu
)
10946 if (cu
->dependencies
!= NULL
)
10947 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10951 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10955 per_cu
->cu
->mark
= 0;
10956 per_cu
= per_cu
->cu
->read_in_chain
;
10960 /* Trivial hash function for partial_die_info: the hash value of a DIE
10961 is its offset in .debug_info for this objfile. */
10964 partial_die_hash (const void *item
)
10966 const struct partial_die_info
*part_die
= item
;
10967 return part_die
->offset
;
10970 /* Trivial comparison function for partial_die_info structures: two DIEs
10971 are equal if they have the same offset. */
10974 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
10976 const struct partial_die_info
*part_die_lhs
= item_lhs
;
10977 const struct partial_die_info
*part_die_rhs
= item_rhs
;
10978 return part_die_lhs
->offset
== part_die_rhs
->offset
;
10981 static struct cmd_list_element
*set_dwarf2_cmdlist
;
10982 static struct cmd_list_element
*show_dwarf2_cmdlist
;
10985 set_dwarf2_cmd (char *args
, int from_tty
)
10987 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
10991 show_dwarf2_cmd (char *args
, int from_tty
)
10993 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
10996 /* If section described by INFO was mmapped, munmap it now. */
10999 munmap_section_buffer (struct dwarf2_section_info
*info
)
11001 if (info
->was_mmapped
)
11004 intptr_t begin
= (intptr_t) info
->buffer
;
11005 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11006 size_t map_length
= info
->size
+ begin
- map_begin
;
11007 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11009 /* Without HAVE_MMAP, we should never be here to begin with. */
11015 /* munmap debug sections for OBJFILE, if necessary. */
11018 dwarf2_per_objfile_cleanup (struct objfile
*objfile
, void *d
)
11020 struct dwarf2_per_objfile
*data
= d
;
11021 munmap_section_buffer (&data
->info
);
11022 munmap_section_buffer (&data
->abbrev
);
11023 munmap_section_buffer (&data
->line
);
11024 munmap_section_buffer (&data
->str
);
11025 munmap_section_buffer (&data
->macinfo
);
11026 munmap_section_buffer (&data
->ranges
);
11027 munmap_section_buffer (&data
->loc
);
11028 munmap_section_buffer (&data
->frame
);
11029 munmap_section_buffer (&data
->eh_frame
);
11032 void _initialize_dwarf2_read (void);
11035 _initialize_dwarf2_read (void)
11037 dwarf2_objfile_data_key
11038 = register_objfile_data_with_cleanup (dwarf2_per_objfile_cleanup
);
11040 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
11041 Set DWARF 2 specific variables.\n\
11042 Configure DWARF 2 variables such as the cache size"),
11043 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
11044 0/*allow-unknown*/, &maintenance_set_cmdlist
);
11046 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
11047 Show DWARF 2 specific variables\n\
11048 Show DWARF 2 variables such as the cache size"),
11049 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
11050 0/*allow-unknown*/, &maintenance_show_cmdlist
);
11052 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
11053 &dwarf2_max_cache_age
, _("\
11054 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
11055 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
11056 A higher limit means that cached compilation units will be stored\n\
11057 in memory longer, and more total memory will be used. Zero disables\n\
11058 caching, which can slow down startup."),
11060 show_dwarf2_max_cache_age
,
11061 &set_dwarf2_cmdlist
,
11062 &show_dwarf2_cmdlist
);
11064 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
11065 Set debugging of the dwarf2 DIE reader."), _("\
11066 Show debugging of the dwarf2 DIE reader."), _("\
11067 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11068 The value is the maximum depth to print."),
11071 &setdebuglist
, &showdebuglist
);