1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 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"
49 #include "gdb_string.h"
50 #include "gdb_assert.h"
51 #include <sys/types.h>
53 #ifndef DWARF2_REG_TO_REGNUM
54 #define DWARF2_REG_TO_REGNUM(REG) (REG)
58 /* .debug_info header for a compilation unit
59 Because of alignment constraints, this structure has padding and cannot
60 be mapped directly onto the beginning of the .debug_info section. */
61 typedef struct comp_unit_header
63 unsigned int length; /* length of the .debug_info
65 unsigned short version; /* version number -- 2 for DWARF
67 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
68 unsigned char addr_size; /* byte size of an address -- 4 */
71 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
74 /* .debug_pubnames header
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct pubnames_header
79 unsigned int length; /* length of the .debug_pubnames
81 unsigned char version; /* version number -- 2 for DWARF
83 unsigned int info_offset; /* offset into .debug_info section */
84 unsigned int info_size; /* byte size of .debug_info section
88 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
90 /* .debug_pubnames header
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct aranges_header
95 unsigned int length; /* byte len of the .debug_aranges
97 unsigned short version; /* version number -- 2 for DWARF
99 unsigned int info_offset; /* offset into .debug_info section */
100 unsigned char addr_size; /* byte size of an address */
101 unsigned char seg_size; /* byte size of segment descriptor */
104 #define _ACTUAL_ARANGES_HEADER_SIZE 12
106 /* .debug_line statement program prologue
107 Because of alignment constraints, this structure has padding and cannot
108 be mapped directly onto the beginning of the .debug_info section. */
109 typedef struct statement_prologue
111 unsigned int total_length; /* byte length of the statement
113 unsigned short version; /* version number -- 2 for DWARF
115 unsigned int prologue_length; /* # bytes between prologue &
117 unsigned char minimum_instruction_length; /* byte size of
119 unsigned char default_is_stmt; /* initial value of is_stmt
122 unsigned char line_range;
123 unsigned char opcode_base; /* number assigned to first special
125 unsigned char *standard_opcode_lengths;
129 /* offsets and sizes of debugging sections */
131 static unsigned int dwarf_info_size;
132 static unsigned int dwarf_abbrev_size;
133 static unsigned int dwarf_line_size;
134 static unsigned int dwarf_pubnames_size;
135 static unsigned int dwarf_aranges_size;
136 static unsigned int dwarf_loc_size;
137 static unsigned int dwarf_macinfo_size;
138 static unsigned int dwarf_str_size;
139 static unsigned int dwarf_ranges_size;
140 unsigned int dwarf_frame_size;
141 unsigned int dwarf_eh_frame_size;
143 static asection *dwarf_info_section;
144 static asection *dwarf_abbrev_section;
145 static asection *dwarf_line_section;
146 static asection *dwarf_pubnames_section;
147 static asection *dwarf_aranges_section;
148 static asection *dwarf_loc_section;
149 static asection *dwarf_macinfo_section;
150 static asection *dwarf_str_section;
151 static asection *dwarf_ranges_section;
152 asection *dwarf_frame_section;
153 asection *dwarf_eh_frame_section;
155 /* names of the debugging sections */
157 #define INFO_SECTION ".debug_info"
158 #define ABBREV_SECTION ".debug_abbrev"
159 #define LINE_SECTION ".debug_line"
160 #define PUBNAMES_SECTION ".debug_pubnames"
161 #define ARANGES_SECTION ".debug_aranges"
162 #define LOC_SECTION ".debug_loc"
163 #define MACINFO_SECTION ".debug_macinfo"
164 #define STR_SECTION ".debug_str"
165 #define RANGES_SECTION ".debug_ranges"
166 #define FRAME_SECTION ".debug_frame"
167 #define EH_FRAME_SECTION ".eh_frame"
169 /* local data types */
171 /* We hold several abbreviation tables in memory at the same time. */
172 #ifndef ABBREV_HASH_SIZE
173 #define ABBREV_HASH_SIZE 121
176 /* The data in a compilation unit header, after target2host
177 translation, looks like this. */
178 struct comp_unit_head
180 unsigned long length;
182 unsigned int abbrev_offset;
183 unsigned char addr_size;
184 unsigned char signed_addr_p;
185 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
186 unsigned int initial_length_size; /* size of the length field; either
189 /* Offset to the first byte of this compilation unit header in the
190 * .debug_info section, for resolving relative reference dies. */
194 /* Pointer to this compilation unit header in the .debug_info
199 /* Pointer to the first die of this compilatio unit. This will
200 * be the first byte following the compilation unit header. */
204 /* Pointer to the next compilation unit header in the program. */
206 struct comp_unit_head *next;
208 /* DWARF abbreviation table associated with this compilation unit */
210 struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
212 /* Base address of this compilation unit. */
214 CORE_ADDR base_address;
216 /* Non-zero if base_address has been set. */
221 /* Internal state when decoding a particular compilation unit. */
224 /* The objfile containing this compilation unit. */
225 struct objfile *objfile;
227 /* The header of the compilation unit.
229 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
230 should be moved to the dwarf2_cu structure; for instance the abbrevs
232 struct comp_unit_head header;
235 /* The line number information for a compilation unit (found in the
236 .debug_line section) begins with a "statement program header",
237 which contains the following information. */
240 unsigned int total_length;
241 unsigned short version;
242 unsigned int header_length;
243 unsigned char minimum_instruction_length;
244 unsigned char default_is_stmt;
246 unsigned char line_range;
247 unsigned char opcode_base;
249 /* standard_opcode_lengths[i] is the number of operands for the
250 standard opcode whose value is i. This means that
251 standard_opcode_lengths[0] is unused, and the last meaningful
252 element is standard_opcode_lengths[opcode_base - 1]. */
253 unsigned char *standard_opcode_lengths;
255 /* The include_directories table. NOTE! These strings are not
256 allocated with xmalloc; instead, they are pointers into
257 debug_line_buffer. If you try to free them, `free' will get
259 unsigned int num_include_dirs, include_dirs_size;
262 /* The file_names table. NOTE! These strings are not allocated
263 with xmalloc; instead, they are pointers into debug_line_buffer.
264 Don't try to free them directly. */
265 unsigned int num_file_names, file_names_size;
269 unsigned int dir_index;
270 unsigned int mod_time;
274 /* The start and end of the statement program following this
275 header. These point into dwarf_line_buffer. */
276 char *statement_program_start, *statement_program_end;
279 /* When we construct a partial symbol table entry we only
280 need this much information. */
281 struct partial_die_info
284 unsigned char has_children;
285 unsigned char is_external;
286 unsigned char is_declaration;
287 unsigned char has_type;
294 struct dwarf_block *locdesc;
295 unsigned int language;
299 /* This data structure holds the information of an abbrev. */
302 unsigned int number; /* number identifying abbrev */
303 enum dwarf_tag tag; /* dwarf tag */
304 int has_children; /* boolean */
305 unsigned int num_attrs; /* number of attributes */
306 struct attr_abbrev *attrs; /* an array of attribute descriptions */
307 struct abbrev_info *next; /* next in chain */
312 enum dwarf_attribute name;
313 enum dwarf_form form;
316 /* This data structure holds a complete die structure. */
319 enum dwarf_tag tag; /* Tag indicating type of die */
320 unsigned int abbrev; /* Abbrev number */
321 unsigned int offset; /* Offset in .debug_info section */
322 unsigned int num_attrs; /* Number of attributes */
323 struct attribute *attrs; /* An array of attributes */
324 struct die_info *next_ref; /* Next die in ref hash table */
326 /* The dies in a compilation unit form an n-ary tree. PARENT
327 points to this die's parent; CHILD points to the first child of
328 this node; and all the children of a given node are chained
329 together via their SIBLING fields, terminated by a die whose
331 struct die_info *child; /* Its first child, if any. */
332 struct die_info *sibling; /* Its next sibling, if any. */
333 struct die_info *parent; /* Its parent, if any. */
335 struct type *type; /* Cached type information */
338 /* Attributes have a name and a value */
341 enum dwarf_attribute name;
342 enum dwarf_form form;
346 struct dwarf_block *blk;
354 struct function_range
357 CORE_ADDR lowpc, highpc;
359 struct function_range *next;
362 static struct function_range *cu_first_fn, *cu_last_fn, *cu_cached_fn;
364 /* Get at parts of an attribute structure */
366 #define DW_STRING(attr) ((attr)->u.str)
367 #define DW_UNSND(attr) ((attr)->u.unsnd)
368 #define DW_BLOCK(attr) ((attr)->u.blk)
369 #define DW_SND(attr) ((attr)->u.snd)
370 #define DW_ADDR(attr) ((attr)->u.addr)
372 /* Blocks are a bunch of untyped bytes. */
379 #ifndef ATTR_ALLOC_CHUNK
380 #define ATTR_ALLOC_CHUNK 4
383 /* A hash table of die offsets for following references. */
384 #ifndef REF_HASH_SIZE
385 #define REF_HASH_SIZE 1021
388 static struct die_info *die_ref_table[REF_HASH_SIZE];
390 /* Obstack for allocating temporary storage used during symbol reading. */
391 static struct obstack dwarf2_tmp_obstack;
393 /* Offset to the first byte of the current compilation unit header,
394 for resolving relative reference dies. */
395 static unsigned int cu_header_offset;
397 /* Allocate fields for structs, unions and enums in this size. */
398 #ifndef DW_FIELD_ALLOC_CHUNK
399 #define DW_FIELD_ALLOC_CHUNK 4
402 /* The language we are debugging. */
403 static enum language cu_language;
404 static const struct language_defn *cu_language_defn;
406 /* Actually data from the sections. */
407 static char *dwarf_info_buffer;
408 static char *dwarf_abbrev_buffer;
409 static char *dwarf_line_buffer;
410 static char *dwarf_str_buffer;
411 static char *dwarf_macinfo_buffer;
412 static char *dwarf_ranges_buffer;
413 static char *dwarf_loc_buffer;
415 /* A zeroed version of a partial die for initialization purposes. */
416 static struct partial_die_info zeroed_partial_die;
418 /* The generic symbol table building routines have separate lists for
419 file scope symbols and all all other scopes (local scopes). So
420 we need to select the right one to pass to add_symbol_to_list().
421 We do it by keeping a pointer to the correct list in list_in_scope.
423 FIXME: The original dwarf code just treated the file scope as the first
424 local scope, and all other local scopes as nested local scopes, and worked
425 fine. Check to see if we really need to distinguish these
427 static struct pending **list_in_scope = &file_symbols;
429 /* FIXME: decode_locdesc sets these variables to describe the location
430 to the caller. These ought to be a structure or something. If
431 none of the flags are set, the object lives at the address returned
432 by decode_locdesc. */
434 static int isreg; /* Object lives in register.
435 decode_locdesc's return value is
436 the register number. */
438 /* This value is added to each symbol value. FIXME: Generalize to
439 the section_offsets structure used by dbxread (once this is done,
440 pass the appropriate section number to end_symtab). */
441 static CORE_ADDR baseaddr; /* Add to each symbol value */
443 /* We put a pointer to this structure in the read_symtab_private field
445 The complete dwarf information for an objfile is kept in the
446 psymbol_obstack, so that absolute die references can be handled.
447 Most of the information in this structure is related to an entire
448 object file and could be passed via the sym_private field of the objfile.
449 It is however conceivable that dwarf2 might not be the only type
450 of symbols read from an object file. */
454 /* Pointer to start of dwarf info buffer for the objfile. */
456 char *dwarf_info_buffer;
458 /* Offset in dwarf_info_buffer for this compilation unit. */
460 unsigned long dwarf_info_offset;
462 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
464 char *dwarf_abbrev_buffer;
466 /* Size of dwarf abbreviation section for the objfile. */
468 unsigned int dwarf_abbrev_size;
470 /* Pointer to start of dwarf line buffer for the objfile. */
472 char *dwarf_line_buffer;
474 /* Size of dwarf_line_buffer, in bytes. */
476 unsigned int dwarf_line_size;
478 /* Pointer to start of dwarf string buffer for the objfile. */
480 char *dwarf_str_buffer;
482 /* Size of dwarf string section for the objfile. */
484 unsigned int dwarf_str_size;
486 /* Pointer to start of dwarf macro buffer for the objfile. */
488 char *dwarf_macinfo_buffer;
490 /* Size of dwarf macinfo section for the objfile. */
492 unsigned int dwarf_macinfo_size;
494 /* Pointer to start of dwarf ranges buffer for the objfile. */
496 char *dwarf_ranges_buffer;
498 /* Size of dwarf ranges buffer for the objfile. */
500 unsigned int dwarf_ranges_size;
502 /* Pointer to start of dwarf locations buffer for the objfile. */
504 char *dwarf_loc_buffer;
506 /* Size of dwarf locations buffer for the objfile. */
508 unsigned int dwarf_loc_size;
511 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
512 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
513 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
514 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
515 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
516 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
517 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
518 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
519 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
520 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
521 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
522 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
523 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
524 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
525 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
527 /* Maintain an array of referenced fundamental types for the current
528 compilation unit being read. For DWARF version 1, we have to construct
529 the fundamental types on the fly, since no information about the
530 fundamental types is supplied. Each such fundamental type is created by
531 calling a language dependent routine to create the type, and then a
532 pointer to that type is then placed in the array at the index specified
533 by it's FT_<TYPENAME> value. The array has a fixed size set by the
534 FT_NUM_MEMBERS compile time constant, which is the number of predefined
535 fundamental types gdb knows how to construct. */
536 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
538 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
539 but this would require a corresponding change in unpack_field_as_long
541 static int bits_per_byte = 8;
543 /* The routines that read and process dies for a C struct or C++ class
544 pass lists of data member fields and lists of member function fields
545 in an instance of a field_info structure, as defined below. */
548 /* List of data member and baseclasses fields. */
551 struct nextfield *next;
558 /* Number of fields. */
561 /* Number of baseclasses. */
564 /* Set if the accesibility of one of the fields is not public. */
565 int non_public_fields;
567 /* Member function fields array, entries are allocated in the order they
568 are encountered in the object file. */
571 struct nextfnfield *next;
572 struct fn_field fnfield;
576 /* Member function fieldlist array, contains name of possibly overloaded
577 member function, number of overloaded member functions and a pointer
578 to the head of the member function field chain. */
583 struct nextfnfield *head;
587 /* Number of entries in the fnfieldlists array. */
591 /* Various complaints about symbol reading that don't abort the process */
594 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1)
596 complaint (&symfile_complaints, "non-constant array bounds form '%s' ignored",
601 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
603 complaint (&symfile_complaints,
604 "statement list doesn't fit in .debug_line section");
608 dwarf2_complex_location_expr_complaint (void)
610 complaint (&symfile_complaints, "location expression too complex");
614 dwarf2_unsupported_at_frame_base_complaint (const char *arg1)
616 complaint (&symfile_complaints,
617 "unsupported DW_AT_frame_base for function '%s'", arg1);
621 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
624 complaint (&symfile_complaints,
625 "const value length mismatch for '%s', got %d, expected %d", arg1,
630 dwarf2_macros_too_long_complaint (void)
632 complaint (&symfile_complaints,
633 "macro info runs off end of `.debug_macinfo' section");
637 dwarf2_macro_malformed_definition_complaint (const char *arg1)
639 complaint (&symfile_complaints,
640 "macro debug info contains a malformed macro definition:\n`%s'",
645 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
647 complaint (&symfile_complaints,
648 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
651 /* local function prototypes */
653 static void dwarf2_locate_sections (bfd *, asection *, void *);
656 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
659 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
661 static char *scan_partial_symbols (char *, CORE_ADDR *, CORE_ADDR *,
663 const char *namespace);
665 static void add_partial_symbol (struct partial_die_info *, struct dwarf2_cu *,
666 const char *namespace);
668 static char *add_partial_namespace (struct partial_die_info *pdi,
670 CORE_ADDR *lowpc, CORE_ADDR *highpc,
671 struct dwarf2_cu *cu,
672 const char *namespace);
674 static char *add_partial_enumeration (struct partial_die_info *enum_pdi,
676 struct dwarf2_cu *cu,
677 const char *namespace);
679 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
682 struct dwarf2_cu *cu);
684 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
686 static void psymtab_to_symtab_1 (struct partial_symtab *);
688 char *dwarf2_read_section (struct objfile *, asection *);
690 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
692 static void dwarf2_empty_abbrev_table (void *);
694 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
697 static char *read_partial_die (struct partial_die_info *,
698 bfd *, char *, struct dwarf2_cu *);
700 static char *read_full_die (struct die_info **, bfd *, char *,
701 struct dwarf2_cu *, int *);
703 static char *read_attribute (struct attribute *, struct attr_abbrev *,
704 bfd *, char *, struct dwarf2_cu *);
706 static char *read_attribute_value (struct attribute *, unsigned,
707 bfd *, char *, struct dwarf2_cu *);
709 static unsigned int read_1_byte (bfd *, char *);
711 static int read_1_signed_byte (bfd *, char *);
713 static unsigned int read_2_bytes (bfd *, char *);
715 static unsigned int read_4_bytes (bfd *, char *);
717 static unsigned long read_8_bytes (bfd *, char *);
719 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
722 static LONGEST read_initial_length (bfd *, char *,
723 struct comp_unit_head *, int *bytes_read);
725 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
728 static char *read_n_bytes (bfd *, char *, unsigned int);
730 static char *read_string (bfd *, char *, unsigned int *);
732 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
735 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
737 static long read_signed_leb128 (bfd *, char *, unsigned int *);
739 static void set_cu_language (unsigned int);
741 static struct attribute *dwarf_attr (struct die_info *, unsigned int);
743 static int die_is_declaration (struct die_info *);
745 static void free_line_header (struct line_header *lh);
747 static struct line_header *(dwarf_decode_line_header
748 (unsigned int offset,
749 bfd *abfd, struct dwarf2_cu *cu));
751 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
754 static void dwarf2_start_subfile (char *, char *);
756 static struct symbol *new_symbol (struct die_info *, struct type *,
759 static void dwarf2_const_value (struct attribute *, struct symbol *,
762 static void dwarf2_const_value_data (struct attribute *attr,
766 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
768 static struct type *die_containing_type (struct die_info *,
772 static struct type *type_at_offset (unsigned int, struct objfile *);
775 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
777 static void read_type_die (struct die_info *, struct dwarf2_cu *);
779 static void read_typedef (struct die_info *, struct dwarf2_cu *);
781 static void read_base_type (struct die_info *, struct dwarf2_cu *);
783 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
785 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
787 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
789 static int dwarf2_get_pc_bounds (struct die_info *,
790 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
792 static void dwarf2_add_field (struct field_info *, struct die_info *,
795 static void dwarf2_attach_fields_to_type (struct field_info *,
796 struct type *, struct dwarf2_cu *);
798 static void dwarf2_add_member_fn (struct field_info *,
799 struct die_info *, struct type *,
802 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
803 struct type *, struct dwarf2_cu *);
805 static void read_structure_scope (struct die_info *, struct dwarf2_cu *);
807 static void read_common_block (struct die_info *, struct dwarf2_cu *);
809 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
811 static void read_enumeration (struct die_info *, struct dwarf2_cu *);
813 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
815 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
817 static void read_array_type (struct die_info *, struct dwarf2_cu *);
819 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
821 static void read_tag_ptr_to_member_type (struct die_info *,
824 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
826 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
828 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
830 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
832 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
834 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
836 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
839 struct die_info *parent);
841 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
844 struct die_info *parent);
846 static void free_die_list (struct die_info *);
848 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
850 static void process_die (struct die_info *, struct dwarf2_cu *);
852 static char *dwarf2_linkage_name (struct die_info *);
854 static char *dwarf2_name (struct die_info *die);
856 static struct die_info *dwarf2_extension (struct die_info *die);
858 static char *dwarf_tag_name (unsigned int);
860 static char *dwarf_attr_name (unsigned int);
862 static char *dwarf_form_name (unsigned int);
864 static char *dwarf_stack_op_name (unsigned int);
866 static char *dwarf_bool_name (unsigned int);
868 static char *dwarf_type_encoding_name (unsigned int);
871 static char *dwarf_cfi_name (unsigned int);
873 struct die_info *copy_die (struct die_info *);
876 static struct die_info *sibling_die (struct die_info *);
878 static void dump_die (struct die_info *);
880 static void dump_die_list (struct die_info *);
882 static void store_in_ref_table (unsigned int, struct die_info *);
884 static void dwarf2_empty_hash_tables (void);
886 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
888 static struct die_info *follow_die_ref (unsigned int);
890 static struct type *dwarf2_fundamental_type (struct objfile *, int);
892 /* memory allocation interface */
894 static void dwarf2_free_tmp_obstack (void *);
896 static struct dwarf_block *dwarf_alloc_block (void);
898 static struct abbrev_info *dwarf_alloc_abbrev (void);
900 static struct die_info *dwarf_alloc_die (void);
902 static void initialize_cu_func_list (void);
904 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR);
906 static void dwarf_decode_macros (struct line_header *, unsigned int,
907 char *, bfd *, struct dwarf2_cu *);
909 static int attr_form_is_block (struct attribute *);
912 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
913 struct dwarf2_cu *cu);
915 /* Try to locate the sections we need for DWARF 2 debugging
916 information and return true if we have enough to do something. */
919 dwarf2_has_info (bfd *abfd)
921 dwarf_info_section = 0;
922 dwarf_abbrev_section = 0;
923 dwarf_line_section = 0;
924 dwarf_str_section = 0;
925 dwarf_macinfo_section = 0;
926 dwarf_frame_section = 0;
927 dwarf_eh_frame_section = 0;
928 dwarf_ranges_section = 0;
929 dwarf_loc_section = 0;
931 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
932 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
935 /* This function is mapped across the sections and remembers the
936 offset and size of each of the debugging sections we are interested
940 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
942 if (strcmp (sectp->name, INFO_SECTION) == 0)
944 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
945 dwarf_info_section = sectp;
947 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
949 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
950 dwarf_abbrev_section = sectp;
952 else if (strcmp (sectp->name, LINE_SECTION) == 0)
954 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
955 dwarf_line_section = sectp;
957 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
959 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
960 dwarf_pubnames_section = sectp;
962 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
964 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
965 dwarf_aranges_section = sectp;
967 else if (strcmp (sectp->name, LOC_SECTION) == 0)
969 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
970 dwarf_loc_section = sectp;
972 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
974 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
975 dwarf_macinfo_section = sectp;
977 else if (strcmp (sectp->name, STR_SECTION) == 0)
979 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
980 dwarf_str_section = sectp;
982 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
984 dwarf_frame_size = bfd_get_section_size_before_reloc (sectp);
985 dwarf_frame_section = sectp;
987 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
989 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
990 if (aflag & SEC_HAS_CONTENTS)
992 dwarf_eh_frame_size = bfd_get_section_size_before_reloc (sectp);
993 dwarf_eh_frame_section = sectp;
996 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
998 dwarf_ranges_size = bfd_get_section_size_before_reloc (sectp);
999 dwarf_ranges_section = sectp;
1003 /* Build a partial symbol table. */
1006 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1009 /* We definitely need the .debug_info and .debug_abbrev sections */
1011 dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1012 dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1014 if (dwarf_line_section)
1015 dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1017 dwarf_line_buffer = NULL;
1019 if (dwarf_str_section)
1020 dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1022 dwarf_str_buffer = NULL;
1024 if (dwarf_macinfo_section)
1025 dwarf_macinfo_buffer = dwarf2_read_section (objfile,
1026 dwarf_macinfo_section);
1028 dwarf_macinfo_buffer = NULL;
1030 if (dwarf_ranges_section)
1031 dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1033 dwarf_ranges_buffer = NULL;
1035 if (dwarf_loc_section)
1036 dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1038 dwarf_loc_buffer = NULL;
1041 || (objfile->global_psymbols.size == 0
1042 && objfile->static_psymbols.size == 0))
1044 init_psymbol_list (objfile, 1024);
1048 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1050 /* Things are significantly easier if we have .debug_aranges and
1051 .debug_pubnames sections */
1053 dwarf2_build_psymtabs_easy (objfile, mainline);
1057 /* only test this case for now */
1059 /* In this case we have to work a bit harder */
1060 dwarf2_build_psymtabs_hard (objfile, mainline);
1065 /* Build the partial symbol table from the information in the
1066 .debug_pubnames and .debug_aranges sections. */
1069 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1071 bfd *abfd = objfile->obfd;
1072 char *aranges_buffer, *pubnames_buffer;
1073 char *aranges_ptr, *pubnames_ptr;
1074 unsigned int entry_length, version, info_offset, info_size;
1076 pubnames_buffer = dwarf2_read_section (objfile,
1077 dwarf_pubnames_section);
1078 pubnames_ptr = pubnames_buffer;
1079 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
1081 struct comp_unit_head cu_header;
1084 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1086 pubnames_ptr += bytes_read;
1087 version = read_1_byte (abfd, pubnames_ptr);
1089 info_offset = read_4_bytes (abfd, pubnames_ptr);
1091 info_size = read_4_bytes (abfd, pubnames_ptr);
1095 aranges_buffer = dwarf2_read_section (objfile,
1096 dwarf_aranges_section);
1101 /* Read in the comp unit header information from the debug_info at
1105 read_comp_unit_head (struct comp_unit_head *cu_header,
1106 char *info_ptr, bfd *abfd)
1110 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1112 info_ptr += bytes_read;
1113 cu_header->version = read_2_bytes (abfd, info_ptr);
1115 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1117 info_ptr += bytes_read;
1118 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1120 signed_addr = bfd_get_sign_extend_vma (abfd);
1121 if (signed_addr < 0)
1122 internal_error (__FILE__, __LINE__,
1123 "read_comp_unit_head: dwarf from non elf file");
1124 cu_header->signed_addr_p = signed_addr;
1128 /* Build the partial symbol table by doing a quick pass through the
1129 .debug_info and .debug_abbrev sections. */
1132 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1134 /* Instead of reading this into a big buffer, we should probably use
1135 mmap() on architectures that support it. (FIXME) */
1136 bfd *abfd = objfile->obfd;
1137 char *info_ptr, *abbrev_ptr;
1138 char *beg_of_comp_unit;
1139 struct partial_die_info comp_unit_die;
1140 struct partial_symtab *pst;
1141 struct cleanup *back_to;
1142 CORE_ADDR lowpc, highpc;
1144 info_ptr = dwarf_info_buffer;
1145 abbrev_ptr = dwarf_abbrev_buffer;
1147 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1148 the partial symbol scan, like attribute values.
1150 We could reduce our peak memory consumption during partial symbol
1151 table construction by freeing stuff from this obstack more often
1152 --- say, after processing each compilation unit, or each die ---
1153 but it turns out that this saves almost nothing. For an
1154 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1155 on dwarf2_tmp_obstack. Some investigation showed:
1157 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1158 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1159 all fixed-length values not requiring dynamic allocation.
1161 2) 30% of the attributes used the form DW_FORM_string. For
1162 DW_FORM_string, read_attribute simply hands back a pointer to
1163 the null-terminated string in dwarf_info_buffer, so no dynamic
1164 allocation is needed there either.
1166 3) The remaining 1% of the attributes all used DW_FORM_block1.
1167 75% of those were DW_AT_frame_base location lists for
1168 functions; the rest were DW_AT_location attributes, probably
1169 for the global variables.
1171 Anyway, what this all means is that the memory the dwarf2
1172 reader uses as temporary space reading partial symbols is about
1173 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1175 obstack_init (&dwarf2_tmp_obstack);
1176 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1178 /* Since the objects we're extracting from dwarf_info_buffer vary in
1179 length, only the individual functions to extract them (like
1180 read_comp_unit_head and read_partial_die) can really know whether
1181 the buffer is large enough to hold another complete object.
1183 At the moment, they don't actually check that. If
1184 dwarf_info_buffer holds just one extra byte after the last
1185 compilation unit's dies, then read_comp_unit_head will happily
1186 read off the end of the buffer. read_partial_die is similarly
1187 casual. Those functions should be fixed.
1189 For this loop condition, simply checking whether there's any data
1190 left at all should be sufficient. */
1191 while (info_ptr < dwarf_info_buffer + dwarf_info_size)
1193 struct dwarf2_cu cu;
1194 beg_of_comp_unit = info_ptr;
1196 cu.objfile = objfile;
1197 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1199 if (cu.header.version != 2)
1201 error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu.header.version, 2, bfd_get_filename (abfd));
1204 if (cu.header.abbrev_offset >= dwarf_abbrev_size)
1206 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1207 (long) cu.header.abbrev_offset,
1208 (long) (beg_of_comp_unit - dwarf_info_buffer),
1209 bfd_get_filename (abfd));
1212 if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size
1213 > dwarf_info_buffer + dwarf_info_size)
1215 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1216 (long) cu.header.length,
1217 (long) (beg_of_comp_unit - dwarf_info_buffer),
1218 bfd_get_filename (abfd));
1221 /* Complete the cu_header */
1222 cu.header.offset = beg_of_comp_unit - dwarf_info_buffer;
1223 cu.header.first_die_ptr = info_ptr;
1224 cu.header.cu_head_ptr = beg_of_comp_unit;
1226 /* Read the abbrevs for this compilation unit into a table */
1227 dwarf2_read_abbrevs (abfd, &cu);
1228 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1230 /* Read the compilation unit die */
1231 info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr,
1234 /* Set the language we're debugging */
1235 set_cu_language (comp_unit_die.language);
1237 /* Allocate a new partial symbol table structure */
1238 pst = start_psymtab_common (objfile, objfile->section_offsets,
1239 comp_unit_die.name ? comp_unit_die.name : "",
1240 comp_unit_die.lowpc,
1241 objfile->global_psymbols.next,
1242 objfile->static_psymbols.next);
1244 pst->read_symtab_private = (char *)
1245 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
1246 cu_header_offset = beg_of_comp_unit - dwarf_info_buffer;
1247 DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
1248 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
1249 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
1250 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
1251 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
1252 DWARF_LINE_SIZE (pst) = dwarf_line_size;
1253 DWARF_STR_BUFFER (pst) = dwarf_str_buffer;
1254 DWARF_STR_SIZE (pst) = dwarf_str_size;
1255 DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer;
1256 DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size;
1257 DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer;
1258 DWARF_RANGES_SIZE (pst) = dwarf_ranges_size;
1259 DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer;
1260 DWARF_LOC_SIZE (pst) = dwarf_loc_size;
1261 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1263 /* Store the function that reads in the rest of the symbol table */
1264 pst->read_symtab = dwarf2_psymtab_to_symtab;
1266 /* Check if comp unit has_children.
1267 If so, read the rest of the partial symbols from this comp unit.
1268 If not, there's no more debug_info for this comp unit. */
1269 if (comp_unit_die.has_children)
1271 lowpc = ((CORE_ADDR) -1);
1272 highpc = ((CORE_ADDR) 0);
1274 info_ptr = scan_partial_symbols (info_ptr, &lowpc, &highpc,
1277 /* If we didn't find a lowpc, set it to highpc to avoid
1278 complaints from `maint check'. */
1279 if (lowpc == ((CORE_ADDR) -1))
1282 /* If the compilation unit didn't have an explicit address range,
1283 then use the information extracted from its child dies. */
1284 if (! comp_unit_die.has_pc_info)
1286 comp_unit_die.lowpc = lowpc;
1287 comp_unit_die.highpc = highpc;
1290 pst->textlow = comp_unit_die.lowpc + baseaddr;
1291 pst->texthigh = comp_unit_die.highpc + baseaddr;
1293 pst->n_global_syms = objfile->global_psymbols.next -
1294 (objfile->global_psymbols.list + pst->globals_offset);
1295 pst->n_static_syms = objfile->static_psymbols.next -
1296 (objfile->static_psymbols.list + pst->statics_offset);
1297 sort_pst_symbols (pst);
1299 /* If there is already a psymtab or symtab for a file of this
1300 name, remove it. (If there is a symtab, more drastic things
1301 also happen.) This happens in VxWorks. */
1302 free_named_symtabs (pst->filename);
1304 info_ptr = beg_of_comp_unit + cu.header.length
1305 + cu.header.initial_length_size;
1307 do_cleanups (back_to);
1310 /* Read in all interesting dies to the end of the compilation unit or
1311 to the end of the current namespace. NAMESPACE is NULL if we
1312 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1313 it's the name of the current namespace. In particular, it's the
1314 empty string if we're currently in the global namespace but have
1315 previously encountered a DW_TAG_namespace. */
1318 scan_partial_symbols (char *info_ptr, CORE_ADDR *lowpc,
1319 CORE_ADDR *highpc, struct dwarf2_cu *cu,
1320 const char *namespace)
1322 struct objfile *objfile = cu->objfile;
1323 bfd *abfd = objfile->obfd;
1324 struct partial_die_info pdi;
1326 /* Now, march along the PDI's, descending into ones which have
1327 interesting children but skipping the children of the other ones,
1328 until we reach the end of the compilation unit. */
1332 /* This flag tells whether or not info_ptr has gotten updated
1334 int info_ptr_updated = 0;
1336 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1338 /* Anonymous namespaces have no name but have interesting
1339 children, so we need to look at them. Ditto for anonymous
1342 if (pdi.name != NULL || pdi.tag == DW_TAG_namespace
1343 || pdi.tag == DW_TAG_enumeration_type)
1347 case DW_TAG_subprogram:
1348 if (pdi.has_pc_info)
1350 if (pdi.lowpc < *lowpc)
1354 if (pdi.highpc > *highpc)
1356 *highpc = pdi.highpc;
1358 if (!pdi.is_declaration)
1360 add_partial_symbol (&pdi, cu, namespace);
1364 case DW_TAG_variable:
1365 case DW_TAG_typedef:
1366 case DW_TAG_union_type:
1367 case DW_TAG_class_type:
1368 case DW_TAG_structure_type:
1369 if (!pdi.is_declaration)
1371 add_partial_symbol (&pdi, cu, namespace);
1374 case DW_TAG_enumeration_type:
1375 if (!pdi.is_declaration)
1377 info_ptr = add_partial_enumeration (&pdi, info_ptr, cu,
1379 info_ptr_updated = 1;
1382 case DW_TAG_base_type:
1383 /* File scope base type definitions are added to the partial
1385 add_partial_symbol (&pdi, cu, namespace);
1387 case DW_TAG_namespace:
1388 /* We've hit a DW_TAG_namespace entry, so we know this
1389 file has been compiled using a compiler that
1390 generates them; update NAMESPACE to reflect that. */
1391 if (namespace == NULL)
1393 info_ptr = add_partial_namespace (&pdi, info_ptr, lowpc, highpc,
1395 info_ptr_updated = 1;
1405 /* If the die has a sibling, skip to the sibling, unless another
1406 function has already updated info_ptr for us. */
1408 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1409 or not we want to update this depends on enough stuff (not
1410 only pdi.tag but also whether or not pdi.name is NULL) that
1411 this seems like the easiest way to handle the issue. */
1413 if (!info_ptr_updated)
1414 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1421 add_partial_symbol (struct partial_die_info *pdi,
1422 struct dwarf2_cu *cu, const char *namespace)
1424 struct objfile *objfile = cu->objfile;
1426 const struct partial_symbol *psym = NULL;
1430 case DW_TAG_subprogram:
1431 if (pdi->is_external)
1433 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1434 mst_text, objfile); */
1435 psym = add_psymbol_to_list (pdi->name, strlen (pdi->name),
1436 VAR_DOMAIN, LOC_BLOCK,
1437 &objfile->global_psymbols,
1438 0, pdi->lowpc + baseaddr,
1439 cu_language, objfile);
1443 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1444 mst_file_text, objfile); */
1445 psym = add_psymbol_to_list (pdi->name, strlen (pdi->name),
1446 VAR_DOMAIN, LOC_BLOCK,
1447 &objfile->static_psymbols,
1448 0, pdi->lowpc + baseaddr,
1449 cu_language, objfile);
1452 case DW_TAG_variable:
1453 if (pdi->is_external)
1456 Don't enter into the minimal symbol tables as there is
1457 a minimal symbol table entry from the ELF symbols already.
1458 Enter into partial symbol table if it has a location
1459 descriptor or a type.
1460 If the location descriptor is missing, new_symbol will create
1461 a LOC_UNRESOLVED symbol, the address of the variable will then
1462 be determined from the minimal symbol table whenever the variable
1464 The address for the partial symbol table entry is not
1465 used by GDB, but it comes in handy for debugging partial symbol
1469 addr = decode_locdesc (pdi->locdesc, cu);
1470 if (pdi->locdesc || pdi->has_type)
1471 psym = add_psymbol_to_list (pdi->name, strlen (pdi->name),
1472 VAR_DOMAIN, LOC_STATIC,
1473 &objfile->global_psymbols,
1475 cu_language, objfile);
1479 /* Static Variable. Skip symbols without location descriptors. */
1480 if (pdi->locdesc == NULL)
1482 addr = decode_locdesc (pdi->locdesc, cu);
1483 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1484 mst_file_data, objfile); */
1485 psym = add_psymbol_to_list (pdi->name, strlen (pdi->name),
1486 VAR_DOMAIN, LOC_STATIC,
1487 &objfile->static_psymbols,
1489 cu_language, objfile);
1492 case DW_TAG_typedef:
1493 case DW_TAG_base_type:
1494 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1495 VAR_DOMAIN, LOC_TYPEDEF,
1496 &objfile->static_psymbols,
1497 0, (CORE_ADDR) 0, cu_language, objfile);
1499 case DW_TAG_class_type:
1500 case DW_TAG_structure_type:
1501 case DW_TAG_union_type:
1502 case DW_TAG_enumeration_type:
1503 /* Skip aggregate types without children, these are external
1505 if (pdi->has_children == 0)
1507 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1508 STRUCT_DOMAIN, LOC_TYPEDEF,
1509 &objfile->static_psymbols,
1510 0, (CORE_ADDR) 0, cu_language, objfile);
1512 if (cu_language == language_cplus)
1514 /* For C++, these implicitly act as typedefs as well. */
1515 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1516 VAR_DOMAIN, LOC_TYPEDEF,
1517 &objfile->static_psymbols,
1518 0, (CORE_ADDR) 0, cu_language, objfile);
1521 case DW_TAG_enumerator:
1522 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1523 VAR_DOMAIN, LOC_CONST,
1524 &objfile->static_psymbols,
1525 0, (CORE_ADDR) 0, cu_language, objfile);
1531 /* Check to see if we should scan the name for possible namespace
1532 info. Only do this if this is C++, if we don't have namespace
1533 debugging info in the file, if the psym is of an appropriate type
1534 (otherwise we'll have psym == NULL), and if we actually had a
1535 mangled name to begin with. */
1537 if (cu_language == language_cplus
1538 && namespace == NULL
1540 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1541 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1545 /* Read a partial die corresponding to a namespace; also, add a symbol
1546 corresponding to that namespace to the symbol table. NAMESPACE is
1547 the name of the enclosing namespace. */
1550 add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
1551 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1552 struct dwarf2_cu *cu, const char *namespace)
1554 struct objfile *objfile = cu->objfile;
1555 const char *new_name = pdi->name;
1558 /* Calculate the full name of the namespace that we just entered. */
1560 if (new_name == NULL)
1561 new_name = "(anonymous namespace)";
1562 full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1);
1563 strcpy (full_name, namespace);
1564 if (*namespace != '\0')
1565 strcat (full_name, "::");
1566 strcat (full_name, new_name);
1568 /* FIXME: carlton/2003-06-27: Once we build qualified names for more
1569 symbols than just namespaces, we should replace this by a call to
1570 add_partial_symbol. */
1572 add_psymbol_to_list (full_name, strlen (full_name),
1573 VAR_DOMAIN, LOC_TYPEDEF,
1574 &objfile->global_psymbols,
1575 0, 0, cu_language, objfile);
1577 /* Now scan partial symbols in that namespace. */
1579 if (pdi->has_children)
1580 info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name);
1585 /* Read a partial die corresponding to an enumeration type. */
1588 add_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr,
1589 struct dwarf2_cu *cu, const char *namespace)
1591 struct objfile *objfile = cu->objfile;
1592 bfd *abfd = objfile->obfd;
1593 struct partial_die_info pdi;
1595 if (enum_pdi->name != NULL)
1596 add_partial_symbol (enum_pdi, cu, namespace);
1600 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1603 if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL)
1604 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1606 add_partial_symbol (&pdi, cu, namespace);
1612 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1616 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
1617 bfd *abfd, struct dwarf2_cu *cu)
1619 /* Do we know the sibling already? */
1621 if (orig_pdi->sibling)
1622 return orig_pdi->sibling;
1624 /* Are there any children to deal with? */
1626 if (!orig_pdi->has_children)
1629 /* Okay, we don't know the sibling, but we have children that we
1630 want to skip. So read children until we run into one without a
1631 tag; return whatever follows it. */
1635 struct partial_die_info pdi;
1637 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1642 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1646 /* Expand this partial symbol table into a full symbol table. */
1649 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
1651 /* FIXME: This is barely more than a stub. */
1656 warning ("bug: psymtab for %s is already read in.", pst->filename);
1662 printf_filtered ("Reading in symbols for %s...", pst->filename);
1663 gdb_flush (gdb_stdout);
1666 psymtab_to_symtab_1 (pst);
1668 /* Finish up the debug error message. */
1670 printf_filtered ("done.\n");
1676 psymtab_to_symtab_1 (struct partial_symtab *pst)
1678 struct objfile *objfile = pst->objfile;
1679 bfd *abfd = objfile->obfd;
1680 struct dwarf2_cu cu;
1681 struct die_info *dies;
1682 unsigned long offset;
1683 CORE_ADDR lowpc, highpc;
1684 struct die_info *child_die;
1686 struct symtab *symtab;
1687 struct cleanup *back_to;
1688 struct attribute *attr;
1690 /* Set local variables from the partial symbol table info. */
1691 offset = DWARF_INFO_OFFSET (pst);
1692 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1693 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1694 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1695 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1696 dwarf_line_size = DWARF_LINE_SIZE (pst);
1697 dwarf_str_buffer = DWARF_STR_BUFFER (pst);
1698 dwarf_str_size = DWARF_STR_SIZE (pst);
1699 dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst);
1700 dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst);
1701 dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst);
1702 dwarf_ranges_size = DWARF_RANGES_SIZE (pst);
1703 dwarf_loc_buffer = DWARF_LOC_BUFFER (pst);
1704 dwarf_loc_size = DWARF_LOC_SIZE (pst);
1705 baseaddr = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
1706 cu_header_offset = offset;
1707 info_ptr = dwarf_info_buffer + offset;
1709 obstack_init (&dwarf2_tmp_obstack);
1710 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1713 make_cleanup (really_free_pendings, NULL);
1715 cu.objfile = objfile;
1717 /* read in the comp_unit header */
1718 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1720 /* Read the abbrevs for this compilation unit */
1721 dwarf2_read_abbrevs (abfd, &cu);
1722 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1724 dies = read_comp_unit (info_ptr, abfd, &cu);
1726 make_cleanup_free_die_list (dies);
1728 /* Find the base address of the compilation unit for range lists and
1729 location lists. It will normally be specified by DW_AT_low_pc.
1730 In DWARF-3 draft 4, the base address could be overridden by
1731 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1732 compilation units with discontinuous ranges. */
1734 cu.header.base_known = 0;
1735 cu.header.base_address = 0;
1737 attr = dwarf_attr (dies, DW_AT_entry_pc);
1740 cu.header.base_address = DW_ADDR (attr);
1741 cu.header.base_known = 1;
1745 attr = dwarf_attr (dies, DW_AT_low_pc);
1748 cu.header.base_address = DW_ADDR (attr);
1749 cu.header.base_known = 1;
1753 /* Do line number decoding in read_file_scope () */
1754 process_die (dies, &cu);
1756 if (!dwarf2_get_pc_bounds (dies, &lowpc, &highpc, &cu))
1758 /* Some compilers don't define a DW_AT_high_pc attribute for
1759 the compilation unit. If the DW_AT_high_pc is missing,
1760 synthesize it, by scanning the DIE's below the compilation unit. */
1762 if (dies->child != NULL)
1764 child_die = dies->child;
1765 while (child_die && child_die->tag)
1767 if (child_die->tag == DW_TAG_subprogram)
1769 CORE_ADDR low, high;
1771 if (dwarf2_get_pc_bounds (child_die, &low, &high, &cu))
1773 highpc = max (highpc, high);
1776 child_die = sibling_die (child_die);
1780 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
1782 /* Set symtab language to language from DW_AT_language.
1783 If the compilation is from a C file generated by language preprocessors,
1784 do not set the language if it was already deduced by start_subfile. */
1786 && !(cu_language == language_c && symtab->language != language_c))
1788 symtab->language = cu_language;
1790 pst->symtab = symtab;
1793 do_cleanups (back_to);
1796 /* Process a die and its children. */
1799 process_die (struct die_info *die, struct dwarf2_cu *cu)
1803 case DW_TAG_padding:
1805 case DW_TAG_compile_unit:
1806 read_file_scope (die, cu);
1808 case DW_TAG_subprogram:
1809 read_subroutine_type (die, cu);
1810 read_func_scope (die, cu);
1812 case DW_TAG_inlined_subroutine:
1813 /* FIXME: These are ignored for now.
1814 They could be used to set breakpoints on all inlined instances
1815 of a function and make GDB `next' properly over inlined functions. */
1817 case DW_TAG_lexical_block:
1818 case DW_TAG_try_block:
1819 case DW_TAG_catch_block:
1820 read_lexical_block_scope (die, cu);
1822 case DW_TAG_class_type:
1823 case DW_TAG_structure_type:
1824 case DW_TAG_union_type:
1825 read_structure_scope (die, cu);
1827 case DW_TAG_enumeration_type:
1828 read_enumeration (die, cu);
1830 case DW_TAG_subroutine_type:
1831 read_subroutine_type (die, cu);
1833 case DW_TAG_array_type:
1834 read_array_type (die, cu);
1836 case DW_TAG_pointer_type:
1837 read_tag_pointer_type (die, cu);
1839 case DW_TAG_ptr_to_member_type:
1840 read_tag_ptr_to_member_type (die, cu);
1842 case DW_TAG_reference_type:
1843 read_tag_reference_type (die, cu);
1845 case DW_TAG_string_type:
1846 read_tag_string_type (die, cu);
1848 case DW_TAG_base_type:
1849 read_base_type (die, cu);
1850 if (dwarf_attr (die, DW_AT_name))
1852 /* Add a typedef symbol for the base type definition. */
1853 new_symbol (die, die->type, cu);
1856 case DW_TAG_common_block:
1857 read_common_block (die, cu);
1859 case DW_TAG_common_inclusion:
1861 case DW_TAG_namespace:
1862 if (!processing_has_namespace_info)
1864 processing_has_namespace_info = 1;
1865 processing_current_namespace = "";
1867 read_namespace (die, cu);
1869 case DW_TAG_imported_declaration:
1870 case DW_TAG_imported_module:
1871 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1872 information contained in these. DW_TAG_imported_declaration
1873 dies shouldn't have children; DW_TAG_imported_module dies
1874 shouldn't in the C++ case, but conceivably could in the
1875 Fortran case, so we'll have to replace this gdb_assert if
1876 Fortran compilers start generating that info. */
1877 if (!processing_has_namespace_info)
1879 processing_has_namespace_info = 1;
1880 processing_current_namespace = "";
1882 gdb_assert (die->child == NULL);
1885 new_symbol (die, NULL, cu);
1891 initialize_cu_func_list (void)
1893 cu_first_fn = cu_last_fn = cu_cached_fn = NULL;
1897 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
1899 struct objfile *objfile = cu->objfile;
1900 struct comp_unit_head *cu_header = &cu->header;
1901 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
1902 CORE_ADDR lowpc = ((CORE_ADDR) -1);
1903 CORE_ADDR highpc = ((CORE_ADDR) 0);
1904 struct attribute *attr;
1905 char *name = "<unknown>";
1906 char *comp_dir = NULL;
1907 struct die_info *child_die;
1908 bfd *abfd = objfile->obfd;
1909 struct line_header *line_header = 0;
1911 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
1913 if (die->child != NULL)
1915 child_die = die->child;
1916 while (child_die && child_die->tag)
1918 if (child_die->tag == DW_TAG_subprogram)
1920 CORE_ADDR low, high;
1922 if (dwarf2_get_pc_bounds (child_die, &low, &high, cu))
1924 lowpc = min (lowpc, low);
1925 highpc = max (highpc, high);
1928 child_die = sibling_die (child_die);
1933 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1934 from finish_block. */
1935 if (lowpc == ((CORE_ADDR) -1))
1940 attr = dwarf_attr (die, DW_AT_name);
1943 name = DW_STRING (attr);
1945 attr = dwarf_attr (die, DW_AT_comp_dir);
1948 comp_dir = DW_STRING (attr);
1951 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1952 directory, get rid of it. */
1953 char *cp = strchr (comp_dir, ':');
1955 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1960 if (objfile->ei.entry_point >= lowpc &&
1961 objfile->ei.entry_point < highpc)
1963 objfile->ei.deprecated_entry_file_lowpc = lowpc;
1964 objfile->ei.deprecated_entry_file_highpc = highpc;
1967 attr = dwarf_attr (die, DW_AT_language);
1970 set_cu_language (DW_UNSND (attr));
1973 /* We assume that we're processing GCC output. */
1974 processing_gcc_compilation = 2;
1976 /* FIXME:Do something here. */
1977 if (dip->at_producer != NULL)
1979 handle_producer (dip->at_producer);
1983 /* The compilation unit may be in a different language or objfile,
1984 zero out all remembered fundamental types. */
1985 memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
1987 start_symtab (name, comp_dir, lowpc);
1988 record_debugformat ("DWARF 2");
1990 initialize_cu_func_list ();
1992 /* Process all dies in compilation unit. */
1993 if (die->child != NULL)
1995 child_die = die->child;
1996 while (child_die && child_die->tag)
1998 process_die (child_die, cu);
1999 child_die = sibling_die (child_die);
2003 /* Decode line number information if present. */
2004 attr = dwarf_attr (die, DW_AT_stmt_list);
2007 unsigned int line_offset = DW_UNSND (attr);
2008 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2011 make_cleanup ((make_cleanup_ftype *) free_line_header,
2012 (void *) line_header);
2013 dwarf_decode_lines (line_header, comp_dir, abfd, cu);
2017 /* Decode macro information, if present. Dwarf 2 macro information
2018 refers to information in the line number info statement program
2019 header, so we can only read it if we've read the header
2021 attr = dwarf_attr (die, DW_AT_macro_info);
2022 if (attr && line_header)
2024 unsigned int macro_offset = DW_UNSND (attr);
2025 dwarf_decode_macros (line_header, macro_offset,
2026 comp_dir, abfd, cu);
2028 do_cleanups (back_to);
2032 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc)
2034 struct function_range *thisfn;
2036 thisfn = (struct function_range *)
2037 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range));
2038 thisfn->name = name;
2039 thisfn->lowpc = lowpc;
2040 thisfn->highpc = highpc;
2041 thisfn->seen_line = 0;
2042 thisfn->next = NULL;
2044 if (cu_last_fn == NULL)
2045 cu_first_fn = thisfn;
2047 cu_last_fn->next = thisfn;
2049 cu_last_fn = thisfn;
2053 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2055 struct objfile *objfile = cu->objfile;
2056 struct context_stack *new;
2059 struct die_info *child_die;
2060 struct attribute *attr;
2063 name = dwarf2_linkage_name (die);
2065 /* Ignore functions with missing or empty names and functions with
2066 missing or invalid low and high pc attributes. */
2067 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2073 /* Record the function range for dwarf_decode_lines. */
2074 add_to_cu_func_list (name, lowpc, highpc);
2076 if (objfile->ei.entry_point >= lowpc &&
2077 objfile->ei.entry_point < highpc)
2079 objfile->ei.entry_func_lowpc = lowpc;
2080 objfile->ei.entry_func_highpc = highpc;
2083 new = push_context (0, lowpc);
2084 new->name = new_symbol (die, die->type, cu);
2086 /* If there is a location expression for DW_AT_frame_base, record
2088 attr = dwarf_attr (die, DW_AT_frame_base);
2090 dwarf2_symbol_mark_computed (attr, new->name, cu);
2092 list_in_scope = &local_symbols;
2094 if (die->child != NULL)
2096 child_die = die->child;
2097 while (child_die && child_die->tag)
2099 process_die (child_die, cu);
2100 child_die = sibling_die (child_die);
2104 new = pop_context ();
2105 /* Make a block for the local symbols within. */
2106 finish_block (new->name, &local_symbols, new->old_blocks,
2107 lowpc, highpc, objfile);
2109 /* In C++, we can have functions nested inside functions (e.g., when
2110 a function declares a class that has methods). This means that
2111 when we finish processing a function scope, we may need to go
2112 back to building a containing block's symbol lists. */
2113 local_symbols = new->locals;
2114 param_symbols = new->params;
2116 /* If we've finished processing a top-level function, subsequent
2117 symbols go in the file symbol list. */
2118 if (outermost_context_p ())
2119 list_in_scope = &file_symbols;
2122 /* Process all the DIES contained within a lexical block scope. Start
2123 a new scope, process the dies, and then close the scope. */
2126 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2128 struct objfile *objfile = cu->objfile;
2129 struct context_stack *new;
2130 CORE_ADDR lowpc, highpc;
2131 struct die_info *child_die;
2133 /* Ignore blocks with missing or invalid low and high pc attributes. */
2134 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2135 as multiple lexical blocks? Handling children in a sane way would
2136 be nasty. Might be easier to properly extend generic blocks to
2138 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2143 push_context (0, lowpc);
2144 if (die->child != NULL)
2146 child_die = die->child;
2147 while (child_die && child_die->tag)
2149 process_die (child_die, cu);
2150 child_die = sibling_die (child_die);
2153 new = pop_context ();
2155 if (local_symbols != NULL)
2157 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2160 local_symbols = new->locals;
2163 /* Get low and high pc attributes from a die. Return 1 if the attributes
2164 are present and valid, otherwise, return 0. Return -1 if the range is
2165 discontinuous, i.e. derived from DW_AT_ranges information. */
2167 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2168 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2170 struct objfile *objfile = cu->objfile;
2171 struct comp_unit_head *cu_header = &cu->header;
2172 struct attribute *attr;
2173 bfd *obfd = objfile->obfd;
2178 attr = dwarf_attr (die, DW_AT_high_pc);
2181 high = DW_ADDR (attr);
2182 attr = dwarf_attr (die, DW_AT_low_pc);
2184 low = DW_ADDR (attr);
2186 /* Found high w/o low attribute. */
2189 /* Found consecutive range of addresses. */
2194 attr = dwarf_attr (die, DW_AT_ranges);
2197 unsigned int addr_size = cu_header->addr_size;
2198 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2199 /* Value of the DW_AT_ranges attribute is the offset in the
2200 .debug_ranges section. */
2201 unsigned int offset = DW_UNSND (attr);
2202 /* Base address selection entry. */
2210 found_base = cu_header->base_known;
2211 base = cu_header->base_address;
2213 if (offset >= dwarf_ranges_size)
2215 complaint (&symfile_complaints,
2216 "Offset %d out of bounds for DW_AT_ranges attribute",
2220 buffer = dwarf_ranges_buffer + offset;
2222 /* Read in the largest possible address. */
2223 marker = read_address (obfd, buffer, cu, &dummy);
2224 if ((marker & mask) == mask)
2226 /* If we found the largest possible address, then
2227 read the base address. */
2228 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2229 buffer += 2 * addr_size;
2230 offset += 2 * addr_size;
2238 CORE_ADDR range_beginning, range_end;
2240 range_beginning = read_address (obfd, buffer, cu, &dummy);
2241 buffer += addr_size;
2242 range_end = read_address (obfd, buffer, cu, &dummy);
2243 buffer += addr_size;
2244 offset += 2 * addr_size;
2246 /* An end of list marker is a pair of zero addresses. */
2247 if (range_beginning == 0 && range_end == 0)
2248 /* Found the end of list entry. */
2251 /* Each base address selection entry is a pair of 2 values.
2252 The first is the largest possible address, the second is
2253 the base address. Check for a base address here. */
2254 if ((range_beginning & mask) == mask)
2256 /* If we found the largest possible address, then
2257 read the base address. */
2258 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2265 /* We have no valid base address for the ranges
2267 complaint (&symfile_complaints,
2268 "Invalid .debug_ranges data (no base address)");
2272 range_beginning += base;
2275 /* FIXME: This is recording everything as a low-high
2276 segment of consecutive addresses. We should have a
2277 data structure for discontiguous block ranges
2281 low = range_beginning;
2287 if (range_beginning < low)
2288 low = range_beginning;
2289 if (range_end > high)
2295 /* If the first entry is an end-of-list marker, the range
2296 describes an empty scope, i.e. no instructions. */
2306 /* When using the GNU linker, .gnu.linkonce. sections are used to
2307 eliminate duplicate copies of functions and vtables and such.
2308 The linker will arbitrarily choose one and discard the others.
2309 The AT_*_pc values for such functions refer to local labels in
2310 these sections. If the section from that file was discarded, the
2311 labels are not in the output, so the relocs get a value of 0.
2312 If this is a discarded function, mark the pc bounds as invalid,
2313 so that GDB will ignore it. */
2314 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2322 /* Add an aggregate field to the field list. */
2325 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2326 struct dwarf2_cu *cu)
2328 struct objfile *objfile = cu->objfile;
2329 struct nextfield *new_field;
2330 struct attribute *attr;
2332 char *fieldname = "";
2334 /* Allocate a new field list entry and link it in. */
2335 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2336 make_cleanup (xfree, new_field);
2337 memset (new_field, 0, sizeof (struct nextfield));
2338 new_field->next = fip->fields;
2339 fip->fields = new_field;
2342 /* Handle accessibility and virtuality of field.
2343 The default accessibility for members is public, the default
2344 accessibility for inheritance is private. */
2345 if (die->tag != DW_TAG_inheritance)
2346 new_field->accessibility = DW_ACCESS_public;
2348 new_field->accessibility = DW_ACCESS_private;
2349 new_field->virtuality = DW_VIRTUALITY_none;
2351 attr = dwarf_attr (die, DW_AT_accessibility);
2353 new_field->accessibility = DW_UNSND (attr);
2354 if (new_field->accessibility != DW_ACCESS_public)
2355 fip->non_public_fields = 1;
2356 attr = dwarf_attr (die, DW_AT_virtuality);
2358 new_field->virtuality = DW_UNSND (attr);
2360 fp = &new_field->field;
2362 if (die->tag == DW_TAG_member && ! die_is_declaration (die))
2364 /* Data member other than a C++ static data member. */
2366 /* Get type of field. */
2367 fp->type = die_type (die, cu);
2369 FIELD_STATIC_KIND (*fp) = 0;
2371 /* Get bit size of field (zero if none). */
2372 attr = dwarf_attr (die, DW_AT_bit_size);
2375 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2379 FIELD_BITSIZE (*fp) = 0;
2382 /* Get bit offset of field. */
2383 attr = dwarf_attr (die, DW_AT_data_member_location);
2386 FIELD_BITPOS (*fp) =
2387 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2390 FIELD_BITPOS (*fp) = 0;
2391 attr = dwarf_attr (die, DW_AT_bit_offset);
2394 if (BITS_BIG_ENDIAN)
2396 /* For big endian bits, the DW_AT_bit_offset gives the
2397 additional bit offset from the MSB of the containing
2398 anonymous object to the MSB of the field. We don't
2399 have to do anything special since we don't need to
2400 know the size of the anonymous object. */
2401 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2405 /* For little endian bits, compute the bit offset to the
2406 MSB of the anonymous object, subtract off the number of
2407 bits from the MSB of the field to the MSB of the
2408 object, and then subtract off the number of bits of
2409 the field itself. The result is the bit offset of
2410 the LSB of the field. */
2412 int bit_offset = DW_UNSND (attr);
2414 attr = dwarf_attr (die, DW_AT_byte_size);
2417 /* The size of the anonymous object containing
2418 the bit field is explicit, so use the
2419 indicated size (in bytes). */
2420 anonymous_size = DW_UNSND (attr);
2424 /* The size of the anonymous object containing
2425 the bit field must be inferred from the type
2426 attribute of the data member containing the
2428 anonymous_size = TYPE_LENGTH (fp->type);
2430 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2431 - bit_offset - FIELD_BITSIZE (*fp);
2435 /* Get name of field. */
2436 attr = dwarf_attr (die, DW_AT_name);
2437 if (attr && DW_STRING (attr))
2438 fieldname = DW_STRING (attr);
2439 fp->name = obsavestring (fieldname, strlen (fieldname),
2440 &objfile->type_obstack);
2442 /* Change accessibility for artificial fields (e.g. virtual table
2443 pointer or virtual base class pointer) to private. */
2444 if (dwarf_attr (die, DW_AT_artificial))
2446 new_field->accessibility = DW_ACCESS_private;
2447 fip->non_public_fields = 1;
2450 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2452 /* C++ static member. */
2454 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2455 is a declaration, but all versions of G++ as of this writing
2456 (so through at least 3.2.1) incorrectly generate
2457 DW_TAG_variable tags. */
2461 /* Get name of field. */
2462 attr = dwarf_attr (die, DW_AT_name);
2463 if (attr && DW_STRING (attr))
2464 fieldname = DW_STRING (attr);
2468 /* Get physical name. */
2469 physname = dwarf2_linkage_name (die);
2471 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
2472 &objfile->type_obstack));
2473 FIELD_TYPE (*fp) = die_type (die, cu);
2474 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
2475 &objfile->type_obstack);
2477 else if (die->tag == DW_TAG_inheritance)
2479 /* C++ base class field. */
2480 attr = dwarf_attr (die, DW_AT_data_member_location);
2482 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
2484 FIELD_BITSIZE (*fp) = 0;
2485 FIELD_STATIC_KIND (*fp) = 0;
2486 FIELD_TYPE (*fp) = die_type (die, cu);
2487 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
2488 fip->nbaseclasses++;
2492 /* Create the vector of fields, and attach it to the type. */
2495 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
2496 struct dwarf2_cu *cu)
2498 int nfields = fip->nfields;
2500 /* Record the field count, allocate space for the array of fields,
2501 and create blank accessibility bitfields if necessary. */
2502 TYPE_NFIELDS (type) = nfields;
2503 TYPE_FIELDS (type) = (struct field *)
2504 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2505 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2507 if (fip->non_public_fields)
2509 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2511 TYPE_FIELD_PRIVATE_BITS (type) =
2512 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2513 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2515 TYPE_FIELD_PROTECTED_BITS (type) =
2516 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2517 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2519 TYPE_FIELD_IGNORE_BITS (type) =
2520 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2521 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2524 /* If the type has baseclasses, allocate and clear a bit vector for
2525 TYPE_FIELD_VIRTUAL_BITS. */
2526 if (fip->nbaseclasses)
2528 int num_bytes = B_BYTES (fip->nbaseclasses);
2531 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2532 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2533 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2534 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
2535 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
2538 /* Copy the saved-up fields into the field vector. Start from the head
2539 of the list, adding to the tail of the field array, so that they end
2540 up in the same order in the array in which they were added to the list. */
2541 while (nfields-- > 0)
2543 TYPE_FIELD (type, nfields) = fip->fields->field;
2544 switch (fip->fields->accessibility)
2546 case DW_ACCESS_private:
2547 SET_TYPE_FIELD_PRIVATE (type, nfields);
2550 case DW_ACCESS_protected:
2551 SET_TYPE_FIELD_PROTECTED (type, nfields);
2554 case DW_ACCESS_public:
2558 /* Unknown accessibility. Complain and treat it as public. */
2560 complaint (&symfile_complaints, "unsupported accessibility %d",
2561 fip->fields->accessibility);
2565 if (nfields < fip->nbaseclasses)
2567 switch (fip->fields->virtuality)
2569 case DW_VIRTUALITY_virtual:
2570 case DW_VIRTUALITY_pure_virtual:
2571 SET_TYPE_FIELD_VIRTUAL (type, nfields);
2575 fip->fields = fip->fields->next;
2579 /* Add a member function to the proper fieldlist. */
2582 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
2583 struct type *type, struct dwarf2_cu *cu)
2585 struct objfile *objfile = cu->objfile;
2586 struct attribute *attr;
2587 struct fnfieldlist *flp;
2589 struct fn_field *fnp;
2592 struct nextfnfield *new_fnfield;
2594 /* Get name of member function. */
2595 attr = dwarf_attr (die, DW_AT_name);
2596 if (attr && DW_STRING (attr))
2597 fieldname = DW_STRING (attr);
2601 /* Get the mangled name. */
2602 physname = dwarf2_linkage_name (die);
2604 /* Look up member function name in fieldlist. */
2605 for (i = 0; i < fip->nfnfields; i++)
2607 if (DEPRECATED_STREQ (fip->fnfieldlists[i].name, fieldname))
2611 /* Create new list element if necessary. */
2612 if (i < fip->nfnfields)
2613 flp = &fip->fnfieldlists[i];
2616 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2618 fip->fnfieldlists = (struct fnfieldlist *)
2619 xrealloc (fip->fnfieldlists,
2620 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2621 * sizeof (struct fnfieldlist));
2622 if (fip->nfnfields == 0)
2623 make_cleanup (free_current_contents, &fip->fnfieldlists);
2625 flp = &fip->fnfieldlists[fip->nfnfields];
2626 flp->name = fieldname;
2632 /* Create a new member function field and chain it to the field list
2634 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2635 make_cleanup (xfree, new_fnfield);
2636 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2637 new_fnfield->next = flp->head;
2638 flp->head = new_fnfield;
2641 /* Fill in the member function field info. */
2642 fnp = &new_fnfield->fnfield;
2643 fnp->physname = obsavestring (physname, strlen (physname),
2644 &objfile->type_obstack);
2645 fnp->type = alloc_type (objfile);
2646 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2648 int nparams = TYPE_NFIELDS (die->type);
2650 /* TYPE is the domain of this method, and DIE->TYPE is the type
2651 of the method itself (TYPE_CODE_METHOD). */
2652 smash_to_method_type (fnp->type, type,
2653 TYPE_TARGET_TYPE (die->type),
2654 TYPE_FIELDS (die->type),
2655 TYPE_NFIELDS (die->type),
2656 TYPE_VARARGS (die->type));
2658 /* Handle static member functions.
2659 Dwarf2 has no clean way to discern C++ static and non-static
2660 member functions. G++ helps GDB by marking the first
2661 parameter for non-static member functions (which is the
2662 this pointer) as artificial. We obtain this information
2663 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2664 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2665 fnp->voffset = VOFFSET_STATIC;
2668 complaint (&symfile_complaints, "member function type missing for '%s'",
2671 /* Get fcontext from DW_AT_containing_type if present. */
2672 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2673 fnp->fcontext = die_containing_type (die, cu);
2675 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2676 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2678 /* Get accessibility. */
2679 attr = dwarf_attr (die, DW_AT_accessibility);
2682 switch (DW_UNSND (attr))
2684 case DW_ACCESS_private:
2685 fnp->is_private = 1;
2687 case DW_ACCESS_protected:
2688 fnp->is_protected = 1;
2693 /* Check for artificial methods. */
2694 attr = dwarf_attr (die, DW_AT_artificial);
2695 if (attr && DW_UNSND (attr) != 0)
2696 fnp->is_artificial = 1;
2698 /* Get index in virtual function table if it is a virtual member function. */
2699 attr = dwarf_attr (die, DW_AT_vtable_elem_location);
2702 /* Support the .debug_loc offsets */
2703 if (attr_form_is_block (attr))
2705 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
2707 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
2709 dwarf2_complex_location_expr_complaint ();
2713 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2719 /* Create the vector of member function fields, and attach it to the type. */
2722 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
2723 struct dwarf2_cu *cu)
2725 struct fnfieldlist *flp;
2726 int total_length = 0;
2729 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2730 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2731 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2733 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2735 struct nextfnfield *nfp = flp->head;
2736 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2739 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2740 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2741 fn_flp->fn_fields = (struct fn_field *)
2742 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2743 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2744 fn_flp->fn_fields[k] = nfp->fnfield;
2746 total_length += flp->length;
2749 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2750 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2753 /* Called when we find the DIE that starts a structure or union scope
2754 (definition) to process all dies that define the members of the
2757 NOTE: we need to call struct_type regardless of whether or not the
2758 DIE has an at_name attribute, since it might be an anonymous
2759 structure or union. This gets the type entered into our set of
2762 However, if the structure is incomplete (an opaque struct/union)
2763 then suppress creating a symbol table entry for it since gdb only
2764 wants to find the one with the complete definition. Note that if
2765 it is complete, we just call new_symbol, which does it's own
2766 checking about whether the struct/union is anonymous or not (and
2767 suppresses creating a symbol table entry itself). */
2770 read_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
2772 struct objfile *objfile = cu->objfile;
2774 struct attribute *attr;
2776 type = alloc_type (objfile);
2778 INIT_CPLUS_SPECIFIC (type);
2779 attr = dwarf_attr (die, DW_AT_name);
2780 if (attr && DW_STRING (attr))
2782 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2783 strlen (DW_STRING (attr)),
2784 &objfile->type_obstack);
2787 if (die->tag == DW_TAG_structure_type)
2789 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2791 else if (die->tag == DW_TAG_union_type)
2793 TYPE_CODE (type) = TYPE_CODE_UNION;
2797 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2799 TYPE_CODE (type) = TYPE_CODE_CLASS;
2802 attr = dwarf_attr (die, DW_AT_byte_size);
2805 TYPE_LENGTH (type) = DW_UNSND (attr);
2809 TYPE_LENGTH (type) = 0;
2812 /* We need to add the type field to the die immediately so we don't
2813 infinitely recurse when dealing with pointers to the structure
2814 type within the structure itself. */
2817 if (die->child != NULL && ! die_is_declaration (die))
2819 struct field_info fi;
2820 struct die_info *child_die;
2821 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
2823 memset (&fi, 0, sizeof (struct field_info));
2825 child_die = die->child;
2827 while (child_die && child_die->tag)
2829 if (child_die->tag == DW_TAG_member
2830 || child_die->tag == DW_TAG_variable)
2832 /* NOTE: carlton/2002-11-05: A C++ static data member
2833 should be a DW_TAG_member that is a declaration, but
2834 all versions of G++ as of this writing (so through at
2835 least 3.2.1) incorrectly generate DW_TAG_variable
2836 tags for them instead. */
2837 dwarf2_add_field (&fi, child_die, cu);
2839 else if (child_die->tag == DW_TAG_subprogram)
2841 /* C++ member function. */
2842 process_die (child_die, cu);
2843 dwarf2_add_member_fn (&fi, child_die, type, cu);
2845 else if (child_die->tag == DW_TAG_inheritance)
2847 /* C++ base class field. */
2848 dwarf2_add_field (&fi, child_die, cu);
2852 process_die (child_die, cu);
2854 child_die = sibling_die (child_die);
2857 /* Attach fields and member functions to the type. */
2859 dwarf2_attach_fields_to_type (&fi, type, cu);
2862 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
2864 /* Get the type which refers to the base class (possibly this
2865 class itself) which contains the vtable pointer for the current
2866 class from the DW_AT_containing_type attribute. */
2868 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2870 struct type *t = die_containing_type (die, cu);
2872 TYPE_VPTR_BASETYPE (type) = t;
2875 static const char vptr_name[] =
2876 {'_', 'v', 'p', 't', 'r', '\0'};
2879 /* Our own class provides vtbl ptr. */
2880 for (i = TYPE_NFIELDS (t) - 1;
2881 i >= TYPE_N_BASECLASSES (t);
2884 char *fieldname = TYPE_FIELD_NAME (t, i);
2886 if (DEPRECATED_STREQN (fieldname, vptr_name, strlen (vptr_name) - 1)
2887 && is_cplus_marker (fieldname[strlen (vptr_name)]))
2889 TYPE_VPTR_FIELDNO (type) = i;
2894 /* Complain if virtual function table field not found. */
2895 if (i < TYPE_N_BASECLASSES (t))
2896 complaint (&symfile_complaints,
2897 "virtual function table pointer not found when defining class '%s'",
2898 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
2903 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2908 new_symbol (die, type, cu);
2910 do_cleanups (back_to);
2914 /* No children, must be stub. */
2915 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2919 /* Given a pointer to a die which begins an enumeration, process all
2920 the dies that define the members of the enumeration.
2922 This will be much nicer in draft 6 of the DWARF spec when our
2923 members will be dies instead squished into the DW_AT_element_list
2926 NOTE: We reverse the order of the element list. */
2929 read_enumeration (struct die_info *die, struct dwarf2_cu *cu)
2931 struct objfile *objfile = cu->objfile;
2932 struct die_info *child_die;
2934 struct field *fields;
2935 struct attribute *attr;
2938 int unsigned_enum = 1;
2940 type = alloc_type (objfile);
2942 TYPE_CODE (type) = TYPE_CODE_ENUM;
2943 attr = dwarf_attr (die, DW_AT_name);
2944 if (attr && DW_STRING (attr))
2946 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2947 strlen (DW_STRING (attr)),
2948 &objfile->type_obstack);
2951 attr = dwarf_attr (die, DW_AT_byte_size);
2954 TYPE_LENGTH (type) = DW_UNSND (attr);
2958 TYPE_LENGTH (type) = 0;
2963 if (die->child != NULL)
2965 child_die = die->child;
2966 while (child_die && child_die->tag)
2968 if (child_die->tag != DW_TAG_enumerator)
2970 process_die (child_die, cu);
2974 attr = dwarf_attr (child_die, DW_AT_name);
2977 sym = new_symbol (child_die, type, cu);
2978 if (SYMBOL_VALUE (sym) < 0)
2981 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
2983 fields = (struct field *)
2985 (num_fields + DW_FIELD_ALLOC_CHUNK)
2986 * sizeof (struct field));
2989 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
2990 FIELD_TYPE (fields[num_fields]) = NULL;
2991 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
2992 FIELD_BITSIZE (fields[num_fields]) = 0;
2993 FIELD_STATIC_KIND (fields[num_fields]) = 0;
2999 child_die = sibling_die (child_die);
3004 TYPE_NFIELDS (type) = num_fields;
3005 TYPE_FIELDS (type) = (struct field *)
3006 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
3007 memcpy (TYPE_FIELDS (type), fields,
3008 sizeof (struct field) * num_fields);
3012 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
3015 new_symbol (die, type, cu);
3018 /* Extract all information from a DW_TAG_array_type DIE and put it in
3019 the DIE's type field. For now, this only handles one dimensional
3023 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3025 struct objfile *objfile = cu->objfile;
3026 struct die_info *child_die;
3027 struct type *type = NULL;
3028 struct type *element_type, *range_type, *index_type;
3029 struct type **range_types = NULL;
3030 struct attribute *attr;
3032 struct cleanup *back_to;
3034 /* Return if we've already decoded this type. */
3040 element_type = die_type (die, cu);
3042 /* Irix 6.2 native cc creates array types without children for
3043 arrays with unspecified length. */
3044 if (die->child == NULL)
3046 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
3047 range_type = create_range_type (NULL, index_type, 0, -1);
3048 die->type = create_array_type (NULL, element_type, range_type);
3052 back_to = make_cleanup (null_cleanup, NULL);
3053 child_die = die->child;
3054 while (child_die && child_die->tag)
3056 if (child_die->tag == DW_TAG_subrange_type)
3058 unsigned int low, high;
3060 /* Default bounds to an array with unspecified length. */
3063 if (cu_language == language_fortran)
3065 /* FORTRAN implies a lower bound of 1, if not given. */
3069 index_type = die_type (child_die, cu);
3070 attr = dwarf_attr (child_die, DW_AT_lower_bound);
3073 if (attr->form == DW_FORM_sdata)
3075 low = DW_SND (attr);
3077 else if (attr->form == DW_FORM_udata
3078 || attr->form == DW_FORM_data1
3079 || attr->form == DW_FORM_data2
3080 || attr->form == DW_FORM_data4
3081 || attr->form == DW_FORM_data8)
3083 low = DW_UNSND (attr);
3087 dwarf2_non_const_array_bound_ignored_complaint
3088 (dwarf_form_name (attr->form));
3090 die->type = lookup_pointer_type (element_type);
3097 attr = dwarf_attr (child_die, DW_AT_upper_bound);
3100 if (attr->form == DW_FORM_sdata)
3102 high = DW_SND (attr);
3104 else if (attr->form == DW_FORM_udata
3105 || attr->form == DW_FORM_data1
3106 || attr->form == DW_FORM_data2
3107 || attr->form == DW_FORM_data4
3108 || attr->form == DW_FORM_data8)
3110 high = DW_UNSND (attr);
3112 else if (attr->form == DW_FORM_block1)
3114 /* GCC encodes arrays with unspecified or dynamic length
3115 with a DW_FORM_block1 attribute.
3116 FIXME: GDB does not yet know how to handle dynamic
3117 arrays properly, treat them as arrays with unspecified
3120 FIXME: jimb/2003-09-22: GDB does not really know
3121 how to handle arrays of unspecified length
3122 either; we just represent them as zero-length
3123 arrays. Choose an appropriate upper bound given
3124 the lower bound we've computed above. */
3129 dwarf2_non_const_array_bound_ignored_complaint
3130 (dwarf_form_name (attr->form));
3132 die->type = lookup_pointer_type (element_type);
3140 /* Create a range type and save it for array type creation. */
3141 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3143 range_types = (struct type **)
3144 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3145 * sizeof (struct type *));
3147 make_cleanup (free_current_contents, &range_types);
3149 range_types[ndim++] = create_range_type (NULL, index_type, low, high);
3151 child_die = sibling_die (child_die);
3154 /* Dwarf2 dimensions are output from left to right, create the
3155 necessary array types in backwards order. */
3156 type = element_type;
3158 type = create_array_type (NULL, type, range_types[ndim]);
3160 /* Understand Dwarf2 support for vector types (like they occur on
3161 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3162 array type. This is not part of the Dwarf2/3 standard yet, but a
3163 custom vendor extension. The main difference between a regular
3164 array and the vector variant is that vectors are passed by value
3166 attr = dwarf_attr (die, DW_AT_GNU_vector);
3168 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3170 do_cleanups (back_to);
3172 /* Install the type in the die. */
3176 /* First cut: install each common block member as a global variable. */
3179 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3181 struct die_info *child_die;
3182 struct attribute *attr;
3184 CORE_ADDR base = (CORE_ADDR) 0;
3186 attr = dwarf_attr (die, DW_AT_location);
3189 /* Support the .debug_loc offsets */
3190 if (attr_form_is_block (attr))
3192 base = decode_locdesc (DW_BLOCK (attr), cu);
3194 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3196 dwarf2_complex_location_expr_complaint ();
3200 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3201 "common block member");
3204 if (die->child != NULL)
3206 child_die = die->child;
3207 while (child_die && child_die->tag)
3209 sym = new_symbol (child_die, NULL, cu);
3210 attr = dwarf_attr (child_die, DW_AT_data_member_location);
3213 SYMBOL_VALUE_ADDRESS (sym) =
3214 base + decode_locdesc (DW_BLOCK (attr), cu);
3215 add_symbol_to_list (sym, &global_symbols);
3217 child_die = sibling_die (child_die);
3222 /* Read a C++ namespace. */
3225 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3227 struct objfile *objfile = cu->objfile;
3228 const char *previous_namespace = processing_current_namespace;
3229 const char *name = NULL;
3231 struct die_info *current_die;
3233 /* Loop through the extensions until we find a name. */
3235 for (current_die = die;
3236 current_die != NULL;
3237 current_die = dwarf2_extension (die))
3239 name = dwarf2_name (current_die);
3244 /* Is it an anonymous namespace? */
3246 is_anonymous = (name == NULL);
3248 name = "(anonymous namespace)";
3250 /* Now build the name of the current namespace. */
3252 if (previous_namespace[0] == '\0')
3254 processing_current_namespace = name;
3258 /* We need temp_name around because processing_current_namespace
3259 is a const char *. */
3260 char *temp_name = alloca (strlen (previous_namespace)
3261 + 2 + strlen(name) + 1);
3262 strcpy (temp_name, previous_namespace);
3263 strcat (temp_name, "::");
3264 strcat (temp_name, name);
3266 processing_current_namespace = temp_name;
3269 /* Add a symbol associated to this if we haven't seen the namespace
3270 before. Also, add a using directive if it's an anonymous
3273 if (dwarf2_extension (die) == NULL)
3277 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3278 this cast will hopefully become unnecessary. */
3279 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3280 (char *) processing_current_namespace,
3282 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3284 new_symbol (die, type, cu);
3287 cp_add_using_directive (processing_current_namespace,
3288 strlen (previous_namespace),
3289 strlen (processing_current_namespace));
3292 if (die->child != NULL)
3294 struct die_info *child_die = die->child;
3296 while (child_die && child_die->tag)
3298 process_die (child_die, cu);
3299 child_die = sibling_die (child_die);
3303 processing_current_namespace = previous_namespace;
3306 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3307 the user defined type vector. */
3310 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3312 struct comp_unit_head *cu_header = &cu->header;
3314 struct attribute *attr_byte_size;
3315 struct attribute *attr_address_class;
3316 int byte_size, addr_class;
3323 type = lookup_pointer_type (die_type (die, cu));
3325 attr_byte_size = dwarf_attr (die, DW_AT_byte_size);
3327 byte_size = DW_UNSND (attr_byte_size);
3329 byte_size = cu_header->addr_size;
3331 attr_address_class = dwarf_attr (die, DW_AT_address_class);
3332 if (attr_address_class)
3333 addr_class = DW_UNSND (attr_address_class);
3335 addr_class = DW_ADDR_none;
3337 /* If the pointer size or address class is different than the
3338 default, create a type variant marked as such and set the
3339 length accordingly. */
3340 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3342 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3346 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
3347 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
3348 type = make_type_with_address_space (type, type_flags);
3350 else if (TYPE_LENGTH (type) != byte_size)
3352 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
3355 /* Should we also complain about unhandled address classes? */
3359 TYPE_LENGTH (type) = byte_size;
3363 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3364 the user defined type vector. */
3367 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
3369 struct objfile *objfile = cu->objfile;
3371 struct type *to_type;
3372 struct type *domain;
3379 type = alloc_type (objfile);
3380 to_type = die_type (die, cu);
3381 domain = die_containing_type (die, cu);
3382 smash_to_member_type (type, domain, to_type);
3387 /* Extract all information from a DW_TAG_reference_type DIE and add to
3388 the user defined type vector. */
3391 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
3393 struct comp_unit_head *cu_header = &cu->header;
3395 struct attribute *attr;
3402 type = lookup_reference_type (die_type (die, cu));
3403 attr = dwarf_attr (die, DW_AT_byte_size);
3406 TYPE_LENGTH (type) = DW_UNSND (attr);
3410 TYPE_LENGTH (type) = cu_header->addr_size;
3416 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
3418 struct type *base_type;
3425 base_type = die_type (die, cu);
3426 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
3430 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
3432 struct type *base_type;
3439 base_type = die_type (die, cu);
3440 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
3443 /* Extract all information from a DW_TAG_string_type DIE and add to
3444 the user defined type vector. It isn't really a user defined type,
3445 but it behaves like one, with other DIE's using an AT_user_def_type
3446 attribute to reference it. */
3449 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3451 struct objfile *objfile = cu->objfile;
3452 struct type *type, *range_type, *index_type, *char_type;
3453 struct attribute *attr;
3454 unsigned int length;
3461 attr = dwarf_attr (die, DW_AT_string_length);
3464 length = DW_UNSND (attr);
3468 /* check for the DW_AT_byte_size attribute */
3469 attr = dwarf_attr (die, DW_AT_byte_size);
3472 length = DW_UNSND (attr);
3479 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
3480 range_type = create_range_type (NULL, index_type, 1, length);
3481 if (cu_language == language_fortran)
3483 /* Need to create a unique string type for bounds
3485 type = create_string_type (0, range_type);
3489 char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
3490 type = create_string_type (char_type, range_type);
3495 /* Handle DIES due to C code like:
3499 int (*funcp)(int a, long l);
3503 ('funcp' generates a DW_TAG_subroutine_type DIE)
3507 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
3509 struct type *type; /* Type that this function returns */
3510 struct type *ftype; /* Function that returns above type */
3511 struct attribute *attr;
3513 /* Decode the type that this subroutine returns */
3518 type = die_type (die, cu);
3519 ftype = lookup_function_type (type);
3521 /* All functions in C++ have prototypes. */
3522 attr = dwarf_attr (die, DW_AT_prototyped);
3523 if ((attr && (DW_UNSND (attr) != 0))
3524 || cu_language == language_cplus)
3525 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
3527 if (die->child != NULL)
3529 struct die_info *child_die;
3533 /* Count the number of parameters.
3534 FIXME: GDB currently ignores vararg functions, but knows about
3535 vararg member functions. */
3536 child_die = die->child;
3537 while (child_die && child_die->tag)
3539 if (child_die->tag == DW_TAG_formal_parameter)
3541 else if (child_die->tag == DW_TAG_unspecified_parameters)
3542 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
3543 child_die = sibling_die (child_die);
3546 /* Allocate storage for parameters and fill them in. */
3547 TYPE_NFIELDS (ftype) = nparams;
3548 TYPE_FIELDS (ftype) = (struct field *)
3549 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
3551 child_die = die->child;
3552 while (child_die && child_die->tag)
3554 if (child_die->tag == DW_TAG_formal_parameter)
3556 /* Dwarf2 has no clean way to discern C++ static and non-static
3557 member functions. G++ helps GDB by marking the first
3558 parameter for non-static member functions (which is the
3559 this pointer) as artificial. We pass this information
3560 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3561 attr = dwarf_attr (child_die, DW_AT_artificial);
3563 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
3565 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
3566 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
3569 child_die = sibling_die (child_die);
3577 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
3579 struct objfile *objfile = cu->objfile;
3580 struct attribute *attr;
3585 attr = dwarf_attr (die, DW_AT_name);
3586 if (attr && DW_STRING (attr))
3588 name = DW_STRING (attr);
3590 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
3591 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
3595 /* Find a representation of a given base type and install
3596 it in the TYPE field of the die. */
3599 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
3601 struct objfile *objfile = cu->objfile;
3603 struct attribute *attr;
3604 int encoding = 0, size = 0;
3606 /* If we've already decoded this die, this is a no-op. */
3612 attr = dwarf_attr (die, DW_AT_encoding);
3615 encoding = DW_UNSND (attr);
3617 attr = dwarf_attr (die, DW_AT_byte_size);
3620 size = DW_UNSND (attr);
3622 attr = dwarf_attr (die, DW_AT_name);
3623 if (attr && DW_STRING (attr))
3625 enum type_code code = TYPE_CODE_INT;
3630 case DW_ATE_address:
3631 /* Turn DW_ATE_address into a void * pointer. */
3632 code = TYPE_CODE_PTR;
3633 type_flags |= TYPE_FLAG_UNSIGNED;
3635 case DW_ATE_boolean:
3636 code = TYPE_CODE_BOOL;
3637 type_flags |= TYPE_FLAG_UNSIGNED;
3639 case DW_ATE_complex_float:
3640 code = TYPE_CODE_COMPLEX;
3643 code = TYPE_CODE_FLT;
3646 case DW_ATE_signed_char:
3648 case DW_ATE_unsigned:
3649 case DW_ATE_unsigned_char:
3650 type_flags |= TYPE_FLAG_UNSIGNED;
3653 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
3654 dwarf_type_encoding_name (encoding));
3657 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
3658 if (encoding == DW_ATE_address)
3659 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID);
3660 else if (encoding == DW_ATE_complex_float)
3663 TYPE_TARGET_TYPE (type)
3664 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
3665 else if (size == 16)
3666 TYPE_TARGET_TYPE (type)
3667 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
3669 TYPE_TARGET_TYPE (type)
3670 = dwarf2_fundamental_type (objfile, FT_FLOAT);
3675 type = dwarf_base_type (encoding, size, cu);
3680 /* Read a whole compilation unit into a linked list of dies. */
3682 static struct die_info *
3683 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
3685 /* Reset die reference table; we are
3686 building new ones now. */
3687 dwarf2_empty_hash_tables ();
3689 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
3692 /* Read a single die and all its descendents. Set the die's sibling
3693 field to NULL; set other fields in the die correctly, and set all
3694 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3695 location of the info_ptr after reading all of those dies. PARENT
3696 is the parent of the die in question. */
3698 static struct die_info *
3699 read_die_and_children (char *info_ptr, bfd *abfd,
3700 struct dwarf2_cu *cu,
3701 char **new_info_ptr,
3702 struct die_info *parent)
3704 struct die_info *die;
3708 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
3709 store_in_ref_table (die->offset, die);
3713 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
3719 *new_info_ptr = cur_ptr;
3722 die->sibling = NULL;
3723 die->parent = parent;
3727 /* Read a die, all of its descendents, and all of its siblings; set
3728 all of the fields of all of the dies correctly. Arguments are as
3729 in read_die_and_children. */
3731 static struct die_info *
3732 read_die_and_siblings (char *info_ptr, bfd *abfd,
3733 struct dwarf2_cu *cu,
3734 char **new_info_ptr,
3735 struct die_info *parent)
3737 struct die_info *first_die, *last_sibling;
3741 first_die = last_sibling = NULL;
3745 struct die_info *die
3746 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
3754 last_sibling->sibling = die;
3759 *new_info_ptr = cur_ptr;
3769 /* Free a linked list of dies. */
3772 free_die_list (struct die_info *dies)
3774 struct die_info *die, *next;
3779 if (die->child != NULL)
3780 free_die_list (die->child);
3781 next = die->sibling;
3789 do_free_die_list_cleanup (void *dies)
3791 free_die_list (dies);
3794 static struct cleanup *
3795 make_cleanup_free_die_list (struct die_info *dies)
3797 return make_cleanup (do_free_die_list_cleanup, dies);
3801 /* Read the contents of the section at OFFSET and of size SIZE from the
3802 object file specified by OBJFILE into the psymbol_obstack and return it. */
3805 dwarf2_read_section (struct objfile *objfile, asection *sectp)
3807 bfd *abfd = objfile->obfd;
3809 bfd_size_type size = bfd_get_section_size_before_reloc (sectp);
3814 buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
3816 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
3820 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
3821 || bfd_bread (buf, size, abfd) != size)
3822 error ("Dwarf Error: Can't read DWARF data from '%s'",
3823 bfd_get_filename (abfd));
3828 /* In DWARF version 2, the description of the debugging information is
3829 stored in a separate .debug_abbrev section. Before we read any
3830 dies from a section we read in all abbreviations and install them
3834 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
3836 struct comp_unit_head *cu_header = &cu->header;
3838 struct abbrev_info *cur_abbrev;
3839 unsigned int abbrev_number, bytes_read, abbrev_name;
3840 unsigned int abbrev_form, hash_number;
3842 /* Initialize dwarf2 abbrevs */
3843 memset (cu_header->dwarf2_abbrevs, 0,
3844 ABBREV_HASH_SIZE*sizeof (struct abbrev_info *));
3846 abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset;
3847 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3848 abbrev_ptr += bytes_read;
3850 /* loop until we reach an abbrev number of 0 */
3851 while (abbrev_number)
3853 cur_abbrev = dwarf_alloc_abbrev ();
3855 /* read in abbrev header */
3856 cur_abbrev->number = abbrev_number;
3857 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3858 abbrev_ptr += bytes_read;
3859 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
3862 /* now read in declarations */
3863 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3864 abbrev_ptr += bytes_read;
3865 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3866 abbrev_ptr += bytes_read;
3869 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
3871 cur_abbrev->attrs = (struct attr_abbrev *)
3872 xrealloc (cur_abbrev->attrs,
3873 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
3874 * sizeof (struct attr_abbrev));
3876 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
3877 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
3878 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3879 abbrev_ptr += bytes_read;
3880 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3881 abbrev_ptr += bytes_read;
3884 hash_number = abbrev_number % ABBREV_HASH_SIZE;
3885 cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number];
3886 cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev;
3888 /* Get next abbreviation.
3889 Under Irix6 the abbreviations for a compilation unit are not
3890 always properly terminated with an abbrev number of 0.
3891 Exit loop if we encounter an abbreviation which we have
3892 already read (which means we are about to read the abbreviations
3893 for the next compile unit) or if the end of the abbreviation
3894 table is reached. */
3895 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
3896 >= dwarf_abbrev_size)
3898 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3899 abbrev_ptr += bytes_read;
3900 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
3905 /* Empty the abbrev table for a new compilation unit. */
3908 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table)
3911 struct abbrev_info *abbrev, *next;
3912 struct abbrev_info **abbrevs;
3914 abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table;
3916 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
3919 abbrev = abbrevs[i];
3922 next = abbrev->next;
3923 xfree (abbrev->attrs);
3931 /* Lookup an abbrev_info structure in the abbrev hash table. */
3933 static struct abbrev_info *
3934 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
3936 struct comp_unit_head *cu_header = &cu->header;
3937 unsigned int hash_number;
3938 struct abbrev_info *abbrev;
3940 hash_number = number % ABBREV_HASH_SIZE;
3941 abbrev = cu_header->dwarf2_abbrevs[hash_number];
3945 if (abbrev->number == number)
3948 abbrev = abbrev->next;
3953 /* Read a minimal amount of information into the minimal die structure. */
3956 read_partial_die (struct partial_die_info *part_die, bfd *abfd,
3957 char *info_ptr, struct dwarf2_cu *cu)
3959 unsigned int abbrev_number, bytes_read, i;
3960 struct abbrev_info *abbrev;
3961 struct attribute attr;
3962 struct attribute spec_attr;
3963 int found_spec_attr = 0;
3964 int has_low_pc_attr = 0;
3965 int has_high_pc_attr = 0;
3967 *part_die = zeroed_partial_die;
3968 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3969 info_ptr += bytes_read;
3973 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
3976 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
3977 bfd_get_filename (abfd));
3979 part_die->offset = info_ptr - dwarf_info_buffer;
3980 part_die->tag = abbrev->tag;
3981 part_die->has_children = abbrev->has_children;
3982 part_die->abbrev = abbrev_number;
3984 for (i = 0; i < abbrev->num_attrs; ++i)
3986 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
3988 /* Store the data if it is of an attribute we want to keep in a
3989 partial symbol table. */
3994 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3995 if (part_die->name == NULL)
3996 part_die->name = DW_STRING (&attr);
3998 case DW_AT_MIPS_linkage_name:
3999 part_die->name = DW_STRING (&attr);
4002 has_low_pc_attr = 1;
4003 part_die->lowpc = DW_ADDR (&attr);
4006 has_high_pc_attr = 1;
4007 part_die->highpc = DW_ADDR (&attr);
4009 case DW_AT_location:
4010 /* Support the .debug_loc offsets */
4011 if (attr_form_is_block (&attr))
4013 part_die->locdesc = DW_BLOCK (&attr);
4015 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4017 dwarf2_complex_location_expr_complaint ();
4021 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4022 "partial symbol information");
4025 case DW_AT_language:
4026 part_die->language = DW_UNSND (&attr);
4028 case DW_AT_external:
4029 part_die->is_external = DW_UNSND (&attr);
4031 case DW_AT_declaration:
4032 part_die->is_declaration = DW_UNSND (&attr);
4035 part_die->has_type = 1;
4037 case DW_AT_abstract_origin:
4038 case DW_AT_specification:
4039 found_spec_attr = 1;
4043 /* Ignore absolute siblings, they might point outside of
4044 the current compile unit. */
4045 if (attr.form == DW_FORM_ref_addr)
4046 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
4049 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr);
4056 /* If we found a reference attribute and the die has no name, try
4057 to find a name in the referred to die. */
4059 if (found_spec_attr && part_die->name == NULL)
4061 struct partial_die_info spec_die;
4064 spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr);
4065 read_partial_die (&spec_die, abfd, spec_ptr, cu);
4068 part_die->name = spec_die.name;
4070 /* Copy DW_AT_external attribute if it is set. */
4071 if (spec_die.is_external)
4072 part_die->is_external = spec_die.is_external;
4076 /* When using the GNU linker, .gnu.linkonce. sections are used to
4077 eliminate duplicate copies of functions and vtables and such.
4078 The linker will arbitrarily choose one and discard the others.
4079 The AT_*_pc values for such functions refer to local labels in
4080 these sections. If the section from that file was discarded, the
4081 labels are not in the output, so the relocs get a value of 0.
4082 If this is a discarded function, mark the pc bounds as invalid,
4083 so that GDB will ignore it. */
4084 if (has_low_pc_attr && has_high_pc_attr
4085 && part_die->lowpc < part_die->highpc
4086 && (part_die->lowpc != 0
4087 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
4088 part_die->has_pc_info = 1;
4092 /* Read the die from the .debug_info section buffer. Set DIEP to
4093 point to a newly allocated die with its information, except for its
4094 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4095 whether the die has children or not. */
4098 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
4099 struct dwarf2_cu *cu, int *has_children)
4101 unsigned int abbrev_number, bytes_read, i, offset;
4102 struct abbrev_info *abbrev;
4103 struct die_info *die;
4105 offset = info_ptr - dwarf_info_buffer;
4106 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4107 info_ptr += bytes_read;
4110 die = dwarf_alloc_die ();
4112 die->abbrev = abbrev_number;
4119 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4122 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4124 bfd_get_filename (abfd));
4126 die = dwarf_alloc_die ();
4127 die->offset = offset;
4128 die->tag = abbrev->tag;
4129 die->abbrev = abbrev_number;
4132 die->num_attrs = abbrev->num_attrs;
4133 die->attrs = (struct attribute *)
4134 xmalloc (die->num_attrs * sizeof (struct attribute));
4136 for (i = 0; i < abbrev->num_attrs; ++i)
4138 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
4139 abfd, info_ptr, cu);
4143 *has_children = abbrev->has_children;
4147 /* Read an attribute value described by an attribute form. */
4150 read_attribute_value (struct attribute *attr, unsigned form,
4151 bfd *abfd, char *info_ptr,
4152 struct dwarf2_cu *cu)
4154 struct comp_unit_head *cu_header = &cu->header;
4155 unsigned int bytes_read;
4156 struct dwarf_block *blk;
4162 case DW_FORM_ref_addr:
4163 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
4164 info_ptr += bytes_read;
4166 case DW_FORM_block2:
4167 blk = dwarf_alloc_block ();
4168 blk->size = read_2_bytes (abfd, info_ptr);
4170 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4171 info_ptr += blk->size;
4172 DW_BLOCK (attr) = blk;
4174 case DW_FORM_block4:
4175 blk = dwarf_alloc_block ();
4176 blk->size = read_4_bytes (abfd, info_ptr);
4178 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4179 info_ptr += blk->size;
4180 DW_BLOCK (attr) = blk;
4183 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4187 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4191 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4194 case DW_FORM_string:
4195 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
4196 info_ptr += bytes_read;
4199 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
4201 info_ptr += bytes_read;
4204 blk = dwarf_alloc_block ();
4205 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4206 info_ptr += bytes_read;
4207 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4208 info_ptr += blk->size;
4209 DW_BLOCK (attr) = blk;
4211 case DW_FORM_block1:
4212 blk = dwarf_alloc_block ();
4213 blk->size = read_1_byte (abfd, info_ptr);
4215 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4216 info_ptr += blk->size;
4217 DW_BLOCK (attr) = blk;
4220 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4224 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4228 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
4229 info_ptr += bytes_read;
4232 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4233 info_ptr += bytes_read;
4236 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4240 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4244 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4248 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4251 case DW_FORM_ref_udata:
4252 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4253 info_ptr += bytes_read;
4255 case DW_FORM_indirect:
4256 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4257 info_ptr += bytes_read;
4258 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
4261 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4262 dwarf_form_name (form),
4263 bfd_get_filename (abfd));
4268 /* Read an attribute described by an abbreviated attribute. */
4271 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
4272 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
4274 attr->name = abbrev->name;
4275 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
4278 /* read dwarf information from a buffer */
4281 read_1_byte (bfd *abfd, char *buf)
4283 return bfd_get_8 (abfd, (bfd_byte *) buf);
4287 read_1_signed_byte (bfd *abfd, char *buf)
4289 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
4293 read_2_bytes (bfd *abfd, char *buf)
4295 return bfd_get_16 (abfd, (bfd_byte *) buf);
4299 read_2_signed_bytes (bfd *abfd, char *buf)
4301 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4305 read_4_bytes (bfd *abfd, char *buf)
4307 return bfd_get_32 (abfd, (bfd_byte *) buf);
4311 read_4_signed_bytes (bfd *abfd, char *buf)
4313 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4316 static unsigned long
4317 read_8_bytes (bfd *abfd, char *buf)
4319 return bfd_get_64 (abfd, (bfd_byte *) buf);
4323 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
4325 struct comp_unit_head *cu_header = &cu->header;
4326 CORE_ADDR retval = 0;
4328 if (cu_header->signed_addr_p)
4330 switch (cu_header->addr_size)
4333 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4336 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4339 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
4342 internal_error (__FILE__, __LINE__,
4343 "read_address: bad switch, signed [in module %s]",
4344 bfd_get_filename (abfd));
4349 switch (cu_header->addr_size)
4352 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
4355 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4358 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4361 internal_error (__FILE__, __LINE__,
4362 "read_address: bad switch, unsigned [in module %s]",
4363 bfd_get_filename (abfd));
4367 *bytes_read = cu_header->addr_size;
4371 /* Read the initial length from a section. The (draft) DWARF 3
4372 specification allows the initial length to take up either 4 bytes
4373 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4374 bytes describe the length and all offsets will be 8 bytes in length
4377 An older, non-standard 64-bit format is also handled by this
4378 function. The older format in question stores the initial length
4379 as an 8-byte quantity without an escape value. Lengths greater
4380 than 2^32 aren't very common which means that the initial 4 bytes
4381 is almost always zero. Since a length value of zero doesn't make
4382 sense for the 32-bit format, this initial zero can be considered to
4383 be an escape value which indicates the presence of the older 64-bit
4384 format. As written, the code can't detect (old format) lengths
4385 greater than 4GB. If it becomes necessary to handle lengths somewhat
4386 larger than 4GB, we could allow other small values (such as the
4387 non-sensical values of 1, 2, and 3) to also be used as escape values
4388 indicating the presence of the old format.
4390 The value returned via bytes_read should be used to increment
4391 the relevant pointer after calling read_initial_length().
4393 As a side effect, this function sets the fields initial_length_size
4394 and offset_size in cu_header to the values appropriate for the
4395 length field. (The format of the initial length field determines
4396 the width of file offsets to be fetched later with fetch_offset().)
4398 [ Note: read_initial_length() and read_offset() are based on the
4399 document entitled "DWARF Debugging Information Format", revision
4400 3, draft 8, dated November 19, 2001. This document was obtained
4403 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4405 This document is only a draft and is subject to change. (So beware.)
4407 Details regarding the older, non-standard 64-bit format were
4408 determined empirically by examining 64-bit ELF files produced
4409 by the SGI toolchain on an IRIX 6.5 machine.
4411 - Kevin, July 16, 2002
4415 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
4420 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4422 if (retval == 0xffffffff)
4424 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
4426 if (cu_header != NULL)
4428 cu_header->initial_length_size = 12;
4429 cu_header->offset_size = 8;
4432 else if (retval == 0)
4434 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4436 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4438 if (cu_header != NULL)
4440 cu_header->initial_length_size = 8;
4441 cu_header->offset_size = 8;
4447 if (cu_header != NULL)
4449 cu_header->initial_length_size = 4;
4450 cu_header->offset_size = 4;
4457 /* Read an offset from the data stream. The size of the offset is
4458 given by cu_header->offset_size. */
4461 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
4466 switch (cu_header->offset_size)
4469 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4473 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4477 internal_error (__FILE__, __LINE__,
4478 "read_offset: bad switch [in module %s]",
4479 bfd_get_filename (abfd));
4486 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
4488 /* If the size of a host char is 8 bits, we can return a pointer
4489 to the buffer, otherwise we have to copy the data to a buffer
4490 allocated on the temporary obstack. */
4491 gdb_assert (HOST_CHAR_BIT == 8);
4496 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4498 /* If the size of a host char is 8 bits, we can return a pointer
4499 to the string, otherwise we have to copy the string to a buffer
4500 allocated on the temporary obstack. */
4501 gdb_assert (HOST_CHAR_BIT == 8);
4504 *bytes_read_ptr = 1;
4507 *bytes_read_ptr = strlen (buf) + 1;
4512 read_indirect_string (bfd *abfd, char *buf,
4513 const struct comp_unit_head *cu_header,
4514 unsigned int *bytes_read_ptr)
4516 LONGEST str_offset = read_offset (abfd, buf, cu_header,
4517 (int *) bytes_read_ptr);
4519 if (dwarf_str_buffer == NULL)
4521 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4522 bfd_get_filename (abfd));
4525 if (str_offset >= dwarf_str_size)
4527 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4528 bfd_get_filename (abfd));
4531 gdb_assert (HOST_CHAR_BIT == 8);
4532 if (dwarf_str_buffer[str_offset] == '\0')
4534 return dwarf_str_buffer + str_offset;
4537 static unsigned long
4538 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4540 unsigned long result;
4541 unsigned int num_read;
4551 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4554 result |= ((unsigned long)(byte & 127) << shift);
4555 if ((byte & 128) == 0)
4561 *bytes_read_ptr = num_read;
4566 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4569 int i, shift, size, num_read;
4579 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4582 result |= ((long)(byte & 127) << shift);
4584 if ((byte & 128) == 0)
4589 if ((shift < size) && (byte & 0x40))
4591 result |= -(1 << shift);
4593 *bytes_read_ptr = num_read;
4598 set_cu_language (unsigned int lang)
4604 cu_language = language_c;
4606 case DW_LANG_C_plus_plus:
4607 cu_language = language_cplus;
4609 case DW_LANG_Fortran77:
4610 case DW_LANG_Fortran90:
4611 case DW_LANG_Fortran95:
4612 cu_language = language_fortran;
4614 case DW_LANG_Mips_Assembler:
4615 cu_language = language_asm;
4618 cu_language = language_java;
4622 case DW_LANG_Cobol74:
4623 case DW_LANG_Cobol85:
4624 case DW_LANG_Pascal83:
4625 case DW_LANG_Modula2:
4627 cu_language = language_minimal;
4630 cu_language_defn = language_def (cu_language);
4633 /* Return the named attribute or NULL if not there. */
4635 static struct attribute *
4636 dwarf_attr (struct die_info *die, unsigned int name)
4639 struct attribute *spec = NULL;
4641 for (i = 0; i < die->num_attrs; ++i)
4643 if (die->attrs[i].name == name)
4645 return &die->attrs[i];
4647 if (die->attrs[i].name == DW_AT_specification
4648 || die->attrs[i].name == DW_AT_abstract_origin)
4649 spec = &die->attrs[i];
4653 struct die_info *ref_die =
4654 follow_die_ref (dwarf2_get_ref_die_offset (spec));
4657 return dwarf_attr (ref_die, name);
4664 die_is_declaration (struct die_info *die)
4666 return (dwarf_attr (die, DW_AT_declaration)
4667 && ! dwarf_attr (die, DW_AT_specification));
4671 /* Free the line_header structure *LH, and any arrays and strings it
4674 free_line_header (struct line_header *lh)
4676 if (lh->standard_opcode_lengths)
4677 xfree (lh->standard_opcode_lengths);
4679 /* Remember that all the lh->file_names[i].name pointers are
4680 pointers into debug_line_buffer, and don't need to be freed. */
4682 xfree (lh->file_names);
4684 /* Similarly for the include directory names. */
4685 if (lh->include_dirs)
4686 xfree (lh->include_dirs);
4692 /* Add an entry to LH's include directory table. */
4694 add_include_dir (struct line_header *lh, char *include_dir)
4696 /* Grow the array if necessary. */
4697 if (lh->include_dirs_size == 0)
4699 lh->include_dirs_size = 1; /* for testing */
4700 lh->include_dirs = xmalloc (lh->include_dirs_size
4701 * sizeof (*lh->include_dirs));
4703 else if (lh->num_include_dirs >= lh->include_dirs_size)
4705 lh->include_dirs_size *= 2;
4706 lh->include_dirs = xrealloc (lh->include_dirs,
4707 (lh->include_dirs_size
4708 * sizeof (*lh->include_dirs)));
4711 lh->include_dirs[lh->num_include_dirs++] = include_dir;
4715 /* Add an entry to LH's file name table. */
4717 add_file_name (struct line_header *lh,
4719 unsigned int dir_index,
4720 unsigned int mod_time,
4721 unsigned int length)
4723 struct file_entry *fe;
4725 /* Grow the array if necessary. */
4726 if (lh->file_names_size == 0)
4728 lh->file_names_size = 1; /* for testing */
4729 lh->file_names = xmalloc (lh->file_names_size
4730 * sizeof (*lh->file_names));
4732 else if (lh->num_file_names >= lh->file_names_size)
4734 lh->file_names_size *= 2;
4735 lh->file_names = xrealloc (lh->file_names,
4736 (lh->file_names_size
4737 * sizeof (*lh->file_names)));
4740 fe = &lh->file_names[lh->num_file_names++];
4742 fe->dir_index = dir_index;
4743 fe->mod_time = mod_time;
4744 fe->length = length;
4748 /* Read the statement program header starting at OFFSET in
4749 dwarf_line_buffer, according to the endianness of ABFD. Return a
4750 pointer to a struct line_header, allocated using xmalloc.
4752 NOTE: the strings in the include directory and file name tables of
4753 the returned object point into debug_line_buffer, and must not be
4755 static struct line_header *
4756 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
4757 struct dwarf2_cu *cu)
4759 struct cleanup *back_to;
4760 struct line_header *lh;
4764 char *cur_dir, *cur_file;
4766 if (dwarf_line_buffer == NULL)
4768 complaint (&symfile_complaints, "missing .debug_line section");
4772 /* Make sure that at least there's room for the total_length field. That
4773 could be 12 bytes long, but we're just going to fudge that. */
4774 if (offset + 4 >= dwarf_line_size)
4776 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4780 lh = xmalloc (sizeof (*lh));
4781 memset (lh, 0, sizeof (*lh));
4782 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
4785 line_ptr = dwarf_line_buffer + offset;
4787 /* read in the header */
4788 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
4789 line_ptr += bytes_read;
4790 if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size)
4792 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4795 lh->statement_program_end = line_ptr + lh->total_length;
4796 lh->version = read_2_bytes (abfd, line_ptr);
4798 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
4799 line_ptr += bytes_read;
4800 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
4802 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
4804 lh->line_base = read_1_signed_byte (abfd, line_ptr);
4806 lh->line_range = read_1_byte (abfd, line_ptr);
4808 lh->opcode_base = read_1_byte (abfd, line_ptr);
4810 lh->standard_opcode_lengths
4811 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
4813 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
4814 for (i = 1; i < lh->opcode_base; ++i)
4816 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
4820 /* Read directory table */
4821 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
4823 line_ptr += bytes_read;
4824 add_include_dir (lh, cur_dir);
4826 line_ptr += bytes_read;
4828 /* Read file name table */
4829 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
4831 unsigned int dir_index, mod_time, length;
4833 line_ptr += bytes_read;
4834 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
4835 line_ptr += bytes_read;
4836 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
4837 line_ptr += bytes_read;
4838 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
4839 line_ptr += bytes_read;
4841 add_file_name (lh, cur_file, dir_index, mod_time, length);
4843 line_ptr += bytes_read;
4844 lh->statement_program_start = line_ptr;
4846 if (line_ptr > dwarf_line_buffer + dwarf_line_size)
4847 complaint (&symfile_complaints,
4848 "line number info header doesn't fit in `.debug_line' section");
4850 discard_cleanups (back_to);
4854 /* This function exists to work around a bug in certain compilers
4855 (particularly GCC 2.95), in which the first line number marker of a
4856 function does not show up until after the prologue, right before
4857 the second line number marker. This function shifts ADDRESS down
4858 to the beginning of the function if necessary, and is called on
4859 addresses passed to record_line. */
4862 check_cu_functions (CORE_ADDR address)
4864 struct function_range *fn;
4866 /* Find the function_range containing address. */
4871 cu_cached_fn = cu_first_fn;
4875 if (fn->lowpc <= address && fn->highpc > address)
4881 while (fn && fn != cu_cached_fn)
4882 if (fn->lowpc <= address && fn->highpc > address)
4892 if (address != fn->lowpc)
4893 complaint (&symfile_complaints,
4894 "misplaced first line number at 0x%lx for '%s'",
4895 (unsigned long) address, fn->name);
4900 /* Decode the line number information for the compilation unit whose
4901 line number info is at OFFSET in the .debug_line section.
4902 The compilation directory of the file is passed in COMP_DIR. */
4905 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
4906 struct dwarf2_cu *cu)
4910 unsigned int bytes_read;
4911 unsigned char op_code, extended_op, adj_opcode;
4913 line_ptr = lh->statement_program_start;
4914 line_end = lh->statement_program_end;
4916 /* Read the statement sequences until there's nothing left. */
4917 while (line_ptr < line_end)
4919 /* state machine registers */
4920 CORE_ADDR address = 0;
4921 unsigned int file = 1;
4922 unsigned int line = 1;
4923 unsigned int column = 0;
4924 int is_stmt = lh->default_is_stmt;
4925 int basic_block = 0;
4926 int end_sequence = 0;
4928 /* Start a subfile for the current file of the state machine. */
4929 if (lh->num_file_names >= file)
4931 /* lh->include_dirs and lh->file_names are 0-based, but the
4932 directory and file name numbers in the statement program
4934 struct file_entry *fe = &lh->file_names[file - 1];
4937 dir = lh->include_dirs[fe->dir_index - 1];
4940 dwarf2_start_subfile (fe->name, dir);
4943 /* Decode the table. */
4944 while (!end_sequence)
4946 op_code = read_1_byte (abfd, line_ptr);
4949 if (op_code >= lh->opcode_base)
4950 { /* Special operand. */
4951 adj_opcode = op_code - lh->opcode_base;
4952 address += (adj_opcode / lh->line_range)
4953 * lh->minimum_instruction_length;
4954 line += lh->line_base + (adj_opcode % lh->line_range);
4955 /* append row to matrix using current values */
4956 record_line (current_subfile, line,
4957 check_cu_functions (address));
4960 else switch (op_code)
4962 case DW_LNS_extended_op:
4963 line_ptr += 1; /* ignore length */
4964 extended_op = read_1_byte (abfd, line_ptr);
4966 switch (extended_op)
4968 case DW_LNE_end_sequence:
4970 record_line (current_subfile, 0, address);
4972 case DW_LNE_set_address:
4973 address = read_address (abfd, line_ptr, cu, &bytes_read);
4974 line_ptr += bytes_read;
4975 address += baseaddr;
4977 case DW_LNE_define_file:
4980 unsigned int dir_index, mod_time, length;
4982 cur_file = read_string (abfd, line_ptr, &bytes_read);
4983 line_ptr += bytes_read;
4985 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
4986 line_ptr += bytes_read;
4988 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
4989 line_ptr += bytes_read;
4991 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
4992 line_ptr += bytes_read;
4993 add_file_name (lh, cur_file, dir_index, mod_time, length);
4997 complaint (&symfile_complaints,
4998 "mangled .debug_line section");
5003 record_line (current_subfile, line,
5004 check_cu_functions (address));
5007 case DW_LNS_advance_pc:
5008 address += lh->minimum_instruction_length
5009 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5010 line_ptr += bytes_read;
5012 case DW_LNS_advance_line:
5013 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
5014 line_ptr += bytes_read;
5016 case DW_LNS_set_file:
5018 /* lh->include_dirs and lh->file_names are 0-based,
5019 but the directory and file name numbers in the
5020 statement program are 1-based. */
5021 struct file_entry *fe;
5023 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5024 line_ptr += bytes_read;
5025 fe = &lh->file_names[file - 1];
5027 dir = lh->include_dirs[fe->dir_index - 1];
5030 dwarf2_start_subfile (fe->name, dir);
5033 case DW_LNS_set_column:
5034 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5035 line_ptr += bytes_read;
5037 case DW_LNS_negate_stmt:
5038 is_stmt = (!is_stmt);
5040 case DW_LNS_set_basic_block:
5043 /* Add to the address register of the state machine the
5044 address increment value corresponding to special opcode
5045 255. Ie, this value is scaled by the minimum instruction
5046 length since special opcode 255 would have scaled the
5048 case DW_LNS_const_add_pc:
5049 address += (lh->minimum_instruction_length
5050 * ((255 - lh->opcode_base) / lh->line_range));
5052 case DW_LNS_fixed_advance_pc:
5053 address += read_2_bytes (abfd, line_ptr);
5057 { /* Unknown standard opcode, ignore it. */
5059 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
5061 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5062 line_ptr += bytes_read;
5070 /* Start a subfile for DWARF. FILENAME is the name of the file and
5071 DIRNAME the name of the source directory which contains FILENAME
5072 or NULL if not known.
5073 This routine tries to keep line numbers from identical absolute and
5074 relative file names in a common subfile.
5076 Using the `list' example from the GDB testsuite, which resides in
5077 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5078 of /srcdir/list0.c yields the following debugging information for list0.c:
5080 DW_AT_name: /srcdir/list0.c
5081 DW_AT_comp_dir: /compdir
5082 files.files[0].name: list0.h
5083 files.files[0].dir: /srcdir
5084 files.files[1].name: list0.c
5085 files.files[1].dir: /srcdir
5087 The line number information for list0.c has to end up in a single
5088 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5091 dwarf2_start_subfile (char *filename, char *dirname)
5093 /* If the filename isn't absolute, try to match an existing subfile
5094 with the full pathname. */
5096 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
5098 struct subfile *subfile;
5099 char *fullname = concat (dirname, "/", filename, NULL);
5101 for (subfile = subfiles; subfile; subfile = subfile->next)
5103 if (FILENAME_CMP (subfile->name, fullname) == 0)
5105 current_subfile = subfile;
5112 start_subfile (filename, dirname);
5116 var_decode_location (struct attribute *attr, struct symbol *sym,
5117 struct dwarf2_cu *cu)
5119 struct objfile *objfile = cu->objfile;
5120 struct comp_unit_head *cu_header = &cu->header;
5122 /* NOTE drow/2003-01-30: There used to be a comment and some special
5123 code here to turn a symbol with DW_AT_external and a
5124 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5125 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5126 with some versions of binutils) where shared libraries could have
5127 relocations against symbols in their debug information - the
5128 minimal symbol would have the right address, but the debug info
5129 would not. It's no longer necessary, because we will explicitly
5130 apply relocations when we read in the debug information now. */
5132 /* A DW_AT_location attribute with no contents indicates that a
5133 variable has been optimized away. */
5134 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
5136 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
5140 /* Handle one degenerate form of location expression specially, to
5141 preserve GDB's previous behavior when section offsets are
5142 specified. If this is just a DW_OP_addr then mark this symbol
5145 if (attr_form_is_block (attr)
5146 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
5147 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
5151 SYMBOL_VALUE_ADDRESS (sym) =
5152 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
5153 fixup_symbol_section (sym, objfile);
5154 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
5155 SYMBOL_SECTION (sym));
5156 SYMBOL_CLASS (sym) = LOC_STATIC;
5160 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5161 expression evaluator, and use LOC_COMPUTED only when necessary
5162 (i.e. when the value of a register or memory location is
5163 referenced, or a thread-local block, etc.). Then again, it might
5164 not be worthwhile. I'm assuming that it isn't unless performance
5165 or memory numbers show me otherwise. */
5167 dwarf2_symbol_mark_computed (attr, sym, cu);
5168 SYMBOL_CLASS (sym) = LOC_COMPUTED;
5171 /* Given a pointer to a DWARF information entry, figure out if we need
5172 to make a symbol table entry for it, and if so, create a new entry
5173 and return a pointer to it.
5174 If TYPE is NULL, determine symbol type from the die, otherwise
5175 used the passed type. */
5177 static struct symbol *
5178 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5180 struct objfile *objfile = cu->objfile;
5181 struct symbol *sym = NULL;
5183 struct attribute *attr = NULL;
5184 struct attribute *attr2 = NULL;
5186 if (die->tag != DW_TAG_namespace)
5187 name = dwarf2_linkage_name (die);
5189 name = TYPE_NAME (type);
5193 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
5194 sizeof (struct symbol));
5195 OBJSTAT (objfile, n_syms++);
5196 memset (sym, 0, sizeof (struct symbol));
5198 /* Cache this symbol's name and the name's demangled form (if any). */
5199 SYMBOL_LANGUAGE (sym) = cu_language;
5200 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
5202 /* Default assumptions.
5203 Use the passed type or decode it from the die. */
5204 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5205 SYMBOL_CLASS (sym) = LOC_STATIC;
5207 SYMBOL_TYPE (sym) = type;
5209 SYMBOL_TYPE (sym) = die_type (die, cu);
5210 attr = dwarf_attr (die, DW_AT_decl_line);
5213 SYMBOL_LINE (sym) = DW_UNSND (attr);
5218 attr = dwarf_attr (die, DW_AT_low_pc);
5221 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
5223 SYMBOL_CLASS (sym) = LOC_LABEL;
5225 case DW_TAG_subprogram:
5226 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5228 SYMBOL_CLASS (sym) = LOC_BLOCK;
5229 attr2 = dwarf_attr (die, DW_AT_external);
5230 if (attr2 && (DW_UNSND (attr2) != 0))
5232 add_symbol_to_list (sym, &global_symbols);
5236 add_symbol_to_list (sym, list_in_scope);
5239 case DW_TAG_variable:
5240 /* Compilation with minimal debug info may result in variables
5241 with missing type entries. Change the misleading `void' type
5242 to something sensible. */
5243 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
5244 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
5245 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
5246 "<variable, no debug info>",
5248 attr = dwarf_attr (die, DW_AT_const_value);
5251 dwarf2_const_value (attr, sym, cu);
5252 attr2 = dwarf_attr (die, DW_AT_external);
5253 if (attr2 && (DW_UNSND (attr2) != 0))
5254 add_symbol_to_list (sym, &global_symbols);
5256 add_symbol_to_list (sym, list_in_scope);
5259 attr = dwarf_attr (die, DW_AT_location);
5262 var_decode_location (attr, sym, cu);
5263 attr2 = dwarf_attr (die, DW_AT_external);
5264 if (attr2 && (DW_UNSND (attr2) != 0))
5265 add_symbol_to_list (sym, &global_symbols);
5267 add_symbol_to_list (sym, list_in_scope);
5271 /* We do not know the address of this symbol.
5272 If it is an external symbol and we have type information
5273 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5274 The address of the variable will then be determined from
5275 the minimal symbol table whenever the variable is
5277 attr2 = dwarf_attr (die, DW_AT_external);
5278 if (attr2 && (DW_UNSND (attr2) != 0)
5279 && dwarf_attr (die, DW_AT_type) != NULL)
5281 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
5282 add_symbol_to_list (sym, &global_symbols);
5286 case DW_TAG_formal_parameter:
5287 attr = dwarf_attr (die, DW_AT_location);
5290 var_decode_location (attr, sym, cu);
5291 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5292 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
5293 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
5295 attr = dwarf_attr (die, DW_AT_const_value);
5298 dwarf2_const_value (attr, sym, cu);
5300 add_symbol_to_list (sym, list_in_scope);
5302 case DW_TAG_unspecified_parameters:
5303 /* From varargs functions; gdb doesn't seem to have any
5304 interest in this information, so just ignore it for now.
5307 case DW_TAG_class_type:
5308 case DW_TAG_structure_type:
5309 case DW_TAG_union_type:
5310 case DW_TAG_enumeration_type:
5311 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5312 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5313 add_symbol_to_list (sym, list_in_scope);
5315 /* The semantics of C++ state that "struct foo { ... }" also
5316 defines a typedef for "foo". Synthesize a typedef symbol so
5317 that "ptype foo" works as expected. */
5318 if (cu_language == language_cplus)
5320 struct symbol *typedef_sym = (struct symbol *)
5321 obstack_alloc (&objfile->symbol_obstack,
5322 sizeof (struct symbol));
5323 *typedef_sym = *sym;
5324 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
5325 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
5326 TYPE_NAME (SYMBOL_TYPE (sym)) =
5327 obsavestring (DEPRECATED_SYMBOL_NAME (sym),
5328 strlen (DEPRECATED_SYMBOL_NAME (sym)),
5329 &objfile->type_obstack);
5330 add_symbol_to_list (typedef_sym, list_in_scope);
5333 case DW_TAG_typedef:
5334 case DW_TAG_base_type:
5335 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5336 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5337 add_symbol_to_list (sym, list_in_scope);
5339 case DW_TAG_enumerator:
5340 attr = dwarf_attr (die, DW_AT_const_value);
5343 dwarf2_const_value (attr, sym, cu);
5345 add_symbol_to_list (sym, list_in_scope);
5347 case DW_TAG_namespace:
5348 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5349 add_symbol_to_list (sym, &global_symbols);
5352 /* Not a tag we recognize. Hopefully we aren't processing
5353 trash data, but since we must specifically ignore things
5354 we don't recognize, there is nothing else we should do at
5356 complaint (&symfile_complaints, "unsupported tag: '%s'",
5357 dwarf_tag_name (die->tag));
5364 /* Copy constant value from an attribute to a symbol. */
5367 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
5368 struct dwarf2_cu *cu)
5370 struct objfile *objfile = cu->objfile;
5371 struct comp_unit_head *cu_header = &cu->header;
5372 struct dwarf_block *blk;
5377 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
5378 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5379 cu_header->addr_size,
5380 TYPE_LENGTH (SYMBOL_TYPE
5382 SYMBOL_VALUE_BYTES (sym) = (char *)
5383 obstack_alloc (&objfile->symbol_obstack, cu_header->addr_size);
5384 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5385 it's body - store_unsigned_integer. */
5386 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
5388 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5390 case DW_FORM_block1:
5391 case DW_FORM_block2:
5392 case DW_FORM_block4:
5394 blk = DW_BLOCK (attr);
5395 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
5396 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5398 TYPE_LENGTH (SYMBOL_TYPE
5400 SYMBOL_VALUE_BYTES (sym) = (char *)
5401 obstack_alloc (&objfile->symbol_obstack, blk->size);
5402 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
5403 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5406 /* The DW_AT_const_value attributes are supposed to carry the
5407 symbol's value "represented as it would be on the target
5408 architecture." By the time we get here, it's already been
5409 converted to host endianness, so we just need to sign- or
5410 zero-extend it as appropriate. */
5412 dwarf2_const_value_data (attr, sym, 8);
5415 dwarf2_const_value_data (attr, sym, 16);
5418 dwarf2_const_value_data (attr, sym, 32);
5421 dwarf2_const_value_data (attr, sym, 64);
5425 SYMBOL_VALUE (sym) = DW_SND (attr);
5426 SYMBOL_CLASS (sym) = LOC_CONST;
5430 SYMBOL_VALUE (sym) = DW_UNSND (attr);
5431 SYMBOL_CLASS (sym) = LOC_CONST;
5435 complaint (&symfile_complaints,
5436 "unsupported const value attribute form: '%s'",
5437 dwarf_form_name (attr->form));
5438 SYMBOL_VALUE (sym) = 0;
5439 SYMBOL_CLASS (sym) = LOC_CONST;
5445 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5446 or zero-extend it as appropriate for the symbol's type. */
5448 dwarf2_const_value_data (struct attribute *attr,
5452 LONGEST l = DW_UNSND (attr);
5454 if (bits < sizeof (l) * 8)
5456 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
5457 l &= ((LONGEST) 1 << bits) - 1;
5459 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
5462 SYMBOL_VALUE (sym) = l;
5463 SYMBOL_CLASS (sym) = LOC_CONST;
5467 /* Return the type of the die in question using its DW_AT_type attribute. */
5469 static struct type *
5470 die_type (struct die_info *die, struct dwarf2_cu *cu)
5473 struct attribute *type_attr;
5474 struct die_info *type_die;
5477 type_attr = dwarf_attr (die, DW_AT_type);
5480 /* A missing DW_AT_type represents a void type. */
5481 return dwarf2_fundamental_type (cu->objfile, FT_VOID);
5485 ref = dwarf2_get_ref_die_offset (type_attr);
5486 type_die = follow_die_ref (ref);
5489 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5490 ref, cu->objfile->name);
5494 type = tag_type_to_type (type_die, cu);
5497 dump_die (type_die);
5498 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5504 /* Return the containing type of the die in question using its
5505 DW_AT_containing_type attribute. */
5507 static struct type *
5508 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
5510 struct type *type = NULL;
5511 struct attribute *type_attr;
5512 struct die_info *type_die = NULL;
5515 type_attr = dwarf_attr (die, DW_AT_containing_type);
5518 ref = dwarf2_get_ref_die_offset (type_attr);
5519 type_die = follow_die_ref (ref);
5522 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
5526 type = tag_type_to_type (type_die, cu);
5531 dump_die (type_die);
5532 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5539 static struct type *
5540 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
5542 struct die_info *die;
5545 die = follow_die_ref (offset);
5548 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
5551 type = tag_type_to_type (die, cu);
5556 static struct type *
5557 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
5565 read_type_die (die, cu);
5569 error ("Dwarf Error: Cannot find type of die [in module %s]",
5577 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
5581 case DW_TAG_class_type:
5582 case DW_TAG_structure_type:
5583 case DW_TAG_union_type:
5584 read_structure_scope (die, cu);
5586 case DW_TAG_enumeration_type:
5587 read_enumeration (die, cu);
5589 case DW_TAG_subprogram:
5590 case DW_TAG_subroutine_type:
5591 read_subroutine_type (die, cu);
5593 case DW_TAG_array_type:
5594 read_array_type (die, cu);
5596 case DW_TAG_pointer_type:
5597 read_tag_pointer_type (die, cu);
5599 case DW_TAG_ptr_to_member_type:
5600 read_tag_ptr_to_member_type (die, cu);
5602 case DW_TAG_reference_type:
5603 read_tag_reference_type (die, cu);
5605 case DW_TAG_const_type:
5606 read_tag_const_type (die, cu);
5608 case DW_TAG_volatile_type:
5609 read_tag_volatile_type (die, cu);
5611 case DW_TAG_string_type:
5612 read_tag_string_type (die, cu);
5614 case DW_TAG_typedef:
5615 read_typedef (die, cu);
5617 case DW_TAG_base_type:
5618 read_base_type (die, cu);
5621 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
5622 dwarf_tag_name (die->tag));
5627 static struct type *
5628 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
5630 struct objfile *objfile = cu->objfile;
5632 /* FIXME - this should not produce a new (struct type *)
5633 every time. It should cache base types. */
5637 case DW_ATE_address:
5638 type = dwarf2_fundamental_type (objfile, FT_VOID);
5640 case DW_ATE_boolean:
5641 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN);
5643 case DW_ATE_complex_float:
5646 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX);
5650 type = dwarf2_fundamental_type (objfile, FT_COMPLEX);
5656 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
5660 type = dwarf2_fundamental_type (objfile, FT_FLOAT);
5667 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
5670 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT);
5674 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
5678 case DW_ATE_signed_char:
5679 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
5681 case DW_ATE_unsigned:
5685 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
5688 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT);
5692 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
5696 case DW_ATE_unsigned_char:
5697 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
5700 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
5707 copy_die (struct die_info *old_die)
5709 struct die_info *new_die;
5712 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
5713 memset (new_die, 0, sizeof (struct die_info));
5715 new_die->tag = old_die->tag;
5716 new_die->has_children = old_die->has_children;
5717 new_die->abbrev = old_die->abbrev;
5718 new_die->offset = old_die->offset;
5719 new_die->type = NULL;
5721 num_attrs = old_die->num_attrs;
5722 new_die->num_attrs = num_attrs;
5723 new_die->attrs = (struct attribute *)
5724 xmalloc (num_attrs * sizeof (struct attribute));
5726 for (i = 0; i < old_die->num_attrs; ++i)
5728 new_die->attrs[i].name = old_die->attrs[i].name;
5729 new_die->attrs[i].form = old_die->attrs[i].form;
5730 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
5733 new_die->next = NULL;
5738 /* Return sibling of die, NULL if no sibling. */
5740 static struct die_info *
5741 sibling_die (struct die_info *die)
5743 return die->sibling;
5746 /* Get linkage name of a die, return NULL if not found. */
5749 dwarf2_linkage_name (struct die_info *die)
5751 struct attribute *attr;
5753 attr = dwarf_attr (die, DW_AT_MIPS_linkage_name);
5754 if (attr && DW_STRING (attr))
5755 return DW_STRING (attr);
5756 attr = dwarf_attr (die, DW_AT_name);
5757 if (attr && DW_STRING (attr))
5758 return DW_STRING (attr);
5762 /* Get name of a die, return NULL if not found. */
5765 dwarf2_name (struct die_info *die)
5767 struct attribute *attr;
5769 attr = dwarf_attr (die, DW_AT_name);
5770 if (attr && DW_STRING (attr))
5771 return DW_STRING (attr);
5775 /* Return the die that this die in an extension of, or NULL if there
5778 static struct die_info *
5779 dwarf2_extension (struct die_info *die)
5781 struct attribute *attr;
5782 struct die_info *extension_die;
5785 attr = dwarf_attr (die, DW_AT_extension);
5789 ref = dwarf2_get_ref_die_offset (attr);
5790 extension_die = follow_die_ref (ref);
5793 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
5796 return extension_die;
5799 /* Convert a DIE tag into its string name. */
5802 dwarf_tag_name (unsigned tag)
5806 case DW_TAG_padding:
5807 return "DW_TAG_padding";
5808 case DW_TAG_array_type:
5809 return "DW_TAG_array_type";
5810 case DW_TAG_class_type:
5811 return "DW_TAG_class_type";
5812 case DW_TAG_entry_point:
5813 return "DW_TAG_entry_point";
5814 case DW_TAG_enumeration_type:
5815 return "DW_TAG_enumeration_type";
5816 case DW_TAG_formal_parameter:
5817 return "DW_TAG_formal_parameter";
5818 case DW_TAG_imported_declaration:
5819 return "DW_TAG_imported_declaration";
5821 return "DW_TAG_label";
5822 case DW_TAG_lexical_block:
5823 return "DW_TAG_lexical_block";
5825 return "DW_TAG_member";
5826 case DW_TAG_pointer_type:
5827 return "DW_TAG_pointer_type";
5828 case DW_TAG_reference_type:
5829 return "DW_TAG_reference_type";
5830 case DW_TAG_compile_unit:
5831 return "DW_TAG_compile_unit";
5832 case DW_TAG_string_type:
5833 return "DW_TAG_string_type";
5834 case DW_TAG_structure_type:
5835 return "DW_TAG_structure_type";
5836 case DW_TAG_subroutine_type:
5837 return "DW_TAG_subroutine_type";
5838 case DW_TAG_typedef:
5839 return "DW_TAG_typedef";
5840 case DW_TAG_union_type:
5841 return "DW_TAG_union_type";
5842 case DW_TAG_unspecified_parameters:
5843 return "DW_TAG_unspecified_parameters";
5844 case DW_TAG_variant:
5845 return "DW_TAG_variant";
5846 case DW_TAG_common_block:
5847 return "DW_TAG_common_block";
5848 case DW_TAG_common_inclusion:
5849 return "DW_TAG_common_inclusion";
5850 case DW_TAG_inheritance:
5851 return "DW_TAG_inheritance";
5852 case DW_TAG_inlined_subroutine:
5853 return "DW_TAG_inlined_subroutine";
5855 return "DW_TAG_module";
5856 case DW_TAG_ptr_to_member_type:
5857 return "DW_TAG_ptr_to_member_type";
5858 case DW_TAG_set_type:
5859 return "DW_TAG_set_type";
5860 case DW_TAG_subrange_type:
5861 return "DW_TAG_subrange_type";
5862 case DW_TAG_with_stmt:
5863 return "DW_TAG_with_stmt";
5864 case DW_TAG_access_declaration:
5865 return "DW_TAG_access_declaration";
5866 case DW_TAG_base_type:
5867 return "DW_TAG_base_type";
5868 case DW_TAG_catch_block:
5869 return "DW_TAG_catch_block";
5870 case DW_TAG_const_type:
5871 return "DW_TAG_const_type";
5872 case DW_TAG_constant:
5873 return "DW_TAG_constant";
5874 case DW_TAG_enumerator:
5875 return "DW_TAG_enumerator";
5876 case DW_TAG_file_type:
5877 return "DW_TAG_file_type";
5879 return "DW_TAG_friend";
5880 case DW_TAG_namelist:
5881 return "DW_TAG_namelist";
5882 case DW_TAG_namelist_item:
5883 return "DW_TAG_namelist_item";
5884 case DW_TAG_packed_type:
5885 return "DW_TAG_packed_type";
5886 case DW_TAG_subprogram:
5887 return "DW_TAG_subprogram";
5888 case DW_TAG_template_type_param:
5889 return "DW_TAG_template_type_param";
5890 case DW_TAG_template_value_param:
5891 return "DW_TAG_template_value_param";
5892 case DW_TAG_thrown_type:
5893 return "DW_TAG_thrown_type";
5894 case DW_TAG_try_block:
5895 return "DW_TAG_try_block";
5896 case DW_TAG_variant_part:
5897 return "DW_TAG_variant_part";
5898 case DW_TAG_variable:
5899 return "DW_TAG_variable";
5900 case DW_TAG_volatile_type:
5901 return "DW_TAG_volatile_type";
5902 case DW_TAG_dwarf_procedure:
5903 return "DW_TAG_dwarf_procedure";
5904 case DW_TAG_restrict_type:
5905 return "DW_TAG_restrict_type";
5906 case DW_TAG_interface_type:
5907 return "DW_TAG_interface_type";
5908 case DW_TAG_namespace:
5909 return "DW_TAG_namespace";
5910 case DW_TAG_imported_module:
5911 return "DW_TAG_imported_module";
5912 case DW_TAG_unspecified_type:
5913 return "DW_TAG_unspecified_type";
5914 case DW_TAG_partial_unit:
5915 return "DW_TAG_partial_unit";
5916 case DW_TAG_imported_unit:
5917 return "DW_TAG_imported_unit";
5918 case DW_TAG_MIPS_loop:
5919 return "DW_TAG_MIPS_loop";
5920 case DW_TAG_format_label:
5921 return "DW_TAG_format_label";
5922 case DW_TAG_function_template:
5923 return "DW_TAG_function_template";
5924 case DW_TAG_class_template:
5925 return "DW_TAG_class_template";
5927 return "DW_TAG_<unknown>";
5931 /* Convert a DWARF attribute code into its string name. */
5934 dwarf_attr_name (unsigned attr)
5939 return "DW_AT_sibling";
5940 case DW_AT_location:
5941 return "DW_AT_location";
5943 return "DW_AT_name";
5944 case DW_AT_ordering:
5945 return "DW_AT_ordering";
5946 case DW_AT_subscr_data:
5947 return "DW_AT_subscr_data";
5948 case DW_AT_byte_size:
5949 return "DW_AT_byte_size";
5950 case DW_AT_bit_offset:
5951 return "DW_AT_bit_offset";
5952 case DW_AT_bit_size:
5953 return "DW_AT_bit_size";
5954 case DW_AT_element_list:
5955 return "DW_AT_element_list";
5956 case DW_AT_stmt_list:
5957 return "DW_AT_stmt_list";
5959 return "DW_AT_low_pc";
5961 return "DW_AT_high_pc";
5962 case DW_AT_language:
5963 return "DW_AT_language";
5965 return "DW_AT_member";
5967 return "DW_AT_discr";
5968 case DW_AT_discr_value:
5969 return "DW_AT_discr_value";
5970 case DW_AT_visibility:
5971 return "DW_AT_visibility";
5973 return "DW_AT_import";
5974 case DW_AT_string_length:
5975 return "DW_AT_string_length";
5976 case DW_AT_common_reference:
5977 return "DW_AT_common_reference";
5978 case DW_AT_comp_dir:
5979 return "DW_AT_comp_dir";
5980 case DW_AT_const_value:
5981 return "DW_AT_const_value";
5982 case DW_AT_containing_type:
5983 return "DW_AT_containing_type";
5984 case DW_AT_default_value:
5985 return "DW_AT_default_value";
5987 return "DW_AT_inline";
5988 case DW_AT_is_optional:
5989 return "DW_AT_is_optional";
5990 case DW_AT_lower_bound:
5991 return "DW_AT_lower_bound";
5992 case DW_AT_producer:
5993 return "DW_AT_producer";
5994 case DW_AT_prototyped:
5995 return "DW_AT_prototyped";
5996 case DW_AT_return_addr:
5997 return "DW_AT_return_addr";
5998 case DW_AT_start_scope:
5999 return "DW_AT_start_scope";
6000 case DW_AT_stride_size:
6001 return "DW_AT_stride_size";
6002 case DW_AT_upper_bound:
6003 return "DW_AT_upper_bound";
6004 case DW_AT_abstract_origin:
6005 return "DW_AT_abstract_origin";
6006 case DW_AT_accessibility:
6007 return "DW_AT_accessibility";
6008 case DW_AT_address_class:
6009 return "DW_AT_address_class";
6010 case DW_AT_artificial:
6011 return "DW_AT_artificial";
6012 case DW_AT_base_types:
6013 return "DW_AT_base_types";
6014 case DW_AT_calling_convention:
6015 return "DW_AT_calling_convention";
6017 return "DW_AT_count";
6018 case DW_AT_data_member_location:
6019 return "DW_AT_data_member_location";
6020 case DW_AT_decl_column:
6021 return "DW_AT_decl_column";
6022 case DW_AT_decl_file:
6023 return "DW_AT_decl_file";
6024 case DW_AT_decl_line:
6025 return "DW_AT_decl_line";
6026 case DW_AT_declaration:
6027 return "DW_AT_declaration";
6028 case DW_AT_discr_list:
6029 return "DW_AT_discr_list";
6030 case DW_AT_encoding:
6031 return "DW_AT_encoding";
6032 case DW_AT_external:
6033 return "DW_AT_external";
6034 case DW_AT_frame_base:
6035 return "DW_AT_frame_base";
6037 return "DW_AT_friend";
6038 case DW_AT_identifier_case:
6039 return "DW_AT_identifier_case";
6040 case DW_AT_macro_info:
6041 return "DW_AT_macro_info";
6042 case DW_AT_namelist_items:
6043 return "DW_AT_namelist_items";
6044 case DW_AT_priority:
6045 return "DW_AT_priority";
6047 return "DW_AT_segment";
6048 case DW_AT_specification:
6049 return "DW_AT_specification";
6050 case DW_AT_static_link:
6051 return "DW_AT_static_link";
6053 return "DW_AT_type";
6054 case DW_AT_use_location:
6055 return "DW_AT_use_location";
6056 case DW_AT_variable_parameter:
6057 return "DW_AT_variable_parameter";
6058 case DW_AT_virtuality:
6059 return "DW_AT_virtuality";
6060 case DW_AT_vtable_elem_location:
6061 return "DW_AT_vtable_elem_location";
6062 case DW_AT_allocated:
6063 return "DW_AT_allocated";
6064 case DW_AT_associated:
6065 return "DW_AT_associated";
6066 case DW_AT_data_location:
6067 return "DW_AT_data_location";
6069 return "DW_AT_stride";
6070 case DW_AT_entry_pc:
6071 return "DW_AT_entry_pc";
6072 case DW_AT_use_UTF8:
6073 return "DW_AT_use_UTF8";
6074 case DW_AT_extension:
6075 return "DW_AT_extension";
6077 return "DW_AT_ranges";
6078 case DW_AT_trampoline:
6079 return "DW_AT_trampoline";
6080 case DW_AT_call_column:
6081 return "DW_AT_call_column";
6082 case DW_AT_call_file:
6083 return "DW_AT_call_file";
6084 case DW_AT_call_line:
6085 return "DW_AT_call_line";
6087 case DW_AT_MIPS_fde:
6088 return "DW_AT_MIPS_fde";
6089 case DW_AT_MIPS_loop_begin:
6090 return "DW_AT_MIPS_loop_begin";
6091 case DW_AT_MIPS_tail_loop_begin:
6092 return "DW_AT_MIPS_tail_loop_begin";
6093 case DW_AT_MIPS_epilog_begin:
6094 return "DW_AT_MIPS_epilog_begin";
6095 case DW_AT_MIPS_loop_unroll_factor:
6096 return "DW_AT_MIPS_loop_unroll_factor";
6097 case DW_AT_MIPS_software_pipeline_depth:
6098 return "DW_AT_MIPS_software_pipeline_depth";
6100 case DW_AT_MIPS_linkage_name:
6101 return "DW_AT_MIPS_linkage_name";
6103 case DW_AT_sf_names:
6104 return "DW_AT_sf_names";
6105 case DW_AT_src_info:
6106 return "DW_AT_src_info";
6107 case DW_AT_mac_info:
6108 return "DW_AT_mac_info";
6109 case DW_AT_src_coords:
6110 return "DW_AT_src_coords";
6111 case DW_AT_body_begin:
6112 return "DW_AT_body_begin";
6113 case DW_AT_body_end:
6114 return "DW_AT_body_end";
6115 case DW_AT_GNU_vector:
6116 return "DW_AT_GNU_vector";
6118 return "DW_AT_<unknown>";
6122 /* Convert a DWARF value form code into its string name. */
6125 dwarf_form_name (unsigned form)
6130 return "DW_FORM_addr";
6131 case DW_FORM_block2:
6132 return "DW_FORM_block2";
6133 case DW_FORM_block4:
6134 return "DW_FORM_block4";
6136 return "DW_FORM_data2";
6138 return "DW_FORM_data4";
6140 return "DW_FORM_data8";
6141 case DW_FORM_string:
6142 return "DW_FORM_string";
6144 return "DW_FORM_block";
6145 case DW_FORM_block1:
6146 return "DW_FORM_block1";
6148 return "DW_FORM_data1";
6150 return "DW_FORM_flag";
6152 return "DW_FORM_sdata";
6154 return "DW_FORM_strp";
6156 return "DW_FORM_udata";
6157 case DW_FORM_ref_addr:
6158 return "DW_FORM_ref_addr";
6160 return "DW_FORM_ref1";
6162 return "DW_FORM_ref2";
6164 return "DW_FORM_ref4";
6166 return "DW_FORM_ref8";
6167 case DW_FORM_ref_udata:
6168 return "DW_FORM_ref_udata";
6169 case DW_FORM_indirect:
6170 return "DW_FORM_indirect";
6172 return "DW_FORM_<unknown>";
6176 /* Convert a DWARF stack opcode into its string name. */
6179 dwarf_stack_op_name (unsigned op)
6184 return "DW_OP_addr";
6186 return "DW_OP_deref";
6188 return "DW_OP_const1u";
6190 return "DW_OP_const1s";
6192 return "DW_OP_const2u";
6194 return "DW_OP_const2s";
6196 return "DW_OP_const4u";
6198 return "DW_OP_const4s";
6200 return "DW_OP_const8u";
6202 return "DW_OP_const8s";
6204 return "DW_OP_constu";
6206 return "DW_OP_consts";
6210 return "DW_OP_drop";
6212 return "DW_OP_over";
6214 return "DW_OP_pick";
6216 return "DW_OP_swap";
6220 return "DW_OP_xderef";
6228 return "DW_OP_minus";
6240 return "DW_OP_plus";
6241 case DW_OP_plus_uconst:
6242 return "DW_OP_plus_uconst";
6248 return "DW_OP_shra";
6266 return "DW_OP_skip";
6268 return "DW_OP_lit0";
6270 return "DW_OP_lit1";
6272 return "DW_OP_lit2";
6274 return "DW_OP_lit3";
6276 return "DW_OP_lit4";
6278 return "DW_OP_lit5";
6280 return "DW_OP_lit6";
6282 return "DW_OP_lit7";
6284 return "DW_OP_lit8";
6286 return "DW_OP_lit9";
6288 return "DW_OP_lit10";
6290 return "DW_OP_lit11";
6292 return "DW_OP_lit12";
6294 return "DW_OP_lit13";
6296 return "DW_OP_lit14";
6298 return "DW_OP_lit15";
6300 return "DW_OP_lit16";
6302 return "DW_OP_lit17";
6304 return "DW_OP_lit18";
6306 return "DW_OP_lit19";
6308 return "DW_OP_lit20";
6310 return "DW_OP_lit21";
6312 return "DW_OP_lit22";
6314 return "DW_OP_lit23";
6316 return "DW_OP_lit24";
6318 return "DW_OP_lit25";
6320 return "DW_OP_lit26";
6322 return "DW_OP_lit27";
6324 return "DW_OP_lit28";
6326 return "DW_OP_lit29";
6328 return "DW_OP_lit30";
6330 return "DW_OP_lit31";
6332 return "DW_OP_reg0";
6334 return "DW_OP_reg1";
6336 return "DW_OP_reg2";
6338 return "DW_OP_reg3";
6340 return "DW_OP_reg4";
6342 return "DW_OP_reg5";
6344 return "DW_OP_reg6";
6346 return "DW_OP_reg7";
6348 return "DW_OP_reg8";
6350 return "DW_OP_reg9";
6352 return "DW_OP_reg10";
6354 return "DW_OP_reg11";
6356 return "DW_OP_reg12";
6358 return "DW_OP_reg13";
6360 return "DW_OP_reg14";
6362 return "DW_OP_reg15";
6364 return "DW_OP_reg16";
6366 return "DW_OP_reg17";
6368 return "DW_OP_reg18";
6370 return "DW_OP_reg19";
6372 return "DW_OP_reg20";
6374 return "DW_OP_reg21";
6376 return "DW_OP_reg22";
6378 return "DW_OP_reg23";
6380 return "DW_OP_reg24";
6382 return "DW_OP_reg25";
6384 return "DW_OP_reg26";
6386 return "DW_OP_reg27";
6388 return "DW_OP_reg28";
6390 return "DW_OP_reg29";
6392 return "DW_OP_reg30";
6394 return "DW_OP_reg31";
6396 return "DW_OP_breg0";
6398 return "DW_OP_breg1";
6400 return "DW_OP_breg2";
6402 return "DW_OP_breg3";
6404 return "DW_OP_breg4";
6406 return "DW_OP_breg5";
6408 return "DW_OP_breg6";
6410 return "DW_OP_breg7";
6412 return "DW_OP_breg8";
6414 return "DW_OP_breg9";
6416 return "DW_OP_breg10";
6418 return "DW_OP_breg11";
6420 return "DW_OP_breg12";
6422 return "DW_OP_breg13";
6424 return "DW_OP_breg14";
6426 return "DW_OP_breg15";
6428 return "DW_OP_breg16";
6430 return "DW_OP_breg17";
6432 return "DW_OP_breg18";
6434 return "DW_OP_breg19";
6436 return "DW_OP_breg20";
6438 return "DW_OP_breg21";
6440 return "DW_OP_breg22";
6442 return "DW_OP_breg23";
6444 return "DW_OP_breg24";
6446 return "DW_OP_breg25";
6448 return "DW_OP_breg26";
6450 return "DW_OP_breg27";
6452 return "DW_OP_breg28";
6454 return "DW_OP_breg29";
6456 return "DW_OP_breg30";
6458 return "DW_OP_breg31";
6460 return "DW_OP_regx";
6462 return "DW_OP_fbreg";
6464 return "DW_OP_bregx";
6466 return "DW_OP_piece";
6467 case DW_OP_deref_size:
6468 return "DW_OP_deref_size";
6469 case DW_OP_xderef_size:
6470 return "DW_OP_xderef_size";
6473 /* DWARF 3 extensions. */
6474 case DW_OP_push_object_address:
6475 return "DW_OP_push_object_address";
6477 return "DW_OP_call2";
6479 return "DW_OP_call4";
6480 case DW_OP_call_ref:
6481 return "DW_OP_call_ref";
6482 /* GNU extensions. */
6483 case DW_OP_GNU_push_tls_address:
6484 return "DW_OP_GNU_push_tls_address";
6486 return "OP_<unknown>";
6491 dwarf_bool_name (unsigned mybool)
6499 /* Convert a DWARF type code into its string name. */
6502 dwarf_type_encoding_name (unsigned enc)
6506 case DW_ATE_address:
6507 return "DW_ATE_address";
6508 case DW_ATE_boolean:
6509 return "DW_ATE_boolean";
6510 case DW_ATE_complex_float:
6511 return "DW_ATE_complex_float";
6513 return "DW_ATE_float";
6515 return "DW_ATE_signed";
6516 case DW_ATE_signed_char:
6517 return "DW_ATE_signed_char";
6518 case DW_ATE_unsigned:
6519 return "DW_ATE_unsigned";
6520 case DW_ATE_unsigned_char:
6521 return "DW_ATE_unsigned_char";
6522 case DW_ATE_imaginary_float:
6523 return "DW_ATE_imaginary_float";
6525 return "DW_ATE_<unknown>";
6529 /* Convert a DWARF call frame info operation to its string name. */
6533 dwarf_cfi_name (unsigned cfi_opc)
6537 case DW_CFA_advance_loc:
6538 return "DW_CFA_advance_loc";
6540 return "DW_CFA_offset";
6541 case DW_CFA_restore:
6542 return "DW_CFA_restore";
6544 return "DW_CFA_nop";
6545 case DW_CFA_set_loc:
6546 return "DW_CFA_set_loc";
6547 case DW_CFA_advance_loc1:
6548 return "DW_CFA_advance_loc1";
6549 case DW_CFA_advance_loc2:
6550 return "DW_CFA_advance_loc2";
6551 case DW_CFA_advance_loc4:
6552 return "DW_CFA_advance_loc4";
6553 case DW_CFA_offset_extended:
6554 return "DW_CFA_offset_extended";
6555 case DW_CFA_restore_extended:
6556 return "DW_CFA_restore_extended";
6557 case DW_CFA_undefined:
6558 return "DW_CFA_undefined";
6559 case DW_CFA_same_value:
6560 return "DW_CFA_same_value";
6561 case DW_CFA_register:
6562 return "DW_CFA_register";
6563 case DW_CFA_remember_state:
6564 return "DW_CFA_remember_state";
6565 case DW_CFA_restore_state:
6566 return "DW_CFA_restore_state";
6567 case DW_CFA_def_cfa:
6568 return "DW_CFA_def_cfa";
6569 case DW_CFA_def_cfa_register:
6570 return "DW_CFA_def_cfa_register";
6571 case DW_CFA_def_cfa_offset:
6572 return "DW_CFA_def_cfa_offset";
6575 case DW_CFA_def_cfa_expression:
6576 return "DW_CFA_def_cfa_expression";
6577 case DW_CFA_expression:
6578 return "DW_CFA_expression";
6579 case DW_CFA_offset_extended_sf:
6580 return "DW_CFA_offset_extended_sf";
6581 case DW_CFA_def_cfa_sf:
6582 return "DW_CFA_def_cfa_sf";
6583 case DW_CFA_def_cfa_offset_sf:
6584 return "DW_CFA_def_cfa_offset_sf";
6586 /* SGI/MIPS specific */
6587 case DW_CFA_MIPS_advance_loc8:
6588 return "DW_CFA_MIPS_advance_loc8";
6590 /* GNU extensions */
6591 case DW_CFA_GNU_window_save:
6592 return "DW_CFA_GNU_window_save";
6593 case DW_CFA_GNU_args_size:
6594 return "DW_CFA_GNU_args_size";
6595 case DW_CFA_GNU_negative_offset_extended:
6596 return "DW_CFA_GNU_negative_offset_extended";
6599 return "DW_CFA_<unknown>";
6605 dump_die (struct die_info *die)
6609 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
6610 dwarf_tag_name (die->tag), die->abbrev, die->offset);
6611 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
6612 dwarf_bool_name (die->child != NULL));
6614 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
6615 for (i = 0; i < die->num_attrs; ++i)
6617 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
6618 dwarf_attr_name (die->attrs[i].name),
6619 dwarf_form_name (die->attrs[i].form));
6620 switch (die->attrs[i].form)
6622 case DW_FORM_ref_addr:
6624 fprintf_unfiltered (gdb_stderr, "address: ");
6625 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
6627 case DW_FORM_block2:
6628 case DW_FORM_block4:
6630 case DW_FORM_block1:
6631 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
6642 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
6644 case DW_FORM_string:
6646 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
6647 DW_STRING (&die->attrs[i])
6648 ? DW_STRING (&die->attrs[i]) : "");
6651 if (DW_UNSND (&die->attrs[i]))
6652 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
6654 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
6656 case DW_FORM_indirect:
6657 /* the reader will have reduced the indirect form to
6658 the "base form" so this form should not occur */
6659 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
6662 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
6663 die->attrs[i].form);
6665 fprintf_unfiltered (gdb_stderr, "\n");
6670 dump_die_list (struct die_info *die)
6675 if (die->child != NULL)
6676 dump_die_list (die->child);
6677 if (die->sibling != NULL)
6678 dump_die_list (die->sibling);
6683 store_in_ref_table (unsigned int offset, struct die_info *die)
6686 struct die_info *old;
6688 h = (offset % REF_HASH_SIZE);
6689 old = die_ref_table[h];
6690 die->next_ref = old;
6691 die_ref_table[h] = die;
6696 dwarf2_empty_hash_tables (void)
6698 memset (die_ref_table, 0, sizeof (die_ref_table));
6702 dwarf2_get_ref_die_offset (struct attribute *attr)
6704 unsigned int result = 0;
6708 case DW_FORM_ref_addr:
6709 result = DW_ADDR (attr);
6715 case DW_FORM_ref_udata:
6716 result = cu_header_offset + DW_UNSND (attr);
6719 complaint (&symfile_complaints,
6720 "unsupported die ref attribute form: '%s'",
6721 dwarf_form_name (attr->form));
6726 static struct die_info *
6727 follow_die_ref (unsigned int offset)
6729 struct die_info *die;
6732 h = (offset % REF_HASH_SIZE);
6733 die = die_ref_table[h];
6736 if (die->offset == offset)
6740 die = die->next_ref;
6745 static struct type *
6746 dwarf2_fundamental_type (struct objfile *objfile, int typeid)
6748 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
6750 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
6751 typeid, objfile->name);
6754 /* Look for this particular type in the fundamental type vector. If
6755 one is not found, create and install one appropriate for the
6756 current language and the current target machine. */
6758 if (ftypes[typeid] == NULL)
6760 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
6763 return (ftypes[typeid]);
6766 /* Decode simple location descriptions.
6767 Given a pointer to a dwarf block that defines a location, compute
6768 the location and return the value.
6770 NOTE drow/2003-11-18: This function is called in two situations
6771 now: for the address of static or global variables (partial symbols
6772 only) and for offsets into structures which are expected to be
6773 (more or less) constant. The partial symbol case should go away,
6774 and only the constant case should remain. That will let this
6775 function complain more accurately. A few special modes are allowed
6776 without complaint for global variables (for instance, global
6777 register values and thread-local values).
6779 A location description containing no operations indicates that the
6780 object is optimized out. The return value is 0 for that case.
6781 FIXME drow/2003-11-16: No callers check for this case any more; soon all
6782 callers will only want a very basic result and this can become a
6785 When the result is a register number, the global isreg flag is set,
6786 otherwise it is cleared.
6788 Note that stack[0] is unused except as a default error return.
6789 Note that stack overflow is not yet handled. */
6792 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
6794 struct objfile *objfile = cu->objfile;
6795 struct comp_unit_head *cu_header = &cu->header;
6797 int size = blk->size;
6798 char *data = blk->data;
6799 CORE_ADDR stack[64];
6801 unsigned int bytes_read, unsnd;
6846 stack[++stacki] = op - DW_OP_lit0;
6882 stack[++stacki] = op - DW_OP_reg0;
6884 dwarf2_complex_location_expr_complaint ();
6889 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
6891 stack[++stacki] = unsnd;
6893 dwarf2_complex_location_expr_complaint ();
6897 stack[++stacki] = read_address (objfile->obfd, &data[i],
6903 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
6908 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
6913 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
6918 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
6923 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
6928 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
6933 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
6939 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
6944 stack[stacki + 1] = stack[stacki];
6949 stack[stacki - 1] += stack[stacki];
6953 case DW_OP_plus_uconst:
6954 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
6959 stack[stacki - 1] -= stack[stacki];
6964 /* If we're not the last op, then we definitely can't encode
6965 this using GDB's address_class enum. This is valid for partial
6966 global symbols, although the variable's address will be bogus
6969 dwarf2_complex_location_expr_complaint ();
6972 case DW_OP_GNU_push_tls_address:
6973 /* The top of the stack has the offset from the beginning
6974 of the thread control block at which the variable is located. */
6975 /* Nothing should follow this operator, so the top of stack would
6977 /* This is valid for partial global symbols, but the variable's
6978 address will be bogus in the psymtab. */
6980 dwarf2_complex_location_expr_complaint ();
6984 complaint (&symfile_complaints, "unsupported stack op: '%s'",
6985 dwarf_stack_op_name (op));
6986 return (stack[stacki]);
6989 return (stack[stacki]);
6992 /* memory allocation interface */
6995 dwarf2_free_tmp_obstack (void *ignore)
6997 obstack_free (&dwarf2_tmp_obstack, NULL);
7000 static struct dwarf_block *
7001 dwarf_alloc_block (void)
7003 struct dwarf_block *blk;
7005 blk = (struct dwarf_block *)
7006 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
7010 static struct abbrev_info *
7011 dwarf_alloc_abbrev (void)
7013 struct abbrev_info *abbrev;
7015 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
7016 memset (abbrev, 0, sizeof (struct abbrev_info));
7020 static struct die_info *
7021 dwarf_alloc_die (void)
7023 struct die_info *die;
7025 die = (struct die_info *) xmalloc (sizeof (struct die_info));
7026 memset (die, 0, sizeof (struct die_info));
7031 /* Macro support. */
7034 /* Return the full name of file number I in *LH's file name table.
7035 Use COMP_DIR as the name of the current directory of the
7036 compilation. The result is allocated using xmalloc; the caller is
7037 responsible for freeing it. */
7039 file_full_name (int file, struct line_header *lh, const char *comp_dir)
7041 struct file_entry *fe = &lh->file_names[file - 1];
7043 if (IS_ABSOLUTE_PATH (fe->name))
7044 return xstrdup (fe->name);
7052 dir = lh->include_dirs[fe->dir_index - 1];
7058 dir_len = strlen (dir);
7059 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
7060 strcpy (full_name, dir);
7061 full_name[dir_len] = '/';
7062 strcpy (full_name + dir_len + 1, fe->name);
7066 return xstrdup (fe->name);
7071 static struct macro_source_file *
7072 macro_start_file (int file, int line,
7073 struct macro_source_file *current_file,
7074 const char *comp_dir,
7075 struct line_header *lh, struct objfile *objfile)
7077 /* The full name of this source file. */
7078 char *full_name = file_full_name (file, lh, comp_dir);
7080 /* We don't create a macro table for this compilation unit
7081 at all until we actually get a filename. */
7082 if (! pending_macros)
7083 pending_macros = new_macro_table (&objfile->symbol_obstack,
7084 objfile->macro_cache);
7087 /* If we have no current file, then this must be the start_file
7088 directive for the compilation unit's main source file. */
7089 current_file = macro_set_main (pending_macros, full_name);
7091 current_file = macro_include (current_file, line, full_name);
7095 return current_file;
7099 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7100 followed by a null byte. */
7102 copy_string (const char *buf, int len)
7104 char *s = xmalloc (len + 1);
7105 memcpy (s, buf, len);
7113 consume_improper_spaces (const char *p, const char *body)
7117 complaint (&symfile_complaints,
7118 "macro definition contains spaces in formal argument list:\n`%s'",
7130 parse_macro_definition (struct macro_source_file *file, int line,
7135 /* The body string takes one of two forms. For object-like macro
7136 definitions, it should be:
7138 <macro name> " " <definition>
7140 For function-like macro definitions, it should be:
7142 <macro name> "() " <definition>
7144 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7146 Spaces may appear only where explicitly indicated, and in the
7149 The Dwarf 2 spec says that an object-like macro's name is always
7150 followed by a space, but versions of GCC around March 2002 omit
7151 the space when the macro's definition is the empty string.
7153 The Dwarf 2 spec says that there should be no spaces between the
7154 formal arguments in a function-like macro's formal argument list,
7155 but versions of GCC around March 2002 include spaces after the
7159 /* Find the extent of the macro name. The macro name is terminated
7160 by either a space or null character (for an object-like macro) or
7161 an opening paren (for a function-like macro). */
7162 for (p = body; *p; p++)
7163 if (*p == ' ' || *p == '(')
7166 if (*p == ' ' || *p == '\0')
7168 /* It's an object-like macro. */
7169 int name_len = p - body;
7170 char *name = copy_string (body, name_len);
7171 const char *replacement;
7174 replacement = body + name_len + 1;
7177 dwarf2_macro_malformed_definition_complaint (body);
7178 replacement = body + name_len;
7181 macro_define_object (file, line, name, replacement);
7187 /* It's a function-like macro. */
7188 char *name = copy_string (body, p - body);
7191 char **argv = xmalloc (argv_size * sizeof (*argv));
7195 p = consume_improper_spaces (p, body);
7197 /* Parse the formal argument list. */
7198 while (*p && *p != ')')
7200 /* Find the extent of the current argument name. */
7201 const char *arg_start = p;
7203 while (*p && *p != ',' && *p != ')' && *p != ' ')
7206 if (! *p || p == arg_start)
7207 dwarf2_macro_malformed_definition_complaint (body);
7210 /* Make sure argv has room for the new argument. */
7211 if (argc >= argv_size)
7214 argv = xrealloc (argv, argv_size * sizeof (*argv));
7217 argv[argc++] = copy_string (arg_start, p - arg_start);
7220 p = consume_improper_spaces (p, body);
7222 /* Consume the comma, if present. */
7227 p = consume_improper_spaces (p, body);
7236 /* Perfectly formed definition, no complaints. */
7237 macro_define_function (file, line, name,
7238 argc, (const char **) argv,
7240 else if (*p == '\0')
7242 /* Complain, but do define it. */
7243 dwarf2_macro_malformed_definition_complaint (body);
7244 macro_define_function (file, line, name,
7245 argc, (const char **) argv,
7249 /* Just complain. */
7250 dwarf2_macro_malformed_definition_complaint (body);
7253 /* Just complain. */
7254 dwarf2_macro_malformed_definition_complaint (body);
7260 for (i = 0; i < argc; i++)
7266 dwarf2_macro_malformed_definition_complaint (body);
7271 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7272 char *comp_dir, bfd *abfd,
7273 struct dwarf2_cu *cu)
7275 char *mac_ptr, *mac_end;
7276 struct macro_source_file *current_file = 0;
7278 if (dwarf_macinfo_buffer == NULL)
7280 complaint (&symfile_complaints, "missing .debug_macinfo section");
7284 mac_ptr = dwarf_macinfo_buffer + offset;
7285 mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size;
7289 enum dwarf_macinfo_record_type macinfo_type;
7291 /* Do we at least have room for a macinfo type byte? */
7292 if (mac_ptr >= mac_end)
7294 dwarf2_macros_too_long_complaint ();
7298 macinfo_type = read_1_byte (abfd, mac_ptr);
7301 switch (macinfo_type)
7303 /* A zero macinfo type indicates the end of the macro
7308 case DW_MACINFO_define:
7309 case DW_MACINFO_undef:
7315 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7316 mac_ptr += bytes_read;
7317 body = read_string (abfd, mac_ptr, &bytes_read);
7318 mac_ptr += bytes_read;
7321 complaint (&symfile_complaints,
7322 "debug info gives macro %s outside of any file: %s",
7324 DW_MACINFO_define ? "definition" : macinfo_type ==
7325 DW_MACINFO_undef ? "undefinition" :
7326 "something-or-other", body);
7329 if (macinfo_type == DW_MACINFO_define)
7330 parse_macro_definition (current_file, line, body);
7331 else if (macinfo_type == DW_MACINFO_undef)
7332 macro_undef (current_file, line, body);
7337 case DW_MACINFO_start_file:
7342 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7343 mac_ptr += bytes_read;
7344 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7345 mac_ptr += bytes_read;
7347 current_file = macro_start_file (file, line,
7348 current_file, comp_dir,
7353 case DW_MACINFO_end_file:
7355 complaint (&symfile_complaints,
7356 "macro debug info has an unmatched `close_file' directive");
7359 current_file = current_file->included_by;
7362 enum dwarf_macinfo_record_type next_type;
7364 /* GCC circa March 2002 doesn't produce the zero
7365 type byte marking the end of the compilation
7366 unit. Complain if it's not there, but exit no
7369 /* Do we at least have room for a macinfo type byte? */
7370 if (mac_ptr >= mac_end)
7372 dwarf2_macros_too_long_complaint ();
7376 /* We don't increment mac_ptr here, so this is just
7378 next_type = read_1_byte (abfd, mac_ptr);
7380 complaint (&symfile_complaints,
7381 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7388 case DW_MACINFO_vendor_ext:
7394 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7395 mac_ptr += bytes_read;
7396 string = read_string (abfd, mac_ptr, &bytes_read);
7397 mac_ptr += bytes_read;
7399 /* We don't recognize any vendor extensions. */
7406 /* Check if the attribute's form is a DW_FORM_block*
7407 if so return true else false. */
7409 attr_form_is_block (struct attribute *attr)
7411 return (attr == NULL ? 0 :
7412 attr->form == DW_FORM_block1
7413 || attr->form == DW_FORM_block2
7414 || attr->form == DW_FORM_block4
7415 || attr->form == DW_FORM_block);
7419 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7420 struct dwarf2_cu *cu)
7422 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
7424 struct dwarf2_loclist_baton *baton;
7426 baton = obstack_alloc (&cu->objfile->symbol_obstack,
7427 sizeof (struct dwarf2_loclist_baton));
7428 baton->objfile = cu->objfile;
7430 /* We don't know how long the location list is, but make sure we
7431 don't run off the edge of the section. */
7432 baton->size = dwarf_loc_size - DW_UNSND (attr);
7433 baton->data = dwarf_loc_buffer + DW_UNSND (attr);
7434 baton->base_address = cu->header.base_address;
7435 if (cu->header.base_known == 0)
7436 complaint (&symfile_complaints,
7437 "Location list used without specifying the CU base address.");
7439 SYMBOL_LOCATION_FUNCS (sym) = &dwarf2_loclist_funcs;
7440 SYMBOL_LOCATION_BATON (sym) = baton;
7444 struct dwarf2_locexpr_baton *baton;
7446 baton = obstack_alloc (&cu->objfile->symbol_obstack,
7447 sizeof (struct dwarf2_locexpr_baton));
7448 baton->objfile = cu->objfile;
7450 if (attr_form_is_block (attr))
7452 /* Note that we're just copying the block's data pointer
7453 here, not the actual data. We're still pointing into the
7454 dwarf_info_buffer for SYM's objfile; right now we never
7455 release that buffer, but when we do clean up properly
7456 this may need to change. */
7457 baton->size = DW_BLOCK (attr)->size;
7458 baton->data = DW_BLOCK (attr)->data;
7462 dwarf2_invalid_attrib_class_complaint ("location description",
7463 SYMBOL_NATURAL_NAME (sym));
7468 SYMBOL_LOCATION_FUNCS (sym) = &dwarf2_locexpr_funcs;
7469 SYMBOL_LOCATION_BATON (sym) = baton;