1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 /* A note on memory usage for this file.
56 At the present time, this code reads the debug info sections into
57 the objfile's objfile_obstack. A definite improvement for startup
58 time, on platforms which do not emit relocations for debug
59 sections, would be to use mmap instead. The object's complete
60 debug information is loaded into memory, partly to simplify
61 absolute DIE references.
63 Whether using obstacks or mmap, the sections should remain loaded
64 until the objfile is released, and pointers into the section data
65 can be used for any other data associated to the objfile (symbol
66 names, type names, location expressions to name a few). */
68 #ifndef DWARF2_REG_TO_REGNUM
69 #define DWARF2_REG_TO_REGNUM(REG) (REG)
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
78 unsigned int length; /* length of the .debug_info
80 unsigned short version; /* version number -- 2 for DWARF
82 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
83 unsigned char addr_size; /* byte size of an address -- 4 */
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
94 unsigned int length; /* length of the .debug_pubnames
96 unsigned char version; /* version number -- 2 for DWARF
98 unsigned int info_offset; /* offset into .debug_info section */
99 unsigned int info_size; /* byte size of .debug_info section
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
110 unsigned int length; /* byte len of the .debug_aranges
112 unsigned short version; /* version number -- 2 for DWARF
114 unsigned int info_offset; /* offset into .debug_info section */
115 unsigned char addr_size; /* byte size of an address */
116 unsigned char seg_size; /* byte size of segment descriptor */
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
126 unsigned int total_length; /* byte length of the statement
128 unsigned short version; /* version number -- 2 for DWARF
130 unsigned int prologue_length; /* # bytes between prologue &
132 unsigned char minimum_instruction_length; /* byte size of
134 unsigned char default_is_stmt; /* initial value of is_stmt
137 unsigned char line_range;
138 unsigned char opcode_base; /* number assigned to first special
140 unsigned char *standard_opcode_lengths;
144 static const struct objfile_data *dwarf2_objfile_data_key;
146 struct dwarf2_per_objfile
148 /* Sizes of debugging sections. */
149 unsigned int info_size;
150 unsigned int abbrev_size;
151 unsigned int line_size;
152 unsigned int pubnames_size;
153 unsigned int aranges_size;
154 unsigned int loc_size;
155 unsigned int macinfo_size;
156 unsigned int str_size;
157 unsigned int ranges_size;
158 unsigned int frame_size;
159 unsigned int eh_frame_size;
161 /* Loaded data from the sections. */
166 char *macinfo_buffer;
171 static struct dwarf2_per_objfile *dwarf2_per_objfile;
173 static asection *dwarf_info_section;
174 static asection *dwarf_abbrev_section;
175 static asection *dwarf_line_section;
176 static asection *dwarf_pubnames_section;
177 static asection *dwarf_aranges_section;
178 static asection *dwarf_loc_section;
179 static asection *dwarf_macinfo_section;
180 static asection *dwarf_str_section;
181 static asection *dwarf_ranges_section;
182 asection *dwarf_frame_section;
183 asection *dwarf_eh_frame_section;
185 /* names of the debugging sections */
187 #define INFO_SECTION ".debug_info"
188 #define ABBREV_SECTION ".debug_abbrev"
189 #define LINE_SECTION ".debug_line"
190 #define PUBNAMES_SECTION ".debug_pubnames"
191 #define ARANGES_SECTION ".debug_aranges"
192 #define LOC_SECTION ".debug_loc"
193 #define MACINFO_SECTION ".debug_macinfo"
194 #define STR_SECTION ".debug_str"
195 #define RANGES_SECTION ".debug_ranges"
196 #define FRAME_SECTION ".debug_frame"
197 #define EH_FRAME_SECTION ".eh_frame"
199 /* local data types */
201 /* We hold several abbreviation tables in memory at the same time. */
202 #ifndef ABBREV_HASH_SIZE
203 #define ABBREV_HASH_SIZE 121
206 /* The data in a compilation unit header, after target2host
207 translation, looks like this. */
208 struct comp_unit_head
210 unsigned long length;
212 unsigned int abbrev_offset;
213 unsigned char addr_size;
214 unsigned char signed_addr_p;
215 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
216 unsigned int initial_length_size; /* size of the length field; either
219 /* Offset to the first byte of this compilation unit header in the
220 * .debug_info section, for resolving relative reference dies. */
224 /* Pointer to this compilation unit header in the .debug_info
229 /* Pointer to the first die of this compilatio unit. This will
230 * be the first byte following the compilation unit header. */
234 /* Pointer to the next compilation unit header in the program. */
236 struct comp_unit_head *next;
238 /* Base address of this compilation unit. */
240 CORE_ADDR base_address;
242 /* Non-zero if base_address has been set. */
247 /* Internal state when decoding a particular compilation unit. */
250 /* The objfile containing this compilation unit. */
251 struct objfile *objfile;
253 /* The header of the compilation unit.
255 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
256 should logically be moved to the dwarf2_cu structure. */
257 struct comp_unit_head header;
259 struct function_range *first_fn, *last_fn, *cached_fn;
261 /* The language we are debugging. */
262 enum language language;
263 const struct language_defn *language_defn;
265 const char *producer;
267 /* The generic symbol table building routines have separate lists for
268 file scope symbols and all all other scopes (local scopes). So
269 we need to select the right one to pass to add_symbol_to_list().
270 We do it by keeping a pointer to the correct list in list_in_scope.
272 FIXME: The original dwarf code just treated the file scope as the
273 first local scope, and all other local scopes as nested local
274 scopes, and worked fine. Check to see if we really need to
275 distinguish these in buildsym.c. */
276 struct pending **list_in_scope;
278 /* Maintain an array of referenced fundamental types for the current
279 compilation unit being read. For DWARF version 1, we have to construct
280 the fundamental types on the fly, since no information about the
281 fundamental types is supplied. Each such fundamental type is created by
282 calling a language dependent routine to create the type, and then a
283 pointer to that type is then placed in the array at the index specified
284 by it's FT_<TYPENAME> value. The array has a fixed size set by the
285 FT_NUM_MEMBERS compile time constant, which is the number of predefined
286 fundamental types gdb knows how to construct. */
287 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info **dwarf2_abbrevs;
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack;
295 /* Hash table holding all the loaded partial DIEs. */
298 /* Storage for things with the same lifetime as this read-in compilation
299 unit, including partial DIEs. */
300 struct obstack comp_unit_obstack;
302 /* This flag will be set if this compilation unit includes any
303 DW_TAG_namespace DIEs. If we know that there are explicit
304 DIEs for namespaces, we don't need to try to infer them
305 from mangled names. */
306 unsigned int has_namespace_info : 1;
309 /* The line number information for a compilation unit (found in the
310 .debug_line section) begins with a "statement program header",
311 which contains the following information. */
314 unsigned int total_length;
315 unsigned short version;
316 unsigned int header_length;
317 unsigned char minimum_instruction_length;
318 unsigned char default_is_stmt;
320 unsigned char line_range;
321 unsigned char opcode_base;
323 /* standard_opcode_lengths[i] is the number of operands for the
324 standard opcode whose value is i. This means that
325 standard_opcode_lengths[0] is unused, and the last meaningful
326 element is standard_opcode_lengths[opcode_base - 1]. */
327 unsigned char *standard_opcode_lengths;
329 /* The include_directories table. NOTE! These strings are not
330 allocated with xmalloc; instead, they are pointers into
331 debug_line_buffer. If you try to free them, `free' will get
333 unsigned int num_include_dirs, include_dirs_size;
336 /* The file_names table. NOTE! These strings are not allocated
337 with xmalloc; instead, they are pointers into debug_line_buffer.
338 Don't try to free them directly. */
339 unsigned int num_file_names, file_names_size;
343 unsigned int dir_index;
344 unsigned int mod_time;
346 int included_p; /* Non-zero if referenced by the Line Number Program. */
349 /* The start and end of the statement program following this
350 header. These point into dwarf2_per_objfile->line_buffer. */
351 char *statement_program_start, *statement_program_end;
354 /* When we construct a partial symbol table entry we only
355 need this much information. */
356 struct partial_die_info
358 /* Offset of this DIE. */
361 /* DWARF-2 tag for this DIE. */
362 ENUM_BITFIELD(dwarf_tag) tag : 16;
364 /* Language code associated with this DIE. This is only used
365 for the compilation unit DIE. */
366 unsigned int language : 8;
368 /* Assorted flags describing the data found in this DIE. */
369 unsigned int has_children : 1;
370 unsigned int is_external : 1;
371 unsigned int is_declaration : 1;
372 unsigned int has_type : 1;
373 unsigned int has_specification : 1;
374 unsigned int has_stmt_list : 1;
375 unsigned int has_pc_info : 1;
377 /* Flag set if the SCOPE field of this structure has been
379 unsigned int scope_set : 1;
381 /* The name of this DIE. Normally the value of DW_AT_name, but
382 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
387 /* The scope to prepend to our children. This is generally
388 allocated on the comp_unit_obstack, so will disappear
389 when this compilation unit leaves the cache. */
392 /* The location description associated with this DIE, if any. */
393 struct dwarf_block *locdesc;
395 /* If HAS_PC_INFO, the PC range associated with this DIE. */
399 /* Pointer into the info_buffer pointing at the target of
400 DW_AT_sibling, if any. */
403 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
404 DW_AT_specification (or DW_AT_abstract_origin or
406 unsigned int spec_offset;
408 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
409 unsigned int line_offset;
411 /* Pointers to this DIE's parent, first child, and next sibling,
413 struct partial_die_info *die_parent, *die_child, *die_sibling;
416 /* This data structure holds the information of an abbrev. */
419 unsigned int number; /* number identifying abbrev */
420 enum dwarf_tag tag; /* dwarf tag */
421 unsigned short has_children; /* boolean */
422 unsigned short num_attrs; /* number of attributes */
423 struct attr_abbrev *attrs; /* an array of attribute descriptions */
424 struct abbrev_info *next; /* next in chain */
429 enum dwarf_attribute name;
430 enum dwarf_form form;
433 /* This data structure holds a complete die structure. */
436 enum dwarf_tag tag; /* Tag indicating type of die */
437 unsigned int abbrev; /* Abbrev number */
438 unsigned int offset; /* Offset in .debug_info section */
439 unsigned int num_attrs; /* Number of attributes */
440 struct attribute *attrs; /* An array of attributes */
441 struct die_info *next_ref; /* Next die in ref hash table */
443 /* The dies in a compilation unit form an n-ary tree. PARENT
444 points to this die's parent; CHILD points to the first child of
445 this node; and all the children of a given node are chained
446 together via their SIBLING fields, terminated by a die whose
448 struct die_info *child; /* Its first child, if any. */
449 struct die_info *sibling; /* Its next sibling, if any. */
450 struct die_info *parent; /* Its parent, if any. */
452 struct type *type; /* Cached type information */
455 /* Attributes have a name and a value */
458 enum dwarf_attribute name;
459 enum dwarf_form form;
463 struct dwarf_block *blk;
471 struct function_range
474 CORE_ADDR lowpc, highpc;
476 struct function_range *next;
479 /* Get at parts of an attribute structure */
481 #define DW_STRING(attr) ((attr)->u.str)
482 #define DW_UNSND(attr) ((attr)->u.unsnd)
483 #define DW_BLOCK(attr) ((attr)->u.blk)
484 #define DW_SND(attr) ((attr)->u.snd)
485 #define DW_ADDR(attr) ((attr)->u.addr)
487 /* Blocks are a bunch of untyped bytes. */
494 #ifndef ATTR_ALLOC_CHUNK
495 #define ATTR_ALLOC_CHUNK 4
498 /* A hash table of die offsets for following references. */
499 #ifndef REF_HASH_SIZE
500 #define REF_HASH_SIZE 1021
503 static struct die_info *die_ref_table[REF_HASH_SIZE];
505 /* Allocate fields for structs, unions and enums in this size. */
506 #ifndef DW_FIELD_ALLOC_CHUNK
507 #define DW_FIELD_ALLOC_CHUNK 4
510 /* A zeroed version of a partial die for initialization purposes. */
511 static struct partial_die_info zeroed_partial_die;
513 /* FIXME: decode_locdesc sets these variables to describe the location
514 to the caller. These ought to be a structure or something. If
515 none of the flags are set, the object lives at the address returned
516 by decode_locdesc. */
518 static int isreg; /* Object lives in register.
519 decode_locdesc's return value is
520 the register number. */
522 /* We put a pointer to this structure in the read_symtab_private field
527 /* Offset in .debug_info for this compilation unit. */
529 unsigned long dwarf_info_offset;
532 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
533 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
535 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
536 but this would require a corresponding change in unpack_field_as_long
538 static int bits_per_byte = 8;
540 /* The routines that read and process dies for a C struct or C++ class
541 pass lists of data member fields and lists of member function fields
542 in an instance of a field_info structure, as defined below. */
545 /* List of data member and baseclasses fields. */
548 struct nextfield *next;
555 /* Number of fields. */
558 /* Number of baseclasses. */
561 /* Set if the accesibility of one of the fields is not public. */
562 int non_public_fields;
564 /* Member function fields array, entries are allocated in the order they
565 are encountered in the object file. */
568 struct nextfnfield *next;
569 struct fn_field fnfield;
573 /* Member function fieldlist array, contains name of possibly overloaded
574 member function, number of overloaded member functions and a pointer
575 to the head of the member function field chain. */
580 struct nextfnfield *head;
584 /* Number of entries in the fnfieldlists array. */
588 /* Various complaints about symbol reading that don't abort the process */
591 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
593 complaint (&symfile_complaints,
594 "statement list doesn't fit in .debug_line section");
598 dwarf2_complex_location_expr_complaint (void)
600 complaint (&symfile_complaints, "location expression too complex");
604 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
607 complaint (&symfile_complaints,
608 "const value length mismatch for '%s', got %d, expected %d", arg1,
613 dwarf2_macros_too_long_complaint (void)
615 complaint (&symfile_complaints,
616 "macro info runs off end of `.debug_macinfo' section");
620 dwarf2_macro_malformed_definition_complaint (const char *arg1)
622 complaint (&symfile_complaints,
623 "macro debug info contains a malformed macro definition:\n`%s'",
628 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
630 complaint (&symfile_complaints,
631 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
634 /* local function prototypes */
636 static void dwarf2_locate_sections (bfd *, asection *, void *);
639 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
642 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
645 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
646 struct partial_die_info *,
647 struct partial_symtab *);
649 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
651 static void scan_partial_symbols (struct partial_die_info *,
652 CORE_ADDR *, CORE_ADDR *,
655 static void add_partial_symbol (struct partial_die_info *,
658 static int pdi_needs_namespace (enum dwarf_tag tag);
660 static void add_partial_namespace (struct partial_die_info *pdi,
661 CORE_ADDR *lowpc, CORE_ADDR *highpc,
662 struct dwarf2_cu *cu);
664 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
665 struct dwarf2_cu *cu);
667 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
670 struct dwarf2_cu *cu);
672 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
674 static void psymtab_to_symtab_1 (struct partial_symtab *);
676 char *dwarf2_read_section (struct objfile *, asection *);
678 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
680 static void dwarf2_free_abbrev_table (void *);
682 static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *);
684 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
687 static struct partial_die_info *load_partial_dies (bfd *, char *, int,
690 static char *read_partial_die (struct partial_die_info *,
691 struct abbrev_info *abbrev, unsigned int,
692 bfd *, char *, struct dwarf2_cu *);
694 static struct partial_die_info *find_partial_die (unsigned long,
696 struct dwarf2_cu **);
698 static void fixup_partial_die (struct partial_die_info *,
701 static char *read_full_die (struct die_info **, bfd *, char *,
702 struct dwarf2_cu *, int *);
704 static char *read_attribute (struct attribute *, struct attr_abbrev *,
705 bfd *, char *, struct dwarf2_cu *);
707 static char *read_attribute_value (struct attribute *, unsigned,
708 bfd *, char *, struct dwarf2_cu *);
710 static unsigned int read_1_byte (bfd *, char *);
712 static int read_1_signed_byte (bfd *, char *);
714 static unsigned int read_2_bytes (bfd *, char *);
716 static unsigned int read_4_bytes (bfd *, char *);
718 static unsigned long read_8_bytes (bfd *, char *);
720 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
723 static LONGEST read_initial_length (bfd *, char *,
724 struct comp_unit_head *, int *bytes_read);
726 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
729 static char *read_n_bytes (bfd *, char *, unsigned int);
731 static char *read_string (bfd *, char *, unsigned int *);
733 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
736 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
738 static long read_signed_leb128 (bfd *, char *, unsigned int *);
740 static char *skip_leb128 (bfd *, char *);
742 static void set_cu_language (unsigned int, struct dwarf2_cu *);
744 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
747 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
748 struct dwarf2_cu *cu);
750 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
752 static struct die_info *die_specification (struct die_info *die,
755 static void free_line_header (struct line_header *lh);
757 static void add_file_name (struct line_header *, char *, unsigned int,
758 unsigned int, unsigned int);
760 static struct line_header *(dwarf_decode_line_header
761 (unsigned int offset,
762 bfd *abfd, struct dwarf2_cu *cu));
764 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
765 struct dwarf2_cu *, struct partial_symtab *);
767 static void dwarf2_start_subfile (char *, char *);
769 static struct symbol *new_symbol (struct die_info *, struct type *,
772 static void dwarf2_const_value (struct attribute *, struct symbol *,
775 static void dwarf2_const_value_data (struct attribute *attr,
779 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
781 static struct type *die_containing_type (struct die_info *,
785 static struct type *type_at_offset (unsigned int, struct objfile *);
788 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
790 static void read_type_die (struct die_info *, struct dwarf2_cu *);
792 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
794 static char *typename_concat (struct obstack *, const char *prefix, const char *suffix,
797 static void read_typedef (struct die_info *, struct dwarf2_cu *);
799 static void read_base_type (struct die_info *, struct dwarf2_cu *);
801 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
803 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
805 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
807 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
809 static int dwarf2_get_pc_bounds (struct die_info *,
810 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
812 static void get_scope_pc_bounds (struct die_info *,
813 CORE_ADDR *, CORE_ADDR *,
816 static void dwarf2_add_field (struct field_info *, struct die_info *,
819 static void dwarf2_attach_fields_to_type (struct field_info *,
820 struct type *, struct dwarf2_cu *);
822 static void dwarf2_add_member_fn (struct field_info *,
823 struct die_info *, struct type *,
826 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
827 struct type *, struct dwarf2_cu *);
829 static void read_structure_type (struct die_info *, struct dwarf2_cu *);
831 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
833 static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu);
835 static void read_common_block (struct die_info *, struct dwarf2_cu *);
837 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
839 static const char *namespace_name (struct die_info *die,
840 int *is_anonymous, struct dwarf2_cu *);
842 static void read_enumeration_type (struct die_info *, struct dwarf2_cu *);
844 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
846 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
848 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
850 static void read_array_type (struct die_info *, struct dwarf2_cu *);
852 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
855 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
857 static void read_tag_ptr_to_member_type (struct die_info *,
860 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
862 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
864 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
866 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
868 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
870 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
872 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
875 struct die_info *parent);
877 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
880 struct die_info *parent);
882 static void free_die_list (struct die_info *);
884 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
886 static void process_die (struct die_info *, struct dwarf2_cu *);
888 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
890 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
892 static struct die_info *dwarf2_extension (struct die_info *die,
895 static char *dwarf_tag_name (unsigned int);
897 static char *dwarf_attr_name (unsigned int);
899 static char *dwarf_form_name (unsigned int);
901 static char *dwarf_stack_op_name (unsigned int);
903 static char *dwarf_bool_name (unsigned int);
905 static char *dwarf_type_encoding_name (unsigned int);
908 static char *dwarf_cfi_name (unsigned int);
910 struct die_info *copy_die (struct die_info *);
913 static struct die_info *sibling_die (struct die_info *);
915 static void dump_die (struct die_info *);
917 static void dump_die_list (struct die_info *);
919 static void store_in_ref_table (unsigned int, struct die_info *);
921 static void dwarf2_empty_hash_tables (void);
923 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
926 static int dwarf2_get_attr_constant_value (struct attribute *, int);
928 static struct die_info *follow_die_ref (unsigned int);
930 static struct type *dwarf2_fundamental_type (struct objfile *, int,
933 /* memory allocation interface */
935 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
937 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
939 static struct die_info *dwarf_alloc_die (void);
941 static void initialize_cu_func_list (struct dwarf2_cu *);
943 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
946 static void dwarf_decode_macros (struct line_header *, unsigned int,
947 char *, bfd *, struct dwarf2_cu *);
949 static int attr_form_is_block (struct attribute *);
952 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
953 struct dwarf2_cu *cu);
955 static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
956 struct dwarf2_cu *cu);
958 static void free_stack_comp_unit (void *);
960 static void *hashtab_obstack_allocate (void *data, size_t size, size_t count);
962 static void dummy_obstack_deallocate (void *object, void *data);
964 static hashval_t partial_die_hash (const void *item);
966 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
968 /* Try to locate the sections we need for DWARF 2 debugging
969 information and return true if we have enough to do something. */
972 dwarf2_has_info (struct objfile *objfile)
974 struct dwarf2_per_objfile *data;
976 /* Initialize per-objfile state. */
977 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
978 memset (data, 0, sizeof (*data));
979 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
980 dwarf2_per_objfile = data;
982 dwarf_info_section = 0;
983 dwarf_abbrev_section = 0;
984 dwarf_line_section = 0;
985 dwarf_str_section = 0;
986 dwarf_macinfo_section = 0;
987 dwarf_frame_section = 0;
988 dwarf_eh_frame_section = 0;
989 dwarf_ranges_section = 0;
990 dwarf_loc_section = 0;
992 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
993 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
996 /* This function is mapped across the sections and remembers the
997 offset and size of each of the debugging sections we are interested
1001 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
1003 if (strcmp (sectp->name, INFO_SECTION) == 0)
1005 dwarf2_per_objfile->info_size = bfd_get_section_size (sectp);
1006 dwarf_info_section = sectp;
1008 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
1010 dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp);
1011 dwarf_abbrev_section = sectp;
1013 else if (strcmp (sectp->name, LINE_SECTION) == 0)
1015 dwarf2_per_objfile->line_size = bfd_get_section_size (sectp);
1016 dwarf_line_section = sectp;
1018 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
1020 dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp);
1021 dwarf_pubnames_section = sectp;
1023 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
1025 dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp);
1026 dwarf_aranges_section = sectp;
1028 else if (strcmp (sectp->name, LOC_SECTION) == 0)
1030 dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp);
1031 dwarf_loc_section = sectp;
1033 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
1035 dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp);
1036 dwarf_macinfo_section = sectp;
1038 else if (strcmp (sectp->name, STR_SECTION) == 0)
1040 dwarf2_per_objfile->str_size = bfd_get_section_size (sectp);
1041 dwarf_str_section = sectp;
1043 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
1045 dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp);
1046 dwarf_frame_section = sectp;
1048 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1050 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1051 if (aflag & SEC_HAS_CONTENTS)
1053 dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp);
1054 dwarf_eh_frame_section = sectp;
1057 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1059 dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp);
1060 dwarf_ranges_section = sectp;
1064 /* Build a partial symbol table. */
1067 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1069 /* We definitely need the .debug_info and .debug_abbrev sections */
1071 dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1072 dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1074 if (dwarf_line_section)
1075 dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1077 dwarf2_per_objfile->line_buffer = NULL;
1079 if (dwarf_str_section)
1080 dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1082 dwarf2_per_objfile->str_buffer = NULL;
1084 if (dwarf_macinfo_section)
1085 dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile,
1086 dwarf_macinfo_section);
1088 dwarf2_per_objfile->macinfo_buffer = NULL;
1090 if (dwarf_ranges_section)
1091 dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1093 dwarf2_per_objfile->ranges_buffer = NULL;
1095 if (dwarf_loc_section)
1096 dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1098 dwarf2_per_objfile->loc_buffer = NULL;
1101 || (objfile->global_psymbols.size == 0
1102 && objfile->static_psymbols.size == 0))
1104 init_psymbol_list (objfile, 1024);
1108 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1110 /* Things are significantly easier if we have .debug_aranges and
1111 .debug_pubnames sections */
1113 dwarf2_build_psymtabs_easy (objfile, mainline);
1117 /* only test this case for now */
1119 /* In this case we have to work a bit harder */
1120 dwarf2_build_psymtabs_hard (objfile, mainline);
1125 /* Build the partial symbol table from the information in the
1126 .debug_pubnames and .debug_aranges sections. */
1129 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1131 bfd *abfd = objfile->obfd;
1132 char *aranges_buffer, *pubnames_buffer;
1133 char *aranges_ptr, *pubnames_ptr;
1134 unsigned int entry_length, version, info_offset, info_size;
1136 pubnames_buffer = dwarf2_read_section (objfile,
1137 dwarf_pubnames_section);
1138 pubnames_ptr = pubnames_buffer;
1139 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size)
1141 struct comp_unit_head cu_header;
1144 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1146 pubnames_ptr += bytes_read;
1147 version = read_1_byte (abfd, pubnames_ptr);
1149 info_offset = read_4_bytes (abfd, pubnames_ptr);
1151 info_size = read_4_bytes (abfd, pubnames_ptr);
1155 aranges_buffer = dwarf2_read_section (objfile,
1156 dwarf_aranges_section);
1161 /* Read in the comp unit header information from the debug_info at
1165 read_comp_unit_head (struct comp_unit_head *cu_header,
1166 char *info_ptr, bfd *abfd)
1170 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1172 info_ptr += bytes_read;
1173 cu_header->version = read_2_bytes (abfd, info_ptr);
1175 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1177 info_ptr += bytes_read;
1178 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1180 signed_addr = bfd_get_sign_extend_vma (abfd);
1181 if (signed_addr < 0)
1182 internal_error (__FILE__, __LINE__,
1183 "read_comp_unit_head: dwarf from non elf file");
1184 cu_header->signed_addr_p = signed_addr;
1189 partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr,
1192 char *beg_of_comp_unit = info_ptr;
1194 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1196 if (header->version != 2)
1197 error ("Dwarf Error: wrong version in compilation unit header "
1198 "(is %d, should be %d) [in module %s]", header->version,
1199 2, bfd_get_filename (abfd));
1201 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size)
1202 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1203 "(offset 0x%lx + 6) [in module %s]",
1204 (long) header->abbrev_offset,
1205 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1206 bfd_get_filename (abfd));
1208 if (beg_of_comp_unit + header->length + header->initial_length_size
1209 > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1210 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1211 "(offset 0x%lx + 0) [in module %s]",
1212 (long) header->length,
1213 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1214 bfd_get_filename (abfd));
1219 /* Allocate a new partial symtab for file named NAME and mark this new
1220 partial symtab as being an include of PST. */
1223 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1224 struct objfile *objfile)
1226 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1228 subpst->section_offsets = pst->section_offsets;
1229 subpst->textlow = 0;
1230 subpst->texthigh = 0;
1232 subpst->dependencies = (struct partial_symtab **)
1233 obstack_alloc (&objfile->objfile_obstack,
1234 sizeof (struct partial_symtab *));
1235 subpst->dependencies[0] = pst;
1236 subpst->number_of_dependencies = 1;
1238 subpst->globals_offset = 0;
1239 subpst->n_global_syms = 0;
1240 subpst->statics_offset = 0;
1241 subpst->n_static_syms = 0;
1242 subpst->symtab = NULL;
1243 subpst->read_symtab = pst->read_symtab;
1246 /* No private part is necessary for include psymtabs. This property
1247 can be used to differentiate between such include psymtabs and
1248 the regular ones. If it ever happens that a regular psymtab can
1249 legitimally have a NULL private part, then we'll have to add a
1250 dedicated field for that in the dwarf2_pinfo structure. */
1251 subpst->read_symtab_private = NULL;
1254 /* Read the Line Number Program data and extract the list of files
1255 included by the source file represented by PST. Build an include
1256 partial symtab for each of these included files.
1258 This procedure assumes that there *is* a Line Number Program in
1259 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1260 before calling this procedure. */
1263 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1264 struct partial_die_info *pdi,
1265 struct partial_symtab *pst)
1267 struct objfile *objfile = cu->objfile;
1268 bfd *abfd = objfile->obfd;
1269 struct line_header *lh;
1271 lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
1273 return; /* No linetable, so no includes. */
1275 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1277 free_line_header (lh);
1281 /* Build the partial symbol table by doing a quick pass through the
1282 .debug_info and .debug_abbrev sections. */
1285 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1287 /* Instead of reading this into a big buffer, we should probably use
1288 mmap() on architectures that support it. (FIXME) */
1289 bfd *abfd = objfile->obfd;
1291 char *beg_of_comp_unit;
1292 struct partial_die_info comp_unit_die;
1293 struct partial_symtab *pst;
1294 CORE_ADDR lowpc, highpc, baseaddr;
1296 info_ptr = dwarf2_per_objfile->info_buffer;
1298 /* Since the objects we're extracting from .debug_info vary in
1299 length, only the individual functions to extract them (like
1300 read_comp_unit_head and load_partial_die) can really know whether
1301 the buffer is large enough to hold another complete object.
1303 At the moment, they don't actually check that. If .debug_info
1304 holds just one extra byte after the last compilation unit's dies,
1305 then read_comp_unit_head will happily read off the end of the
1306 buffer. read_partial_die is similarly casual. Those functions
1309 For this loop condition, simply checking whether there's any data
1310 left at all should be sufficient. */
1311 while (info_ptr < (dwarf2_per_objfile->info_buffer
1312 + dwarf2_per_objfile->info_size))
1314 struct cleanup *back_to_inner;
1315 struct dwarf2_cu cu;
1316 struct abbrev_info *abbrev;
1317 unsigned int bytes_read;
1318 struct dwarf2_per_cu_data *this_cu;
1320 beg_of_comp_unit = info_ptr;
1322 memset (&cu, 0, sizeof (cu));
1324 obstack_init (&cu.comp_unit_obstack);
1326 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1328 cu.objfile = objfile;
1329 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1331 /* Complete the cu_header */
1332 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1333 cu.header.first_die_ptr = info_ptr;
1334 cu.header.cu_head_ptr = beg_of_comp_unit;
1336 cu.list_in_scope = &file_symbols;
1338 cu.partial_dies = NULL;
1340 /* Read the abbrevs for this compilation unit into a table */
1341 dwarf2_read_abbrevs (abfd, &cu);
1342 make_cleanup (dwarf2_free_abbrev_table, &cu);
1344 /* Read the compilation unit die */
1345 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1346 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1347 abfd, info_ptr, &cu);
1349 /* Set the language we're debugging */
1350 set_cu_language (comp_unit_die.language, &cu);
1352 /* Allocate a new partial symbol table structure */
1353 pst = start_psymtab_common (objfile, objfile->section_offsets,
1354 comp_unit_die.name ? comp_unit_die.name : "",
1355 comp_unit_die.lowpc,
1356 objfile->global_psymbols.next,
1357 objfile->static_psymbols.next);
1359 if (comp_unit_die.dirname)
1360 pst->dirname = xstrdup (comp_unit_die.dirname);
1362 pst->read_symtab_private = (char *)
1363 obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
1364 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1365 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1367 /* Store the function that reads in the rest of the symbol table */
1368 pst->read_symtab = dwarf2_psymtab_to_symtab;
1370 /* Check if comp unit has_children.
1371 If so, read the rest of the partial symbols from this comp unit.
1372 If not, there's no more debug_info for this comp unit. */
1373 if (comp_unit_die.has_children)
1375 struct partial_die_info *first_die;
1377 lowpc = ((CORE_ADDR) -1);
1378 highpc = ((CORE_ADDR) 0);
1380 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1382 scan_partial_symbols (first_die, &lowpc, &highpc, &cu);
1384 /* If we didn't find a lowpc, set it to highpc to avoid
1385 complaints from `maint check'. */
1386 if (lowpc == ((CORE_ADDR) -1))
1389 /* If the compilation unit didn't have an explicit address range,
1390 then use the information extracted from its child dies. */
1391 if (! comp_unit_die.has_pc_info)
1393 comp_unit_die.lowpc = lowpc;
1394 comp_unit_die.highpc = highpc;
1397 pst->textlow = comp_unit_die.lowpc + baseaddr;
1398 pst->texthigh = comp_unit_die.highpc + baseaddr;
1400 pst->n_global_syms = objfile->global_psymbols.next -
1401 (objfile->global_psymbols.list + pst->globals_offset);
1402 pst->n_static_syms = objfile->static_psymbols.next -
1403 (objfile->static_psymbols.list + pst->statics_offset);
1404 sort_pst_symbols (pst);
1406 /* If there is already a psymtab or symtab for a file of this
1407 name, remove it. (If there is a symtab, more drastic things
1408 also happen.) This happens in VxWorks. */
1409 free_named_symtabs (pst->filename);
1411 if (comp_unit_die.has_stmt_list)
1413 /* Get the list of files included in the current compilation unit,
1414 and build a psymtab for each of them. */
1415 dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst);
1418 info_ptr = beg_of_comp_unit + cu.header.length
1419 + cu.header.initial_length_size;
1421 do_cleanups (back_to_inner);
1425 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1426 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1430 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1431 CORE_ADDR *highpc, struct dwarf2_cu *cu)
1433 struct objfile *objfile = cu->objfile;
1434 bfd *abfd = objfile->obfd;
1435 struct partial_die_info *pdi;
1437 /* Now, march along the PDI's, descending into ones which have
1438 interesting children but skipping the children of the other ones,
1439 until we reach the end of the compilation unit. */
1445 fixup_partial_die (pdi, cu);
1447 /* Anonymous namespaces have no name but have interesting
1448 children, so we need to look at them. Ditto for anonymous
1451 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1452 || pdi->tag == DW_TAG_enumeration_type)
1456 case DW_TAG_subprogram:
1457 if (pdi->has_pc_info)
1459 if (pdi->lowpc < *lowpc)
1461 *lowpc = pdi->lowpc;
1463 if (pdi->highpc > *highpc)
1465 *highpc = pdi->highpc;
1467 if (!pdi->is_declaration)
1469 add_partial_symbol (pdi, cu);
1473 case DW_TAG_variable:
1474 case DW_TAG_typedef:
1475 case DW_TAG_union_type:
1476 if (!pdi->is_declaration)
1478 add_partial_symbol (pdi, cu);
1481 case DW_TAG_class_type:
1482 case DW_TAG_structure_type:
1483 if (!pdi->is_declaration)
1485 add_partial_symbol (pdi, cu);
1488 case DW_TAG_enumeration_type:
1489 if (!pdi->is_declaration)
1490 add_partial_enumeration (pdi, cu);
1492 case DW_TAG_base_type:
1493 case DW_TAG_subrange_type:
1494 /* File scope base type definitions are added to the partial
1496 add_partial_symbol (pdi, cu);
1498 case DW_TAG_namespace:
1499 add_partial_namespace (pdi, lowpc, highpc, cu);
1506 /* If the die has a sibling, skip to the sibling. */
1508 pdi = pdi->die_sibling;
1512 /* Functions used to compute the fully scoped name of a partial DIE.
1514 Normally, this is simple. For C++, the parent DIE's fully scoped
1515 name is concatenated with "::" and the partial DIE's name. For
1516 Java, the same thing occurs except that "." is used instead of "::".
1517 Enumerators are an exception; they use the scope of their parent
1518 enumeration type, i.e. the name of the enumeration type is not
1519 prepended to the enumerator.
1521 There are two complexities. One is DW_AT_specification; in this
1522 case "parent" means the parent of the target of the specification,
1523 instead of the direct parent of the DIE. The other is compilers
1524 which do not emit DW_TAG_namespace; in this case we try to guess
1525 the fully qualified name of structure types from their members'
1526 linkage names. This must be done using the DIE's children rather
1527 than the children of any DW_AT_specification target. We only need
1528 to do this for structures at the top level, i.e. if the target of
1529 any DW_AT_specification (if any; otherwise the DIE itself) does not
1532 /* Compute the scope prefix associated with PDI's parent, in
1533 compilation unit CU. The result will be allocated on CU's
1534 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1535 field. NULL is returned if no prefix is necessary. */
1537 partial_die_parent_scope (struct partial_die_info *pdi,
1538 struct dwarf2_cu *cu)
1540 char *grandparent_scope;
1541 struct partial_die_info *parent, *real_pdi;
1542 struct dwarf2_cu *spec_cu;
1544 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1545 then this means the parent of the specification DIE. */
1549 while (real_pdi->has_specification)
1550 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1552 parent = real_pdi->die_parent;
1556 if (parent->scope_set)
1557 return parent->scope;
1559 fixup_partial_die (parent, cu);
1561 grandparent_scope = partial_die_parent_scope (parent, spec_cu);
1563 if (parent->tag == DW_TAG_namespace
1564 || parent->tag == DW_TAG_structure_type
1565 || parent->tag == DW_TAG_class_type
1566 || parent->tag == DW_TAG_union_type)
1568 if (grandparent_scope == NULL)
1569 parent->scope = parent->name;
1571 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
1574 else if (parent->tag == DW_TAG_enumeration_type)
1575 /* Enumerators should not get the name of the enumeration as a prefix. */
1576 parent->scope = grandparent_scope;
1579 /* FIXME drow/2004-04-01: What should we be doing with
1580 function-local names? For partial symbols, we should probably be
1582 complaint (&symfile_complaints,
1583 "unhandled containing DIE tag %d for DIE at %d",
1584 parent->tag, pdi->offset);
1585 parent->scope = grandparent_scope;
1588 parent->scope_set = 1;
1589 return parent->scope;
1592 /* Return the fully scoped name associated with PDI, from compilation unit
1593 CU. The result will be allocated with malloc. */
1595 partial_die_full_name (struct partial_die_info *pdi,
1596 struct dwarf2_cu *cu)
1600 parent_scope = partial_die_parent_scope (pdi, cu);
1601 if (parent_scope == NULL)
1604 return typename_concat (NULL, parent_scope, pdi->name, cu);
1608 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
1610 struct objfile *objfile = cu->objfile;
1613 const char *my_prefix;
1614 const struct partial_symbol *psym = NULL;
1616 int built_actual_name = 0;
1618 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1622 if (pdi_needs_namespace (pdi->tag))
1624 actual_name = partial_die_full_name (pdi, cu);
1626 built_actual_name = 1;
1629 if (actual_name == NULL)
1630 actual_name = pdi->name;
1634 case DW_TAG_subprogram:
1635 if (pdi->is_external)
1637 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1638 mst_text, objfile); */
1639 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1640 VAR_DOMAIN, LOC_BLOCK,
1641 &objfile->global_psymbols,
1642 0, pdi->lowpc + baseaddr,
1643 cu->language, objfile);
1647 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1648 mst_file_text, objfile); */
1649 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1650 VAR_DOMAIN, LOC_BLOCK,
1651 &objfile->static_psymbols,
1652 0, pdi->lowpc + baseaddr,
1653 cu->language, objfile);
1656 case DW_TAG_variable:
1657 if (pdi->is_external)
1660 Don't enter into the minimal symbol tables as there is
1661 a minimal symbol table entry from the ELF symbols already.
1662 Enter into partial symbol table if it has a location
1663 descriptor or a type.
1664 If the location descriptor is missing, new_symbol will create
1665 a LOC_UNRESOLVED symbol, the address of the variable will then
1666 be determined from the minimal symbol table whenever the variable
1668 The address for the partial symbol table entry is not
1669 used by GDB, but it comes in handy for debugging partial symbol
1673 addr = decode_locdesc (pdi->locdesc, cu);
1674 if (pdi->locdesc || pdi->has_type)
1675 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1676 VAR_DOMAIN, LOC_STATIC,
1677 &objfile->global_psymbols,
1679 cu->language, objfile);
1683 /* Static Variable. Skip symbols without location descriptors. */
1684 if (pdi->locdesc == NULL)
1686 addr = decode_locdesc (pdi->locdesc, cu);
1687 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1688 mst_file_data, objfile); */
1689 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1690 VAR_DOMAIN, LOC_STATIC,
1691 &objfile->static_psymbols,
1693 cu->language, objfile);
1696 case DW_TAG_typedef:
1697 case DW_TAG_base_type:
1698 case DW_TAG_subrange_type:
1699 add_psymbol_to_list (actual_name, strlen (actual_name),
1700 VAR_DOMAIN, LOC_TYPEDEF,
1701 &objfile->static_psymbols,
1702 0, (CORE_ADDR) 0, cu->language, objfile);
1704 case DW_TAG_namespace:
1705 add_psymbol_to_list (actual_name, strlen (actual_name),
1706 VAR_DOMAIN, LOC_TYPEDEF,
1707 &objfile->global_psymbols,
1708 0, (CORE_ADDR) 0, cu->language, objfile);
1710 case DW_TAG_class_type:
1711 case DW_TAG_structure_type:
1712 case DW_TAG_union_type:
1713 case DW_TAG_enumeration_type:
1714 /* Skip aggregate types without children, these are external
1716 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1717 static vs. global. */
1718 if (pdi->has_children == 0)
1720 add_psymbol_to_list (actual_name, strlen (actual_name),
1721 STRUCT_DOMAIN, LOC_TYPEDEF,
1722 (cu->language == language_cplus
1723 || cu->language == language_java)
1724 ? &objfile->global_psymbols
1725 : &objfile->static_psymbols,
1726 0, (CORE_ADDR) 0, cu->language, objfile);
1728 if (cu->language == language_cplus
1729 || cu->language == language_java)
1731 /* For C++ and Java, these implicitly act as typedefs as well. */
1732 add_psymbol_to_list (actual_name, strlen (actual_name),
1733 VAR_DOMAIN, LOC_TYPEDEF,
1734 &objfile->global_psymbols,
1735 0, (CORE_ADDR) 0, cu->language, objfile);
1738 case DW_TAG_enumerator:
1739 add_psymbol_to_list (actual_name, strlen (actual_name),
1740 VAR_DOMAIN, LOC_CONST,
1741 (cu->language == language_cplus
1742 || cu->language == language_java)
1743 ? &objfile->global_psymbols
1744 : &objfile->static_psymbols,
1745 0, (CORE_ADDR) 0, cu->language, objfile);
1751 /* Check to see if we should scan the name for possible namespace
1752 info. Only do this if this is C++, if we don't have namespace
1753 debugging info in the file, if the psym is of an appropriate type
1754 (otherwise we'll have psym == NULL), and if we actually had a
1755 mangled name to begin with. */
1757 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1758 cases which do not set PSYM above? */
1760 if (cu->language == language_cplus
1761 && cu->has_namespace_info == 0
1763 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1764 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1767 if (built_actual_name)
1768 xfree (actual_name);
1771 /* Determine whether a die of type TAG living in a C++ class or
1772 namespace needs to have the name of the scope prepended to the
1773 name listed in the die. */
1776 pdi_needs_namespace (enum dwarf_tag tag)
1780 case DW_TAG_namespace:
1781 case DW_TAG_typedef:
1782 case DW_TAG_class_type:
1783 case DW_TAG_structure_type:
1784 case DW_TAG_union_type:
1785 case DW_TAG_enumeration_type:
1786 case DW_TAG_enumerator:
1793 /* Read a partial die corresponding to a namespace; also, add a symbol
1794 corresponding to that namespace to the symbol table. NAMESPACE is
1795 the name of the enclosing namespace. */
1798 add_partial_namespace (struct partial_die_info *pdi,
1799 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1800 struct dwarf2_cu *cu)
1802 struct objfile *objfile = cu->objfile;
1804 /* Add a symbol for the namespace. */
1806 add_partial_symbol (pdi, cu);
1808 /* Now scan partial symbols in that namespace. */
1810 if (pdi->has_children)
1811 scan_partial_symbols (pdi->die_child, lowpc, highpc, cu);
1814 /* See if we can figure out if the class lives in a namespace. We do
1815 this by looking for a member function; its demangled name will
1816 contain namespace info, if there is any. */
1819 guess_structure_name (struct partial_die_info *struct_pdi,
1820 struct dwarf2_cu *cu)
1822 if ((cu->language == language_cplus
1823 || cu->language == language_java)
1824 && cu->has_namespace_info == 0
1825 && struct_pdi->has_children)
1827 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1828 what template types look like, because the demangler
1829 frequently doesn't give the same name as the debug info. We
1830 could fix this by only using the demangled name to get the
1831 prefix (but see comment in read_structure_type). */
1833 struct partial_die_info *child_pdi = struct_pdi->die_child;
1834 struct partial_die_info *real_pdi;
1835 struct dwarf2_cu *spec_cu;
1837 /* If this DIE (this DIE's specification, if any) has a parent, then
1838 we should not do this. We'll prepend the parent's fully qualified
1839 name when we create the partial symbol. */
1841 real_pdi = struct_pdi;
1843 while (real_pdi->has_specification)
1844 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1846 if (real_pdi->die_parent != NULL)
1849 while (child_pdi != NULL)
1851 if (child_pdi->tag == DW_TAG_subprogram)
1853 char *actual_class_name
1854 = language_class_name_from_physname (cu->language_defn,
1856 if (actual_class_name != NULL)
1859 = obsavestring (actual_class_name,
1860 strlen (actual_class_name),
1861 &cu->comp_unit_obstack);
1862 xfree (actual_class_name);
1867 child_pdi = child_pdi->die_sibling;
1872 /* Read a partial die corresponding to an enumeration type. */
1875 add_partial_enumeration (struct partial_die_info *enum_pdi,
1876 struct dwarf2_cu *cu)
1878 struct objfile *objfile = cu->objfile;
1879 bfd *abfd = objfile->obfd;
1880 struct partial_die_info *pdi;
1882 if (enum_pdi->name != NULL)
1883 add_partial_symbol (enum_pdi, cu);
1885 pdi = enum_pdi->die_child;
1888 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
1889 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1891 add_partial_symbol (pdi, cu);
1892 pdi = pdi->die_sibling;
1896 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1897 Return the corresponding abbrev, or NULL if the number is zero (indicating
1898 an empty DIE). In either case *BYTES_READ will be set to the length of
1899 the initial number. */
1901 static struct abbrev_info *
1902 peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu)
1904 bfd *abfd = cu->objfile->obfd;
1905 unsigned int abbrev_number;
1906 struct abbrev_info *abbrev;
1908 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
1910 if (abbrev_number == 0)
1913 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
1916 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
1917 bfd_get_filename (abfd));
1923 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1924 pointer to the end of a series of DIEs, terminated by an empty
1925 DIE. Any children of the skipped DIEs will also be skipped. */
1928 skip_children (char *info_ptr, struct dwarf2_cu *cu)
1930 struct abbrev_info *abbrev;
1931 unsigned int bytes_read;
1935 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1937 return info_ptr + bytes_read;
1939 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
1943 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1944 should point just after the initial uleb128 of a DIE, and the
1945 abbrev corresponding to that skipped uleb128 should be passed in
1946 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1950 skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
1951 struct dwarf2_cu *cu)
1953 unsigned int bytes_read;
1954 struct attribute attr;
1955 bfd *abfd = cu->objfile->obfd;
1956 unsigned int form, i;
1958 for (i = 0; i < abbrev->num_attrs; i++)
1960 /* The only abbrev we care about is DW_AT_sibling. */
1961 if (abbrev->attrs[i].name == DW_AT_sibling)
1963 read_attribute (&attr, &abbrev->attrs[i],
1964 abfd, info_ptr, cu);
1965 if (attr.form == DW_FORM_ref_addr)
1966 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
1968 return dwarf2_per_objfile->info_buffer
1969 + dwarf2_get_ref_die_offset (&attr, cu);
1972 /* If it isn't DW_AT_sibling, skip this attribute. */
1973 form = abbrev->attrs[i].form;
1978 case DW_FORM_ref_addr:
1979 info_ptr += cu->header.addr_size;
1998 case DW_FORM_string:
1999 read_string (abfd, info_ptr, &bytes_read);
2000 info_ptr += bytes_read;
2003 info_ptr += cu->header.offset_size;
2006 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2007 info_ptr += bytes_read;
2009 case DW_FORM_block1:
2010 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2012 case DW_FORM_block2:
2013 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2015 case DW_FORM_block4:
2016 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2020 case DW_FORM_ref_udata:
2021 info_ptr = skip_leb128 (abfd, info_ptr);
2023 case DW_FORM_indirect:
2024 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2025 info_ptr += bytes_read;
2026 /* We need to continue parsing from here, so just go back to
2028 goto skip_attribute;
2031 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2032 dwarf_form_name (form),
2033 bfd_get_filename (abfd));
2037 if (abbrev->has_children)
2038 return skip_children (info_ptr, cu);
2043 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2044 the next DIE after ORIG_PDI. */
2047 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
2048 bfd *abfd, struct dwarf2_cu *cu)
2050 /* Do we know the sibling already? */
2052 if (orig_pdi->sibling)
2053 return orig_pdi->sibling;
2055 /* Are there any children to deal with? */
2057 if (!orig_pdi->has_children)
2060 /* Skip the children the long way. */
2062 return skip_children (info_ptr, cu);
2065 /* Expand this partial symbol table into a full symbol table. */
2068 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2070 /* FIXME: This is barely more than a stub. */
2075 warning ("bug: psymtab for %s is already read in.", pst->filename);
2081 printf_filtered ("Reading in symbols for %s...", pst->filename);
2082 gdb_flush (gdb_stdout);
2085 psymtab_to_symtab_1 (pst);
2087 /* Finish up the debug error message. */
2089 printf_filtered ("done.\n");
2095 psymtab_to_symtab_1 (struct partial_symtab *pst)
2097 struct objfile *objfile = pst->objfile;
2098 bfd *abfd = objfile->obfd;
2099 struct dwarf2_cu cu;
2100 struct die_info *dies;
2101 unsigned long offset;
2102 CORE_ADDR lowpc, highpc;
2103 struct die_info *child_die;
2105 struct symtab *symtab;
2106 struct cleanup *back_to;
2107 struct attribute *attr;
2111 for (i = 0; i < pst->number_of_dependencies; i++)
2112 if (!pst->dependencies[i]->readin)
2114 /* Inform about additional files that need to be read in. */
2117 fputs_filtered (" ", gdb_stdout);
2119 fputs_filtered ("and ", gdb_stdout);
2121 printf_filtered ("%s...", pst->dependencies[i]->filename);
2122 wrap_here (""); /* Flush output */
2123 gdb_flush (gdb_stdout);
2125 psymtab_to_symtab_1 (pst->dependencies[i]);
2128 if (pst->read_symtab_private == NULL)
2130 /* It's an include file, no symbols to read for it.
2131 Everything is in the parent symtab. */
2136 dwarf2_per_objfile = objfile_data (pst->objfile, dwarf2_objfile_data_key);
2138 /* Set local variables from the partial symbol table info. */
2139 offset = DWARF_INFO_OFFSET (pst);
2141 info_ptr = dwarf2_per_objfile->info_buffer + offset;
2142 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2144 /* We're in the global namespace. */
2145 processing_current_prefix = "";
2147 obstack_init (&cu.comp_unit_obstack);
2148 back_to = make_cleanup (free_stack_comp_unit, &cu);
2151 make_cleanup (really_free_pendings, NULL);
2153 cu.objfile = objfile;
2155 /* read in the comp_unit header */
2156 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
2158 /* Read the abbrevs for this compilation unit */
2159 dwarf2_read_abbrevs (abfd, &cu);
2160 make_cleanup (dwarf2_free_abbrev_table, &cu);
2162 cu.header.offset = offset;
2164 cu.list_in_scope = &file_symbols;
2166 dies = read_comp_unit (info_ptr, abfd, &cu);
2168 make_cleanup_free_die_list (dies);
2170 /* Find the base address of the compilation unit for range lists and
2171 location lists. It will normally be specified by DW_AT_low_pc.
2172 In DWARF-3 draft 4, the base address could be overridden by
2173 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2174 compilation units with discontinuous ranges. */
2176 cu.header.base_known = 0;
2177 cu.header.base_address = 0;
2179 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
2182 cu.header.base_address = DW_ADDR (attr);
2183 cu.header.base_known = 1;
2187 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
2190 cu.header.base_address = DW_ADDR (attr);
2191 cu.header.base_known = 1;
2195 /* Do line number decoding in read_file_scope () */
2196 process_die (dies, &cu);
2198 /* Some compilers don't define a DW_AT_high_pc attribute for the
2199 compilation unit. If the DW_AT_high_pc is missing, synthesize
2200 it, by scanning the DIE's below the compilation unit. */
2201 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
2203 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2205 /* Set symtab language to language from DW_AT_language.
2206 If the compilation is from a C file generated by language preprocessors,
2207 do not set the language if it was already deduced by start_subfile. */
2209 && !(cu.language == language_c && symtab->language != language_c))
2211 symtab->language = cu.language;
2213 pst->symtab = symtab;
2216 do_cleanups (back_to);
2219 /* Process a die and its children. */
2222 process_die (struct die_info *die, struct dwarf2_cu *cu)
2226 case DW_TAG_padding:
2228 case DW_TAG_compile_unit:
2229 read_file_scope (die, cu);
2231 case DW_TAG_subprogram:
2232 read_subroutine_type (die, cu);
2233 read_func_scope (die, cu);
2235 case DW_TAG_inlined_subroutine:
2236 /* FIXME: These are ignored for now.
2237 They could be used to set breakpoints on all inlined instances
2238 of a function and make GDB `next' properly over inlined functions. */
2240 case DW_TAG_lexical_block:
2241 case DW_TAG_try_block:
2242 case DW_TAG_catch_block:
2243 read_lexical_block_scope (die, cu);
2245 case DW_TAG_class_type:
2246 case DW_TAG_structure_type:
2247 case DW_TAG_union_type:
2248 read_structure_type (die, cu);
2249 process_structure_scope (die, cu);
2251 case DW_TAG_enumeration_type:
2252 read_enumeration_type (die, cu);
2253 process_enumeration_scope (die, cu);
2256 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2257 a symbol or process any children. Therefore it doesn't do anything
2258 that won't be done on-demand by read_type_die. */
2259 case DW_TAG_subroutine_type:
2260 read_subroutine_type (die, cu);
2262 case DW_TAG_array_type:
2263 read_array_type (die, cu);
2265 case DW_TAG_pointer_type:
2266 read_tag_pointer_type (die, cu);
2268 case DW_TAG_ptr_to_member_type:
2269 read_tag_ptr_to_member_type (die, cu);
2271 case DW_TAG_reference_type:
2272 read_tag_reference_type (die, cu);
2274 case DW_TAG_string_type:
2275 read_tag_string_type (die, cu);
2279 case DW_TAG_base_type:
2280 read_base_type (die, cu);
2281 /* Add a typedef symbol for the type definition, if it has a
2283 new_symbol (die, die->type, cu);
2285 case DW_TAG_subrange_type:
2286 read_subrange_type (die, cu);
2287 /* Add a typedef symbol for the type definition, if it has a
2289 new_symbol (die, die->type, cu);
2291 case DW_TAG_common_block:
2292 read_common_block (die, cu);
2294 case DW_TAG_common_inclusion:
2296 case DW_TAG_namespace:
2297 processing_has_namespace_info = 1;
2298 read_namespace (die, cu);
2300 case DW_TAG_imported_declaration:
2301 case DW_TAG_imported_module:
2302 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2303 information contained in these. DW_TAG_imported_declaration
2304 dies shouldn't have children; DW_TAG_imported_module dies
2305 shouldn't in the C++ case, but conceivably could in the
2306 Fortran case, so we'll have to replace this gdb_assert if
2307 Fortran compilers start generating that info. */
2308 processing_has_namespace_info = 1;
2309 gdb_assert (die->child == NULL);
2312 new_symbol (die, NULL, cu);
2318 initialize_cu_func_list (struct dwarf2_cu *cu)
2320 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2324 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2326 struct objfile *objfile = cu->objfile;
2327 struct comp_unit_head *cu_header = &cu->header;
2328 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2329 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2330 CORE_ADDR highpc = ((CORE_ADDR) 0);
2331 struct attribute *attr;
2332 char *name = "<unknown>";
2333 char *comp_dir = NULL;
2334 struct die_info *child_die;
2335 bfd *abfd = objfile->obfd;
2336 struct line_header *line_header = 0;
2339 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2341 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2343 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2344 from finish_block. */
2345 if (lowpc == ((CORE_ADDR) -1))
2350 attr = dwarf2_attr (die, DW_AT_name, cu);
2353 name = DW_STRING (attr);
2355 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2358 comp_dir = DW_STRING (attr);
2361 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2362 directory, get rid of it. */
2363 char *cp = strchr (comp_dir, ':');
2365 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2370 attr = dwarf2_attr (die, DW_AT_language, cu);
2373 set_cu_language (DW_UNSND (attr), cu);
2376 attr = dwarf2_attr (die, DW_AT_producer, cu);
2378 cu->producer = DW_STRING (attr);
2380 /* We assume that we're processing GCC output. */
2381 processing_gcc_compilation = 2;
2383 /* FIXME:Do something here. */
2384 if (dip->at_producer != NULL)
2386 handle_producer (dip->at_producer);
2390 /* The compilation unit may be in a different language or objfile,
2391 zero out all remembered fundamental types. */
2392 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2394 start_symtab (name, comp_dir, lowpc);
2395 record_debugformat ("DWARF 2");
2397 initialize_cu_func_list (cu);
2399 /* Process all dies in compilation unit. */
2400 if (die->child != NULL)
2402 child_die = die->child;
2403 while (child_die && child_die->tag)
2405 process_die (child_die, cu);
2406 child_die = sibling_die (child_die);
2410 /* Decode line number information if present. */
2411 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2414 unsigned int line_offset = DW_UNSND (attr);
2415 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2418 make_cleanup ((make_cleanup_ftype *) free_line_header,
2419 (void *) line_header);
2420 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
2424 /* Decode macro information, if present. Dwarf 2 macro information
2425 refers to information in the line number info statement program
2426 header, so we can only read it if we've read the header
2428 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2429 if (attr && line_header)
2431 unsigned int macro_offset = DW_UNSND (attr);
2432 dwarf_decode_macros (line_header, macro_offset,
2433 comp_dir, abfd, cu);
2435 do_cleanups (back_to);
2439 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2440 struct dwarf2_cu *cu)
2442 struct function_range *thisfn;
2444 thisfn = (struct function_range *)
2445 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
2446 thisfn->name = name;
2447 thisfn->lowpc = lowpc;
2448 thisfn->highpc = highpc;
2449 thisfn->seen_line = 0;
2450 thisfn->next = NULL;
2452 if (cu->last_fn == NULL)
2453 cu->first_fn = thisfn;
2455 cu->last_fn->next = thisfn;
2457 cu->last_fn = thisfn;
2461 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2463 struct objfile *objfile = cu->objfile;
2464 struct context_stack *new;
2467 struct die_info *child_die;
2468 struct attribute *attr;
2470 const char *previous_prefix = processing_current_prefix;
2471 struct cleanup *back_to = NULL;
2474 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2476 name = dwarf2_linkage_name (die, cu);
2478 /* Ignore functions with missing or empty names and functions with
2479 missing or invalid low and high pc attributes. */
2480 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2483 if (cu->language == language_cplus
2484 || cu->language == language_java)
2486 struct die_info *spec_die = die_specification (die, cu);
2488 /* NOTE: carlton/2004-01-23: We have to be careful in the
2489 presence of DW_AT_specification. For example, with GCC 3.4,
2494 // Definition of N::foo.
2498 then we'll have a tree of DIEs like this:
2500 1: DW_TAG_compile_unit
2501 2: DW_TAG_namespace // N
2502 3: DW_TAG_subprogram // declaration of N::foo
2503 4: DW_TAG_subprogram // definition of N::foo
2504 DW_AT_specification // refers to die #3
2506 Thus, when processing die #4, we have to pretend that we're
2507 in the context of its DW_AT_specification, namely the contex
2510 if (spec_die != NULL)
2512 char *specification_prefix = determine_prefix (spec_die, cu);
2513 processing_current_prefix = specification_prefix;
2514 back_to = make_cleanup (xfree, specification_prefix);
2521 /* Record the function range for dwarf_decode_lines. */
2522 add_to_cu_func_list (name, lowpc, highpc, cu);
2524 new = push_context (0, lowpc);
2525 new->name = new_symbol (die, die->type, cu);
2527 /* If there is a location expression for DW_AT_frame_base, record
2529 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2531 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2532 expression is being recorded directly in the function's symbol
2533 and not in a separate frame-base object. I guess this hack is
2534 to avoid adding some sort of frame-base adjunct/annex to the
2535 function's symbol :-(. The problem with doing this is that it
2536 results in a function symbol with a location expression that
2537 has nothing to do with the location of the function, ouch! The
2538 relationship should be: a function's symbol has-a frame base; a
2539 frame-base has-a location expression. */
2540 dwarf2_symbol_mark_computed (attr, new->name, cu);
2542 cu->list_in_scope = &local_symbols;
2544 if (die->child != NULL)
2546 child_die = die->child;
2547 while (child_die && child_die->tag)
2549 process_die (child_die, cu);
2550 child_die = sibling_die (child_die);
2554 new = pop_context ();
2555 /* Make a block for the local symbols within. */
2556 finish_block (new->name, &local_symbols, new->old_blocks,
2557 lowpc, highpc, objfile);
2559 /* In C++, we can have functions nested inside functions (e.g., when
2560 a function declares a class that has methods). This means that
2561 when we finish processing a function scope, we may need to go
2562 back to building a containing block's symbol lists. */
2563 local_symbols = new->locals;
2564 param_symbols = new->params;
2566 /* If we've finished processing a top-level function, subsequent
2567 symbols go in the file symbol list. */
2568 if (outermost_context_p ())
2569 cu->list_in_scope = &file_symbols;
2571 processing_current_prefix = previous_prefix;
2572 if (back_to != NULL)
2573 do_cleanups (back_to);
2576 /* Process all the DIES contained within a lexical block scope. Start
2577 a new scope, process the dies, and then close the scope. */
2580 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2582 struct objfile *objfile = cu->objfile;
2583 struct context_stack *new;
2584 CORE_ADDR lowpc, highpc;
2585 struct die_info *child_die;
2588 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2590 /* Ignore blocks with missing or invalid low and high pc attributes. */
2591 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2592 as multiple lexical blocks? Handling children in a sane way would
2593 be nasty. Might be easier to properly extend generic blocks to
2595 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2600 push_context (0, lowpc);
2601 if (die->child != NULL)
2603 child_die = die->child;
2604 while (child_die && child_die->tag)
2606 process_die (child_die, cu);
2607 child_die = sibling_die (child_die);
2610 new = pop_context ();
2612 if (local_symbols != NULL)
2614 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2617 local_symbols = new->locals;
2620 /* Get low and high pc attributes from a die. Return 1 if the attributes
2621 are present and valid, otherwise, return 0. Return -1 if the range is
2622 discontinuous, i.e. derived from DW_AT_ranges information. */
2624 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2625 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2627 struct objfile *objfile = cu->objfile;
2628 struct comp_unit_head *cu_header = &cu->header;
2629 struct attribute *attr;
2630 bfd *obfd = objfile->obfd;
2635 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2638 high = DW_ADDR (attr);
2639 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2641 low = DW_ADDR (attr);
2643 /* Found high w/o low attribute. */
2646 /* Found consecutive range of addresses. */
2651 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2654 unsigned int addr_size = cu_header->addr_size;
2655 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2656 /* Value of the DW_AT_ranges attribute is the offset in the
2657 .debug_ranges section. */
2658 unsigned int offset = DW_UNSND (attr);
2659 /* Base address selection entry. */
2667 found_base = cu_header->base_known;
2668 base = cu_header->base_address;
2670 if (offset >= dwarf2_per_objfile->ranges_size)
2672 complaint (&symfile_complaints,
2673 "Offset %d out of bounds for DW_AT_ranges attribute",
2677 buffer = dwarf2_per_objfile->ranges_buffer + offset;
2679 /* Read in the largest possible address. */
2680 marker = read_address (obfd, buffer, cu, &dummy);
2681 if ((marker & mask) == mask)
2683 /* If we found the largest possible address, then
2684 read the base address. */
2685 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2686 buffer += 2 * addr_size;
2687 offset += 2 * addr_size;
2695 CORE_ADDR range_beginning, range_end;
2697 range_beginning = read_address (obfd, buffer, cu, &dummy);
2698 buffer += addr_size;
2699 range_end = read_address (obfd, buffer, cu, &dummy);
2700 buffer += addr_size;
2701 offset += 2 * addr_size;
2703 /* An end of list marker is a pair of zero addresses. */
2704 if (range_beginning == 0 && range_end == 0)
2705 /* Found the end of list entry. */
2708 /* Each base address selection entry is a pair of 2 values.
2709 The first is the largest possible address, the second is
2710 the base address. Check for a base address here. */
2711 if ((range_beginning & mask) == mask)
2713 /* If we found the largest possible address, then
2714 read the base address. */
2715 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2722 /* We have no valid base address for the ranges
2724 complaint (&symfile_complaints,
2725 "Invalid .debug_ranges data (no base address)");
2729 range_beginning += base;
2732 /* FIXME: This is recording everything as a low-high
2733 segment of consecutive addresses. We should have a
2734 data structure for discontiguous block ranges
2738 low = range_beginning;
2744 if (range_beginning < low)
2745 low = range_beginning;
2746 if (range_end > high)
2752 /* If the first entry is an end-of-list marker, the range
2753 describes an empty scope, i.e. no instructions. */
2763 /* When using the GNU linker, .gnu.linkonce. sections are used to
2764 eliminate duplicate copies of functions and vtables and such.
2765 The linker will arbitrarily choose one and discard the others.
2766 The AT_*_pc values for such functions refer to local labels in
2767 these sections. If the section from that file was discarded, the
2768 labels are not in the output, so the relocs get a value of 0.
2769 If this is a discarded function, mark the pc bounds as invalid,
2770 so that GDB will ignore it. */
2771 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2779 /* Get the low and high pc's represented by the scope DIE, and store
2780 them in *LOWPC and *HIGHPC. If the correct values can't be
2781 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2784 get_scope_pc_bounds (struct die_info *die,
2785 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2786 struct dwarf2_cu *cu)
2788 CORE_ADDR best_low = (CORE_ADDR) -1;
2789 CORE_ADDR best_high = (CORE_ADDR) 0;
2790 CORE_ADDR current_low, current_high;
2792 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
2794 best_low = current_low;
2795 best_high = current_high;
2799 struct die_info *child = die->child;
2801 while (child && child->tag)
2803 switch (child->tag) {
2804 case DW_TAG_subprogram:
2805 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
2807 best_low = min (best_low, current_low);
2808 best_high = max (best_high, current_high);
2811 case DW_TAG_namespace:
2812 /* FIXME: carlton/2004-01-16: Should we do this for
2813 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2814 that current GCC's always emit the DIEs corresponding
2815 to definitions of methods of classes as children of a
2816 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2817 the DIEs giving the declarations, which could be
2818 anywhere). But I don't see any reason why the
2819 standards says that they have to be there. */
2820 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
2822 if (current_low != ((CORE_ADDR) -1))
2824 best_low = min (best_low, current_low);
2825 best_high = max (best_high, current_high);
2833 child = sibling_die (child);
2838 *highpc = best_high;
2841 /* Add an aggregate field to the field list. */
2844 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2845 struct dwarf2_cu *cu)
2847 struct objfile *objfile = cu->objfile;
2848 struct nextfield *new_field;
2849 struct attribute *attr;
2851 char *fieldname = "";
2853 /* Allocate a new field list entry and link it in. */
2854 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2855 make_cleanup (xfree, new_field);
2856 memset (new_field, 0, sizeof (struct nextfield));
2857 new_field->next = fip->fields;
2858 fip->fields = new_field;
2861 /* Handle accessibility and virtuality of field.
2862 The default accessibility for members is public, the default
2863 accessibility for inheritance is private. */
2864 if (die->tag != DW_TAG_inheritance)
2865 new_field->accessibility = DW_ACCESS_public;
2867 new_field->accessibility = DW_ACCESS_private;
2868 new_field->virtuality = DW_VIRTUALITY_none;
2870 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2872 new_field->accessibility = DW_UNSND (attr);
2873 if (new_field->accessibility != DW_ACCESS_public)
2874 fip->non_public_fields = 1;
2875 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
2877 new_field->virtuality = DW_UNSND (attr);
2879 fp = &new_field->field;
2881 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
2883 /* Data member other than a C++ static data member. */
2885 /* Get type of field. */
2886 fp->type = die_type (die, cu);
2888 FIELD_STATIC_KIND (*fp) = 0;
2890 /* Get bit size of field (zero if none). */
2891 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
2894 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2898 FIELD_BITSIZE (*fp) = 0;
2901 /* Get bit offset of field. */
2902 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2905 FIELD_BITPOS (*fp) =
2906 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2909 FIELD_BITPOS (*fp) = 0;
2910 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
2913 if (BITS_BIG_ENDIAN)
2915 /* For big endian bits, the DW_AT_bit_offset gives the
2916 additional bit offset from the MSB of the containing
2917 anonymous object to the MSB of the field. We don't
2918 have to do anything special since we don't need to
2919 know the size of the anonymous object. */
2920 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2924 /* For little endian bits, compute the bit offset to the
2925 MSB of the anonymous object, subtract off the number of
2926 bits from the MSB of the field to the MSB of the
2927 object, and then subtract off the number of bits of
2928 the field itself. The result is the bit offset of
2929 the LSB of the field. */
2931 int bit_offset = DW_UNSND (attr);
2933 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2936 /* The size of the anonymous object containing
2937 the bit field is explicit, so use the
2938 indicated size (in bytes). */
2939 anonymous_size = DW_UNSND (attr);
2943 /* The size of the anonymous object containing
2944 the bit field must be inferred from the type
2945 attribute of the data member containing the
2947 anonymous_size = TYPE_LENGTH (fp->type);
2949 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2950 - bit_offset - FIELD_BITSIZE (*fp);
2954 /* Get name of field. */
2955 attr = dwarf2_attr (die, DW_AT_name, cu);
2956 if (attr && DW_STRING (attr))
2957 fieldname = DW_STRING (attr);
2959 /* The name is already allocated along with this objfile, so we don't
2960 need to duplicate it for the type. */
2961 fp->name = fieldname;
2963 /* Change accessibility for artificial fields (e.g. virtual table
2964 pointer or virtual base class pointer) to private. */
2965 if (dwarf2_attr (die, DW_AT_artificial, cu))
2967 new_field->accessibility = DW_ACCESS_private;
2968 fip->non_public_fields = 1;
2971 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2973 /* C++ static member. */
2975 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2976 is a declaration, but all versions of G++ as of this writing
2977 (so through at least 3.2.1) incorrectly generate
2978 DW_TAG_variable tags. */
2982 /* Get name of field. */
2983 attr = dwarf2_attr (die, DW_AT_name, cu);
2984 if (attr && DW_STRING (attr))
2985 fieldname = DW_STRING (attr);
2989 /* Get physical name. */
2990 physname = dwarf2_linkage_name (die, cu);
2992 /* The name is already allocated along with this objfile, so we don't
2993 need to duplicate it for the type. */
2994 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
2995 FIELD_TYPE (*fp) = die_type (die, cu);
2996 FIELD_NAME (*fp) = fieldname;
2998 else if (die->tag == DW_TAG_inheritance)
3000 /* C++ base class field. */
3001 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3003 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
3005 FIELD_BITSIZE (*fp) = 0;
3006 FIELD_STATIC_KIND (*fp) = 0;
3007 FIELD_TYPE (*fp) = die_type (die, cu);
3008 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
3009 fip->nbaseclasses++;
3013 /* Create the vector of fields, and attach it to the type. */
3016 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
3017 struct dwarf2_cu *cu)
3019 int nfields = fip->nfields;
3021 /* Record the field count, allocate space for the array of fields,
3022 and create blank accessibility bitfields if necessary. */
3023 TYPE_NFIELDS (type) = nfields;
3024 TYPE_FIELDS (type) = (struct field *)
3025 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3026 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3028 if (fip->non_public_fields)
3030 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3032 TYPE_FIELD_PRIVATE_BITS (type) =
3033 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3034 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3036 TYPE_FIELD_PROTECTED_BITS (type) =
3037 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3038 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3040 TYPE_FIELD_IGNORE_BITS (type) =
3041 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3042 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3045 /* If the type has baseclasses, allocate and clear a bit vector for
3046 TYPE_FIELD_VIRTUAL_BITS. */
3047 if (fip->nbaseclasses)
3049 int num_bytes = B_BYTES (fip->nbaseclasses);
3052 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3053 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3054 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3055 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
3056 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
3059 /* Copy the saved-up fields into the field vector. Start from the head
3060 of the list, adding to the tail of the field array, so that they end
3061 up in the same order in the array in which they were added to the list. */
3062 while (nfields-- > 0)
3064 TYPE_FIELD (type, nfields) = fip->fields->field;
3065 switch (fip->fields->accessibility)
3067 case DW_ACCESS_private:
3068 SET_TYPE_FIELD_PRIVATE (type, nfields);
3071 case DW_ACCESS_protected:
3072 SET_TYPE_FIELD_PROTECTED (type, nfields);
3075 case DW_ACCESS_public:
3079 /* Unknown accessibility. Complain and treat it as public. */
3081 complaint (&symfile_complaints, "unsupported accessibility %d",
3082 fip->fields->accessibility);
3086 if (nfields < fip->nbaseclasses)
3088 switch (fip->fields->virtuality)
3090 case DW_VIRTUALITY_virtual:
3091 case DW_VIRTUALITY_pure_virtual:
3092 SET_TYPE_FIELD_VIRTUAL (type, nfields);
3096 fip->fields = fip->fields->next;
3100 /* Add a member function to the proper fieldlist. */
3103 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
3104 struct type *type, struct dwarf2_cu *cu)
3106 struct objfile *objfile = cu->objfile;
3107 struct attribute *attr;
3108 struct fnfieldlist *flp;
3110 struct fn_field *fnp;
3113 struct nextfnfield *new_fnfield;
3115 /* Get name of member function. */
3116 attr = dwarf2_attr (die, DW_AT_name, cu);
3117 if (attr && DW_STRING (attr))
3118 fieldname = DW_STRING (attr);
3122 /* Get the mangled name. */
3123 physname = dwarf2_linkage_name (die, cu);
3125 /* Look up member function name in fieldlist. */
3126 for (i = 0; i < fip->nfnfields; i++)
3128 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
3132 /* Create new list element if necessary. */
3133 if (i < fip->nfnfields)
3134 flp = &fip->fnfieldlists[i];
3137 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
3139 fip->fnfieldlists = (struct fnfieldlist *)
3140 xrealloc (fip->fnfieldlists,
3141 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
3142 * sizeof (struct fnfieldlist));
3143 if (fip->nfnfields == 0)
3144 make_cleanup (free_current_contents, &fip->fnfieldlists);
3146 flp = &fip->fnfieldlists[fip->nfnfields];
3147 flp->name = fieldname;
3153 /* Create a new member function field and chain it to the field list
3155 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
3156 make_cleanup (xfree, new_fnfield);
3157 memset (new_fnfield, 0, sizeof (struct nextfnfield));
3158 new_fnfield->next = flp->head;
3159 flp->head = new_fnfield;
3162 /* Fill in the member function field info. */
3163 fnp = &new_fnfield->fnfield;
3164 /* The name is already allocated along with this objfile, so we don't
3165 need to duplicate it for the type. */
3166 fnp->physname = physname ? physname : "";
3167 fnp->type = alloc_type (objfile);
3168 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
3170 int nparams = TYPE_NFIELDS (die->type);
3172 /* TYPE is the domain of this method, and DIE->TYPE is the type
3173 of the method itself (TYPE_CODE_METHOD). */
3174 smash_to_method_type (fnp->type, type,
3175 TYPE_TARGET_TYPE (die->type),
3176 TYPE_FIELDS (die->type),
3177 TYPE_NFIELDS (die->type),
3178 TYPE_VARARGS (die->type));
3180 /* Handle static member functions.
3181 Dwarf2 has no clean way to discern C++ static and non-static
3182 member functions. G++ helps GDB by marking the first
3183 parameter for non-static member functions (which is the
3184 this pointer) as artificial. We obtain this information
3185 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3186 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
3187 fnp->voffset = VOFFSET_STATIC;
3190 complaint (&symfile_complaints, "member function type missing for '%s'",
3193 /* Get fcontext from DW_AT_containing_type if present. */
3194 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3195 fnp->fcontext = die_containing_type (die, cu);
3197 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3198 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3200 /* Get accessibility. */
3201 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3204 switch (DW_UNSND (attr))
3206 case DW_ACCESS_private:
3207 fnp->is_private = 1;
3209 case DW_ACCESS_protected:
3210 fnp->is_protected = 1;
3215 /* Check for artificial methods. */
3216 attr = dwarf2_attr (die, DW_AT_artificial, cu);
3217 if (attr && DW_UNSND (attr) != 0)
3218 fnp->is_artificial = 1;
3220 /* Get index in virtual function table if it is a virtual member function. */
3221 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
3224 /* Support the .debug_loc offsets */
3225 if (attr_form_is_block (attr))
3227 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
3229 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3231 dwarf2_complex_location_expr_complaint ();
3235 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3241 /* Create the vector of member function fields, and attach it to the type. */
3244 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
3245 struct dwarf2_cu *cu)
3247 struct fnfieldlist *flp;
3248 int total_length = 0;
3251 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3252 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3253 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
3255 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
3257 struct nextfnfield *nfp = flp->head;
3258 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
3261 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
3262 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
3263 fn_flp->fn_fields = (struct fn_field *)
3264 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
3265 for (k = flp->length; (k--, nfp); nfp = nfp->next)
3266 fn_flp->fn_fields[k] = nfp->fnfield;
3268 total_length += flp->length;
3271 TYPE_NFN_FIELDS (type) = fip->nfnfields;
3272 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3276 /* Returns non-zero if NAME is the name of a vtable member in CU's
3277 language, zero otherwise. */
3279 is_vtable_name (const char *name, struct dwarf2_cu *cu)
3281 static const char vptr[] = "_vptr";
3282 static const char vtable[] = "vtable";
3284 /* Look for the C++ and Java forms of the vtable. */
3285 if ((cu->language == language_java
3286 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
3287 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
3288 && is_cplus_marker (name[sizeof (vptr) - 1])))
3295 /* Called when we find the DIE that starts a structure or union scope
3296 (definition) to process all dies that define the members of the
3299 NOTE: we need to call struct_type regardless of whether or not the
3300 DIE has an at_name attribute, since it might be an anonymous
3301 structure or union. This gets the type entered into our set of
3304 However, if the structure is incomplete (an opaque struct/union)
3305 then suppress creating a symbol table entry for it since gdb only
3306 wants to find the one with the complete definition. Note that if
3307 it is complete, we just call new_symbol, which does it's own
3308 checking about whether the struct/union is anonymous or not (and
3309 suppresses creating a symbol table entry itself). */
3312 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3314 struct objfile *objfile = cu->objfile;
3316 struct attribute *attr;
3317 const char *previous_prefix = processing_current_prefix;
3318 struct cleanup *back_to = NULL;
3323 type = alloc_type (objfile);
3325 INIT_CPLUS_SPECIFIC (type);
3326 attr = dwarf2_attr (die, DW_AT_name, cu);
3327 if (attr && DW_STRING (attr))
3329 if (cu->language == language_cplus
3330 || cu->language == language_java)
3332 char *new_prefix = determine_class_name (die, cu);
3333 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3334 strlen (new_prefix),
3335 &objfile->objfile_obstack);
3336 back_to = make_cleanup (xfree, new_prefix);
3337 processing_current_prefix = new_prefix;
3341 /* The name is already allocated along with this objfile, so
3342 we don't need to duplicate it for the type. */
3343 TYPE_TAG_NAME (type) = DW_STRING (attr);
3347 if (die->tag == DW_TAG_structure_type)
3349 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3351 else if (die->tag == DW_TAG_union_type)
3353 TYPE_CODE (type) = TYPE_CODE_UNION;
3357 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3359 TYPE_CODE (type) = TYPE_CODE_CLASS;
3362 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3365 TYPE_LENGTH (type) = DW_UNSND (attr);
3369 TYPE_LENGTH (type) = 0;
3372 if (die_is_declaration (die, cu))
3373 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3375 /* We need to add the type field to the die immediately so we don't
3376 infinitely recurse when dealing with pointers to the structure
3377 type within the structure itself. */
3380 if (die->child != NULL && ! die_is_declaration (die, cu))
3382 struct field_info fi;
3383 struct die_info *child_die;
3384 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3386 memset (&fi, 0, sizeof (struct field_info));
3388 child_die = die->child;
3390 while (child_die && child_die->tag)
3392 if (child_die->tag == DW_TAG_member
3393 || child_die->tag == DW_TAG_variable)
3395 /* NOTE: carlton/2002-11-05: A C++ static data member
3396 should be a DW_TAG_member that is a declaration, but
3397 all versions of G++ as of this writing (so through at
3398 least 3.2.1) incorrectly generate DW_TAG_variable
3399 tags for them instead. */
3400 dwarf2_add_field (&fi, child_die, cu);
3402 else if (child_die->tag == DW_TAG_subprogram)
3404 /* C++ member function. */
3405 read_type_die (child_die, cu);
3406 dwarf2_add_member_fn (&fi, child_die, type, cu);
3408 else if (child_die->tag == DW_TAG_inheritance)
3410 /* C++ base class field. */
3411 dwarf2_add_field (&fi, child_die, cu);
3413 child_die = sibling_die (child_die);
3416 /* Attach fields and member functions to the type. */
3418 dwarf2_attach_fields_to_type (&fi, type, cu);
3421 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3423 /* Get the type which refers to the base class (possibly this
3424 class itself) which contains the vtable pointer for the current
3425 class from the DW_AT_containing_type attribute. */
3427 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3429 struct type *t = die_containing_type (die, cu);
3431 TYPE_VPTR_BASETYPE (type) = t;
3436 /* Our own class provides vtbl ptr. */
3437 for (i = TYPE_NFIELDS (t) - 1;
3438 i >= TYPE_N_BASECLASSES (t);
3441 char *fieldname = TYPE_FIELD_NAME (t, i);
3443 if (is_vtable_name (fieldname, cu))
3445 TYPE_VPTR_FIELDNO (type) = i;
3450 /* Complain if virtual function table field not found. */
3451 if (i < TYPE_N_BASECLASSES (t))
3452 complaint (&symfile_complaints,
3453 "virtual function table pointer not found when defining class '%s'",
3454 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3459 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3464 do_cleanups (back_to);
3467 processing_current_prefix = previous_prefix;
3468 if (back_to != NULL)
3469 do_cleanups (back_to);
3473 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3475 struct objfile *objfile = cu->objfile;
3476 const char *previous_prefix = processing_current_prefix;
3477 struct die_info *child_die = die->child;
3479 if (TYPE_TAG_NAME (die->type) != NULL)
3480 processing_current_prefix = TYPE_TAG_NAME (die->type);
3482 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3483 snapshots) has been known to create a die giving a declaration
3484 for a class that has, as a child, a die giving a definition for a
3485 nested class. So we have to process our children even if the
3486 current die is a declaration. Normally, of course, a declaration
3487 won't have any children at all. */
3489 while (child_die != NULL && child_die->tag)
3491 if (child_die->tag == DW_TAG_member
3492 || child_die->tag == DW_TAG_variable
3493 || child_die->tag == DW_TAG_inheritance)
3498 process_die (child_die, cu);
3500 child_die = sibling_die (child_die);
3503 if (die->child != NULL && ! die_is_declaration (die, cu))
3504 new_symbol (die, die->type, cu);
3506 processing_current_prefix = previous_prefix;
3509 /* Given a DW_AT_enumeration_type die, set its type. We do not
3510 complete the type's fields yet, or create any symbols. */
3513 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3515 struct objfile *objfile = cu->objfile;
3517 struct attribute *attr;
3522 type = alloc_type (objfile);
3524 TYPE_CODE (type) = TYPE_CODE_ENUM;
3525 attr = dwarf2_attr (die, DW_AT_name, cu);
3526 if (attr && DW_STRING (attr))
3528 char *name = DW_STRING (attr);
3530 if (processing_has_namespace_info)
3532 TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack,
3533 processing_current_prefix,
3538 /* The name is already allocated along with this objfile, so
3539 we don't need to duplicate it for the type. */
3540 TYPE_TAG_NAME (type) = name;
3544 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3547 TYPE_LENGTH (type) = DW_UNSND (attr);
3551 TYPE_LENGTH (type) = 0;
3557 /* Determine the name of the type represented by DIE, which should be
3558 a named C++ or Java compound type. Return the name in question; the caller
3559 is responsible for xfree()'ing it. */
3562 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3564 struct cleanup *back_to = NULL;
3565 struct die_info *spec_die = die_specification (die, cu);
3566 char *new_prefix = NULL;
3568 /* If this is the definition of a class that is declared by another
3569 die, then processing_current_prefix may not be accurate; see
3570 read_func_scope for a similar example. */
3571 if (spec_die != NULL)
3573 char *specification_prefix = determine_prefix (spec_die, cu);
3574 processing_current_prefix = specification_prefix;
3575 back_to = make_cleanup (xfree, specification_prefix);
3578 /* If we don't have namespace debug info, guess the name by trying
3579 to demangle the names of members, just like we did in
3580 guess_structure_name. */
3581 if (!processing_has_namespace_info)
3583 struct die_info *child;
3585 for (child = die->child;
3586 child != NULL && child->tag != 0;
3587 child = sibling_die (child))
3589 if (child->tag == DW_TAG_subprogram)
3592 = language_class_name_from_physname (cu->language_defn,
3596 if (new_prefix != NULL)
3602 if (new_prefix == NULL)
3604 const char *name = dwarf2_name (die, cu);
3605 new_prefix = typename_concat (NULL, processing_current_prefix,
3606 name ? name : "<<anonymous>>",
3610 if (back_to != NULL)
3611 do_cleanups (back_to);
3616 /* Given a pointer to a die which begins an enumeration, process all
3617 the dies that define the members of the enumeration, and create the
3618 symbol for the enumeration type.
3620 NOTE: We reverse the order of the element list. */
3623 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3625 struct objfile *objfile = cu->objfile;
3626 struct die_info *child_die;
3627 struct field *fields;
3628 struct attribute *attr;
3631 int unsigned_enum = 1;
3635 if (die->child != NULL)
3637 child_die = die->child;
3638 while (child_die && child_die->tag)
3640 if (child_die->tag != DW_TAG_enumerator)
3642 process_die (child_die, cu);
3646 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3649 sym = new_symbol (child_die, die->type, cu);
3650 if (SYMBOL_VALUE (sym) < 0)
3653 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3655 fields = (struct field *)
3657 (num_fields + DW_FIELD_ALLOC_CHUNK)
3658 * sizeof (struct field));
3661 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3662 FIELD_TYPE (fields[num_fields]) = NULL;
3663 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3664 FIELD_BITSIZE (fields[num_fields]) = 0;
3665 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3671 child_die = sibling_die (child_die);
3676 TYPE_NFIELDS (die->type) = num_fields;
3677 TYPE_FIELDS (die->type) = (struct field *)
3678 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
3679 memcpy (TYPE_FIELDS (die->type), fields,
3680 sizeof (struct field) * num_fields);
3684 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
3687 new_symbol (die, die->type, cu);
3690 /* Extract all information from a DW_TAG_array_type DIE and put it in
3691 the DIE's type field. For now, this only handles one dimensional
3695 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3697 struct objfile *objfile = cu->objfile;
3698 struct die_info *child_die;
3699 struct type *type = NULL;
3700 struct type *element_type, *range_type, *index_type;
3701 struct type **range_types = NULL;
3702 struct attribute *attr;
3704 struct cleanup *back_to;
3706 /* Return if we've already decoded this type. */
3712 element_type = die_type (die, cu);
3714 /* Irix 6.2 native cc creates array types without children for
3715 arrays with unspecified length. */
3716 if (die->child == NULL)
3718 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3719 range_type = create_range_type (NULL, index_type, 0, -1);
3720 die->type = create_array_type (NULL, element_type, range_type);
3724 back_to = make_cleanup (null_cleanup, NULL);
3725 child_die = die->child;
3726 while (child_die && child_die->tag)
3728 if (child_die->tag == DW_TAG_subrange_type)
3730 read_subrange_type (child_die, cu);
3732 if (child_die->type != NULL)
3734 /* The range type was succesfully read. Save it for
3735 the array type creation. */
3736 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3738 range_types = (struct type **)
3739 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3740 * sizeof (struct type *));
3742 make_cleanup (free_current_contents, &range_types);
3744 range_types[ndim++] = child_die->type;
3747 child_die = sibling_die (child_die);
3750 /* Dwarf2 dimensions are output from left to right, create the
3751 necessary array types in backwards order. */
3753 type = element_type;
3755 if (read_array_order (die, cu) == DW_ORD_col_major)
3759 type = create_array_type (NULL, type, range_types[i++]);
3764 type = create_array_type (NULL, type, range_types[ndim]);
3767 /* Understand Dwarf2 support for vector types (like they occur on
3768 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3769 array type. This is not part of the Dwarf2/3 standard yet, but a
3770 custom vendor extension. The main difference between a regular
3771 array and the vector variant is that vectors are passed by value
3773 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
3775 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3777 do_cleanups (back_to);
3779 /* Install the type in the die. */
3783 static enum dwarf_array_dim_ordering
3784 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
3786 struct attribute *attr;
3788 attr = dwarf2_attr (die, DW_AT_ordering, cu);
3790 if (attr) return DW_SND (attr);
3793 GNU F77 is a special case, as at 08/2004 array type info is the
3794 opposite order to the dwarf2 specification, but data is still
3795 laid out as per normal fortran.
3797 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
3801 if (cu->language == language_fortran &&
3802 cu->producer && strstr (cu->producer, "GNU F77"))
3804 return DW_ORD_row_major;
3807 switch (cu->language_defn->la_array_ordering)
3809 case array_column_major:
3810 return DW_ORD_col_major;
3811 case array_row_major:
3813 return DW_ORD_row_major;
3818 /* First cut: install each common block member as a global variable. */
3821 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3823 struct die_info *child_die;
3824 struct attribute *attr;
3826 CORE_ADDR base = (CORE_ADDR) 0;
3828 attr = dwarf2_attr (die, DW_AT_location, cu);
3831 /* Support the .debug_loc offsets */
3832 if (attr_form_is_block (attr))
3834 base = decode_locdesc (DW_BLOCK (attr), cu);
3836 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3838 dwarf2_complex_location_expr_complaint ();
3842 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3843 "common block member");
3846 if (die->child != NULL)
3848 child_die = die->child;
3849 while (child_die && child_die->tag)
3851 sym = new_symbol (child_die, NULL, cu);
3852 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
3855 SYMBOL_VALUE_ADDRESS (sym) =
3856 base + decode_locdesc (DW_BLOCK (attr), cu);
3857 add_symbol_to_list (sym, &global_symbols);
3859 child_die = sibling_die (child_die);
3864 /* Read a C++ namespace. */
3867 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3869 struct objfile *objfile = cu->objfile;
3870 const char *previous_prefix = processing_current_prefix;
3873 struct die_info *current_die;
3874 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3876 name = namespace_name (die, &is_anonymous, cu);
3878 /* Now build the name of the current namespace. */
3880 if (previous_prefix[0] == '\0')
3882 processing_current_prefix = name;
3886 char *temp_name = typename_concat (NULL, previous_prefix, name, cu);
3887 make_cleanup (xfree, temp_name);
3888 processing_current_prefix = temp_name;
3891 /* Add a symbol associated to this if we haven't seen the namespace
3892 before. Also, add a using directive if it's an anonymous
3895 if (dwarf2_extension (die, cu) == NULL)
3899 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3900 this cast will hopefully become unnecessary. */
3901 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3902 (char *) processing_current_prefix,
3904 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3906 new_symbol (die, type, cu);
3910 cp_add_using_directive (processing_current_prefix,
3911 strlen (previous_prefix),
3912 strlen (processing_current_prefix));
3915 if (die->child != NULL)
3917 struct die_info *child_die = die->child;
3919 while (child_die && child_die->tag)
3921 process_die (child_die, cu);
3922 child_die = sibling_die (child_die);
3926 processing_current_prefix = previous_prefix;
3927 do_cleanups (back_to);
3930 /* Return the name of the namespace represented by DIE. Set
3931 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3935 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
3937 struct die_info *current_die;
3938 const char *name = NULL;
3940 /* Loop through the extensions until we find a name. */
3942 for (current_die = die;
3943 current_die != NULL;
3944 current_die = dwarf2_extension (die, cu))
3946 name = dwarf2_name (current_die, cu);
3951 /* Is it an anonymous namespace? */
3953 *is_anonymous = (name == NULL);
3955 name = "(anonymous namespace)";
3960 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3961 the user defined type vector. */
3964 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3966 struct comp_unit_head *cu_header = &cu->header;
3968 struct attribute *attr_byte_size;
3969 struct attribute *attr_address_class;
3970 int byte_size, addr_class;
3977 type = lookup_pointer_type (die_type (die, cu));
3979 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
3981 byte_size = DW_UNSND (attr_byte_size);
3983 byte_size = cu_header->addr_size;
3985 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
3986 if (attr_address_class)
3987 addr_class = DW_UNSND (attr_address_class);
3989 addr_class = DW_ADDR_none;
3991 /* If the pointer size or address class is different than the
3992 default, create a type variant marked as such and set the
3993 length accordingly. */
3994 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3996 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4000 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
4001 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
4002 type = make_type_with_address_space (type, type_flags);
4004 else if (TYPE_LENGTH (type) != byte_size)
4006 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
4009 /* Should we also complain about unhandled address classes? */
4013 TYPE_LENGTH (type) = byte_size;
4017 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4018 the user defined type vector. */
4021 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
4023 struct objfile *objfile = cu->objfile;
4025 struct type *to_type;
4026 struct type *domain;
4033 type = alloc_type (objfile);
4034 to_type = die_type (die, cu);
4035 domain = die_containing_type (die, cu);
4036 smash_to_member_type (type, domain, to_type);
4041 /* Extract all information from a DW_TAG_reference_type DIE and add to
4042 the user defined type vector. */
4045 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
4047 struct comp_unit_head *cu_header = &cu->header;
4049 struct attribute *attr;
4056 type = lookup_reference_type (die_type (die, cu));
4057 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4060 TYPE_LENGTH (type) = DW_UNSND (attr);
4064 TYPE_LENGTH (type) = cu_header->addr_size;
4070 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
4072 struct type *base_type;
4079 base_type = die_type (die, cu);
4080 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
4084 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
4086 struct type *base_type;
4093 base_type = die_type (die, cu);
4094 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
4097 /* Extract all information from a DW_TAG_string_type DIE and add to
4098 the user defined type vector. It isn't really a user defined type,
4099 but it behaves like one, with other DIE's using an AT_user_def_type
4100 attribute to reference it. */
4103 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
4105 struct objfile *objfile = cu->objfile;
4106 struct type *type, *range_type, *index_type, *char_type;
4107 struct attribute *attr;
4108 unsigned int length;
4115 attr = dwarf2_attr (die, DW_AT_string_length, cu);
4118 length = DW_UNSND (attr);
4122 /* check for the DW_AT_byte_size attribute */
4123 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4126 length = DW_UNSND (attr);
4133 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
4134 range_type = create_range_type (NULL, index_type, 1, length);
4135 if (cu->language == language_fortran)
4137 /* Need to create a unique string type for bounds
4139 type = create_string_type (0, range_type);
4143 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
4144 type = create_string_type (char_type, range_type);
4149 /* Handle DIES due to C code like:
4153 int (*funcp)(int a, long l);
4157 ('funcp' generates a DW_TAG_subroutine_type DIE)
4161 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
4163 struct type *type; /* Type that this function returns */
4164 struct type *ftype; /* Function that returns above type */
4165 struct attribute *attr;
4167 /* Decode the type that this subroutine returns */
4172 type = die_type (die, cu);
4173 ftype = lookup_function_type (type);
4175 /* All functions in C++ and Java have prototypes. */
4176 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
4177 if ((attr && (DW_UNSND (attr) != 0))
4178 || cu->language == language_cplus
4179 || cu->language == language_java)
4180 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
4182 if (die->child != NULL)
4184 struct die_info *child_die;
4188 /* Count the number of parameters.
4189 FIXME: GDB currently ignores vararg functions, but knows about
4190 vararg member functions. */
4191 child_die = die->child;
4192 while (child_die && child_die->tag)
4194 if (child_die->tag == DW_TAG_formal_parameter)
4196 else if (child_die->tag == DW_TAG_unspecified_parameters)
4197 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
4198 child_die = sibling_die (child_die);
4201 /* Allocate storage for parameters and fill them in. */
4202 TYPE_NFIELDS (ftype) = nparams;
4203 TYPE_FIELDS (ftype) = (struct field *)
4204 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
4206 child_die = die->child;
4207 while (child_die && child_die->tag)
4209 if (child_die->tag == DW_TAG_formal_parameter)
4211 /* Dwarf2 has no clean way to discern C++ static and non-static
4212 member functions. G++ helps GDB by marking the first
4213 parameter for non-static member functions (which is the
4214 this pointer) as artificial. We pass this information
4215 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4216 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
4218 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
4220 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
4221 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
4224 child_die = sibling_die (child_die);
4232 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
4234 struct objfile *objfile = cu->objfile;
4235 struct attribute *attr;
4240 attr = dwarf2_attr (die, DW_AT_name, cu);
4241 if (attr && DW_STRING (attr))
4243 name = DW_STRING (attr);
4245 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
4246 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
4250 /* Find a representation of a given base type and install
4251 it in the TYPE field of the die. */
4254 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
4256 struct objfile *objfile = cu->objfile;
4258 struct attribute *attr;
4259 int encoding = 0, size = 0;
4261 /* If we've already decoded this die, this is a no-op. */
4267 attr = dwarf2_attr (die, DW_AT_encoding, cu);
4270 encoding = DW_UNSND (attr);
4272 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4275 size = DW_UNSND (attr);
4277 attr = dwarf2_attr (die, DW_AT_name, cu);
4278 if (attr && DW_STRING (attr))
4280 enum type_code code = TYPE_CODE_INT;
4285 case DW_ATE_address:
4286 /* Turn DW_ATE_address into a void * pointer. */
4287 code = TYPE_CODE_PTR;
4288 type_flags |= TYPE_FLAG_UNSIGNED;
4290 case DW_ATE_boolean:
4291 code = TYPE_CODE_BOOL;
4292 type_flags |= TYPE_FLAG_UNSIGNED;
4294 case DW_ATE_complex_float:
4295 code = TYPE_CODE_COMPLEX;
4298 code = TYPE_CODE_FLT;
4301 case DW_ATE_signed_char:
4303 case DW_ATE_unsigned:
4304 case DW_ATE_unsigned_char:
4305 type_flags |= TYPE_FLAG_UNSIGNED;
4308 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
4309 dwarf_type_encoding_name (encoding));
4312 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
4313 if (encoding == DW_ATE_address)
4314 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
4316 else if (encoding == DW_ATE_complex_float)
4319 TYPE_TARGET_TYPE (type)
4320 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
4321 else if (size == 16)
4322 TYPE_TARGET_TYPE (type)
4323 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
4325 TYPE_TARGET_TYPE (type)
4326 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4331 type = dwarf_base_type (encoding, size, cu);
4336 /* Read the given DW_AT_subrange DIE. */
4339 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4341 struct type *base_type;
4342 struct type *range_type;
4343 struct attribute *attr;
4347 /* If we have already decoded this die, then nothing more to do. */
4351 base_type = die_type (die, cu);
4352 if (base_type == NULL)
4354 complaint (&symfile_complaints,
4355 "DW_AT_type missing from DW_TAG_subrange_type");
4359 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4360 base_type = alloc_type (NULL);
4362 if (cu->language == language_fortran)
4364 /* FORTRAN implies a lower bound of 1, if not given. */
4368 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4370 low = dwarf2_get_attr_constant_value (attr, 0);
4372 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4375 if (attr->form == DW_FORM_block1)
4377 /* GCC encodes arrays with unspecified or dynamic length
4378 with a DW_FORM_block1 attribute.
4379 FIXME: GDB does not yet know how to handle dynamic
4380 arrays properly, treat them as arrays with unspecified
4383 FIXME: jimb/2003-09-22: GDB does not really know
4384 how to handle arrays of unspecified length
4385 either; we just represent them as zero-length
4386 arrays. Choose an appropriate upper bound given
4387 the lower bound we've computed above. */
4391 high = dwarf2_get_attr_constant_value (attr, 1);
4394 range_type = create_range_type (NULL, base_type, low, high);
4396 attr = dwarf2_attr (die, DW_AT_name, cu);
4397 if (attr && DW_STRING (attr))
4398 TYPE_NAME (range_type) = DW_STRING (attr);
4400 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4402 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4404 die->type = range_type;
4408 /* Read a whole compilation unit into a linked list of dies. */
4410 static struct die_info *
4411 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4413 /* Reset die reference table; we are
4414 building new ones now. */
4415 dwarf2_empty_hash_tables ();
4417 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4420 /* Read a single die and all its descendents. Set the die's sibling
4421 field to NULL; set other fields in the die correctly, and set all
4422 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4423 location of the info_ptr after reading all of those dies. PARENT
4424 is the parent of the die in question. */
4426 static struct die_info *
4427 read_die_and_children (char *info_ptr, bfd *abfd,
4428 struct dwarf2_cu *cu,
4429 char **new_info_ptr,
4430 struct die_info *parent)
4432 struct die_info *die;
4436 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4437 store_in_ref_table (die->offset, die);
4441 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4447 *new_info_ptr = cur_ptr;
4450 die->sibling = NULL;
4451 die->parent = parent;
4455 /* Read a die, all of its descendents, and all of its siblings; set
4456 all of the fields of all of the dies correctly. Arguments are as
4457 in read_die_and_children. */
4459 static struct die_info *
4460 read_die_and_siblings (char *info_ptr, bfd *abfd,
4461 struct dwarf2_cu *cu,
4462 char **new_info_ptr,
4463 struct die_info *parent)
4465 struct die_info *first_die, *last_sibling;
4469 first_die = last_sibling = NULL;
4473 struct die_info *die
4474 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4482 last_sibling->sibling = die;
4487 *new_info_ptr = cur_ptr;
4497 /* Free a linked list of dies. */
4500 free_die_list (struct die_info *dies)
4502 struct die_info *die, *next;
4507 if (die->child != NULL)
4508 free_die_list (die->child);
4509 next = die->sibling;
4517 do_free_die_list_cleanup (void *dies)
4519 free_die_list (dies);
4522 static struct cleanup *
4523 make_cleanup_free_die_list (struct die_info *dies)
4525 return make_cleanup (do_free_die_list_cleanup, dies);
4529 /* Read the contents of the section at OFFSET and of size SIZE from the
4530 object file specified by OBJFILE into the objfile_obstack and return it. */
4533 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4535 bfd *abfd = objfile->obfd;
4537 bfd_size_type size = bfd_get_section_size (sectp);
4542 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4544 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4548 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4549 || bfd_bread (buf, size, abfd) != size)
4550 error ("Dwarf Error: Can't read DWARF data from '%s'",
4551 bfd_get_filename (abfd));
4556 /* In DWARF version 2, the description of the debugging information is
4557 stored in a separate .debug_abbrev section. Before we read any
4558 dies from a section we read in all abbreviations and install them
4559 in a hash table. This function also sets flags in CU describing
4560 the data found in the abbrev table. */
4563 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4565 struct comp_unit_head *cu_header = &cu->header;
4567 struct abbrev_info *cur_abbrev;
4568 unsigned int abbrev_number, bytes_read, abbrev_name;
4569 unsigned int abbrev_form, hash_number;
4570 struct attr_abbrev *cur_attrs;
4571 unsigned int allocated_attrs;
4573 /* Initialize dwarf2 abbrevs */
4574 obstack_init (&cu->abbrev_obstack);
4575 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
4577 * sizeof (struct abbrev_info *)));
4578 memset (cu->dwarf2_abbrevs, 0,
4579 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
4581 abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset;
4582 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4583 abbrev_ptr += bytes_read;
4585 allocated_attrs = ATTR_ALLOC_CHUNK;
4586 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
4588 /* loop until we reach an abbrev number of 0 */
4589 while (abbrev_number)
4591 cur_abbrev = dwarf_alloc_abbrev (cu);
4593 /* read in abbrev header */
4594 cur_abbrev->number = abbrev_number;
4595 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4596 abbrev_ptr += bytes_read;
4597 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4600 if (cur_abbrev->tag == DW_TAG_namespace)
4601 cu->has_namespace_info = 1;
4603 /* now read in declarations */
4604 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4605 abbrev_ptr += bytes_read;
4606 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4607 abbrev_ptr += bytes_read;
4610 if (cur_abbrev->num_attrs == allocated_attrs)
4612 allocated_attrs += ATTR_ALLOC_CHUNK;
4614 = xrealloc (cur_attrs, (allocated_attrs
4615 * sizeof (struct attr_abbrev)));
4617 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
4618 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4619 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4620 abbrev_ptr += bytes_read;
4621 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4622 abbrev_ptr += bytes_read;
4625 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
4626 (cur_abbrev->num_attrs
4627 * sizeof (struct attr_abbrev)));
4628 memcpy (cur_abbrev->attrs, cur_attrs,
4629 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
4631 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4632 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
4633 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
4635 /* Get next abbreviation.
4636 Under Irix6 the abbreviations for a compilation unit are not
4637 always properly terminated with an abbrev number of 0.
4638 Exit loop if we encounter an abbreviation which we have
4639 already read (which means we are about to read the abbreviations
4640 for the next compile unit) or if the end of the abbreviation
4641 table is reached. */
4642 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer)
4643 >= dwarf2_per_objfile->abbrev_size)
4645 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4646 abbrev_ptr += bytes_read;
4647 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4654 /* Release the memory used by the abbrev table for a compilation unit. */
4657 dwarf2_free_abbrev_table (void *ptr_to_cu)
4659 struct dwarf2_cu *cu = ptr_to_cu;
4661 obstack_free (&cu->abbrev_obstack, NULL);
4662 cu->dwarf2_abbrevs = NULL;
4665 /* Lookup an abbrev_info structure in the abbrev hash table. */
4667 static struct abbrev_info *
4668 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4670 unsigned int hash_number;
4671 struct abbrev_info *abbrev;
4673 hash_number = number % ABBREV_HASH_SIZE;
4674 abbrev = cu->dwarf2_abbrevs[hash_number];
4678 if (abbrev->number == number)
4681 abbrev = abbrev->next;
4686 /* Returns nonzero if TAG represents a type that we might generate a partial
4690 is_type_tag_for_partial (int tag)
4695 /* Some types that would be reasonable to generate partial symbols for,
4696 that we don't at present. */
4697 case DW_TAG_array_type:
4698 case DW_TAG_file_type:
4699 case DW_TAG_ptr_to_member_type:
4700 case DW_TAG_set_type:
4701 case DW_TAG_string_type:
4702 case DW_TAG_subroutine_type:
4704 case DW_TAG_base_type:
4705 case DW_TAG_class_type:
4706 case DW_TAG_enumeration_type:
4707 case DW_TAG_structure_type:
4708 case DW_TAG_subrange_type:
4709 case DW_TAG_typedef:
4710 case DW_TAG_union_type:
4717 /* Load all DIEs that are interesting for partial symbols into memory. */
4719 static struct partial_die_info *
4720 load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab,
4721 struct dwarf2_cu *cu)
4723 struct partial_die_info *part_die;
4724 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
4725 struct abbrev_info *abbrev;
4726 unsigned int bytes_read;
4728 int nesting_level = 1;
4734 = htab_create_alloc_ex (cu->header.length / 12,
4738 &cu->comp_unit_obstack,
4739 hashtab_obstack_allocate,
4740 dummy_obstack_deallocate);
4742 part_die = obstack_alloc (&cu->comp_unit_obstack,
4743 sizeof (struct partial_die_info));
4747 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4749 /* A NULL abbrev means the end of a series of children. */
4752 if (--nesting_level == 0)
4754 /* PART_DIE was probably the last thing allocated on the
4755 comp_unit_obstack, so we could call obstack_free
4756 here. We don't do that because the waste is small,
4757 and will be cleaned up when we're done with this
4758 compilation unit. This way, we're also more robust
4759 against other users of the comp_unit_obstack. */
4762 info_ptr += bytes_read;
4763 last_die = parent_die;
4764 parent_die = parent_die->die_parent;
4768 /* Check whether this DIE is interesting enough to save. */
4769 if (!is_type_tag_for_partial (abbrev->tag)
4770 && abbrev->tag != DW_TAG_enumerator
4771 && abbrev->tag != DW_TAG_subprogram
4772 && abbrev->tag != DW_TAG_variable
4773 && abbrev->tag != DW_TAG_namespace)
4775 /* Otherwise we skip to the next sibling, if any. */
4776 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
4780 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
4781 abfd, info_ptr, cu);
4783 /* This two-pass algorithm for processing partial symbols has a
4784 high cost in cache pressure. Thus, handle some simple cases
4785 here which cover the majority of C partial symbols. DIEs
4786 which neither have specification tags in them, nor could have
4787 specification tags elsewhere pointing at them, can simply be
4788 processed and discarded.
4790 This segment is also optional; scan_partial_symbols and
4791 add_partial_symbol will handle these DIEs if we chain
4792 them in normally. When compilers which do not emit large
4793 quantities of duplicate debug information are more common,
4794 this code can probably be removed. */
4796 /* Any complete simple types at the top level (pretty much all
4797 of them, for a language without namespaces), can be processed
4799 if (parent_die == NULL
4800 && part_die->has_specification == 0
4801 && part_die->is_declaration == 0
4802 && (part_die->tag == DW_TAG_typedef
4803 || part_die->tag == DW_TAG_base_type
4804 || part_die->tag == DW_TAG_subrange_type))
4806 if (building_psymtab && part_die->name != NULL)
4807 add_psymbol_to_list (part_die->name, strlen (part_die->name),
4808 VAR_DOMAIN, LOC_TYPEDEF,
4809 &cu->objfile->static_psymbols,
4810 0, (CORE_ADDR) 0, cu->language, cu->objfile);
4811 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
4815 /* If we're at the second level, and we're an enumerator, and
4816 our parent has no specification (meaning possibly lives in a
4817 namespace elsewhere), then we can add the partial symbol now
4818 instead of queueing it. */
4819 if (part_die->tag == DW_TAG_enumerator
4820 && parent_die != NULL
4821 && parent_die->die_parent == NULL
4822 && parent_die->tag == DW_TAG_enumeration_type
4823 && parent_die->has_specification == 0)
4825 if (part_die->name == NULL)
4826 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
4827 else if (building_psymtab)
4828 add_psymbol_to_list (part_die->name, strlen (part_die->name),
4829 VAR_DOMAIN, LOC_CONST,
4830 (cu->language == language_cplus
4831 || cu->language == language_java)
4832 ? &cu->objfile->global_psymbols
4833 : &cu->objfile->static_psymbols,
4834 0, (CORE_ADDR) 0, cu->language, cu->objfile);
4836 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
4840 /* We'll save this DIE so link it in. */
4841 part_die->die_parent = parent_die;
4842 part_die->die_sibling = NULL;
4843 part_die->die_child = NULL;
4845 if (last_die && last_die == parent_die)
4846 last_die->die_child = part_die;
4848 last_die->die_sibling = part_die;
4850 last_die = part_die;
4852 if (first_die == NULL)
4853 first_die = part_die;
4855 /* Maybe add the DIE to the hash table. Not all DIEs that we
4856 find interesting need to be in the hash table, because we
4857 also have the parent/sibling/child chains; only those that we
4858 might refer to by offset later during partial symbol reading.
4860 For now this means things that might have be the target of a
4861 DW_AT_specification, DW_AT_abstract_origin, or
4862 DW_AT_extension. DW_AT_extension will refer only to
4863 namespaces; DW_AT_abstract_origin refers to functions (and
4864 many things under the function DIE, but we do not recurse
4865 into function DIEs during partial symbol reading) and
4866 possibly variables as well; DW_AT_specification refers to
4867 declarations. Declarations ought to have the DW_AT_declaration
4868 flag. It happens that GCC forgets to put it in sometimes, but
4869 only for functions, not for types.
4871 Adding more things than necessary to the hash table is harmless
4872 except for the performance cost. Adding too few will result in
4873 internal errors in find_partial_die. */
4875 if (abbrev->tag == DW_TAG_subprogram
4876 || abbrev->tag == DW_TAG_variable
4877 || abbrev->tag == DW_TAG_namespace
4878 || part_die->is_declaration)
4882 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
4883 part_die->offset, INSERT);
4887 part_die = obstack_alloc (&cu->comp_unit_obstack,
4888 sizeof (struct partial_die_info));
4890 /* For some DIEs we want to follow their children (if any). For C
4891 we have no reason to follow the children of structures; for other
4892 languages we have to, both so that we can get at method physnames
4893 to infer fully qualified class names, and for DW_AT_specification. */
4894 if (last_die->has_children
4895 && (last_die->tag == DW_TAG_namespace
4896 || last_die->tag == DW_TAG_enumeration_type
4897 || (cu->language != language_c
4898 && (last_die->tag == DW_TAG_class_type
4899 || last_die->tag == DW_TAG_structure_type
4900 || last_die->tag == DW_TAG_union_type))))
4903 parent_die = last_die;
4907 /* Otherwise we skip to the next sibling, if any. */
4908 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
4910 /* Back to the top, do it again. */
4914 /* Read a minimal amount of information into the minimal die structure. */
4917 read_partial_die (struct partial_die_info *part_die,
4918 struct abbrev_info *abbrev,
4919 unsigned int abbrev_len, bfd *abfd,
4920 char *info_ptr, struct dwarf2_cu *cu)
4922 unsigned int bytes_read, i;
4923 struct attribute attr;
4924 int has_low_pc_attr = 0;
4925 int has_high_pc_attr = 0;
4927 memset (part_die, 0, sizeof (struct partial_die_info));
4929 part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer;
4931 info_ptr += abbrev_len;
4936 part_die->tag = abbrev->tag;
4937 part_die->has_children = abbrev->has_children;
4939 for (i = 0; i < abbrev->num_attrs; ++i)
4941 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4943 /* Store the data if it is of an attribute we want to keep in a
4944 partial symbol table. */
4949 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4950 if (part_die->name == NULL)
4951 part_die->name = DW_STRING (&attr);
4953 case DW_AT_comp_dir:
4954 if (part_die->dirname == NULL)
4955 part_die->dirname = DW_STRING (&attr);
4957 case DW_AT_MIPS_linkage_name:
4958 part_die->name = DW_STRING (&attr);
4961 has_low_pc_attr = 1;
4962 part_die->lowpc = DW_ADDR (&attr);
4965 has_high_pc_attr = 1;
4966 part_die->highpc = DW_ADDR (&attr);
4968 case DW_AT_location:
4969 /* Support the .debug_loc offsets */
4970 if (attr_form_is_block (&attr))
4972 part_die->locdesc = DW_BLOCK (&attr);
4974 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4976 dwarf2_complex_location_expr_complaint ();
4980 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4981 "partial symbol information");
4984 case DW_AT_language:
4985 part_die->language = DW_UNSND (&attr);
4987 case DW_AT_external:
4988 part_die->is_external = DW_UNSND (&attr);
4990 case DW_AT_declaration:
4991 part_die->is_declaration = DW_UNSND (&attr);
4994 part_die->has_type = 1;
4996 case DW_AT_abstract_origin:
4997 case DW_AT_specification:
4998 case DW_AT_extension:
4999 part_die->has_specification = 1;
5000 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu);
5003 /* Ignore absolute siblings, they might point outside of
5004 the current compile unit. */
5005 if (attr.form == DW_FORM_ref_addr)
5006 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
5008 part_die->sibling = dwarf2_per_objfile->info_buffer
5009 + dwarf2_get_ref_die_offset (&attr, cu);
5011 case DW_AT_stmt_list:
5012 part_die->has_stmt_list = 1;
5013 part_die->line_offset = DW_UNSND (&attr);
5020 /* When using the GNU linker, .gnu.linkonce. sections are used to
5021 eliminate duplicate copies of functions and vtables and such.
5022 The linker will arbitrarily choose one and discard the others.
5023 The AT_*_pc values for such functions refer to local labels in
5024 these sections. If the section from that file was discarded, the
5025 labels are not in the output, so the relocs get a value of 0.
5026 If this is a discarded function, mark the pc bounds as invalid,
5027 so that GDB will ignore it. */
5028 if (has_low_pc_attr && has_high_pc_attr
5029 && part_die->lowpc < part_die->highpc
5030 && (part_die->lowpc != 0
5031 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
5032 part_die->has_pc_info = 1;
5036 /* Find a cached partial DIE at OFFSET in CU. */
5038 static struct partial_die_info *
5039 find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu)
5041 struct partial_die_info *lookup_die = NULL;
5042 struct partial_die_info part_die;
5044 part_die.offset = offset;
5045 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
5047 if (lookup_die == NULL)
5048 internal_error (__FILE__, __LINE__,
5049 "could not find partial DIE in cache\n");
5054 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5056 static struct partial_die_info *
5057 find_partial_die (unsigned long offset, struct dwarf2_cu *cu,
5058 struct dwarf2_cu **target_cu)
5060 struct dwarf2_per_cu_data *per_cu;
5062 if (offset >= cu->header.offset
5063 && offset < cu->header.offset + cu->header.length)
5066 return find_partial_die_in_comp_unit (offset, cu);
5069 internal_error (__FILE__, __LINE__,
5070 "unsupported inter-compilation-unit reference");
5073 /* Adjust PART_DIE before generating a symbol for it. This function
5074 may set the is_external flag or change the DIE's name. */
5077 fixup_partial_die (struct partial_die_info *part_die,
5078 struct dwarf2_cu *cu)
5080 /* If we found a reference attribute and the DIE has no name, try
5081 to find a name in the referred to DIE. */
5083 if (part_die->name == NULL && part_die->has_specification)
5085 struct partial_die_info *spec_die;
5086 struct dwarf2_cu *spec_cu;
5088 spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu);
5090 fixup_partial_die (spec_die, spec_cu);
5094 part_die->name = spec_die->name;
5096 /* Copy DW_AT_external attribute if it is set. */
5097 if (spec_die->is_external)
5098 part_die->is_external = spec_die->is_external;
5102 /* Set default names for some unnamed DIEs. */
5103 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
5104 || part_die->tag == DW_TAG_class_type))
5105 part_die->name = "(anonymous class)";
5107 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
5108 part_die->name = "(anonymous namespace)";
5110 if (part_die->tag == DW_TAG_structure_type
5111 || part_die->tag == DW_TAG_class_type
5112 || part_die->tag == DW_TAG_union_type)
5113 guess_structure_name (part_die, cu);
5116 /* Read the die from the .debug_info section buffer. Set DIEP to
5117 point to a newly allocated die with its information, except for its
5118 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5119 whether the die has children or not. */
5122 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
5123 struct dwarf2_cu *cu, int *has_children)
5125 unsigned int abbrev_number, bytes_read, i, offset;
5126 struct abbrev_info *abbrev;
5127 struct die_info *die;
5129 offset = info_ptr - dwarf2_per_objfile->info_buffer;
5130 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5131 info_ptr += bytes_read;
5134 die = dwarf_alloc_die ();
5136 die->abbrev = abbrev_number;
5143 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
5146 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5148 bfd_get_filename (abfd));
5150 die = dwarf_alloc_die ();
5151 die->offset = offset;
5152 die->tag = abbrev->tag;
5153 die->abbrev = abbrev_number;
5156 die->num_attrs = abbrev->num_attrs;
5157 die->attrs = (struct attribute *)
5158 xmalloc (die->num_attrs * sizeof (struct attribute));
5160 for (i = 0; i < abbrev->num_attrs; ++i)
5162 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
5163 abfd, info_ptr, cu);
5167 *has_children = abbrev->has_children;
5171 /* Read an attribute value described by an attribute form. */
5174 read_attribute_value (struct attribute *attr, unsigned form,
5175 bfd *abfd, char *info_ptr,
5176 struct dwarf2_cu *cu)
5178 struct comp_unit_head *cu_header = &cu->header;
5179 unsigned int bytes_read;
5180 struct dwarf_block *blk;
5186 case DW_FORM_ref_addr:
5187 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
5188 info_ptr += bytes_read;
5190 case DW_FORM_block2:
5191 blk = dwarf_alloc_block (cu);
5192 blk->size = read_2_bytes (abfd, info_ptr);
5194 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5195 info_ptr += blk->size;
5196 DW_BLOCK (attr) = blk;
5198 case DW_FORM_block4:
5199 blk = dwarf_alloc_block (cu);
5200 blk->size = read_4_bytes (abfd, info_ptr);
5202 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5203 info_ptr += blk->size;
5204 DW_BLOCK (attr) = blk;
5207 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5211 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5215 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5218 case DW_FORM_string:
5219 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
5220 info_ptr += bytes_read;
5223 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
5225 info_ptr += bytes_read;
5228 blk = dwarf_alloc_block (cu);
5229 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5230 info_ptr += bytes_read;
5231 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5232 info_ptr += blk->size;
5233 DW_BLOCK (attr) = blk;
5235 case DW_FORM_block1:
5236 blk = dwarf_alloc_block (cu);
5237 blk->size = read_1_byte (abfd, info_ptr);
5239 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5240 info_ptr += blk->size;
5241 DW_BLOCK (attr) = blk;
5244 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5248 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5252 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
5253 info_ptr += bytes_read;
5256 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5257 info_ptr += bytes_read;
5260 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5264 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5268 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5272 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5275 case DW_FORM_ref_udata:
5276 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5277 info_ptr += bytes_read;
5279 case DW_FORM_indirect:
5280 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5281 info_ptr += bytes_read;
5282 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
5285 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5286 dwarf_form_name (form),
5287 bfd_get_filename (abfd));
5292 /* Read an attribute described by an abbreviated attribute. */
5295 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
5296 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
5298 attr->name = abbrev->name;
5299 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
5302 /* read dwarf information from a buffer */
5305 read_1_byte (bfd *abfd, char *buf)
5307 return bfd_get_8 (abfd, (bfd_byte *) buf);
5311 read_1_signed_byte (bfd *abfd, char *buf)
5313 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
5317 read_2_bytes (bfd *abfd, char *buf)
5319 return bfd_get_16 (abfd, (bfd_byte *) buf);
5323 read_2_signed_bytes (bfd *abfd, char *buf)
5325 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5329 read_4_bytes (bfd *abfd, char *buf)
5331 return bfd_get_32 (abfd, (bfd_byte *) buf);
5335 read_4_signed_bytes (bfd *abfd, char *buf)
5337 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5340 static unsigned long
5341 read_8_bytes (bfd *abfd, char *buf)
5343 return bfd_get_64 (abfd, (bfd_byte *) buf);
5347 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
5349 struct comp_unit_head *cu_header = &cu->header;
5350 CORE_ADDR retval = 0;
5352 if (cu_header->signed_addr_p)
5354 switch (cu_header->addr_size)
5357 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5360 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5363 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
5366 internal_error (__FILE__, __LINE__,
5367 "read_address: bad switch, signed [in module %s]",
5368 bfd_get_filename (abfd));
5373 switch (cu_header->addr_size)
5376 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
5379 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5382 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5385 internal_error (__FILE__, __LINE__,
5386 "read_address: bad switch, unsigned [in module %s]",
5387 bfd_get_filename (abfd));
5391 *bytes_read = cu_header->addr_size;
5395 /* Read the initial length from a section. The (draft) DWARF 3
5396 specification allows the initial length to take up either 4 bytes
5397 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5398 bytes describe the length and all offsets will be 8 bytes in length
5401 An older, non-standard 64-bit format is also handled by this
5402 function. The older format in question stores the initial length
5403 as an 8-byte quantity without an escape value. Lengths greater
5404 than 2^32 aren't very common which means that the initial 4 bytes
5405 is almost always zero. Since a length value of zero doesn't make
5406 sense for the 32-bit format, this initial zero can be considered to
5407 be an escape value which indicates the presence of the older 64-bit
5408 format. As written, the code can't detect (old format) lengths
5409 greater than 4GB. If it becomes necessary to handle lengths somewhat
5410 larger than 4GB, we could allow other small values (such as the
5411 non-sensical values of 1, 2, and 3) to also be used as escape values
5412 indicating the presence of the old format.
5414 The value returned via bytes_read should be used to increment
5415 the relevant pointer after calling read_initial_length().
5417 As a side effect, this function sets the fields initial_length_size
5418 and offset_size in cu_header to the values appropriate for the
5419 length field. (The format of the initial length field determines
5420 the width of file offsets to be fetched later with fetch_offset().)
5422 [ Note: read_initial_length() and read_offset() are based on the
5423 document entitled "DWARF Debugging Information Format", revision
5424 3, draft 8, dated November 19, 2001. This document was obtained
5427 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5429 This document is only a draft and is subject to change. (So beware.)
5431 Details regarding the older, non-standard 64-bit format were
5432 determined empirically by examining 64-bit ELF files produced
5433 by the SGI toolchain on an IRIX 6.5 machine.
5435 - Kevin, July 16, 2002
5439 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
5444 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5446 if (retval == 0xffffffff)
5448 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
5450 if (cu_header != NULL)
5452 cu_header->initial_length_size = 12;
5453 cu_header->offset_size = 8;
5456 else if (retval == 0)
5458 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5460 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5462 if (cu_header != NULL)
5464 cu_header->initial_length_size = 8;
5465 cu_header->offset_size = 8;
5471 if (cu_header != NULL)
5473 cu_header->initial_length_size = 4;
5474 cu_header->offset_size = 4;
5481 /* Read an offset from the data stream. The size of the offset is
5482 given by cu_header->offset_size. */
5485 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
5490 switch (cu_header->offset_size)
5493 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5497 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5501 internal_error (__FILE__, __LINE__,
5502 "read_offset: bad switch [in module %s]",
5503 bfd_get_filename (abfd));
5510 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
5512 /* If the size of a host char is 8 bits, we can return a pointer
5513 to the buffer, otherwise we have to copy the data to a buffer
5514 allocated on the temporary obstack. */
5515 gdb_assert (HOST_CHAR_BIT == 8);
5520 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5522 /* If the size of a host char is 8 bits, we can return a pointer
5523 to the string, otherwise we have to copy the string to a buffer
5524 allocated on the temporary obstack. */
5525 gdb_assert (HOST_CHAR_BIT == 8);
5528 *bytes_read_ptr = 1;
5531 *bytes_read_ptr = strlen (buf) + 1;
5536 read_indirect_string (bfd *abfd, char *buf,
5537 const struct comp_unit_head *cu_header,
5538 unsigned int *bytes_read_ptr)
5540 LONGEST str_offset = read_offset (abfd, buf, cu_header,
5541 (int *) bytes_read_ptr);
5543 if (dwarf2_per_objfile->str_buffer == NULL)
5545 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5546 bfd_get_filename (abfd));
5549 if (str_offset >= dwarf2_per_objfile->str_size)
5551 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5552 bfd_get_filename (abfd));
5555 gdb_assert (HOST_CHAR_BIT == 8);
5556 if (dwarf2_per_objfile->str_buffer[str_offset] == '\0')
5558 return dwarf2_per_objfile->str_buffer + str_offset;
5561 static unsigned long
5562 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5564 unsigned long result;
5565 unsigned int num_read;
5575 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5578 result |= ((unsigned long)(byte & 127) << shift);
5579 if ((byte & 128) == 0)
5585 *bytes_read_ptr = num_read;
5590 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5593 int i, shift, size, num_read;
5603 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5606 result |= ((long)(byte & 127) << shift);
5608 if ((byte & 128) == 0)
5613 if ((shift < size) && (byte & 0x40))
5615 result |= -(1 << shift);
5617 *bytes_read_ptr = num_read;
5621 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5624 skip_leb128 (bfd *abfd, char *buf)
5630 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5632 if ((byte & 128) == 0)
5638 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
5644 cu->language = language_c;
5646 case DW_LANG_C_plus_plus:
5647 cu->language = language_cplus;
5649 case DW_LANG_Fortran77:
5650 case DW_LANG_Fortran90:
5651 case DW_LANG_Fortran95:
5652 cu->language = language_fortran;
5654 case DW_LANG_Mips_Assembler:
5655 cu->language = language_asm;
5658 cu->language = language_java;
5662 case DW_LANG_Cobol74:
5663 case DW_LANG_Cobol85:
5664 case DW_LANG_Pascal83:
5665 case DW_LANG_Modula2:
5667 cu->language = language_minimal;
5670 cu->language_defn = language_def (cu->language);
5673 /* Return the named attribute or NULL if not there. */
5675 static struct attribute *
5676 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
5679 struct attribute *spec = NULL;
5681 for (i = 0; i < die->num_attrs; ++i)
5683 if (die->attrs[i].name == name)
5685 return &die->attrs[i];
5687 if (die->attrs[i].name == DW_AT_specification
5688 || die->attrs[i].name == DW_AT_abstract_origin)
5689 spec = &die->attrs[i];
5693 struct die_info *ref_die =
5694 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
5697 return dwarf2_attr (ref_die, name, cu);
5703 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5704 and holds a non-zero value. This function should only be used for
5705 DW_FORM_flag attributes. */
5708 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
5710 struct attribute *attr = dwarf2_attr (die, name, cu);
5712 return (attr && DW_UNSND (attr));
5716 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5718 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5719 which value is non-zero. However, we have to be careful with
5720 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5721 (via dwarf2_flag_true_p) follows this attribute. So we may
5722 end up accidently finding a declaration attribute that belongs
5723 to a different DIE referenced by the specification attribute,
5724 even though the given DIE does not have a declaration attribute. */
5725 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
5726 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
5729 /* Return the die giving the specification for DIE, if there is
5732 static struct die_info *
5733 die_specification (struct die_info *die, struct dwarf2_cu *cu)
5735 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
5737 if (spec_attr == NULL)
5740 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
5743 /* Free the line_header structure *LH, and any arrays and strings it
5746 free_line_header (struct line_header *lh)
5748 if (lh->standard_opcode_lengths)
5749 xfree (lh->standard_opcode_lengths);
5751 /* Remember that all the lh->file_names[i].name pointers are
5752 pointers into debug_line_buffer, and don't need to be freed. */
5754 xfree (lh->file_names);
5756 /* Similarly for the include directory names. */
5757 if (lh->include_dirs)
5758 xfree (lh->include_dirs);
5764 /* Add an entry to LH's include directory table. */
5766 add_include_dir (struct line_header *lh, char *include_dir)
5768 /* Grow the array if necessary. */
5769 if (lh->include_dirs_size == 0)
5771 lh->include_dirs_size = 1; /* for testing */
5772 lh->include_dirs = xmalloc (lh->include_dirs_size
5773 * sizeof (*lh->include_dirs));
5775 else if (lh->num_include_dirs >= lh->include_dirs_size)
5777 lh->include_dirs_size *= 2;
5778 lh->include_dirs = xrealloc (lh->include_dirs,
5779 (lh->include_dirs_size
5780 * sizeof (*lh->include_dirs)));
5783 lh->include_dirs[lh->num_include_dirs++] = include_dir;
5787 /* Add an entry to LH's file name table. */
5789 add_file_name (struct line_header *lh,
5791 unsigned int dir_index,
5792 unsigned int mod_time,
5793 unsigned int length)
5795 struct file_entry *fe;
5797 /* Grow the array if necessary. */
5798 if (lh->file_names_size == 0)
5800 lh->file_names_size = 1; /* for testing */
5801 lh->file_names = xmalloc (lh->file_names_size
5802 * sizeof (*lh->file_names));
5804 else if (lh->num_file_names >= lh->file_names_size)
5806 lh->file_names_size *= 2;
5807 lh->file_names = xrealloc (lh->file_names,
5808 (lh->file_names_size
5809 * sizeof (*lh->file_names)));
5812 fe = &lh->file_names[lh->num_file_names++];
5814 fe->dir_index = dir_index;
5815 fe->mod_time = mod_time;
5816 fe->length = length;
5821 /* Read the statement program header starting at OFFSET in
5822 .debug_line, according to the endianness of ABFD. Return a pointer
5823 to a struct line_header, allocated using xmalloc.
5825 NOTE: the strings in the include directory and file name tables of
5826 the returned object point into debug_line_buffer, and must not be
5828 static struct line_header *
5829 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5830 struct dwarf2_cu *cu)
5832 struct cleanup *back_to;
5833 struct line_header *lh;
5837 char *cur_dir, *cur_file;
5839 if (dwarf2_per_objfile->line_buffer == NULL)
5841 complaint (&symfile_complaints, "missing .debug_line section");
5845 /* Make sure that at least there's room for the total_length field. That
5846 could be 12 bytes long, but we're just going to fudge that. */
5847 if (offset + 4 >= dwarf2_per_objfile->line_size)
5849 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5853 lh = xmalloc (sizeof (*lh));
5854 memset (lh, 0, sizeof (*lh));
5855 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5858 line_ptr = dwarf2_per_objfile->line_buffer + offset;
5860 /* read in the header */
5861 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
5862 line_ptr += bytes_read;
5863 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer
5864 + dwarf2_per_objfile->line_size))
5866 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5869 lh->statement_program_end = line_ptr + lh->total_length;
5870 lh->version = read_2_bytes (abfd, line_ptr);
5872 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5873 line_ptr += bytes_read;
5874 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5876 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5878 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5880 lh->line_range = read_1_byte (abfd, line_ptr);
5882 lh->opcode_base = read_1_byte (abfd, line_ptr);
5884 lh->standard_opcode_lengths
5885 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5887 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5888 for (i = 1; i < lh->opcode_base; ++i)
5890 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5894 /* Read directory table */
5895 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5897 line_ptr += bytes_read;
5898 add_include_dir (lh, cur_dir);
5900 line_ptr += bytes_read;
5902 /* Read file name table */
5903 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5905 unsigned int dir_index, mod_time, length;
5907 line_ptr += bytes_read;
5908 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5909 line_ptr += bytes_read;
5910 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5911 line_ptr += bytes_read;
5912 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5913 line_ptr += bytes_read;
5915 add_file_name (lh, cur_file, dir_index, mod_time, length);
5917 line_ptr += bytes_read;
5918 lh->statement_program_start = line_ptr;
5920 if (line_ptr > (dwarf2_per_objfile->line_buffer
5921 + dwarf2_per_objfile->line_size))
5922 complaint (&symfile_complaints,
5923 "line number info header doesn't fit in `.debug_line' section");
5925 discard_cleanups (back_to);
5929 /* This function exists to work around a bug in certain compilers
5930 (particularly GCC 2.95), in which the first line number marker of a
5931 function does not show up until after the prologue, right before
5932 the second line number marker. This function shifts ADDRESS down
5933 to the beginning of the function if necessary, and is called on
5934 addresses passed to record_line. */
5937 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
5939 struct function_range *fn;
5941 /* Find the function_range containing address. */
5946 cu->cached_fn = cu->first_fn;
5950 if (fn->lowpc <= address && fn->highpc > address)
5956 while (fn && fn != cu->cached_fn)
5957 if (fn->lowpc <= address && fn->highpc > address)
5967 if (address != fn->lowpc)
5968 complaint (&symfile_complaints,
5969 "misplaced first line number at 0x%lx for '%s'",
5970 (unsigned long) address, fn->name);
5975 /* Decode the Line Number Program (LNP) for the given line_header
5976 structure and CU. The actual information extracted and the type
5977 of structures created from the LNP depends on the value of PST.
5979 1. If PST is NULL, then this procedure uses the data from the program
5980 to create all necessary symbol tables, and their linetables.
5981 The compilation directory of the file is passed in COMP_DIR,
5982 and must not be NULL.
5984 2. If PST is not NULL, this procedure reads the program to determine
5985 the list of files included by the unit represented by PST, and
5986 builds all the associated partial symbol tables. In this case,
5987 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
5988 is not used to compute the full name of the symtab, and therefore
5989 omitting it when building the partial symtab does not introduce
5990 the potential for inconsistency - a partial symtab and its associated
5991 symbtab having a different fullname -). */
5994 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5995 struct dwarf2_cu *cu, struct partial_symtab *pst)
5999 unsigned int bytes_read;
6000 unsigned char op_code, extended_op, adj_opcode;
6002 struct objfile *objfile = cu->objfile;
6003 const int decode_for_pst_p = (pst != NULL);
6005 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6007 line_ptr = lh->statement_program_start;
6008 line_end = lh->statement_program_end;
6010 /* Read the statement sequences until there's nothing left. */
6011 while (line_ptr < line_end)
6013 /* state machine registers */
6014 CORE_ADDR address = 0;
6015 unsigned int file = 1;
6016 unsigned int line = 1;
6017 unsigned int column = 0;
6018 int is_stmt = lh->default_is_stmt;
6019 int basic_block = 0;
6020 int end_sequence = 0;
6022 if (!decode_for_pst_p && lh->num_file_names >= file)
6024 /* Start a subfile for the current file of the state machine. */
6025 /* lh->include_dirs and lh->file_names are 0-based, but the
6026 directory and file name numbers in the statement program
6028 struct file_entry *fe = &lh->file_names[file - 1];
6031 dir = lh->include_dirs[fe->dir_index - 1];
6034 dwarf2_start_subfile (fe->name, dir);
6037 /* Decode the table. */
6038 while (!end_sequence)
6040 op_code = read_1_byte (abfd, line_ptr);
6043 if (op_code >= lh->opcode_base)
6044 { /* Special operand. */
6045 adj_opcode = op_code - lh->opcode_base;
6046 address += (adj_opcode / lh->line_range)
6047 * lh->minimum_instruction_length;
6048 line += lh->line_base + (adj_opcode % lh->line_range);
6049 lh->file_names[file - 1].included_p = 1;
6050 if (!decode_for_pst_p)
6052 /* append row to matrix using current values */
6053 record_line (current_subfile, line,
6054 check_cu_functions (address, cu));
6058 else switch (op_code)
6060 case DW_LNS_extended_op:
6061 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6062 line_ptr += bytes_read;
6063 extended_op = read_1_byte (abfd, line_ptr);
6065 switch (extended_op)
6067 case DW_LNE_end_sequence:
6069 lh->file_names[file - 1].included_p = 1;
6070 if (!decode_for_pst_p)
6071 record_line (current_subfile, 0, address);
6073 case DW_LNE_set_address:
6074 address = read_address (abfd, line_ptr, cu, &bytes_read);
6075 line_ptr += bytes_read;
6076 address += baseaddr;
6078 case DW_LNE_define_file:
6081 unsigned int dir_index, mod_time, length;
6083 cur_file = read_string (abfd, line_ptr, &bytes_read);
6084 line_ptr += bytes_read;
6086 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6087 line_ptr += bytes_read;
6089 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6090 line_ptr += bytes_read;
6092 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6093 line_ptr += bytes_read;
6094 add_file_name (lh, cur_file, dir_index, mod_time, length);
6098 complaint (&symfile_complaints,
6099 "mangled .debug_line section");
6104 lh->file_names[file - 1].included_p = 1;
6105 if (!decode_for_pst_p)
6106 record_line (current_subfile, line,
6107 check_cu_functions (address, cu));
6110 case DW_LNS_advance_pc:
6111 address += lh->minimum_instruction_length
6112 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6113 line_ptr += bytes_read;
6115 case DW_LNS_advance_line:
6116 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
6117 line_ptr += bytes_read;
6119 case DW_LNS_set_file:
6121 /* lh->include_dirs and lh->file_names are 0-based,
6122 but the directory and file name numbers in the
6123 statement program are 1-based. */
6124 struct file_entry *fe;
6126 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6127 line_ptr += bytes_read;
6128 fe = &lh->file_names[file - 1];
6130 dir = lh->include_dirs[fe->dir_index - 1];
6133 if (!decode_for_pst_p)
6134 dwarf2_start_subfile (fe->name, dir);
6137 case DW_LNS_set_column:
6138 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6139 line_ptr += bytes_read;
6141 case DW_LNS_negate_stmt:
6142 is_stmt = (!is_stmt);
6144 case DW_LNS_set_basic_block:
6147 /* Add to the address register of the state machine the
6148 address increment value corresponding to special opcode
6149 255. Ie, this value is scaled by the minimum instruction
6150 length since special opcode 255 would have scaled the
6152 case DW_LNS_const_add_pc:
6153 address += (lh->minimum_instruction_length
6154 * ((255 - lh->opcode_base) / lh->line_range));
6156 case DW_LNS_fixed_advance_pc:
6157 address += read_2_bytes (abfd, line_ptr);
6161 { /* Unknown standard opcode, ignore it. */
6163 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
6165 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6166 line_ptr += bytes_read;
6173 if (decode_for_pst_p)
6177 /* Now that we're done scanning the Line Header Program, we can
6178 create the psymtab of each included file. */
6179 for (file_index = 0; file_index < lh->num_file_names; file_index++)
6180 if (lh->file_names[file_index].included_p == 1)
6182 char *include_name = lh->file_names [file_index].name;
6184 if (strcmp (include_name, pst->filename) != 0)
6185 dwarf2_create_include_psymtab (include_name, pst, objfile);
6190 /* Start a subfile for DWARF. FILENAME is the name of the file and
6191 DIRNAME the name of the source directory which contains FILENAME
6192 or NULL if not known.
6193 This routine tries to keep line numbers from identical absolute and
6194 relative file names in a common subfile.
6196 Using the `list' example from the GDB testsuite, which resides in
6197 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6198 of /srcdir/list0.c yields the following debugging information for list0.c:
6200 DW_AT_name: /srcdir/list0.c
6201 DW_AT_comp_dir: /compdir
6202 files.files[0].name: list0.h
6203 files.files[0].dir: /srcdir
6204 files.files[1].name: list0.c
6205 files.files[1].dir: /srcdir
6207 The line number information for list0.c has to end up in a single
6208 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6211 dwarf2_start_subfile (char *filename, char *dirname)
6213 /* If the filename isn't absolute, try to match an existing subfile
6214 with the full pathname. */
6216 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
6218 struct subfile *subfile;
6219 char *fullname = concat (dirname, "/", filename, NULL);
6221 for (subfile = subfiles; subfile; subfile = subfile->next)
6223 if (FILENAME_CMP (subfile->name, fullname) == 0)
6225 current_subfile = subfile;
6232 start_subfile (filename, dirname);
6236 var_decode_location (struct attribute *attr, struct symbol *sym,
6237 struct dwarf2_cu *cu)
6239 struct objfile *objfile = cu->objfile;
6240 struct comp_unit_head *cu_header = &cu->header;
6242 /* NOTE drow/2003-01-30: There used to be a comment and some special
6243 code here to turn a symbol with DW_AT_external and a
6244 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6245 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6246 with some versions of binutils) where shared libraries could have
6247 relocations against symbols in their debug information - the
6248 minimal symbol would have the right address, but the debug info
6249 would not. It's no longer necessary, because we will explicitly
6250 apply relocations when we read in the debug information now. */
6252 /* A DW_AT_location attribute with no contents indicates that a
6253 variable has been optimized away. */
6254 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
6256 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
6260 /* Handle one degenerate form of location expression specially, to
6261 preserve GDB's previous behavior when section offsets are
6262 specified. If this is just a DW_OP_addr then mark this symbol
6265 if (attr_form_is_block (attr)
6266 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
6267 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
6271 SYMBOL_VALUE_ADDRESS (sym) =
6272 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
6273 fixup_symbol_section (sym, objfile);
6274 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
6275 SYMBOL_SECTION (sym));
6276 SYMBOL_CLASS (sym) = LOC_STATIC;
6280 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6281 expression evaluator, and use LOC_COMPUTED only when necessary
6282 (i.e. when the value of a register or memory location is
6283 referenced, or a thread-local block, etc.). Then again, it might
6284 not be worthwhile. I'm assuming that it isn't unless performance
6285 or memory numbers show me otherwise. */
6287 dwarf2_symbol_mark_computed (attr, sym, cu);
6288 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6291 /* Given a pointer to a DWARF information entry, figure out if we need
6292 to make a symbol table entry for it, and if so, create a new entry
6293 and return a pointer to it.
6294 If TYPE is NULL, determine symbol type from the die, otherwise
6295 used the passed type. */
6297 static struct symbol *
6298 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6300 struct objfile *objfile = cu->objfile;
6301 struct symbol *sym = NULL;
6303 struct attribute *attr = NULL;
6304 struct attribute *attr2 = NULL;
6307 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6309 if (die->tag != DW_TAG_namespace)
6310 name = dwarf2_linkage_name (die, cu);
6312 name = TYPE_NAME (type);
6316 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6317 sizeof (struct symbol));
6318 OBJSTAT (objfile, n_syms++);
6319 memset (sym, 0, sizeof (struct symbol));
6321 /* Cache this symbol's name and the name's demangled form (if any). */
6322 SYMBOL_LANGUAGE (sym) = cu->language;
6323 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6325 /* Default assumptions.
6326 Use the passed type or decode it from the die. */
6327 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6328 SYMBOL_CLASS (sym) = LOC_STATIC;
6330 SYMBOL_TYPE (sym) = type;
6332 SYMBOL_TYPE (sym) = die_type (die, cu);
6333 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
6336 SYMBOL_LINE (sym) = DW_UNSND (attr);
6341 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6344 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
6346 SYMBOL_CLASS (sym) = LOC_LABEL;
6348 case DW_TAG_subprogram:
6349 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6351 SYMBOL_CLASS (sym) = LOC_BLOCK;
6352 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6353 if (attr2 && (DW_UNSND (attr2) != 0))
6355 add_symbol_to_list (sym, &global_symbols);
6359 add_symbol_to_list (sym, cu->list_in_scope);
6362 case DW_TAG_variable:
6363 /* Compilation with minimal debug info may result in variables
6364 with missing type entries. Change the misleading `void' type
6365 to something sensible. */
6366 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
6367 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
6368 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
6369 "<variable, no debug info>",
6371 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6374 dwarf2_const_value (attr, sym, cu);
6375 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6376 if (attr2 && (DW_UNSND (attr2) != 0))
6377 add_symbol_to_list (sym, &global_symbols);
6379 add_symbol_to_list (sym, cu->list_in_scope);
6382 attr = dwarf2_attr (die, DW_AT_location, cu);
6385 var_decode_location (attr, sym, cu);
6386 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6387 if (attr2 && (DW_UNSND (attr2) != 0))
6388 add_symbol_to_list (sym, &global_symbols);
6390 add_symbol_to_list (sym, cu->list_in_scope);
6394 /* We do not know the address of this symbol.
6395 If it is an external symbol and we have type information
6396 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6397 The address of the variable will then be determined from
6398 the minimal symbol table whenever the variable is
6400 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6401 if (attr2 && (DW_UNSND (attr2) != 0)
6402 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
6404 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6405 add_symbol_to_list (sym, &global_symbols);
6409 case DW_TAG_formal_parameter:
6410 attr = dwarf2_attr (die, DW_AT_location, cu);
6413 var_decode_location (attr, sym, cu);
6414 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6415 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
6416 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
6418 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6421 dwarf2_const_value (attr, sym, cu);
6423 add_symbol_to_list (sym, cu->list_in_scope);
6425 case DW_TAG_unspecified_parameters:
6426 /* From varargs functions; gdb doesn't seem to have any
6427 interest in this information, so just ignore it for now.
6430 case DW_TAG_class_type:
6431 case DW_TAG_structure_type:
6432 case DW_TAG_union_type:
6433 case DW_TAG_enumeration_type:
6434 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6435 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6437 /* Make sure that the symbol includes appropriate enclosing
6438 classes/namespaces in its name. These are calculated in
6439 read_structure_type, and the correct name is saved in
6442 if (cu->language == language_cplus
6443 || cu->language == language_java)
6445 struct type *type = SYMBOL_TYPE (sym);
6447 if (TYPE_TAG_NAME (type) != NULL)
6449 /* FIXME: carlton/2003-11-10: Should this use
6450 SYMBOL_SET_NAMES instead? (The same problem also
6451 arises further down in this function.) */
6452 /* The type's name is already allocated along with
6453 this objfile, so we don't need to duplicate it
6455 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
6460 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6461 really ever be static objects: otherwise, if you try
6462 to, say, break of a class's method and you're in a file
6463 which doesn't mention that class, it won't work unless
6464 the check for all static symbols in lookup_symbol_aux
6465 saves you. See the OtherFileClass tests in
6466 gdb.c++/namespace.exp. */
6468 struct pending **list_to_add;
6470 list_to_add = (cu->list_in_scope == &file_symbols
6471 && (cu->language == language_cplus
6472 || cu->language == language_java)
6473 ? &global_symbols : cu->list_in_scope);
6475 add_symbol_to_list (sym, list_to_add);
6477 /* The semantics of C++ state that "struct foo { ... }" also
6478 defines a typedef for "foo". A Java class declaration also
6479 defines a typedef for the class. Synthesize a typedef symbol
6480 so that "ptype foo" works as expected. */
6481 if (cu->language == language_cplus
6482 || cu->language == language_java)
6484 struct symbol *typedef_sym = (struct symbol *)
6485 obstack_alloc (&objfile->objfile_obstack,
6486 sizeof (struct symbol));
6487 *typedef_sym = *sym;
6488 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
6489 /* The symbol's name is already allocated along with
6490 this objfile, so we don't need to duplicate it for
6492 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
6493 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym);
6494 add_symbol_to_list (typedef_sym, list_to_add);
6498 case DW_TAG_typedef:
6499 if (processing_has_namespace_info
6500 && processing_current_prefix[0] != '\0')
6502 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6503 processing_current_prefix,
6506 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6507 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6508 add_symbol_to_list (sym, cu->list_in_scope);
6510 case DW_TAG_base_type:
6511 case DW_TAG_subrange_type:
6512 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6513 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6514 add_symbol_to_list (sym, cu->list_in_scope);
6516 case DW_TAG_enumerator:
6517 if (processing_has_namespace_info
6518 && processing_current_prefix[0] != '\0')
6520 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6521 processing_current_prefix,
6524 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6527 dwarf2_const_value (attr, sym, cu);
6530 /* NOTE: carlton/2003-11-10: See comment above in the
6531 DW_TAG_class_type, etc. block. */
6533 struct pending **list_to_add;
6535 list_to_add = (cu->list_in_scope == &file_symbols
6536 && (cu->language == language_cplus
6537 || cu->language == language_java)
6538 ? &global_symbols : cu->list_in_scope);
6540 add_symbol_to_list (sym, list_to_add);
6543 case DW_TAG_namespace:
6544 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6545 add_symbol_to_list (sym, &global_symbols);
6548 /* Not a tag we recognize. Hopefully we aren't processing
6549 trash data, but since we must specifically ignore things
6550 we don't recognize, there is nothing else we should do at
6552 complaint (&symfile_complaints, "unsupported tag: '%s'",
6553 dwarf_tag_name (die->tag));
6560 /* Copy constant value from an attribute to a symbol. */
6563 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
6564 struct dwarf2_cu *cu)
6566 struct objfile *objfile = cu->objfile;
6567 struct comp_unit_head *cu_header = &cu->header;
6568 struct dwarf_block *blk;
6573 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
6574 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6575 cu_header->addr_size,
6576 TYPE_LENGTH (SYMBOL_TYPE
6578 SYMBOL_VALUE_BYTES (sym) = (char *)
6579 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
6580 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6581 it's body - store_unsigned_integer. */
6582 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
6584 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6586 case DW_FORM_block1:
6587 case DW_FORM_block2:
6588 case DW_FORM_block4:
6590 blk = DW_BLOCK (attr);
6591 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
6592 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6594 TYPE_LENGTH (SYMBOL_TYPE
6596 SYMBOL_VALUE_BYTES (sym) = (char *)
6597 obstack_alloc (&objfile->objfile_obstack, blk->size);
6598 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
6599 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6602 /* The DW_AT_const_value attributes are supposed to carry the
6603 symbol's value "represented as it would be on the target
6604 architecture." By the time we get here, it's already been
6605 converted to host endianness, so we just need to sign- or
6606 zero-extend it as appropriate. */
6608 dwarf2_const_value_data (attr, sym, 8);
6611 dwarf2_const_value_data (attr, sym, 16);
6614 dwarf2_const_value_data (attr, sym, 32);
6617 dwarf2_const_value_data (attr, sym, 64);
6621 SYMBOL_VALUE (sym) = DW_SND (attr);
6622 SYMBOL_CLASS (sym) = LOC_CONST;
6626 SYMBOL_VALUE (sym) = DW_UNSND (attr);
6627 SYMBOL_CLASS (sym) = LOC_CONST;
6631 complaint (&symfile_complaints,
6632 "unsupported const value attribute form: '%s'",
6633 dwarf_form_name (attr->form));
6634 SYMBOL_VALUE (sym) = 0;
6635 SYMBOL_CLASS (sym) = LOC_CONST;
6641 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6642 or zero-extend it as appropriate for the symbol's type. */
6644 dwarf2_const_value_data (struct attribute *attr,
6648 LONGEST l = DW_UNSND (attr);
6650 if (bits < sizeof (l) * 8)
6652 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
6653 l &= ((LONGEST) 1 << bits) - 1;
6655 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
6658 SYMBOL_VALUE (sym) = l;
6659 SYMBOL_CLASS (sym) = LOC_CONST;
6663 /* Return the type of the die in question using its DW_AT_type attribute. */
6665 static struct type *
6666 die_type (struct die_info *die, struct dwarf2_cu *cu)
6669 struct attribute *type_attr;
6670 struct die_info *type_die;
6673 type_attr = dwarf2_attr (die, DW_AT_type, cu);
6676 /* A missing DW_AT_type represents a void type. */
6677 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
6681 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6682 type_die = follow_die_ref (ref);
6685 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6686 ref, cu->objfile->name);
6690 type = tag_type_to_type (type_die, cu);
6693 dump_die (type_die);
6694 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6700 /* Return the containing type of the die in question using its
6701 DW_AT_containing_type attribute. */
6703 static struct type *
6704 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
6706 struct type *type = NULL;
6707 struct attribute *type_attr;
6708 struct die_info *type_die = NULL;
6711 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
6714 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6715 type_die = follow_die_ref (ref);
6718 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
6722 type = tag_type_to_type (type_die, cu);
6727 dump_die (type_die);
6728 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6735 static struct type *
6736 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
6738 struct die_info *die;
6741 die = follow_die_ref (offset);
6744 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
6747 type = tag_type_to_type (die, cu);
6752 static struct type *
6753 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
6761 read_type_die (die, cu);
6765 error ("Dwarf Error: Cannot find type of die [in module %s]",
6773 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6775 char *prefix = determine_prefix (die, cu);
6776 const char *old_prefix = processing_current_prefix;
6777 struct cleanup *back_to = make_cleanup (xfree, prefix);
6778 processing_current_prefix = prefix;
6782 case DW_TAG_class_type:
6783 case DW_TAG_structure_type:
6784 case DW_TAG_union_type:
6785 read_structure_type (die, cu);
6787 case DW_TAG_enumeration_type:
6788 read_enumeration_type (die, cu);
6790 case DW_TAG_subprogram:
6791 case DW_TAG_subroutine_type:
6792 read_subroutine_type (die, cu);
6794 case DW_TAG_array_type:
6795 read_array_type (die, cu);
6797 case DW_TAG_pointer_type:
6798 read_tag_pointer_type (die, cu);
6800 case DW_TAG_ptr_to_member_type:
6801 read_tag_ptr_to_member_type (die, cu);
6803 case DW_TAG_reference_type:
6804 read_tag_reference_type (die, cu);
6806 case DW_TAG_const_type:
6807 read_tag_const_type (die, cu);
6809 case DW_TAG_volatile_type:
6810 read_tag_volatile_type (die, cu);
6812 case DW_TAG_string_type:
6813 read_tag_string_type (die, cu);
6815 case DW_TAG_typedef:
6816 read_typedef (die, cu);
6818 case DW_TAG_subrange_type:
6819 read_subrange_type (die, cu);
6821 case DW_TAG_base_type:
6822 read_base_type (die, cu);
6825 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
6826 dwarf_tag_name (die->tag));
6830 processing_current_prefix = old_prefix;
6831 do_cleanups (back_to);
6834 /* Return the name of the namespace/class that DIE is defined within,
6835 or "" if we can't tell. The caller should xfree the result. */
6837 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6838 therein) for an example of how to use this function to deal with
6839 DW_AT_specification. */
6842 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6844 struct die_info *parent;
6846 if (cu->language != language_cplus
6847 && cu->language != language_java)
6850 parent = die->parent;
6854 return xstrdup ("");
6858 switch (parent->tag) {
6859 case DW_TAG_namespace:
6861 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6862 before doing this check? */
6863 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6865 return xstrdup (TYPE_TAG_NAME (parent->type));
6870 char *parent_prefix = determine_prefix (parent, cu);
6871 char *retval = typename_concat (NULL, parent_prefix,
6872 namespace_name (parent, &dummy,
6875 xfree (parent_prefix);
6880 case DW_TAG_class_type:
6881 case DW_TAG_structure_type:
6883 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6885 return xstrdup (TYPE_TAG_NAME (parent->type));
6889 const char *old_prefix = processing_current_prefix;
6890 char *new_prefix = determine_prefix (parent, cu);
6893 processing_current_prefix = new_prefix;
6894 retval = determine_class_name (parent, cu);
6895 processing_current_prefix = old_prefix;
6902 return determine_prefix (parent, cu);
6907 /* Return a newly-allocated string formed by concatenating PREFIX and
6908 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
6909 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
6910 perform an obconcat, otherwise allocate storage for the result. The CU argument
6911 is used to determine the language and hence, the appropriate separator. */
6913 #define MAX_SEP_LEN 2 /* sizeof ("::") */
6916 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
6917 struct dwarf2_cu *cu)
6921 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
6923 else if (cu->language == language_java)
6930 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
6935 strcpy (retval, prefix);
6936 strcat (retval, sep);
6939 strcat (retval, suffix);
6945 /* We have an obstack. */
6946 return obconcat (obs, prefix, sep, suffix);
6950 static struct type *
6951 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6953 struct objfile *objfile = cu->objfile;
6955 /* FIXME - this should not produce a new (struct type *)
6956 every time. It should cache base types. */
6960 case DW_ATE_address:
6961 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
6963 case DW_ATE_boolean:
6964 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
6966 case DW_ATE_complex_float:
6969 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
6973 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
6979 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
6983 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
6990 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6993 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
6997 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7001 case DW_ATE_signed_char:
7002 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
7004 case DW_ATE_unsigned:
7008 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7011 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
7015 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
7019 case DW_ATE_unsigned_char:
7020 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7023 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7030 copy_die (struct die_info *old_die)
7032 struct die_info *new_die;
7035 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
7036 memset (new_die, 0, sizeof (struct die_info));
7038 new_die->tag = old_die->tag;
7039 new_die->has_children = old_die->has_children;
7040 new_die->abbrev = old_die->abbrev;
7041 new_die->offset = old_die->offset;
7042 new_die->type = NULL;
7044 num_attrs = old_die->num_attrs;
7045 new_die->num_attrs = num_attrs;
7046 new_die->attrs = (struct attribute *)
7047 xmalloc (num_attrs * sizeof (struct attribute));
7049 for (i = 0; i < old_die->num_attrs; ++i)
7051 new_die->attrs[i].name = old_die->attrs[i].name;
7052 new_die->attrs[i].form = old_die->attrs[i].form;
7053 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
7056 new_die->next = NULL;
7061 /* Return sibling of die, NULL if no sibling. */
7063 static struct die_info *
7064 sibling_die (struct die_info *die)
7066 return die->sibling;
7069 /* Get linkage name of a die, return NULL if not found. */
7072 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7074 struct attribute *attr;
7076 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7077 if (attr && DW_STRING (attr))
7078 return DW_STRING (attr);
7079 attr = dwarf2_attr (die, DW_AT_name, cu);
7080 if (attr && DW_STRING (attr))
7081 return DW_STRING (attr);
7085 /* Get name of a die, return NULL if not found. */
7088 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
7090 struct attribute *attr;
7092 attr = dwarf2_attr (die, DW_AT_name, cu);
7093 if (attr && DW_STRING (attr))
7094 return DW_STRING (attr);
7098 /* Return the die that this die in an extension of, or NULL if there
7101 static struct die_info *
7102 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
7104 struct attribute *attr;
7105 struct die_info *extension_die;
7108 attr = dwarf2_attr (die, DW_AT_extension, cu);
7112 ref = dwarf2_get_ref_die_offset (attr, cu);
7113 extension_die = follow_die_ref (ref);
7116 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
7119 return extension_die;
7122 /* Convert a DIE tag into its string name. */
7125 dwarf_tag_name (unsigned tag)
7129 case DW_TAG_padding:
7130 return "DW_TAG_padding";
7131 case DW_TAG_array_type:
7132 return "DW_TAG_array_type";
7133 case DW_TAG_class_type:
7134 return "DW_TAG_class_type";
7135 case DW_TAG_entry_point:
7136 return "DW_TAG_entry_point";
7137 case DW_TAG_enumeration_type:
7138 return "DW_TAG_enumeration_type";
7139 case DW_TAG_formal_parameter:
7140 return "DW_TAG_formal_parameter";
7141 case DW_TAG_imported_declaration:
7142 return "DW_TAG_imported_declaration";
7144 return "DW_TAG_label";
7145 case DW_TAG_lexical_block:
7146 return "DW_TAG_lexical_block";
7148 return "DW_TAG_member";
7149 case DW_TAG_pointer_type:
7150 return "DW_TAG_pointer_type";
7151 case DW_TAG_reference_type:
7152 return "DW_TAG_reference_type";
7153 case DW_TAG_compile_unit:
7154 return "DW_TAG_compile_unit";
7155 case DW_TAG_string_type:
7156 return "DW_TAG_string_type";
7157 case DW_TAG_structure_type:
7158 return "DW_TAG_structure_type";
7159 case DW_TAG_subroutine_type:
7160 return "DW_TAG_subroutine_type";
7161 case DW_TAG_typedef:
7162 return "DW_TAG_typedef";
7163 case DW_TAG_union_type:
7164 return "DW_TAG_union_type";
7165 case DW_TAG_unspecified_parameters:
7166 return "DW_TAG_unspecified_parameters";
7167 case DW_TAG_variant:
7168 return "DW_TAG_variant";
7169 case DW_TAG_common_block:
7170 return "DW_TAG_common_block";
7171 case DW_TAG_common_inclusion:
7172 return "DW_TAG_common_inclusion";
7173 case DW_TAG_inheritance:
7174 return "DW_TAG_inheritance";
7175 case DW_TAG_inlined_subroutine:
7176 return "DW_TAG_inlined_subroutine";
7178 return "DW_TAG_module";
7179 case DW_TAG_ptr_to_member_type:
7180 return "DW_TAG_ptr_to_member_type";
7181 case DW_TAG_set_type:
7182 return "DW_TAG_set_type";
7183 case DW_TAG_subrange_type:
7184 return "DW_TAG_subrange_type";
7185 case DW_TAG_with_stmt:
7186 return "DW_TAG_with_stmt";
7187 case DW_TAG_access_declaration:
7188 return "DW_TAG_access_declaration";
7189 case DW_TAG_base_type:
7190 return "DW_TAG_base_type";
7191 case DW_TAG_catch_block:
7192 return "DW_TAG_catch_block";
7193 case DW_TAG_const_type:
7194 return "DW_TAG_const_type";
7195 case DW_TAG_constant:
7196 return "DW_TAG_constant";
7197 case DW_TAG_enumerator:
7198 return "DW_TAG_enumerator";
7199 case DW_TAG_file_type:
7200 return "DW_TAG_file_type";
7202 return "DW_TAG_friend";
7203 case DW_TAG_namelist:
7204 return "DW_TAG_namelist";
7205 case DW_TAG_namelist_item:
7206 return "DW_TAG_namelist_item";
7207 case DW_TAG_packed_type:
7208 return "DW_TAG_packed_type";
7209 case DW_TAG_subprogram:
7210 return "DW_TAG_subprogram";
7211 case DW_TAG_template_type_param:
7212 return "DW_TAG_template_type_param";
7213 case DW_TAG_template_value_param:
7214 return "DW_TAG_template_value_param";
7215 case DW_TAG_thrown_type:
7216 return "DW_TAG_thrown_type";
7217 case DW_TAG_try_block:
7218 return "DW_TAG_try_block";
7219 case DW_TAG_variant_part:
7220 return "DW_TAG_variant_part";
7221 case DW_TAG_variable:
7222 return "DW_TAG_variable";
7223 case DW_TAG_volatile_type:
7224 return "DW_TAG_volatile_type";
7225 case DW_TAG_dwarf_procedure:
7226 return "DW_TAG_dwarf_procedure";
7227 case DW_TAG_restrict_type:
7228 return "DW_TAG_restrict_type";
7229 case DW_TAG_interface_type:
7230 return "DW_TAG_interface_type";
7231 case DW_TAG_namespace:
7232 return "DW_TAG_namespace";
7233 case DW_TAG_imported_module:
7234 return "DW_TAG_imported_module";
7235 case DW_TAG_unspecified_type:
7236 return "DW_TAG_unspecified_type";
7237 case DW_TAG_partial_unit:
7238 return "DW_TAG_partial_unit";
7239 case DW_TAG_imported_unit:
7240 return "DW_TAG_imported_unit";
7241 case DW_TAG_MIPS_loop:
7242 return "DW_TAG_MIPS_loop";
7243 case DW_TAG_format_label:
7244 return "DW_TAG_format_label";
7245 case DW_TAG_function_template:
7246 return "DW_TAG_function_template";
7247 case DW_TAG_class_template:
7248 return "DW_TAG_class_template";
7250 return "DW_TAG_<unknown>";
7254 /* Convert a DWARF attribute code into its string name. */
7257 dwarf_attr_name (unsigned attr)
7262 return "DW_AT_sibling";
7263 case DW_AT_location:
7264 return "DW_AT_location";
7266 return "DW_AT_name";
7267 case DW_AT_ordering:
7268 return "DW_AT_ordering";
7269 case DW_AT_subscr_data:
7270 return "DW_AT_subscr_data";
7271 case DW_AT_byte_size:
7272 return "DW_AT_byte_size";
7273 case DW_AT_bit_offset:
7274 return "DW_AT_bit_offset";
7275 case DW_AT_bit_size:
7276 return "DW_AT_bit_size";
7277 case DW_AT_element_list:
7278 return "DW_AT_element_list";
7279 case DW_AT_stmt_list:
7280 return "DW_AT_stmt_list";
7282 return "DW_AT_low_pc";
7284 return "DW_AT_high_pc";
7285 case DW_AT_language:
7286 return "DW_AT_language";
7288 return "DW_AT_member";
7290 return "DW_AT_discr";
7291 case DW_AT_discr_value:
7292 return "DW_AT_discr_value";
7293 case DW_AT_visibility:
7294 return "DW_AT_visibility";
7296 return "DW_AT_import";
7297 case DW_AT_string_length:
7298 return "DW_AT_string_length";
7299 case DW_AT_common_reference:
7300 return "DW_AT_common_reference";
7301 case DW_AT_comp_dir:
7302 return "DW_AT_comp_dir";
7303 case DW_AT_const_value:
7304 return "DW_AT_const_value";
7305 case DW_AT_containing_type:
7306 return "DW_AT_containing_type";
7307 case DW_AT_default_value:
7308 return "DW_AT_default_value";
7310 return "DW_AT_inline";
7311 case DW_AT_is_optional:
7312 return "DW_AT_is_optional";
7313 case DW_AT_lower_bound:
7314 return "DW_AT_lower_bound";
7315 case DW_AT_producer:
7316 return "DW_AT_producer";
7317 case DW_AT_prototyped:
7318 return "DW_AT_prototyped";
7319 case DW_AT_return_addr:
7320 return "DW_AT_return_addr";
7321 case DW_AT_start_scope:
7322 return "DW_AT_start_scope";
7323 case DW_AT_stride_size:
7324 return "DW_AT_stride_size";
7325 case DW_AT_upper_bound:
7326 return "DW_AT_upper_bound";
7327 case DW_AT_abstract_origin:
7328 return "DW_AT_abstract_origin";
7329 case DW_AT_accessibility:
7330 return "DW_AT_accessibility";
7331 case DW_AT_address_class:
7332 return "DW_AT_address_class";
7333 case DW_AT_artificial:
7334 return "DW_AT_artificial";
7335 case DW_AT_base_types:
7336 return "DW_AT_base_types";
7337 case DW_AT_calling_convention:
7338 return "DW_AT_calling_convention";
7340 return "DW_AT_count";
7341 case DW_AT_data_member_location:
7342 return "DW_AT_data_member_location";
7343 case DW_AT_decl_column:
7344 return "DW_AT_decl_column";
7345 case DW_AT_decl_file:
7346 return "DW_AT_decl_file";
7347 case DW_AT_decl_line:
7348 return "DW_AT_decl_line";
7349 case DW_AT_declaration:
7350 return "DW_AT_declaration";
7351 case DW_AT_discr_list:
7352 return "DW_AT_discr_list";
7353 case DW_AT_encoding:
7354 return "DW_AT_encoding";
7355 case DW_AT_external:
7356 return "DW_AT_external";
7357 case DW_AT_frame_base:
7358 return "DW_AT_frame_base";
7360 return "DW_AT_friend";
7361 case DW_AT_identifier_case:
7362 return "DW_AT_identifier_case";
7363 case DW_AT_macro_info:
7364 return "DW_AT_macro_info";
7365 case DW_AT_namelist_items:
7366 return "DW_AT_namelist_items";
7367 case DW_AT_priority:
7368 return "DW_AT_priority";
7370 return "DW_AT_segment";
7371 case DW_AT_specification:
7372 return "DW_AT_specification";
7373 case DW_AT_static_link:
7374 return "DW_AT_static_link";
7376 return "DW_AT_type";
7377 case DW_AT_use_location:
7378 return "DW_AT_use_location";
7379 case DW_AT_variable_parameter:
7380 return "DW_AT_variable_parameter";
7381 case DW_AT_virtuality:
7382 return "DW_AT_virtuality";
7383 case DW_AT_vtable_elem_location:
7384 return "DW_AT_vtable_elem_location";
7385 case DW_AT_allocated:
7386 return "DW_AT_allocated";
7387 case DW_AT_associated:
7388 return "DW_AT_associated";
7389 case DW_AT_data_location:
7390 return "DW_AT_data_location";
7392 return "DW_AT_stride";
7393 case DW_AT_entry_pc:
7394 return "DW_AT_entry_pc";
7395 case DW_AT_use_UTF8:
7396 return "DW_AT_use_UTF8";
7397 case DW_AT_extension:
7398 return "DW_AT_extension";
7400 return "DW_AT_ranges";
7401 case DW_AT_trampoline:
7402 return "DW_AT_trampoline";
7403 case DW_AT_call_column:
7404 return "DW_AT_call_column";
7405 case DW_AT_call_file:
7406 return "DW_AT_call_file";
7407 case DW_AT_call_line:
7408 return "DW_AT_call_line";
7410 case DW_AT_MIPS_fde:
7411 return "DW_AT_MIPS_fde";
7412 case DW_AT_MIPS_loop_begin:
7413 return "DW_AT_MIPS_loop_begin";
7414 case DW_AT_MIPS_tail_loop_begin:
7415 return "DW_AT_MIPS_tail_loop_begin";
7416 case DW_AT_MIPS_epilog_begin:
7417 return "DW_AT_MIPS_epilog_begin";
7418 case DW_AT_MIPS_loop_unroll_factor:
7419 return "DW_AT_MIPS_loop_unroll_factor";
7420 case DW_AT_MIPS_software_pipeline_depth:
7421 return "DW_AT_MIPS_software_pipeline_depth";
7423 case DW_AT_MIPS_linkage_name:
7424 return "DW_AT_MIPS_linkage_name";
7426 case DW_AT_sf_names:
7427 return "DW_AT_sf_names";
7428 case DW_AT_src_info:
7429 return "DW_AT_src_info";
7430 case DW_AT_mac_info:
7431 return "DW_AT_mac_info";
7432 case DW_AT_src_coords:
7433 return "DW_AT_src_coords";
7434 case DW_AT_body_begin:
7435 return "DW_AT_body_begin";
7436 case DW_AT_body_end:
7437 return "DW_AT_body_end";
7438 case DW_AT_GNU_vector:
7439 return "DW_AT_GNU_vector";
7441 return "DW_AT_<unknown>";
7445 /* Convert a DWARF value form code into its string name. */
7448 dwarf_form_name (unsigned form)
7453 return "DW_FORM_addr";
7454 case DW_FORM_block2:
7455 return "DW_FORM_block2";
7456 case DW_FORM_block4:
7457 return "DW_FORM_block4";
7459 return "DW_FORM_data2";
7461 return "DW_FORM_data4";
7463 return "DW_FORM_data8";
7464 case DW_FORM_string:
7465 return "DW_FORM_string";
7467 return "DW_FORM_block";
7468 case DW_FORM_block1:
7469 return "DW_FORM_block1";
7471 return "DW_FORM_data1";
7473 return "DW_FORM_flag";
7475 return "DW_FORM_sdata";
7477 return "DW_FORM_strp";
7479 return "DW_FORM_udata";
7480 case DW_FORM_ref_addr:
7481 return "DW_FORM_ref_addr";
7483 return "DW_FORM_ref1";
7485 return "DW_FORM_ref2";
7487 return "DW_FORM_ref4";
7489 return "DW_FORM_ref8";
7490 case DW_FORM_ref_udata:
7491 return "DW_FORM_ref_udata";
7492 case DW_FORM_indirect:
7493 return "DW_FORM_indirect";
7495 return "DW_FORM_<unknown>";
7499 /* Convert a DWARF stack opcode into its string name. */
7502 dwarf_stack_op_name (unsigned op)
7507 return "DW_OP_addr";
7509 return "DW_OP_deref";
7511 return "DW_OP_const1u";
7513 return "DW_OP_const1s";
7515 return "DW_OP_const2u";
7517 return "DW_OP_const2s";
7519 return "DW_OP_const4u";
7521 return "DW_OP_const4s";
7523 return "DW_OP_const8u";
7525 return "DW_OP_const8s";
7527 return "DW_OP_constu";
7529 return "DW_OP_consts";
7533 return "DW_OP_drop";
7535 return "DW_OP_over";
7537 return "DW_OP_pick";
7539 return "DW_OP_swap";
7543 return "DW_OP_xderef";
7551 return "DW_OP_minus";
7563 return "DW_OP_plus";
7564 case DW_OP_plus_uconst:
7565 return "DW_OP_plus_uconst";
7571 return "DW_OP_shra";
7589 return "DW_OP_skip";
7591 return "DW_OP_lit0";
7593 return "DW_OP_lit1";
7595 return "DW_OP_lit2";
7597 return "DW_OP_lit3";
7599 return "DW_OP_lit4";
7601 return "DW_OP_lit5";
7603 return "DW_OP_lit6";
7605 return "DW_OP_lit7";
7607 return "DW_OP_lit8";
7609 return "DW_OP_lit9";
7611 return "DW_OP_lit10";
7613 return "DW_OP_lit11";
7615 return "DW_OP_lit12";
7617 return "DW_OP_lit13";
7619 return "DW_OP_lit14";
7621 return "DW_OP_lit15";
7623 return "DW_OP_lit16";
7625 return "DW_OP_lit17";
7627 return "DW_OP_lit18";
7629 return "DW_OP_lit19";
7631 return "DW_OP_lit20";
7633 return "DW_OP_lit21";
7635 return "DW_OP_lit22";
7637 return "DW_OP_lit23";
7639 return "DW_OP_lit24";
7641 return "DW_OP_lit25";
7643 return "DW_OP_lit26";
7645 return "DW_OP_lit27";
7647 return "DW_OP_lit28";
7649 return "DW_OP_lit29";
7651 return "DW_OP_lit30";
7653 return "DW_OP_lit31";
7655 return "DW_OP_reg0";
7657 return "DW_OP_reg1";
7659 return "DW_OP_reg2";
7661 return "DW_OP_reg3";
7663 return "DW_OP_reg4";
7665 return "DW_OP_reg5";
7667 return "DW_OP_reg6";
7669 return "DW_OP_reg7";
7671 return "DW_OP_reg8";
7673 return "DW_OP_reg9";
7675 return "DW_OP_reg10";
7677 return "DW_OP_reg11";
7679 return "DW_OP_reg12";
7681 return "DW_OP_reg13";
7683 return "DW_OP_reg14";
7685 return "DW_OP_reg15";
7687 return "DW_OP_reg16";
7689 return "DW_OP_reg17";
7691 return "DW_OP_reg18";
7693 return "DW_OP_reg19";
7695 return "DW_OP_reg20";
7697 return "DW_OP_reg21";
7699 return "DW_OP_reg22";
7701 return "DW_OP_reg23";
7703 return "DW_OP_reg24";
7705 return "DW_OP_reg25";
7707 return "DW_OP_reg26";
7709 return "DW_OP_reg27";
7711 return "DW_OP_reg28";
7713 return "DW_OP_reg29";
7715 return "DW_OP_reg30";
7717 return "DW_OP_reg31";
7719 return "DW_OP_breg0";
7721 return "DW_OP_breg1";
7723 return "DW_OP_breg2";
7725 return "DW_OP_breg3";
7727 return "DW_OP_breg4";
7729 return "DW_OP_breg5";
7731 return "DW_OP_breg6";
7733 return "DW_OP_breg7";
7735 return "DW_OP_breg8";
7737 return "DW_OP_breg9";
7739 return "DW_OP_breg10";
7741 return "DW_OP_breg11";
7743 return "DW_OP_breg12";
7745 return "DW_OP_breg13";
7747 return "DW_OP_breg14";
7749 return "DW_OP_breg15";
7751 return "DW_OP_breg16";
7753 return "DW_OP_breg17";
7755 return "DW_OP_breg18";
7757 return "DW_OP_breg19";
7759 return "DW_OP_breg20";
7761 return "DW_OP_breg21";
7763 return "DW_OP_breg22";
7765 return "DW_OP_breg23";
7767 return "DW_OP_breg24";
7769 return "DW_OP_breg25";
7771 return "DW_OP_breg26";
7773 return "DW_OP_breg27";
7775 return "DW_OP_breg28";
7777 return "DW_OP_breg29";
7779 return "DW_OP_breg30";
7781 return "DW_OP_breg31";
7783 return "DW_OP_regx";
7785 return "DW_OP_fbreg";
7787 return "DW_OP_bregx";
7789 return "DW_OP_piece";
7790 case DW_OP_deref_size:
7791 return "DW_OP_deref_size";
7792 case DW_OP_xderef_size:
7793 return "DW_OP_xderef_size";
7796 /* DWARF 3 extensions. */
7797 case DW_OP_push_object_address:
7798 return "DW_OP_push_object_address";
7800 return "DW_OP_call2";
7802 return "DW_OP_call4";
7803 case DW_OP_call_ref:
7804 return "DW_OP_call_ref";
7805 /* GNU extensions. */
7806 case DW_OP_GNU_push_tls_address:
7807 return "DW_OP_GNU_push_tls_address";
7809 return "OP_<unknown>";
7814 dwarf_bool_name (unsigned mybool)
7822 /* Convert a DWARF type code into its string name. */
7825 dwarf_type_encoding_name (unsigned enc)
7829 case DW_ATE_address:
7830 return "DW_ATE_address";
7831 case DW_ATE_boolean:
7832 return "DW_ATE_boolean";
7833 case DW_ATE_complex_float:
7834 return "DW_ATE_complex_float";
7836 return "DW_ATE_float";
7838 return "DW_ATE_signed";
7839 case DW_ATE_signed_char:
7840 return "DW_ATE_signed_char";
7841 case DW_ATE_unsigned:
7842 return "DW_ATE_unsigned";
7843 case DW_ATE_unsigned_char:
7844 return "DW_ATE_unsigned_char";
7845 case DW_ATE_imaginary_float:
7846 return "DW_ATE_imaginary_float";
7848 return "DW_ATE_<unknown>";
7852 /* Convert a DWARF call frame info operation to its string name. */
7856 dwarf_cfi_name (unsigned cfi_opc)
7860 case DW_CFA_advance_loc:
7861 return "DW_CFA_advance_loc";
7863 return "DW_CFA_offset";
7864 case DW_CFA_restore:
7865 return "DW_CFA_restore";
7867 return "DW_CFA_nop";
7868 case DW_CFA_set_loc:
7869 return "DW_CFA_set_loc";
7870 case DW_CFA_advance_loc1:
7871 return "DW_CFA_advance_loc1";
7872 case DW_CFA_advance_loc2:
7873 return "DW_CFA_advance_loc2";
7874 case DW_CFA_advance_loc4:
7875 return "DW_CFA_advance_loc4";
7876 case DW_CFA_offset_extended:
7877 return "DW_CFA_offset_extended";
7878 case DW_CFA_restore_extended:
7879 return "DW_CFA_restore_extended";
7880 case DW_CFA_undefined:
7881 return "DW_CFA_undefined";
7882 case DW_CFA_same_value:
7883 return "DW_CFA_same_value";
7884 case DW_CFA_register:
7885 return "DW_CFA_register";
7886 case DW_CFA_remember_state:
7887 return "DW_CFA_remember_state";
7888 case DW_CFA_restore_state:
7889 return "DW_CFA_restore_state";
7890 case DW_CFA_def_cfa:
7891 return "DW_CFA_def_cfa";
7892 case DW_CFA_def_cfa_register:
7893 return "DW_CFA_def_cfa_register";
7894 case DW_CFA_def_cfa_offset:
7895 return "DW_CFA_def_cfa_offset";
7898 case DW_CFA_def_cfa_expression:
7899 return "DW_CFA_def_cfa_expression";
7900 case DW_CFA_expression:
7901 return "DW_CFA_expression";
7902 case DW_CFA_offset_extended_sf:
7903 return "DW_CFA_offset_extended_sf";
7904 case DW_CFA_def_cfa_sf:
7905 return "DW_CFA_def_cfa_sf";
7906 case DW_CFA_def_cfa_offset_sf:
7907 return "DW_CFA_def_cfa_offset_sf";
7909 /* SGI/MIPS specific */
7910 case DW_CFA_MIPS_advance_loc8:
7911 return "DW_CFA_MIPS_advance_loc8";
7913 /* GNU extensions */
7914 case DW_CFA_GNU_window_save:
7915 return "DW_CFA_GNU_window_save";
7916 case DW_CFA_GNU_args_size:
7917 return "DW_CFA_GNU_args_size";
7918 case DW_CFA_GNU_negative_offset_extended:
7919 return "DW_CFA_GNU_negative_offset_extended";
7922 return "DW_CFA_<unknown>";
7928 dump_die (struct die_info *die)
7932 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7933 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7934 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7935 dwarf_bool_name (die->child != NULL));
7937 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7938 for (i = 0; i < die->num_attrs; ++i)
7940 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7941 dwarf_attr_name (die->attrs[i].name),
7942 dwarf_form_name (die->attrs[i].form));
7943 switch (die->attrs[i].form)
7945 case DW_FORM_ref_addr:
7947 fprintf_unfiltered (gdb_stderr, "address: ");
7948 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7950 case DW_FORM_block2:
7951 case DW_FORM_block4:
7953 case DW_FORM_block1:
7954 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7965 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7967 case DW_FORM_string:
7969 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7970 DW_STRING (&die->attrs[i])
7971 ? DW_STRING (&die->attrs[i]) : "");
7974 if (DW_UNSND (&die->attrs[i]))
7975 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7977 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7979 case DW_FORM_indirect:
7980 /* the reader will have reduced the indirect form to
7981 the "base form" so this form should not occur */
7982 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7985 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7986 die->attrs[i].form);
7988 fprintf_unfiltered (gdb_stderr, "\n");
7993 dump_die_list (struct die_info *die)
7998 if (die->child != NULL)
7999 dump_die_list (die->child);
8000 if (die->sibling != NULL)
8001 dump_die_list (die->sibling);
8006 store_in_ref_table (unsigned int offset, struct die_info *die)
8009 struct die_info *old;
8011 h = (offset % REF_HASH_SIZE);
8012 old = die_ref_table[h];
8013 die->next_ref = old;
8014 die_ref_table[h] = die;
8019 dwarf2_empty_hash_tables (void)
8021 memset (die_ref_table, 0, sizeof (die_ref_table));
8025 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
8027 unsigned int result = 0;
8031 case DW_FORM_ref_addr:
8032 result = DW_ADDR (attr);
8038 case DW_FORM_ref_udata:
8039 result = cu->header.offset + DW_UNSND (attr);
8042 complaint (&symfile_complaints,
8043 "unsupported die ref attribute form: '%s'",
8044 dwarf_form_name (attr->form));
8049 /* Return the constant value held by the given attribute. Return -1
8050 if the value held by the attribute is not constant. */
8053 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
8055 if (attr->form == DW_FORM_sdata)
8056 return DW_SND (attr);
8057 else if (attr->form == DW_FORM_udata
8058 || attr->form == DW_FORM_data1
8059 || attr->form == DW_FORM_data2
8060 || attr->form == DW_FORM_data4
8061 || attr->form == DW_FORM_data8)
8062 return DW_UNSND (attr);
8065 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
8066 dwarf_form_name (attr->form));
8067 return default_value;
8071 static struct die_info *
8072 follow_die_ref (unsigned int offset)
8074 struct die_info *die;
8077 h = (offset % REF_HASH_SIZE);
8078 die = die_ref_table[h];
8081 if (die->offset == offset)
8085 die = die->next_ref;
8090 static struct type *
8091 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
8092 struct dwarf2_cu *cu)
8094 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
8096 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8097 typeid, objfile->name);
8100 /* Look for this particular type in the fundamental type vector. If
8101 one is not found, create and install one appropriate for the
8102 current language and the current target machine. */
8104 if (cu->ftypes[typeid] == NULL)
8106 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
8109 return (cu->ftypes[typeid]);
8112 /* Decode simple location descriptions.
8113 Given a pointer to a dwarf block that defines a location, compute
8114 the location and return the value.
8116 NOTE drow/2003-11-18: This function is called in two situations
8117 now: for the address of static or global variables (partial symbols
8118 only) and for offsets into structures which are expected to be
8119 (more or less) constant. The partial symbol case should go away,
8120 and only the constant case should remain. That will let this
8121 function complain more accurately. A few special modes are allowed
8122 without complaint for global variables (for instance, global
8123 register values and thread-local values).
8125 A location description containing no operations indicates that the
8126 object is optimized out. The return value is 0 for that case.
8127 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8128 callers will only want a very basic result and this can become a
8131 When the result is a register number, the global isreg flag is set,
8132 otherwise it is cleared.
8134 Note that stack[0] is unused except as a default error return.
8135 Note that stack overflow is not yet handled. */
8138 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
8140 struct objfile *objfile = cu->objfile;
8141 struct comp_unit_head *cu_header = &cu->header;
8143 int size = blk->size;
8144 char *data = blk->data;
8145 CORE_ADDR stack[64];
8147 unsigned int bytes_read, unsnd;
8192 stack[++stacki] = op - DW_OP_lit0;
8228 stack[++stacki] = op - DW_OP_reg0;
8230 dwarf2_complex_location_expr_complaint ();
8235 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8237 stack[++stacki] = unsnd;
8239 dwarf2_complex_location_expr_complaint ();
8243 stack[++stacki] = read_address (objfile->obfd, &data[i],
8249 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
8254 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
8259 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
8264 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
8269 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
8274 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
8279 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
8285 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
8290 stack[stacki + 1] = stack[stacki];
8295 stack[stacki - 1] += stack[stacki];
8299 case DW_OP_plus_uconst:
8300 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8305 stack[stacki - 1] -= stack[stacki];
8310 /* If we're not the last op, then we definitely can't encode
8311 this using GDB's address_class enum. This is valid for partial
8312 global symbols, although the variable's address will be bogus
8315 dwarf2_complex_location_expr_complaint ();
8318 case DW_OP_GNU_push_tls_address:
8319 /* The top of the stack has the offset from the beginning
8320 of the thread control block at which the variable is located. */
8321 /* Nothing should follow this operator, so the top of stack would
8323 /* This is valid for partial global symbols, but the variable's
8324 address will be bogus in the psymtab. */
8326 dwarf2_complex_location_expr_complaint ();
8330 complaint (&symfile_complaints, "unsupported stack op: '%s'",
8331 dwarf_stack_op_name (op));
8332 return (stack[stacki]);
8335 return (stack[stacki]);
8338 /* memory allocation interface */
8340 static struct dwarf_block *
8341 dwarf_alloc_block (struct dwarf2_cu *cu)
8343 struct dwarf_block *blk;
8345 blk = (struct dwarf_block *)
8346 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
8350 static struct abbrev_info *
8351 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
8353 struct abbrev_info *abbrev;
8355 abbrev = (struct abbrev_info *)
8356 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
8357 memset (abbrev, 0, sizeof (struct abbrev_info));
8361 static struct die_info *
8362 dwarf_alloc_die (void)
8364 struct die_info *die;
8366 die = (struct die_info *) xmalloc (sizeof (struct die_info));
8367 memset (die, 0, sizeof (struct die_info));
8372 /* Macro support. */
8375 /* Return the full name of file number I in *LH's file name table.
8376 Use COMP_DIR as the name of the current directory of the
8377 compilation. The result is allocated using xmalloc; the caller is
8378 responsible for freeing it. */
8380 file_full_name (int file, struct line_header *lh, const char *comp_dir)
8382 struct file_entry *fe = &lh->file_names[file - 1];
8384 if (IS_ABSOLUTE_PATH (fe->name))
8385 return xstrdup (fe->name);
8393 dir = lh->include_dirs[fe->dir_index - 1];
8399 dir_len = strlen (dir);
8400 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
8401 strcpy (full_name, dir);
8402 full_name[dir_len] = '/';
8403 strcpy (full_name + dir_len + 1, fe->name);
8407 return xstrdup (fe->name);
8412 static struct macro_source_file *
8413 macro_start_file (int file, int line,
8414 struct macro_source_file *current_file,
8415 const char *comp_dir,
8416 struct line_header *lh, struct objfile *objfile)
8418 /* The full name of this source file. */
8419 char *full_name = file_full_name (file, lh, comp_dir);
8421 /* We don't create a macro table for this compilation unit
8422 at all until we actually get a filename. */
8423 if (! pending_macros)
8424 pending_macros = new_macro_table (&objfile->objfile_obstack,
8425 objfile->macro_cache);
8428 /* If we have no current file, then this must be the start_file
8429 directive for the compilation unit's main source file. */
8430 current_file = macro_set_main (pending_macros, full_name);
8432 current_file = macro_include (current_file, line, full_name);
8436 return current_file;
8440 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8441 followed by a null byte. */
8443 copy_string (const char *buf, int len)
8445 char *s = xmalloc (len + 1);
8446 memcpy (s, buf, len);
8454 consume_improper_spaces (const char *p, const char *body)
8458 complaint (&symfile_complaints,
8459 "macro definition contains spaces in formal argument list:\n`%s'",
8471 parse_macro_definition (struct macro_source_file *file, int line,
8476 /* The body string takes one of two forms. For object-like macro
8477 definitions, it should be:
8479 <macro name> " " <definition>
8481 For function-like macro definitions, it should be:
8483 <macro name> "() " <definition>
8485 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8487 Spaces may appear only where explicitly indicated, and in the
8490 The Dwarf 2 spec says that an object-like macro's name is always
8491 followed by a space, but versions of GCC around March 2002 omit
8492 the space when the macro's definition is the empty string.
8494 The Dwarf 2 spec says that there should be no spaces between the
8495 formal arguments in a function-like macro's formal argument list,
8496 but versions of GCC around March 2002 include spaces after the
8500 /* Find the extent of the macro name. The macro name is terminated
8501 by either a space or null character (for an object-like macro) or
8502 an opening paren (for a function-like macro). */
8503 for (p = body; *p; p++)
8504 if (*p == ' ' || *p == '(')
8507 if (*p == ' ' || *p == '\0')
8509 /* It's an object-like macro. */
8510 int name_len = p - body;
8511 char *name = copy_string (body, name_len);
8512 const char *replacement;
8515 replacement = body + name_len + 1;
8518 dwarf2_macro_malformed_definition_complaint (body);
8519 replacement = body + name_len;
8522 macro_define_object (file, line, name, replacement);
8528 /* It's a function-like macro. */
8529 char *name = copy_string (body, p - body);
8532 char **argv = xmalloc (argv_size * sizeof (*argv));
8536 p = consume_improper_spaces (p, body);
8538 /* Parse the formal argument list. */
8539 while (*p && *p != ')')
8541 /* Find the extent of the current argument name. */
8542 const char *arg_start = p;
8544 while (*p && *p != ',' && *p != ')' && *p != ' ')
8547 if (! *p || p == arg_start)
8548 dwarf2_macro_malformed_definition_complaint (body);
8551 /* Make sure argv has room for the new argument. */
8552 if (argc >= argv_size)
8555 argv = xrealloc (argv, argv_size * sizeof (*argv));
8558 argv[argc++] = copy_string (arg_start, p - arg_start);
8561 p = consume_improper_spaces (p, body);
8563 /* Consume the comma, if present. */
8568 p = consume_improper_spaces (p, body);
8577 /* Perfectly formed definition, no complaints. */
8578 macro_define_function (file, line, name,
8579 argc, (const char **) argv,
8581 else if (*p == '\0')
8583 /* Complain, but do define it. */
8584 dwarf2_macro_malformed_definition_complaint (body);
8585 macro_define_function (file, line, name,
8586 argc, (const char **) argv,
8590 /* Just complain. */
8591 dwarf2_macro_malformed_definition_complaint (body);
8594 /* Just complain. */
8595 dwarf2_macro_malformed_definition_complaint (body);
8601 for (i = 0; i < argc; i++)
8607 dwarf2_macro_malformed_definition_complaint (body);
8612 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
8613 char *comp_dir, bfd *abfd,
8614 struct dwarf2_cu *cu)
8616 char *mac_ptr, *mac_end;
8617 struct macro_source_file *current_file = 0;
8619 if (dwarf2_per_objfile->macinfo_buffer == NULL)
8621 complaint (&symfile_complaints, "missing .debug_macinfo section");
8625 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
8626 mac_end = dwarf2_per_objfile->macinfo_buffer
8627 + dwarf2_per_objfile->macinfo_size;
8631 enum dwarf_macinfo_record_type macinfo_type;
8633 /* Do we at least have room for a macinfo type byte? */
8634 if (mac_ptr >= mac_end)
8636 dwarf2_macros_too_long_complaint ();
8640 macinfo_type = read_1_byte (abfd, mac_ptr);
8643 switch (macinfo_type)
8645 /* A zero macinfo type indicates the end of the macro
8650 case DW_MACINFO_define:
8651 case DW_MACINFO_undef:
8657 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8658 mac_ptr += bytes_read;
8659 body = read_string (abfd, mac_ptr, &bytes_read);
8660 mac_ptr += bytes_read;
8663 complaint (&symfile_complaints,
8664 "debug info gives macro %s outside of any file: %s",
8666 DW_MACINFO_define ? "definition" : macinfo_type ==
8667 DW_MACINFO_undef ? "undefinition" :
8668 "something-or-other", body);
8671 if (macinfo_type == DW_MACINFO_define)
8672 parse_macro_definition (current_file, line, body);
8673 else if (macinfo_type == DW_MACINFO_undef)
8674 macro_undef (current_file, line, body);
8679 case DW_MACINFO_start_file:
8684 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8685 mac_ptr += bytes_read;
8686 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8687 mac_ptr += bytes_read;
8689 current_file = macro_start_file (file, line,
8690 current_file, comp_dir,
8695 case DW_MACINFO_end_file:
8697 complaint (&symfile_complaints,
8698 "macro debug info has an unmatched `close_file' directive");
8701 current_file = current_file->included_by;
8704 enum dwarf_macinfo_record_type next_type;
8706 /* GCC circa March 2002 doesn't produce the zero
8707 type byte marking the end of the compilation
8708 unit. Complain if it's not there, but exit no
8711 /* Do we at least have room for a macinfo type byte? */
8712 if (mac_ptr >= mac_end)
8714 dwarf2_macros_too_long_complaint ();
8718 /* We don't increment mac_ptr here, so this is just
8720 next_type = read_1_byte (abfd, mac_ptr);
8722 complaint (&symfile_complaints,
8723 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8730 case DW_MACINFO_vendor_ext:
8736 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8737 mac_ptr += bytes_read;
8738 string = read_string (abfd, mac_ptr, &bytes_read);
8739 mac_ptr += bytes_read;
8741 /* We don't recognize any vendor extensions. */
8748 /* Check if the attribute's form is a DW_FORM_block*
8749 if so return true else false. */
8751 attr_form_is_block (struct attribute *attr)
8753 return (attr == NULL ? 0 :
8754 attr->form == DW_FORM_block1
8755 || attr->form == DW_FORM_block2
8756 || attr->form == DW_FORM_block4
8757 || attr->form == DW_FORM_block);
8761 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
8762 struct dwarf2_cu *cu)
8764 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
8766 struct dwarf2_loclist_baton *baton;
8768 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8769 sizeof (struct dwarf2_loclist_baton));
8770 baton->objfile = cu->objfile;
8772 /* We don't know how long the location list is, but make sure we
8773 don't run off the edge of the section. */
8774 baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr);
8775 baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr);
8776 baton->base_address = cu->header.base_address;
8777 if (cu->header.base_known == 0)
8778 complaint (&symfile_complaints,
8779 "Location list used without specifying the CU base address.");
8781 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
8782 SYMBOL_LOCATION_BATON (sym) = baton;
8786 struct dwarf2_locexpr_baton *baton;
8788 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8789 sizeof (struct dwarf2_locexpr_baton));
8790 baton->objfile = cu->objfile;
8792 if (attr_form_is_block (attr))
8794 /* Note that we're just copying the block's data pointer
8795 here, not the actual data. We're still pointing into the
8796 info_buffer for SYM's objfile; right now we never release
8797 that buffer, but when we do clean up properly this may
8799 baton->size = DW_BLOCK (attr)->size;
8800 baton->data = DW_BLOCK (attr)->data;
8804 dwarf2_invalid_attrib_class_complaint ("location description",
8805 SYMBOL_NATURAL_NAME (sym));
8810 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
8811 SYMBOL_LOCATION_BATON (sym) = baton;
8815 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8816 when we're finished with it. We can't free the pointer itself, but
8817 release any associated storage.
8819 Only used during partial symbol parsing. */
8822 free_stack_comp_unit (void *data)
8824 struct dwarf2_cu *cu = data;
8826 obstack_free (&cu->comp_unit_obstack, NULL);
8827 cu->partial_dies = NULL;
8830 /* Allocation function for the libiberty hash table which uses an
8834 hashtab_obstack_allocate (void *data, size_t size, size_t count)
8836 unsigned int total = size * count;
8837 void *ptr = obstack_alloc ((struct obstack *) data, total);
8838 memset (ptr, 0, total);
8842 /* Trivial deallocation function for the libiberty splay tree and hash
8843 table - don't deallocate anything. Rely on later deletion of the
8847 dummy_obstack_deallocate (void *object, void *data)
8852 /* Trivial hash function for partial_die_info: the hash value of a DIE
8853 is its offset in .debug_info for this objfile. */
8856 partial_die_hash (const void *item)
8858 const struct partial_die_info *part_die = item;
8859 return part_die->offset;
8862 /* Trivial comparison function for partial_die_info structures: two DIEs
8863 are equal if they have the same offset. */
8866 partial_die_eq (const void *item_lhs, const void *item_rhs)
8868 const struct partial_die_info *part_die_lhs = item_lhs;
8869 const struct partial_die_info *part_die_rhs = item_rhs;
8870 return part_die_lhs->offset == part_die_rhs->offset;
8873 void _initialize_dwarf2_read (void);
8876 _initialize_dwarf2_read (void)
8878 dwarf2_objfile_data_key = register_objfile_data ();