1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
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;
234 struct function_range *first_fn, *last_fn, *cached_fn;
236 /* The language we are debugging. */
237 enum language language;
238 const struct language_defn *language_defn;
240 /* The generic symbol table building routines have separate lists for
241 file scope symbols and all all other scopes (local scopes). So
242 we need to select the right one to pass to add_symbol_to_list().
243 We do it by keeping a pointer to the correct list in list_in_scope.
245 FIXME: The original dwarf code just treated the file scope as the
246 first local scope, and all other local scopes as nested local
247 scopes, and worked fine. Check to see if we really need to
248 distinguish these in buildsym.c. */
249 struct pending **list_in_scope;
251 /* Maintain an array of referenced fundamental types for the current
252 compilation unit being read. For DWARF version 1, we have to construct
253 the fundamental types on the fly, since no information about the
254 fundamental types is supplied. Each such fundamental type is created by
255 calling a language dependent routine to create the type, and then a
256 pointer to that type is then placed in the array at the index specified
257 by it's FT_<TYPENAME> value. The array has a fixed size set by the
258 FT_NUM_MEMBERS compile time constant, which is the number of predefined
259 fundamental types gdb knows how to construct. */
260 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
263 /* The line number information for a compilation unit (found in the
264 .debug_line section) begins with a "statement program header",
265 which contains the following information. */
268 unsigned int total_length;
269 unsigned short version;
270 unsigned int header_length;
271 unsigned char minimum_instruction_length;
272 unsigned char default_is_stmt;
274 unsigned char line_range;
275 unsigned char opcode_base;
277 /* standard_opcode_lengths[i] is the number of operands for the
278 standard opcode whose value is i. This means that
279 standard_opcode_lengths[0] is unused, and the last meaningful
280 element is standard_opcode_lengths[opcode_base - 1]. */
281 unsigned char *standard_opcode_lengths;
283 /* The include_directories table. NOTE! These strings are not
284 allocated with xmalloc; instead, they are pointers into
285 debug_line_buffer. If you try to free them, `free' will get
287 unsigned int num_include_dirs, include_dirs_size;
290 /* The file_names table. NOTE! These strings are not allocated
291 with xmalloc; instead, they are pointers into debug_line_buffer.
292 Don't try to free them directly. */
293 unsigned int num_file_names, file_names_size;
297 unsigned int dir_index;
298 unsigned int mod_time;
302 /* The start and end of the statement program following this
303 header. These point into dwarf_line_buffer. */
304 char *statement_program_start, *statement_program_end;
307 /* When we construct a partial symbol table entry we only
308 need this much information. */
309 struct partial_die_info
312 unsigned char has_children;
313 unsigned char is_external;
314 unsigned char is_declaration;
315 unsigned char has_type;
322 struct dwarf_block *locdesc;
323 unsigned int language;
327 /* This data structure holds the information of an abbrev. */
330 unsigned int number; /* number identifying abbrev */
331 enum dwarf_tag tag; /* dwarf tag */
332 int has_children; /* boolean */
333 unsigned int num_attrs; /* number of attributes */
334 struct attr_abbrev *attrs; /* an array of attribute descriptions */
335 struct abbrev_info *next; /* next in chain */
340 enum dwarf_attribute name;
341 enum dwarf_form form;
344 /* This data structure holds a complete die structure. */
347 enum dwarf_tag tag; /* Tag indicating type of die */
348 unsigned int abbrev; /* Abbrev number */
349 unsigned int offset; /* Offset in .debug_info section */
350 unsigned int num_attrs; /* Number of attributes */
351 struct attribute *attrs; /* An array of attributes */
352 struct die_info *next_ref; /* Next die in ref hash table */
354 /* The dies in a compilation unit form an n-ary tree. PARENT
355 points to this die's parent; CHILD points to the first child of
356 this node; and all the children of a given node are chained
357 together via their SIBLING fields, terminated by a die whose
359 struct die_info *child; /* Its first child, if any. */
360 struct die_info *sibling; /* Its next sibling, if any. */
361 struct die_info *parent; /* Its parent, if any. */
363 struct type *type; /* Cached type information */
366 /* Attributes have a name and a value */
369 enum dwarf_attribute name;
370 enum dwarf_form form;
374 struct dwarf_block *blk;
382 struct function_range
385 CORE_ADDR lowpc, highpc;
387 struct function_range *next;
390 /* Get at parts of an attribute structure */
392 #define DW_STRING(attr) ((attr)->u.str)
393 #define DW_UNSND(attr) ((attr)->u.unsnd)
394 #define DW_BLOCK(attr) ((attr)->u.blk)
395 #define DW_SND(attr) ((attr)->u.snd)
396 #define DW_ADDR(attr) ((attr)->u.addr)
398 /* Blocks are a bunch of untyped bytes. */
405 #ifndef ATTR_ALLOC_CHUNK
406 #define ATTR_ALLOC_CHUNK 4
409 /* A hash table of die offsets for following references. */
410 #ifndef REF_HASH_SIZE
411 #define REF_HASH_SIZE 1021
414 static struct die_info *die_ref_table[REF_HASH_SIZE];
416 /* Obstack for allocating temporary storage used during symbol reading. */
417 static struct obstack dwarf2_tmp_obstack;
419 /* Allocate fields for structs, unions and enums in this size. */
420 #ifndef DW_FIELD_ALLOC_CHUNK
421 #define DW_FIELD_ALLOC_CHUNK 4
424 /* Actually data from the sections. */
425 static char *dwarf_info_buffer;
426 static char *dwarf_abbrev_buffer;
427 static char *dwarf_line_buffer;
428 static char *dwarf_str_buffer;
429 static char *dwarf_macinfo_buffer;
430 static char *dwarf_ranges_buffer;
431 static char *dwarf_loc_buffer;
433 /* A zeroed version of a partial die for initialization purposes. */
434 static struct partial_die_info zeroed_partial_die;
436 /* FIXME: decode_locdesc sets these variables to describe the location
437 to the caller. These ought to be a structure or something. If
438 none of the flags are set, the object lives at the address returned
439 by decode_locdesc. */
441 static int isreg; /* Object lives in register.
442 decode_locdesc's return value is
443 the register number. */
445 /* We put a pointer to this structure in the read_symtab_private field
447 The complete dwarf information for an objfile is kept in the
448 objfile_obstack, so that absolute die references can be handled.
449 Most of the information in this structure is related to an entire
450 object file and could be passed via the sym_private field of the objfile.
451 It is however conceivable that dwarf2 might not be the only type
452 of symbols read from an object file. */
456 /* Pointer to start of dwarf info buffer for the objfile. */
458 char *dwarf_info_buffer;
460 /* Offset in dwarf_info_buffer for this compilation unit. */
462 unsigned long dwarf_info_offset;
464 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
466 char *dwarf_abbrev_buffer;
468 /* Size of dwarf abbreviation section for the objfile. */
470 unsigned int dwarf_abbrev_size;
472 /* Pointer to start of dwarf line buffer for the objfile. */
474 char *dwarf_line_buffer;
476 /* Size of dwarf_line_buffer, in bytes. */
478 unsigned int dwarf_line_size;
480 /* Pointer to start of dwarf string buffer for the objfile. */
482 char *dwarf_str_buffer;
484 /* Size of dwarf string section for the objfile. */
486 unsigned int dwarf_str_size;
488 /* Pointer to start of dwarf macro buffer for the objfile. */
490 char *dwarf_macinfo_buffer;
492 /* Size of dwarf macinfo section for the objfile. */
494 unsigned int dwarf_macinfo_size;
496 /* Pointer to start of dwarf ranges buffer for the objfile. */
498 char *dwarf_ranges_buffer;
500 /* Size of dwarf ranges buffer for the objfile. */
502 unsigned int dwarf_ranges_size;
504 /* Pointer to start of dwarf locations buffer for the objfile. */
506 char *dwarf_loc_buffer;
508 /* Size of dwarf locations buffer for the objfile. */
510 unsigned int dwarf_loc_size;
513 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
514 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
515 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
516 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
517 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
518 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
519 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
520 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
521 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
522 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
523 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
524 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
525 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
526 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
527 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
529 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
530 but this would require a corresponding change in unpack_field_as_long
532 static int bits_per_byte = 8;
534 /* The routines that read and process dies for a C struct or C++ class
535 pass lists of data member fields and lists of member function fields
536 in an instance of a field_info structure, as defined below. */
539 /* List of data member and baseclasses fields. */
542 struct nextfield *next;
549 /* Number of fields. */
552 /* Number of baseclasses. */
555 /* Set if the accesibility of one of the fields is not public. */
556 int non_public_fields;
558 /* Member function fields array, entries are allocated in the order they
559 are encountered in the object file. */
562 struct nextfnfield *next;
563 struct fn_field fnfield;
567 /* Member function fieldlist array, contains name of possibly overloaded
568 member function, number of overloaded member functions and a pointer
569 to the head of the member function field chain. */
574 struct nextfnfield *head;
578 /* Number of entries in the fnfieldlists array. */
582 /* Various complaints about symbol reading that don't abort the process */
585 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
587 complaint (&symfile_complaints,
588 "statement list doesn't fit in .debug_line section");
592 dwarf2_complex_location_expr_complaint (void)
594 complaint (&symfile_complaints, "location expression too complex");
598 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
601 complaint (&symfile_complaints,
602 "const value length mismatch for '%s', got %d, expected %d", arg1,
607 dwarf2_macros_too_long_complaint (void)
609 complaint (&symfile_complaints,
610 "macro info runs off end of `.debug_macinfo' section");
614 dwarf2_macro_malformed_definition_complaint (const char *arg1)
616 complaint (&symfile_complaints,
617 "macro debug info contains a malformed macro definition:\n`%s'",
622 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
624 complaint (&symfile_complaints,
625 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
628 /* local function prototypes */
630 static void dwarf2_locate_sections (bfd *, asection *, void *);
633 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
636 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
638 static char *scan_partial_symbols (char *, CORE_ADDR *, CORE_ADDR *,
640 const char *namespace);
642 static void add_partial_symbol (struct partial_die_info *, struct dwarf2_cu *,
643 const char *namespace);
645 static int pdi_needs_namespace (enum dwarf_tag tag, const char *namespace);
647 static char *add_partial_namespace (struct partial_die_info *pdi,
649 CORE_ADDR *lowpc, CORE_ADDR *highpc,
650 struct dwarf2_cu *cu,
651 const char *namespace);
653 static char *add_partial_structure (struct partial_die_info *struct_pdi,
655 struct dwarf2_cu *cu,
656 const char *namespace);
658 static char *add_partial_enumeration (struct partial_die_info *enum_pdi,
660 struct dwarf2_cu *cu,
661 const char *namespace);
663 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
666 struct dwarf2_cu *cu);
668 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
670 static void psymtab_to_symtab_1 (struct partial_symtab *);
672 char *dwarf2_read_section (struct objfile *, asection *);
674 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
676 static void dwarf2_empty_abbrev_table (void *);
678 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
681 static char *read_partial_die (struct partial_die_info *,
682 bfd *, char *, struct dwarf2_cu *);
684 static char *read_full_die (struct die_info **, bfd *, char *,
685 struct dwarf2_cu *, int *);
687 static char *read_attribute (struct attribute *, struct attr_abbrev *,
688 bfd *, char *, struct dwarf2_cu *);
690 static char *read_attribute_value (struct attribute *, unsigned,
691 bfd *, char *, struct dwarf2_cu *);
693 static unsigned int read_1_byte (bfd *, char *);
695 static int read_1_signed_byte (bfd *, char *);
697 static unsigned int read_2_bytes (bfd *, char *);
699 static unsigned int read_4_bytes (bfd *, char *);
701 static unsigned long read_8_bytes (bfd *, char *);
703 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
706 static LONGEST read_initial_length (bfd *, char *,
707 struct comp_unit_head *, int *bytes_read);
709 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
712 static char *read_n_bytes (bfd *, char *, unsigned int);
714 static char *read_string (bfd *, char *, unsigned int *);
716 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
719 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
721 static long read_signed_leb128 (bfd *, char *, unsigned int *);
723 static void set_cu_language (unsigned int, struct dwarf2_cu *);
725 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
728 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
730 static struct die_info *die_specification (struct die_info *die,
733 static void free_line_header (struct line_header *lh);
735 static struct line_header *(dwarf_decode_line_header
736 (unsigned int offset,
737 bfd *abfd, struct dwarf2_cu *cu));
739 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
742 static void dwarf2_start_subfile (char *, char *);
744 static struct symbol *new_symbol (struct die_info *, struct type *,
747 static void dwarf2_const_value (struct attribute *, struct symbol *,
750 static void dwarf2_const_value_data (struct attribute *attr,
754 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
756 static struct type *die_containing_type (struct die_info *,
760 static struct type *type_at_offset (unsigned int, struct objfile *);
763 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
765 static void read_type_die (struct die_info *, struct dwarf2_cu *);
767 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
769 static char *typename_concat (const char *prefix, const char *suffix);
771 static void read_typedef (struct die_info *, struct dwarf2_cu *);
773 static void read_base_type (struct die_info *, struct dwarf2_cu *);
775 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
777 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
779 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
781 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
783 static int dwarf2_get_pc_bounds (struct die_info *,
784 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
786 static void get_scope_pc_bounds (struct die_info *,
787 CORE_ADDR *, CORE_ADDR *,
790 static void dwarf2_add_field (struct field_info *, struct die_info *,
793 static void dwarf2_attach_fields_to_type (struct field_info *,
794 struct type *, struct dwarf2_cu *);
796 static void dwarf2_add_member_fn (struct field_info *,
797 struct die_info *, struct type *,
800 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
801 struct type *, struct dwarf2_cu *);
803 static void read_structure_type (struct die_info *, struct dwarf2_cu *);
805 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
807 static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu);
809 static void read_common_block (struct die_info *, struct dwarf2_cu *);
811 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
813 static const char *namespace_name (struct die_info *die,
814 int *is_anonymous, struct dwarf2_cu *);
816 static void read_enumeration_type (struct die_info *, struct dwarf2_cu *);
818 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
820 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
822 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
824 static void read_array_type (struct die_info *, struct dwarf2_cu *);
826 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
828 static void read_tag_ptr_to_member_type (struct die_info *,
831 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
833 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
835 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
837 static void read_tag_restrict_type (struct die_info *, struct dwarf2_cu *);
839 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
841 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
843 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
845 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
848 struct die_info *parent);
850 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
853 struct die_info *parent);
855 static void free_die_list (struct die_info *);
857 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
859 static void process_die (struct die_info *, struct dwarf2_cu *);
861 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
863 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
865 static struct die_info *dwarf2_extension (struct die_info *die,
868 static char *dwarf_tag_name (unsigned int);
870 static char *dwarf_attr_name (unsigned int);
872 static char *dwarf_form_name (unsigned int);
874 static char *dwarf_stack_op_name (unsigned int);
876 static char *dwarf_bool_name (unsigned int);
878 static char *dwarf_type_encoding_name (unsigned int);
881 static char *dwarf_cfi_name (unsigned int);
883 struct die_info *copy_die (struct die_info *);
886 static struct die_info *sibling_die (struct die_info *);
888 static void dump_die (struct die_info *);
890 static void dump_die_list (struct die_info *);
892 static void store_in_ref_table (unsigned int, struct die_info *);
894 static void dwarf2_empty_hash_tables (void);
896 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
899 static int dwarf2_get_attr_constant_value (struct attribute *, int);
901 static struct die_info *follow_die_ref (unsigned int);
903 static struct type *dwarf2_fundamental_type (struct objfile *, int,
906 /* memory allocation interface */
908 static void dwarf2_free_tmp_obstack (void *);
910 static struct dwarf_block *dwarf_alloc_block (void);
912 static struct abbrev_info *dwarf_alloc_abbrev (void);
914 static struct die_info *dwarf_alloc_die (void);
916 static void initialize_cu_func_list (struct dwarf2_cu *);
918 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
921 static void dwarf_decode_macros (struct line_header *, unsigned int,
922 char *, bfd *, struct dwarf2_cu *);
924 static int attr_form_is_block (struct attribute *);
927 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
928 struct dwarf2_cu *cu);
930 /* Try to locate the sections we need for DWARF 2 debugging
931 information and return true if we have enough to do something. */
934 dwarf2_has_info (bfd *abfd)
936 dwarf_info_section = 0;
937 dwarf_abbrev_section = 0;
938 dwarf_line_section = 0;
939 dwarf_str_section = 0;
940 dwarf_macinfo_section = 0;
941 dwarf_frame_section = 0;
942 dwarf_eh_frame_section = 0;
943 dwarf_ranges_section = 0;
944 dwarf_loc_section = 0;
946 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
947 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
950 /* This function is mapped across the sections and remembers the
951 offset and size of each of the debugging sections we are interested
955 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
957 if (strcmp (sectp->name, INFO_SECTION) == 0)
959 dwarf_info_size = bfd_get_section_size (sectp);
960 dwarf_info_section = sectp;
962 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
964 dwarf_abbrev_size = bfd_get_section_size (sectp);
965 dwarf_abbrev_section = sectp;
967 else if (strcmp (sectp->name, LINE_SECTION) == 0)
969 dwarf_line_size = bfd_get_section_size (sectp);
970 dwarf_line_section = sectp;
972 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
974 dwarf_pubnames_size = bfd_get_section_size (sectp);
975 dwarf_pubnames_section = sectp;
977 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
979 dwarf_aranges_size = bfd_get_section_size (sectp);
980 dwarf_aranges_section = sectp;
982 else if (strcmp (sectp->name, LOC_SECTION) == 0)
984 dwarf_loc_size = bfd_get_section_size (sectp);
985 dwarf_loc_section = sectp;
987 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
989 dwarf_macinfo_size = bfd_get_section_size (sectp);
990 dwarf_macinfo_section = sectp;
992 else if (strcmp (sectp->name, STR_SECTION) == 0)
994 dwarf_str_size = bfd_get_section_size (sectp);
995 dwarf_str_section = sectp;
997 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
999 dwarf_frame_size = bfd_get_section_size (sectp);
1000 dwarf_frame_section = sectp;
1002 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1004 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1005 if (aflag & SEC_HAS_CONTENTS)
1007 dwarf_eh_frame_size = bfd_get_section_size (sectp);
1008 dwarf_eh_frame_section = sectp;
1011 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1013 dwarf_ranges_size = bfd_get_section_size (sectp);
1014 dwarf_ranges_section = sectp;
1018 /* Build a partial symbol table. */
1021 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1024 /* We definitely need the .debug_info and .debug_abbrev sections */
1026 dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1027 dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1029 if (dwarf_line_section)
1030 dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1032 dwarf_line_buffer = NULL;
1034 if (dwarf_str_section)
1035 dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1037 dwarf_str_buffer = NULL;
1039 if (dwarf_macinfo_section)
1040 dwarf_macinfo_buffer = dwarf2_read_section (objfile,
1041 dwarf_macinfo_section);
1043 dwarf_macinfo_buffer = NULL;
1045 if (dwarf_ranges_section)
1046 dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1048 dwarf_ranges_buffer = NULL;
1050 if (dwarf_loc_section)
1051 dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1053 dwarf_loc_buffer = NULL;
1056 || (objfile->global_psymbols.size == 0
1057 && objfile->static_psymbols.size == 0))
1059 init_psymbol_list (objfile, 1024);
1063 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1065 /* Things are significantly easier if we have .debug_aranges and
1066 .debug_pubnames sections */
1068 dwarf2_build_psymtabs_easy (objfile, mainline);
1072 /* only test this case for now */
1074 /* In this case we have to work a bit harder */
1075 dwarf2_build_psymtabs_hard (objfile, mainline);
1080 /* Build the partial symbol table from the information in the
1081 .debug_pubnames and .debug_aranges sections. */
1084 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1086 bfd *abfd = objfile->obfd;
1087 char *aranges_buffer, *pubnames_buffer;
1088 char *aranges_ptr, *pubnames_ptr;
1089 unsigned int entry_length, version, info_offset, info_size;
1091 pubnames_buffer = dwarf2_read_section (objfile,
1092 dwarf_pubnames_section);
1093 pubnames_ptr = pubnames_buffer;
1094 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
1096 struct comp_unit_head cu_header;
1099 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1101 pubnames_ptr += bytes_read;
1102 version = read_1_byte (abfd, pubnames_ptr);
1104 info_offset = read_4_bytes (abfd, pubnames_ptr);
1106 info_size = read_4_bytes (abfd, pubnames_ptr);
1110 aranges_buffer = dwarf2_read_section (objfile,
1111 dwarf_aranges_section);
1116 /* Read in the comp unit header information from the debug_info at
1120 read_comp_unit_head (struct comp_unit_head *cu_header,
1121 char *info_ptr, bfd *abfd)
1125 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1127 info_ptr += bytes_read;
1128 cu_header->version = read_2_bytes (abfd, info_ptr);
1130 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1132 info_ptr += bytes_read;
1133 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1135 signed_addr = bfd_get_sign_extend_vma (abfd);
1136 if (signed_addr < 0)
1137 internal_error (__FILE__, __LINE__,
1138 "read_comp_unit_head: dwarf from non elf file");
1139 cu_header->signed_addr_p = signed_addr;
1143 /* Build the partial symbol table by doing a quick pass through the
1144 .debug_info and .debug_abbrev sections. */
1147 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1149 /* Instead of reading this into a big buffer, we should probably use
1150 mmap() on architectures that support it. (FIXME) */
1151 bfd *abfd = objfile->obfd;
1152 char *info_ptr, *abbrev_ptr;
1153 char *beg_of_comp_unit;
1154 struct partial_die_info comp_unit_die;
1155 struct partial_symtab *pst;
1156 struct cleanup *back_to;
1157 CORE_ADDR lowpc, highpc, baseaddr;
1159 info_ptr = dwarf_info_buffer;
1160 abbrev_ptr = dwarf_abbrev_buffer;
1162 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1163 the partial symbol scan, like attribute values.
1165 We could reduce our peak memory consumption during partial symbol
1166 table construction by freeing stuff from this obstack more often
1167 --- say, after processing each compilation unit, or each die ---
1168 but it turns out that this saves almost nothing. For an
1169 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1170 on dwarf2_tmp_obstack. Some investigation showed:
1172 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1173 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1174 all fixed-length values not requiring dynamic allocation.
1176 2) 30% of the attributes used the form DW_FORM_string. For
1177 DW_FORM_string, read_attribute simply hands back a pointer to
1178 the null-terminated string in dwarf_info_buffer, so no dynamic
1179 allocation is needed there either.
1181 3) The remaining 1% of the attributes all used DW_FORM_block1.
1182 75% of those were DW_AT_frame_base location lists for
1183 functions; the rest were DW_AT_location attributes, probably
1184 for the global variables.
1186 Anyway, what this all means is that the memory the dwarf2
1187 reader uses as temporary space reading partial symbols is about
1188 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1190 obstack_init (&dwarf2_tmp_obstack);
1191 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1193 /* Since the objects we're extracting from dwarf_info_buffer vary in
1194 length, only the individual functions to extract them (like
1195 read_comp_unit_head and read_partial_die) can really know whether
1196 the buffer is large enough to hold another complete object.
1198 At the moment, they don't actually check that. If
1199 dwarf_info_buffer holds just one extra byte after the last
1200 compilation unit's dies, then read_comp_unit_head will happily
1201 read off the end of the buffer. read_partial_die is similarly
1202 casual. Those functions should be fixed.
1204 For this loop condition, simply checking whether there's any data
1205 left at all should be sufficient. */
1206 while (info_ptr < dwarf_info_buffer + dwarf_info_size)
1208 struct dwarf2_cu cu;
1209 beg_of_comp_unit = info_ptr;
1211 cu.objfile = objfile;
1212 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1214 if (cu.header.version != 2)
1216 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));
1219 if (cu.header.abbrev_offset >= dwarf_abbrev_size)
1221 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1222 (long) cu.header.abbrev_offset,
1223 (long) (beg_of_comp_unit - dwarf_info_buffer),
1224 bfd_get_filename (abfd));
1227 if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size
1228 > dwarf_info_buffer + dwarf_info_size)
1230 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1231 (long) cu.header.length,
1232 (long) (beg_of_comp_unit - dwarf_info_buffer),
1233 bfd_get_filename (abfd));
1236 /* Complete the cu_header */
1237 cu.header.offset = beg_of_comp_unit - dwarf_info_buffer;
1238 cu.header.first_die_ptr = info_ptr;
1239 cu.header.cu_head_ptr = beg_of_comp_unit;
1241 cu.list_in_scope = &file_symbols;
1243 /* Read the abbrevs for this compilation unit into a table */
1244 dwarf2_read_abbrevs (abfd, &cu);
1245 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1247 /* Read the compilation unit die */
1248 info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr,
1251 /* Set the language we're debugging */
1252 set_cu_language (comp_unit_die.language, &cu);
1254 /* Allocate a new partial symbol table structure */
1255 pst = start_psymtab_common (objfile, objfile->section_offsets,
1256 comp_unit_die.name ? comp_unit_die.name : "",
1257 comp_unit_die.lowpc,
1258 objfile->global_psymbols.next,
1259 objfile->static_psymbols.next);
1261 pst->read_symtab_private = (char *)
1262 obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
1263 DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
1264 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
1265 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
1266 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
1267 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
1268 DWARF_LINE_SIZE (pst) = dwarf_line_size;
1269 DWARF_STR_BUFFER (pst) = dwarf_str_buffer;
1270 DWARF_STR_SIZE (pst) = dwarf_str_size;
1271 DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer;
1272 DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size;
1273 DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer;
1274 DWARF_RANGES_SIZE (pst) = dwarf_ranges_size;
1275 DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer;
1276 DWARF_LOC_SIZE (pst) = dwarf_loc_size;
1277 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1279 /* Store the function that reads in the rest of the symbol table */
1280 pst->read_symtab = dwarf2_psymtab_to_symtab;
1282 /* Check if comp unit has_children.
1283 If so, read the rest of the partial symbols from this comp unit.
1284 If not, there's no more debug_info for this comp unit. */
1285 if (comp_unit_die.has_children)
1287 lowpc = ((CORE_ADDR) -1);
1288 highpc = ((CORE_ADDR) 0);
1290 info_ptr = scan_partial_symbols (info_ptr, &lowpc, &highpc,
1293 /* If we didn't find a lowpc, set it to highpc to avoid
1294 complaints from `maint check'. */
1295 if (lowpc == ((CORE_ADDR) -1))
1298 /* If the compilation unit didn't have an explicit address range,
1299 then use the information extracted from its child dies. */
1300 if (! comp_unit_die.has_pc_info)
1302 comp_unit_die.lowpc = lowpc;
1303 comp_unit_die.highpc = highpc;
1306 pst->textlow = comp_unit_die.lowpc + baseaddr;
1307 pst->texthigh = comp_unit_die.highpc + baseaddr;
1309 pst->n_global_syms = objfile->global_psymbols.next -
1310 (objfile->global_psymbols.list + pst->globals_offset);
1311 pst->n_static_syms = objfile->static_psymbols.next -
1312 (objfile->static_psymbols.list + pst->statics_offset);
1313 sort_pst_symbols (pst);
1315 /* If there is already a psymtab or symtab for a file of this
1316 name, remove it. (If there is a symtab, more drastic things
1317 also happen.) This happens in VxWorks. */
1318 free_named_symtabs (pst->filename);
1320 info_ptr = beg_of_comp_unit + cu.header.length
1321 + cu.header.initial_length_size;
1323 do_cleanups (back_to);
1326 /* Read in all interesting dies to the end of the compilation unit or
1327 to the end of the current namespace. NAMESPACE is NULL if we
1328 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1329 it's the name of the current namespace. In particular, it's the
1330 empty string if we're currently in the global namespace but have
1331 previously encountered a DW_TAG_namespace. */
1334 scan_partial_symbols (char *info_ptr, CORE_ADDR *lowpc,
1335 CORE_ADDR *highpc, struct dwarf2_cu *cu,
1336 const char *namespace)
1338 struct objfile *objfile = cu->objfile;
1339 bfd *abfd = objfile->obfd;
1340 struct partial_die_info pdi;
1342 /* Now, march along the PDI's, descending into ones which have
1343 interesting children but skipping the children of the other ones,
1344 until we reach the end of the compilation unit. */
1348 /* This flag tells whether or not info_ptr has gotten updated
1350 int info_ptr_updated = 0;
1352 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1354 /* Anonymous namespaces have no name but have interesting
1355 children, so we need to look at them. Ditto for anonymous
1358 if (pdi.name != NULL || pdi.tag == DW_TAG_namespace
1359 || pdi.tag == DW_TAG_enumeration_type)
1363 case DW_TAG_subprogram:
1364 if (pdi.has_pc_info)
1366 if (pdi.lowpc < *lowpc)
1370 if (pdi.highpc > *highpc)
1372 *highpc = pdi.highpc;
1374 if (!pdi.is_declaration)
1376 add_partial_symbol (&pdi, cu, namespace);
1380 case DW_TAG_variable:
1381 case DW_TAG_typedef:
1382 case DW_TAG_union_type:
1383 if (!pdi.is_declaration)
1385 add_partial_symbol (&pdi, cu, namespace);
1388 case DW_TAG_class_type:
1389 case DW_TAG_structure_type:
1390 if (!pdi.is_declaration)
1392 info_ptr = add_partial_structure (&pdi, info_ptr, cu,
1394 info_ptr_updated = 1;
1397 case DW_TAG_enumeration_type:
1398 if (!pdi.is_declaration)
1400 info_ptr = add_partial_enumeration (&pdi, info_ptr, cu,
1402 info_ptr_updated = 1;
1405 case DW_TAG_base_type:
1406 case DW_TAG_subrange_type:
1407 /* File scope base type definitions are added to the partial
1409 add_partial_symbol (&pdi, cu, namespace);
1411 case DW_TAG_namespace:
1412 /* We've hit a DW_TAG_namespace entry, so we know this
1413 file has been compiled using a compiler that
1414 generates them; update NAMESPACE to reflect that. */
1415 if (namespace == NULL)
1417 info_ptr = add_partial_namespace (&pdi, info_ptr, lowpc, highpc,
1419 info_ptr_updated = 1;
1429 /* If the die has a sibling, skip to the sibling, unless another
1430 function has already updated info_ptr for us. */
1432 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1433 or not we want to update this depends on enough stuff (not
1434 only pdi.tag but also whether or not pdi.name is NULL) that
1435 this seems like the easiest way to handle the issue. */
1437 if (!info_ptr_updated)
1438 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1445 add_partial_symbol (struct partial_die_info *pdi,
1446 struct dwarf2_cu *cu, const char *namespace)
1448 struct objfile *objfile = cu->objfile;
1450 char *actual_name = pdi->name;
1451 const struct partial_symbol *psym = NULL;
1454 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1456 /* If we're not in the global namespace and if the namespace name
1457 isn't encoded in a mangled actual_name, add it. */
1459 if (pdi_needs_namespace (pdi->tag, namespace))
1461 actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1);
1462 strcpy (actual_name, namespace);
1463 strcat (actual_name, "::");
1464 strcat (actual_name, pdi->name);
1469 case DW_TAG_subprogram:
1470 if (pdi->is_external)
1472 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1473 mst_text, objfile); */
1474 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1475 VAR_DOMAIN, LOC_BLOCK,
1476 &objfile->global_psymbols,
1477 0, pdi->lowpc + baseaddr,
1478 cu->language, objfile);
1482 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1483 mst_file_text, objfile); */
1484 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1485 VAR_DOMAIN, LOC_BLOCK,
1486 &objfile->static_psymbols,
1487 0, pdi->lowpc + baseaddr,
1488 cu->language, objfile);
1491 case DW_TAG_variable:
1492 if (pdi->is_external)
1495 Don't enter into the minimal symbol tables as there is
1496 a minimal symbol table entry from the ELF symbols already.
1497 Enter into partial symbol table if it has a location
1498 descriptor or a type.
1499 If the location descriptor is missing, new_symbol will create
1500 a LOC_UNRESOLVED symbol, the address of the variable will then
1501 be determined from the minimal symbol table whenever the variable
1503 The address for the partial symbol table entry is not
1504 used by GDB, but it comes in handy for debugging partial symbol
1508 addr = decode_locdesc (pdi->locdesc, cu);
1509 if (pdi->locdesc || pdi->has_type)
1510 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1511 VAR_DOMAIN, LOC_STATIC,
1512 &objfile->global_psymbols,
1514 cu->language, objfile);
1518 /* Static Variable. Skip symbols without location descriptors. */
1519 if (pdi->locdesc == NULL)
1521 addr = decode_locdesc (pdi->locdesc, cu);
1522 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1523 mst_file_data, objfile); */
1524 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1525 VAR_DOMAIN, LOC_STATIC,
1526 &objfile->static_psymbols,
1528 cu->language, objfile);
1531 case DW_TAG_typedef:
1532 case DW_TAG_base_type:
1533 case DW_TAG_subrange_type:
1534 add_psymbol_to_list (actual_name, strlen (actual_name),
1535 VAR_DOMAIN, LOC_TYPEDEF,
1536 &objfile->static_psymbols,
1537 0, (CORE_ADDR) 0, cu->language, objfile);
1539 case DW_TAG_class_type:
1540 case DW_TAG_structure_type:
1541 case DW_TAG_union_type:
1542 case DW_TAG_enumeration_type:
1543 /* Skip aggregate types without children, these are external
1545 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1546 static vs. global. */
1547 if (pdi->has_children == 0)
1549 add_psymbol_to_list (actual_name, strlen (actual_name),
1550 STRUCT_DOMAIN, LOC_TYPEDEF,
1551 cu->language == language_cplus
1552 ? &objfile->global_psymbols
1553 : &objfile->static_psymbols,
1554 0, (CORE_ADDR) 0, cu->language, objfile);
1556 if (cu->language == language_cplus)
1558 /* For C++, these implicitly act as typedefs as well. */
1559 add_psymbol_to_list (actual_name, strlen (actual_name),
1560 VAR_DOMAIN, LOC_TYPEDEF,
1561 &objfile->global_psymbols,
1562 0, (CORE_ADDR) 0, cu->language, objfile);
1565 case DW_TAG_enumerator:
1566 add_psymbol_to_list (actual_name, strlen (actual_name),
1567 VAR_DOMAIN, LOC_CONST,
1568 cu->language == language_cplus
1569 ? &objfile->global_psymbols
1570 : &objfile->static_psymbols,
1571 0, (CORE_ADDR) 0, cu->language, objfile);
1577 /* Check to see if we should scan the name for possible namespace
1578 info. Only do this if this is C++, if we don't have namespace
1579 debugging info in the file, if the psym is of an appropriate type
1580 (otherwise we'll have psym == NULL), and if we actually had a
1581 mangled name to begin with. */
1583 if (cu->language == language_cplus
1584 && namespace == NULL
1586 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1587 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1591 /* Determine whether a die of type TAG living in the C++ namespace
1592 NAMESPACE needs to have the name of the namespace prepended to the
1593 name listed in the die. */
1596 pdi_needs_namespace (enum dwarf_tag tag, const char *namespace)
1598 if (namespace == NULL || namespace[0] == '\0')
1603 case DW_TAG_typedef:
1604 case DW_TAG_class_type:
1605 case DW_TAG_structure_type:
1606 case DW_TAG_union_type:
1607 case DW_TAG_enumeration_type:
1608 case DW_TAG_enumerator:
1615 /* Read a partial die corresponding to a namespace; also, add a symbol
1616 corresponding to that namespace to the symbol table. NAMESPACE is
1617 the name of the enclosing namespace. */
1620 add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
1621 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1622 struct dwarf2_cu *cu, const char *namespace)
1624 struct objfile *objfile = cu->objfile;
1625 const char *new_name = pdi->name;
1628 /* Calculate the full name of the namespace that we just entered. */
1630 if (new_name == NULL)
1631 new_name = "(anonymous namespace)";
1632 full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1);
1633 strcpy (full_name, namespace);
1634 if (*namespace != '\0')
1635 strcat (full_name, "::");
1636 strcat (full_name, new_name);
1638 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1639 to add_partial_symbol, because we don't have a way to pass in the
1640 full name to that function; that might be a flaw in
1641 add_partial_symbol's interface. */
1643 add_psymbol_to_list (full_name, strlen (full_name),
1644 VAR_DOMAIN, LOC_TYPEDEF,
1645 &objfile->global_psymbols,
1646 0, 0, cu->language, objfile);
1648 /* Now scan partial symbols in that namespace. */
1650 if (pdi->has_children)
1651 info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name);
1656 /* Read a partial die corresponding to a class or structure. */
1659 add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
1660 struct dwarf2_cu *cu,
1661 const char *namespace)
1663 bfd *abfd = cu->objfile->obfd;
1664 char *actual_class_name = NULL;
1666 if (cu->language == language_cplus
1667 && (namespace == NULL || namespace[0] == '\0')
1668 && struct_pdi->name != NULL
1669 && struct_pdi->has_children)
1671 /* See if we can figure out if the class lives in a namespace
1672 (or is nested within another class.) We do this by looking
1673 for a member function; its demangled name will contain
1674 namespace info, if there is any. */
1676 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1677 what template types look like, because the demangler
1678 frequently doesn't give the same name as the debug info. We
1679 could fix this by only using the demangled name to get the
1680 prefix (but see comment in read_structure_type). */
1682 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1683 the appropriate debug information, so it would be nice to be
1684 able to avoid this hack. But NAMESPACE may not be the
1685 namespace where this class was defined: NAMESPACE reflects
1686 where STRUCT_PDI occurs in the tree of dies, but because of
1687 DW_AT_specification, that may not actually tell us where the
1688 class is defined. (See the comment in read_func_scope for an
1689 example of how this could occur.)
1691 Unfortunately, our current partial symtab data structures are
1692 completely unable to deal with DW_AT_specification. So, for
1693 now, the best thing to do is to get nesting information from
1694 places other than the tree structure of dies if there's any
1695 chance that a DW_AT_specification is involved. :-( */
1697 char *next_child = info_ptr;
1701 struct partial_die_info child_pdi;
1703 next_child = read_partial_die (&child_pdi, abfd, next_child,
1707 if (child_pdi.tag == DW_TAG_subprogram)
1709 actual_class_name = class_name_from_physname (child_pdi.name);
1710 if (actual_class_name != NULL)
1711 struct_pdi->name = actual_class_name;
1716 next_child = locate_pdi_sibling (&child_pdi, next_child,
1722 add_partial_symbol (struct_pdi, cu, namespace);
1723 xfree (actual_class_name);
1725 return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu);
1728 /* Read a partial die corresponding to an enumeration type. */
1731 add_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr,
1732 struct dwarf2_cu *cu, const char *namespace)
1734 struct objfile *objfile = cu->objfile;
1735 bfd *abfd = objfile->obfd;
1736 struct partial_die_info pdi;
1738 if (enum_pdi->name != NULL)
1739 add_partial_symbol (enum_pdi, cu, namespace);
1743 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1746 if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL)
1747 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1749 add_partial_symbol (&pdi, cu, namespace);
1755 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1759 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
1760 bfd *abfd, struct dwarf2_cu *cu)
1762 /* Do we know the sibling already? */
1764 if (orig_pdi->sibling)
1765 return orig_pdi->sibling;
1767 /* Are there any children to deal with? */
1769 if (!orig_pdi->has_children)
1772 /* Okay, we don't know the sibling, but we have children that we
1773 want to skip. So read children until we run into one without a
1774 tag; return whatever follows it. */
1778 struct partial_die_info pdi;
1780 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1785 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1789 /* Expand this partial symbol table into a full symbol table. */
1792 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
1794 /* FIXME: This is barely more than a stub. */
1799 warning ("bug: psymtab for %s is already read in.", pst->filename);
1805 printf_filtered ("Reading in symbols for %s...", pst->filename);
1806 gdb_flush (gdb_stdout);
1809 psymtab_to_symtab_1 (pst);
1811 /* Finish up the debug error message. */
1813 printf_filtered ("done.\n");
1819 psymtab_to_symtab_1 (struct partial_symtab *pst)
1821 struct objfile *objfile = pst->objfile;
1822 bfd *abfd = objfile->obfd;
1823 struct dwarf2_cu cu;
1824 struct die_info *dies;
1825 unsigned long offset;
1826 CORE_ADDR lowpc, highpc;
1827 struct die_info *child_die;
1829 struct symtab *symtab;
1830 struct cleanup *back_to;
1831 struct attribute *attr;
1834 /* Set local variables from the partial symbol table info. */
1835 offset = DWARF_INFO_OFFSET (pst);
1836 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1837 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1838 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1839 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1840 dwarf_line_size = DWARF_LINE_SIZE (pst);
1841 dwarf_str_buffer = DWARF_STR_BUFFER (pst);
1842 dwarf_str_size = DWARF_STR_SIZE (pst);
1843 dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst);
1844 dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst);
1845 dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst);
1846 dwarf_ranges_size = DWARF_RANGES_SIZE (pst);
1847 dwarf_loc_buffer = DWARF_LOC_BUFFER (pst);
1848 dwarf_loc_size = DWARF_LOC_SIZE (pst);
1849 info_ptr = dwarf_info_buffer + offset;
1850 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1852 /* We're in the global namespace. */
1853 processing_current_prefix = "";
1855 obstack_init (&dwarf2_tmp_obstack);
1856 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1859 make_cleanup (really_free_pendings, NULL);
1861 cu.objfile = objfile;
1863 /* read in the comp_unit header */
1864 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1866 /* Read the abbrevs for this compilation unit */
1867 dwarf2_read_abbrevs (abfd, &cu);
1868 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1870 cu.header.offset = offset;
1872 cu.list_in_scope = &file_symbols;
1874 dies = read_comp_unit (info_ptr, abfd, &cu);
1876 make_cleanup_free_die_list (dies);
1878 /* Find the base address of the compilation unit for range lists and
1879 location lists. It will normally be specified by DW_AT_low_pc.
1880 In DWARF-3 draft 4, the base address could be overridden by
1881 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1882 compilation units with discontinuous ranges. */
1884 cu.header.base_known = 0;
1885 cu.header.base_address = 0;
1887 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
1890 cu.header.base_address = DW_ADDR (attr);
1891 cu.header.base_known = 1;
1895 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
1898 cu.header.base_address = DW_ADDR (attr);
1899 cu.header.base_known = 1;
1903 /* Do line number decoding in read_file_scope () */
1904 process_die (dies, &cu);
1906 /* Some compilers don't define a DW_AT_high_pc attribute for the
1907 compilation unit. If the DW_AT_high_pc is missing, synthesize
1908 it, by scanning the DIE's below the compilation unit. */
1909 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
1911 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
1913 /* Set symtab language to language from DW_AT_language.
1914 If the compilation is from a C file generated by language preprocessors,
1915 do not set the language if it was already deduced by start_subfile. */
1917 && !(cu.language == language_c && symtab->language != language_c))
1919 symtab->language = cu.language;
1921 pst->symtab = symtab;
1924 do_cleanups (back_to);
1927 /* Process a die and its children. */
1930 process_die (struct die_info *die, struct dwarf2_cu *cu)
1934 case DW_TAG_padding:
1936 case DW_TAG_compile_unit:
1937 read_file_scope (die, cu);
1939 case DW_TAG_subprogram:
1940 read_subroutine_type (die, cu);
1941 read_func_scope (die, cu);
1943 case DW_TAG_inlined_subroutine:
1944 /* FIXME: These are ignored for now.
1945 They could be used to set breakpoints on all inlined instances
1946 of a function and make GDB `next' properly over inlined functions. */
1948 case DW_TAG_lexical_block:
1949 case DW_TAG_try_block:
1950 case DW_TAG_catch_block:
1951 read_lexical_block_scope (die, cu);
1953 case DW_TAG_class_type:
1954 case DW_TAG_structure_type:
1955 case DW_TAG_union_type:
1956 read_structure_type (die, cu);
1957 process_structure_scope (die, cu);
1959 case DW_TAG_enumeration_type:
1960 read_enumeration_type (die, cu);
1961 process_enumeration_scope (die, cu);
1964 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
1965 a symbol or process any children. Therefore it doesn't do anything
1966 that won't be done on-demand by read_type_die. */
1967 case DW_TAG_subroutine_type:
1968 read_subroutine_type (die, cu);
1970 case DW_TAG_array_type:
1971 read_array_type (die, cu);
1973 case DW_TAG_pointer_type:
1974 read_tag_pointer_type (die, cu);
1976 case DW_TAG_ptr_to_member_type:
1977 read_tag_ptr_to_member_type (die, cu);
1979 case DW_TAG_reference_type:
1980 read_tag_reference_type (die, cu);
1982 case DW_TAG_string_type:
1983 read_tag_string_type (die, cu);
1987 case DW_TAG_base_type:
1988 read_base_type (die, cu);
1989 /* Add a typedef symbol for the type definition, if it has a
1991 new_symbol (die, die->type, cu);
1993 case DW_TAG_subrange_type:
1994 read_subrange_type (die, cu);
1995 /* Add a typedef symbol for the type definition, if it has a
1997 new_symbol (die, die->type, cu);
1999 case DW_TAG_common_block:
2000 read_common_block (die, cu);
2002 case DW_TAG_common_inclusion:
2004 case DW_TAG_namespace:
2005 processing_has_namespace_info = 1;
2006 read_namespace (die, cu);
2008 case DW_TAG_imported_declaration:
2009 case DW_TAG_imported_module:
2010 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2011 information contained in these. DW_TAG_imported_declaration
2012 dies shouldn't have children; DW_TAG_imported_module dies
2013 shouldn't in the C++ case, but conceivably could in the
2014 Fortran case, so we'll have to replace this gdb_assert if
2015 Fortran compilers start generating that info. */
2016 processing_has_namespace_info = 1;
2017 gdb_assert (die->child == NULL);
2020 new_symbol (die, NULL, cu);
2026 initialize_cu_func_list (struct dwarf2_cu *cu)
2028 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2032 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2034 struct objfile *objfile = cu->objfile;
2035 struct comp_unit_head *cu_header = &cu->header;
2036 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2037 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2038 CORE_ADDR highpc = ((CORE_ADDR) 0);
2039 struct attribute *attr;
2040 char *name = "<unknown>";
2041 char *comp_dir = NULL;
2042 struct die_info *child_die;
2043 bfd *abfd = objfile->obfd;
2044 struct line_header *line_header = 0;
2047 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2049 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2051 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2052 from finish_block. */
2053 if (lowpc == ((CORE_ADDR) -1))
2058 attr = dwarf2_attr (die, DW_AT_name, cu);
2061 name = DW_STRING (attr);
2063 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2066 comp_dir = DW_STRING (attr);
2069 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2070 directory, get rid of it. */
2071 char *cp = strchr (comp_dir, ':');
2073 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2078 if (objfile->ei.entry_point >= lowpc &&
2079 objfile->ei.entry_point < highpc)
2081 objfile->ei.deprecated_entry_file_lowpc = lowpc;
2082 objfile->ei.deprecated_entry_file_highpc = highpc;
2085 attr = dwarf2_attr (die, DW_AT_language, cu);
2088 set_cu_language (DW_UNSND (attr), cu);
2091 /* We assume that we're processing GCC output. */
2092 processing_gcc_compilation = 2;
2094 /* FIXME:Do something here. */
2095 if (dip->at_producer != NULL)
2097 handle_producer (dip->at_producer);
2101 /* The compilation unit may be in a different language or objfile,
2102 zero out all remembered fundamental types. */
2103 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2105 start_symtab (name, comp_dir, lowpc);
2106 record_debugformat ("DWARF 2");
2108 initialize_cu_func_list (cu);
2110 /* Process all dies in compilation unit. */
2111 if (die->child != NULL)
2113 child_die = die->child;
2114 while (child_die && child_die->tag)
2116 process_die (child_die, cu);
2117 child_die = sibling_die (child_die);
2121 /* Decode line number information if present. */
2122 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2125 unsigned int line_offset = DW_UNSND (attr);
2126 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2129 make_cleanup ((make_cleanup_ftype *) free_line_header,
2130 (void *) line_header);
2131 dwarf_decode_lines (line_header, comp_dir, abfd, cu);
2135 /* Decode macro information, if present. Dwarf 2 macro information
2136 refers to information in the line number info statement program
2137 header, so we can only read it if we've read the header
2139 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2140 if (attr && line_header)
2142 unsigned int macro_offset = DW_UNSND (attr);
2143 dwarf_decode_macros (line_header, macro_offset,
2144 comp_dir, abfd, cu);
2146 do_cleanups (back_to);
2150 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2151 struct dwarf2_cu *cu)
2153 struct function_range *thisfn;
2155 thisfn = (struct function_range *)
2156 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range));
2157 thisfn->name = name;
2158 thisfn->lowpc = lowpc;
2159 thisfn->highpc = highpc;
2160 thisfn->seen_line = 0;
2161 thisfn->next = NULL;
2163 if (cu->last_fn == NULL)
2164 cu->first_fn = thisfn;
2166 cu->last_fn->next = thisfn;
2168 cu->last_fn = thisfn;
2172 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2174 struct objfile *objfile = cu->objfile;
2175 struct context_stack *new;
2178 struct die_info *child_die;
2179 struct attribute *attr;
2181 const char *previous_prefix = processing_current_prefix;
2182 struct cleanup *back_to = NULL;
2185 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2187 name = dwarf2_linkage_name (die, cu);
2189 /* Ignore functions with missing or empty names and functions with
2190 missing or invalid low and high pc attributes. */
2191 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2194 if (cu->language == language_cplus)
2196 struct die_info *spec_die = die_specification (die, cu);
2198 /* NOTE: carlton/2004-01-23: We have to be careful in the
2199 presence of DW_AT_specification. For example, with GCC 3.4,
2204 // Definition of N::foo.
2208 then we'll have a tree of DIEs like this:
2210 1: DW_TAG_compile_unit
2211 2: DW_TAG_namespace // N
2212 3: DW_TAG_subprogram // declaration of N::foo
2213 4: DW_TAG_subprogram // definition of N::foo
2214 DW_AT_specification // refers to die #3
2216 Thus, when processing die #4, we have to pretend that we're
2217 in the context of its DW_AT_specification, namely the contex
2220 if (spec_die != NULL)
2222 char *specification_prefix = determine_prefix (spec_die, cu);
2223 processing_current_prefix = specification_prefix;
2224 back_to = make_cleanup (xfree, specification_prefix);
2231 /* Record the function range for dwarf_decode_lines. */
2232 add_to_cu_func_list (name, lowpc, highpc, cu);
2234 if (objfile->ei.entry_point >= lowpc &&
2235 objfile->ei.entry_point < highpc)
2237 objfile->ei.entry_func_lowpc = lowpc;
2238 objfile->ei.entry_func_highpc = highpc;
2241 new = push_context (0, lowpc);
2242 new->name = new_symbol (die, die->type, cu);
2244 /* If there is a location expression for DW_AT_frame_base, record
2246 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2248 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2249 expression is being recorded directly in the function's symbol
2250 and not in a separate frame-base object. I guess this hack is
2251 to avoid adding some sort of frame-base adjunct/annex to the
2252 function's symbol :-(. The problem with doing this is that it
2253 results in a function symbol with a location expression that
2254 has nothing to do with the location of the function, ouch! The
2255 relationship should be: a function's symbol has-a frame base; a
2256 frame-base has-a location expression. */
2257 dwarf2_symbol_mark_computed (attr, new->name, cu);
2259 cu->list_in_scope = &local_symbols;
2261 if (die->child != NULL)
2263 child_die = die->child;
2264 while (child_die && child_die->tag)
2266 process_die (child_die, cu);
2267 child_die = sibling_die (child_die);
2271 new = pop_context ();
2272 /* Make a block for the local symbols within. */
2273 finish_block (new->name, &local_symbols, new->old_blocks,
2274 lowpc, highpc, objfile);
2276 /* In C++, we can have functions nested inside functions (e.g., when
2277 a function declares a class that has methods). This means that
2278 when we finish processing a function scope, we may need to go
2279 back to building a containing block's symbol lists. */
2280 local_symbols = new->locals;
2281 param_symbols = new->params;
2283 /* If we've finished processing a top-level function, subsequent
2284 symbols go in the file symbol list. */
2285 if (outermost_context_p ())
2286 cu->list_in_scope = &file_symbols;
2288 processing_current_prefix = previous_prefix;
2289 if (back_to != NULL)
2290 do_cleanups (back_to);
2293 /* Process all the DIES contained within a lexical block scope. Start
2294 a new scope, process the dies, and then close the scope. */
2297 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2299 struct objfile *objfile = cu->objfile;
2300 struct context_stack *new;
2301 CORE_ADDR lowpc, highpc;
2302 struct die_info *child_die;
2305 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2307 /* Ignore blocks with missing or invalid low and high pc attributes. */
2308 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2309 as multiple lexical blocks? Handling children in a sane way would
2310 be nasty. Might be easier to properly extend generic blocks to
2312 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2317 push_context (0, lowpc);
2318 if (die->child != NULL)
2320 child_die = die->child;
2321 while (child_die && child_die->tag)
2323 process_die (child_die, cu);
2324 child_die = sibling_die (child_die);
2327 new = pop_context ();
2329 if (local_symbols != NULL)
2331 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2334 local_symbols = new->locals;
2337 /* Get low and high pc attributes from a die. Return 1 if the attributes
2338 are present and valid, otherwise, return 0. Return -1 if the range is
2339 discontinuous, i.e. derived from DW_AT_ranges information. */
2341 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2342 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2344 struct objfile *objfile = cu->objfile;
2345 struct comp_unit_head *cu_header = &cu->header;
2346 struct attribute *attr;
2347 bfd *obfd = objfile->obfd;
2352 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2355 high = DW_ADDR (attr);
2356 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2358 low = DW_ADDR (attr);
2360 /* Found high w/o low attribute. */
2363 /* Found consecutive range of addresses. */
2368 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2371 unsigned int addr_size = cu_header->addr_size;
2372 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2373 /* Value of the DW_AT_ranges attribute is the offset in the
2374 .debug_ranges section. */
2375 unsigned int offset = DW_UNSND (attr);
2376 /* Base address selection entry. */
2384 found_base = cu_header->base_known;
2385 base = cu_header->base_address;
2387 if (offset >= dwarf_ranges_size)
2389 complaint (&symfile_complaints,
2390 "Offset %d out of bounds for DW_AT_ranges attribute",
2394 buffer = dwarf_ranges_buffer + offset;
2396 /* Read in the largest possible address. */
2397 marker = read_address (obfd, buffer, cu, &dummy);
2398 if ((marker & mask) == mask)
2400 /* If we found the largest possible address, then
2401 read the base address. */
2402 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2403 buffer += 2 * addr_size;
2404 offset += 2 * addr_size;
2412 CORE_ADDR range_beginning, range_end;
2414 range_beginning = read_address (obfd, buffer, cu, &dummy);
2415 buffer += addr_size;
2416 range_end = read_address (obfd, buffer, cu, &dummy);
2417 buffer += addr_size;
2418 offset += 2 * addr_size;
2420 /* An end of list marker is a pair of zero addresses. */
2421 if (range_beginning == 0 && range_end == 0)
2422 /* Found the end of list entry. */
2425 /* Each base address selection entry is a pair of 2 values.
2426 The first is the largest possible address, the second is
2427 the base address. Check for a base address here. */
2428 if ((range_beginning & mask) == mask)
2430 /* If we found the largest possible address, then
2431 read the base address. */
2432 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2439 /* We have no valid base address for the ranges
2441 complaint (&symfile_complaints,
2442 "Invalid .debug_ranges data (no base address)");
2446 range_beginning += base;
2449 /* FIXME: This is recording everything as a low-high
2450 segment of consecutive addresses. We should have a
2451 data structure for discontiguous block ranges
2455 low = range_beginning;
2461 if (range_beginning < low)
2462 low = range_beginning;
2463 if (range_end > high)
2469 /* If the first entry is an end-of-list marker, the range
2470 describes an empty scope, i.e. no instructions. */
2480 /* When using the GNU linker, .gnu.linkonce. sections are used to
2481 eliminate duplicate copies of functions and vtables and such.
2482 The linker will arbitrarily choose one and discard the others.
2483 The AT_*_pc values for such functions refer to local labels in
2484 these sections. If the section from that file was discarded, the
2485 labels are not in the output, so the relocs get a value of 0.
2486 If this is a discarded function, mark the pc bounds as invalid,
2487 so that GDB will ignore it. */
2488 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2496 /* Get the low and high pc's represented by the scope DIE, and store
2497 them in *LOWPC and *HIGHPC. If the correct values can't be
2498 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2501 get_scope_pc_bounds (struct die_info *die,
2502 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2503 struct dwarf2_cu *cu)
2505 CORE_ADDR best_low = (CORE_ADDR) -1;
2506 CORE_ADDR best_high = (CORE_ADDR) 0;
2507 CORE_ADDR current_low, current_high;
2509 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
2511 best_low = current_low;
2512 best_high = current_high;
2516 struct die_info *child = die->child;
2518 while (child && child->tag)
2520 switch (child->tag) {
2521 case DW_TAG_subprogram:
2522 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
2524 best_low = min (best_low, current_low);
2525 best_high = max (best_high, current_high);
2528 case DW_TAG_namespace:
2529 /* FIXME: carlton/2004-01-16: Should we do this for
2530 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2531 that current GCC's always emit the DIEs corresponding
2532 to definitions of methods of classes as children of a
2533 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2534 the DIEs giving the declarations, which could be
2535 anywhere). But I don't see any reason why the
2536 standards says that they have to be there. */
2537 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
2539 if (current_low != ((CORE_ADDR) -1))
2541 best_low = min (best_low, current_low);
2542 best_high = max (best_high, current_high);
2550 child = sibling_die (child);
2555 *highpc = best_high;
2558 /* Add an aggregate field to the field list. */
2561 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2562 struct dwarf2_cu *cu)
2564 struct objfile *objfile = cu->objfile;
2565 struct nextfield *new_field;
2566 struct attribute *attr;
2568 char *fieldname = "";
2570 /* Allocate a new field list entry and link it in. */
2571 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2572 make_cleanup (xfree, new_field);
2573 memset (new_field, 0, sizeof (struct nextfield));
2574 new_field->next = fip->fields;
2575 fip->fields = new_field;
2578 /* Handle accessibility and virtuality of field.
2579 The default accessibility for members is public, the default
2580 accessibility for inheritance is private. */
2581 if (die->tag != DW_TAG_inheritance)
2582 new_field->accessibility = DW_ACCESS_public;
2584 new_field->accessibility = DW_ACCESS_private;
2585 new_field->virtuality = DW_VIRTUALITY_none;
2587 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2589 new_field->accessibility = DW_UNSND (attr);
2590 if (new_field->accessibility != DW_ACCESS_public)
2591 fip->non_public_fields = 1;
2592 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
2594 new_field->virtuality = DW_UNSND (attr);
2596 fp = &new_field->field;
2598 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
2600 /* Data member other than a C++ static data member. */
2602 /* Get type of field. */
2603 fp->type = die_type (die, cu);
2605 FIELD_STATIC_KIND (*fp) = 0;
2607 /* Get bit size of field (zero if none). */
2608 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
2611 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2615 FIELD_BITSIZE (*fp) = 0;
2618 /* Get bit offset of field. */
2619 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2622 FIELD_BITPOS (*fp) =
2623 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2626 FIELD_BITPOS (*fp) = 0;
2627 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
2630 if (BITS_BIG_ENDIAN)
2632 /* For big endian bits, the DW_AT_bit_offset gives the
2633 additional bit offset from the MSB of the containing
2634 anonymous object to the MSB of the field. We don't
2635 have to do anything special since we don't need to
2636 know the size of the anonymous object. */
2637 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2641 /* For little endian bits, compute the bit offset to the
2642 MSB of the anonymous object, subtract off the number of
2643 bits from the MSB of the field to the MSB of the
2644 object, and then subtract off the number of bits of
2645 the field itself. The result is the bit offset of
2646 the LSB of the field. */
2648 int bit_offset = DW_UNSND (attr);
2650 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2653 /* The size of the anonymous object containing
2654 the bit field is explicit, so use the
2655 indicated size (in bytes). */
2656 anonymous_size = DW_UNSND (attr);
2660 /* The size of the anonymous object containing
2661 the bit field must be inferred from the type
2662 attribute of the data member containing the
2664 anonymous_size = TYPE_LENGTH (fp->type);
2666 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2667 - bit_offset - FIELD_BITSIZE (*fp);
2671 /* Get name of field. */
2672 attr = dwarf2_attr (die, DW_AT_name, cu);
2673 if (attr && DW_STRING (attr))
2674 fieldname = DW_STRING (attr);
2675 fp->name = obsavestring (fieldname, strlen (fieldname),
2676 &objfile->objfile_obstack);
2678 /* Change accessibility for artificial fields (e.g. virtual table
2679 pointer or virtual base class pointer) to private. */
2680 if (dwarf2_attr (die, DW_AT_artificial, cu))
2682 new_field->accessibility = DW_ACCESS_private;
2683 fip->non_public_fields = 1;
2686 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2688 /* C++ static member. */
2690 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2691 is a declaration, but all versions of G++ as of this writing
2692 (so through at least 3.2.1) incorrectly generate
2693 DW_TAG_variable tags. */
2697 /* Get name of field. */
2698 attr = dwarf2_attr (die, DW_AT_name, cu);
2699 if (attr && DW_STRING (attr))
2700 fieldname = DW_STRING (attr);
2704 /* Get physical name. */
2705 physname = dwarf2_linkage_name (die, cu);
2707 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
2708 &objfile->objfile_obstack));
2709 FIELD_TYPE (*fp) = die_type (die, cu);
2710 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
2711 &objfile->objfile_obstack);
2713 else if (die->tag == DW_TAG_inheritance)
2715 /* C++ base class field. */
2716 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2718 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
2720 FIELD_BITSIZE (*fp) = 0;
2721 FIELD_STATIC_KIND (*fp) = 0;
2722 FIELD_TYPE (*fp) = die_type (die, cu);
2723 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
2724 fip->nbaseclasses++;
2728 /* Create the vector of fields, and attach it to the type. */
2731 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
2732 struct dwarf2_cu *cu)
2734 int nfields = fip->nfields;
2736 /* Record the field count, allocate space for the array of fields,
2737 and create blank accessibility bitfields if necessary. */
2738 TYPE_NFIELDS (type) = nfields;
2739 TYPE_FIELDS (type) = (struct field *)
2740 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2741 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2743 if (fip->non_public_fields)
2745 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2747 TYPE_FIELD_PRIVATE_BITS (type) =
2748 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2749 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2751 TYPE_FIELD_PROTECTED_BITS (type) =
2752 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2753 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2755 TYPE_FIELD_IGNORE_BITS (type) =
2756 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2757 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2760 /* If the type has baseclasses, allocate and clear a bit vector for
2761 TYPE_FIELD_VIRTUAL_BITS. */
2762 if (fip->nbaseclasses)
2764 int num_bytes = B_BYTES (fip->nbaseclasses);
2767 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2768 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2769 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2770 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
2771 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
2774 /* Copy the saved-up fields into the field vector. Start from the head
2775 of the list, adding to the tail of the field array, so that they end
2776 up in the same order in the array in which they were added to the list. */
2777 while (nfields-- > 0)
2779 TYPE_FIELD (type, nfields) = fip->fields->field;
2780 switch (fip->fields->accessibility)
2782 case DW_ACCESS_private:
2783 SET_TYPE_FIELD_PRIVATE (type, nfields);
2786 case DW_ACCESS_protected:
2787 SET_TYPE_FIELD_PROTECTED (type, nfields);
2790 case DW_ACCESS_public:
2794 /* Unknown accessibility. Complain and treat it as public. */
2796 complaint (&symfile_complaints, "unsupported accessibility %d",
2797 fip->fields->accessibility);
2801 if (nfields < fip->nbaseclasses)
2803 switch (fip->fields->virtuality)
2805 case DW_VIRTUALITY_virtual:
2806 case DW_VIRTUALITY_pure_virtual:
2807 SET_TYPE_FIELD_VIRTUAL (type, nfields);
2811 fip->fields = fip->fields->next;
2815 /* Add a member function to the proper fieldlist. */
2818 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
2819 struct type *type, struct dwarf2_cu *cu)
2821 struct objfile *objfile = cu->objfile;
2822 struct attribute *attr;
2823 struct fnfieldlist *flp;
2825 struct fn_field *fnp;
2828 struct nextfnfield *new_fnfield;
2830 /* Get name of member function. */
2831 attr = dwarf2_attr (die, DW_AT_name, cu);
2832 if (attr && DW_STRING (attr))
2833 fieldname = DW_STRING (attr);
2837 /* Get the mangled name. */
2838 physname = dwarf2_linkage_name (die, cu);
2840 /* Look up member function name in fieldlist. */
2841 for (i = 0; i < fip->nfnfields; i++)
2843 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
2847 /* Create new list element if necessary. */
2848 if (i < fip->nfnfields)
2849 flp = &fip->fnfieldlists[i];
2852 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2854 fip->fnfieldlists = (struct fnfieldlist *)
2855 xrealloc (fip->fnfieldlists,
2856 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2857 * sizeof (struct fnfieldlist));
2858 if (fip->nfnfields == 0)
2859 make_cleanup (free_current_contents, &fip->fnfieldlists);
2861 flp = &fip->fnfieldlists[fip->nfnfields];
2862 flp->name = fieldname;
2868 /* Create a new member function field and chain it to the field list
2870 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2871 make_cleanup (xfree, new_fnfield);
2872 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2873 new_fnfield->next = flp->head;
2874 flp->head = new_fnfield;
2877 /* Fill in the member function field info. */
2878 fnp = &new_fnfield->fnfield;
2879 fnp->physname = obsavestring (physname, strlen (physname),
2880 &objfile->objfile_obstack);
2881 fnp->type = alloc_type (objfile);
2882 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2884 int nparams = TYPE_NFIELDS (die->type);
2886 /* TYPE is the domain of this method, and DIE->TYPE is the type
2887 of the method itself (TYPE_CODE_METHOD). */
2888 smash_to_method_type (fnp->type, type,
2889 TYPE_TARGET_TYPE (die->type),
2890 TYPE_FIELDS (die->type),
2891 TYPE_NFIELDS (die->type),
2892 TYPE_VARARGS (die->type));
2894 /* Handle static member functions.
2895 Dwarf2 has no clean way to discern C++ static and non-static
2896 member functions. G++ helps GDB by marking the first
2897 parameter for non-static member functions (which is the
2898 this pointer) as artificial. We obtain this information
2899 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2900 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2901 fnp->voffset = VOFFSET_STATIC;
2904 complaint (&symfile_complaints, "member function type missing for '%s'",
2907 /* Get fcontext from DW_AT_containing_type if present. */
2908 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
2909 fnp->fcontext = die_containing_type (die, cu);
2911 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2912 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2914 /* Get accessibility. */
2915 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2918 switch (DW_UNSND (attr))
2920 case DW_ACCESS_private:
2921 fnp->is_private = 1;
2923 case DW_ACCESS_protected:
2924 fnp->is_protected = 1;
2929 /* Check for artificial methods. */
2930 attr = dwarf2_attr (die, DW_AT_artificial, cu);
2931 if (attr && DW_UNSND (attr) != 0)
2932 fnp->is_artificial = 1;
2934 /* Get index in virtual function table if it is a virtual member function. */
2935 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
2938 /* Support the .debug_loc offsets */
2939 if (attr_form_is_block (attr))
2941 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
2943 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
2945 dwarf2_complex_location_expr_complaint ();
2949 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2955 /* Create the vector of member function fields, and attach it to the type. */
2958 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
2959 struct dwarf2_cu *cu)
2961 struct fnfieldlist *flp;
2962 int total_length = 0;
2965 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2966 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2967 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2969 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2971 struct nextfnfield *nfp = flp->head;
2972 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2975 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2976 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2977 fn_flp->fn_fields = (struct fn_field *)
2978 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2979 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2980 fn_flp->fn_fields[k] = nfp->fnfield;
2982 total_length += flp->length;
2985 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2986 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2989 /* Called when we find the DIE that starts a structure or union scope
2990 (definition) to process all dies that define the members of the
2993 NOTE: we need to call struct_type regardless of whether or not the
2994 DIE has an at_name attribute, since it might be an anonymous
2995 structure or union. This gets the type entered into our set of
2998 However, if the structure is incomplete (an opaque struct/union)
2999 then suppress creating a symbol table entry for it since gdb only
3000 wants to find the one with the complete definition. Note that if
3001 it is complete, we just call new_symbol, which does it's own
3002 checking about whether the struct/union is anonymous or not (and
3003 suppresses creating a symbol table entry itself). */
3006 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3008 struct objfile *objfile = cu->objfile;
3010 struct attribute *attr;
3011 const char *previous_prefix = processing_current_prefix;
3012 struct cleanup *back_to = NULL;
3017 type = alloc_type (objfile);
3019 INIT_CPLUS_SPECIFIC (type);
3020 attr = dwarf2_attr (die, DW_AT_name, cu);
3021 if (attr && DW_STRING (attr))
3023 if (cu->language == language_cplus)
3025 char *new_prefix = determine_class_name (die, cu);
3026 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3027 strlen (new_prefix),
3028 &objfile->objfile_obstack);
3029 back_to = make_cleanup (xfree, new_prefix);
3030 processing_current_prefix = new_prefix;
3034 TYPE_TAG_NAME (type) = DW_STRING (attr);
3038 if (die->tag == DW_TAG_structure_type)
3040 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3042 else if (die->tag == DW_TAG_union_type)
3044 TYPE_CODE (type) = TYPE_CODE_UNION;
3048 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3050 TYPE_CODE (type) = TYPE_CODE_CLASS;
3053 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3056 TYPE_LENGTH (type) = DW_UNSND (attr);
3060 TYPE_LENGTH (type) = 0;
3063 /* We need to add the type field to the die immediately so we don't
3064 infinitely recurse when dealing with pointers to the structure
3065 type within the structure itself. */
3068 if (die->child != NULL && ! die_is_declaration (die, cu))
3070 struct field_info fi;
3071 struct die_info *child_die;
3072 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3074 memset (&fi, 0, sizeof (struct field_info));
3076 child_die = die->child;
3078 while (child_die && child_die->tag)
3080 if (child_die->tag == DW_TAG_member
3081 || child_die->tag == DW_TAG_variable)
3083 /* NOTE: carlton/2002-11-05: A C++ static data member
3084 should be a DW_TAG_member that is a declaration, but
3085 all versions of G++ as of this writing (so through at
3086 least 3.2.1) incorrectly generate DW_TAG_variable
3087 tags for them instead. */
3088 dwarf2_add_field (&fi, child_die, cu);
3090 else if (child_die->tag == DW_TAG_subprogram)
3092 /* C++ member function. */
3093 read_type_die (child_die, cu);
3094 dwarf2_add_member_fn (&fi, child_die, type, cu);
3096 else if (child_die->tag == DW_TAG_inheritance)
3098 /* C++ base class field. */
3099 dwarf2_add_field (&fi, child_die, cu);
3101 child_die = sibling_die (child_die);
3104 /* Attach fields and member functions to the type. */
3106 dwarf2_attach_fields_to_type (&fi, type, cu);
3109 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3111 /* Get the type which refers to the base class (possibly this
3112 class itself) which contains the vtable pointer for the current
3113 class from the DW_AT_containing_type attribute. */
3115 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3117 struct type *t = die_containing_type (die, cu);
3119 TYPE_VPTR_BASETYPE (type) = t;
3122 static const char vptr_name[] =
3123 {'_', 'v', 'p', 't', 'r', '\0'};
3126 /* Our own class provides vtbl ptr. */
3127 for (i = TYPE_NFIELDS (t) - 1;
3128 i >= TYPE_N_BASECLASSES (t);
3131 char *fieldname = TYPE_FIELD_NAME (t, i);
3133 if ((strncmp (fieldname, vptr_name,
3134 strlen (vptr_name) - 1)
3136 && is_cplus_marker (fieldname[strlen (vptr_name)]))
3138 TYPE_VPTR_FIELDNO (type) = i;
3143 /* Complain if virtual function table field not found. */
3144 if (i < TYPE_N_BASECLASSES (t))
3145 complaint (&symfile_complaints,
3146 "virtual function table pointer not found when defining class '%s'",
3147 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3152 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3157 do_cleanups (back_to);
3161 /* No children, must be stub. */
3162 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3165 processing_current_prefix = previous_prefix;
3166 if (back_to != NULL)
3167 do_cleanups (back_to);
3171 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3173 struct objfile *objfile = cu->objfile;
3174 const char *previous_prefix = processing_current_prefix;
3175 struct die_info *child_die = die->child;
3177 if (TYPE_TAG_NAME (die->type) != NULL)
3178 processing_current_prefix = TYPE_TAG_NAME (die->type);
3180 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3181 snapshots) has been known to create a die giving a declaration
3182 for a class that has, as a child, a die giving a definition for a
3183 nested class. So we have to process our children even if the
3184 current die is a declaration. Normally, of course, a declaration
3185 won't have any children at all. */
3187 while (child_die != NULL && child_die->tag)
3189 if (child_die->tag == DW_TAG_member
3190 || child_die->tag == DW_TAG_variable
3191 || child_die->tag == DW_TAG_inheritance)
3196 process_die (child_die, cu);
3198 child_die = sibling_die (child_die);
3201 if (die->child != NULL && ! die_is_declaration (die, cu))
3202 new_symbol (die, die->type, cu);
3204 processing_current_prefix = previous_prefix;
3207 /* Given a DW_AT_enumeration_type die, set its type. We do not
3208 complete the type's fields yet, or create any symbols. */
3211 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3213 struct objfile *objfile = cu->objfile;
3215 struct attribute *attr;
3220 type = alloc_type (objfile);
3222 TYPE_CODE (type) = TYPE_CODE_ENUM;
3223 attr = dwarf2_attr (die, DW_AT_name, cu);
3224 if (attr && DW_STRING (attr))
3226 const char *name = DW_STRING (attr);
3228 if (processing_has_namespace_info)
3230 TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack,
3231 processing_current_prefix,
3232 processing_current_prefix[0] == '\0'
3238 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
3239 &objfile->objfile_obstack);
3243 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3246 TYPE_LENGTH (type) = DW_UNSND (attr);
3250 TYPE_LENGTH (type) = 0;
3256 /* Determine the name of the type represented by DIE, which should be
3257 a named C++ compound type. Return the name in question; the caller
3258 is responsible for xfree()'ing it. */
3261 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3263 struct cleanup *back_to = NULL;
3264 struct die_info *spec_die = die_specification (die, cu);
3265 char *new_prefix = NULL;
3267 /* If this is the definition of a class that is declared by another
3268 die, then processing_current_prefix may not be accurate; see
3269 read_func_scope for a similar example. */
3270 if (spec_die != NULL)
3272 char *specification_prefix = determine_prefix (spec_die, cu);
3273 processing_current_prefix = specification_prefix;
3274 back_to = make_cleanup (xfree, specification_prefix);
3277 /* If we don't have namespace debug info, guess the name by trying
3278 to demangle the names of members, just like we did in
3279 add_partial_structure. */
3280 if (!processing_has_namespace_info)
3282 struct die_info *child;
3284 for (child = die->child;
3285 child != NULL && child->tag != 0;
3286 child = sibling_die (child))
3288 if (child->tag == DW_TAG_subprogram)
3290 new_prefix = class_name_from_physname (dwarf2_linkage_name
3293 if (new_prefix != NULL)
3299 if (new_prefix == NULL)
3301 const char *name = dwarf2_name (die, cu);
3302 new_prefix = typename_concat (processing_current_prefix,
3303 name ? name : "<<anonymous>>");
3306 if (back_to != NULL)
3307 do_cleanups (back_to);
3312 /* Given a pointer to a die which begins an enumeration, process all
3313 the dies that define the members of the enumeration, and create the
3314 symbol for the enumeration type.
3316 NOTE: We reverse the order of the element list. */
3319 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3321 struct objfile *objfile = cu->objfile;
3322 struct die_info *child_die;
3323 struct field *fields;
3324 struct attribute *attr;
3327 int unsigned_enum = 1;
3331 if (die->child != NULL)
3333 child_die = die->child;
3334 while (child_die && child_die->tag)
3336 if (child_die->tag != DW_TAG_enumerator)
3338 process_die (child_die, cu);
3342 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3345 sym = new_symbol (child_die, die->type, cu);
3346 if (SYMBOL_VALUE (sym) < 0)
3349 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3351 fields = (struct field *)
3353 (num_fields + DW_FIELD_ALLOC_CHUNK)
3354 * sizeof (struct field));
3357 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3358 FIELD_TYPE (fields[num_fields]) = NULL;
3359 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3360 FIELD_BITSIZE (fields[num_fields]) = 0;
3361 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3367 child_die = sibling_die (child_die);
3372 TYPE_NFIELDS (die->type) = num_fields;
3373 TYPE_FIELDS (die->type) = (struct field *)
3374 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
3375 memcpy (TYPE_FIELDS (die->type), fields,
3376 sizeof (struct field) * num_fields);
3380 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
3383 new_symbol (die, die->type, cu);
3386 /* Extract all information from a DW_TAG_array_type DIE and put it in
3387 the DIE's type field. For now, this only handles one dimensional
3391 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3393 struct objfile *objfile = cu->objfile;
3394 struct die_info *child_die;
3395 struct type *type = NULL;
3396 struct type *element_type, *range_type, *index_type;
3397 struct type **range_types = NULL;
3398 struct attribute *attr;
3400 struct cleanup *back_to;
3402 /* Return if we've already decoded this type. */
3408 element_type = die_type (die, cu);
3410 /* Irix 6.2 native cc creates array types without children for
3411 arrays with unspecified length. */
3412 if (die->child == NULL)
3414 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3415 range_type = create_range_type (NULL, index_type, 0, -1);
3416 die->type = create_array_type (NULL, element_type, range_type);
3420 back_to = make_cleanup (null_cleanup, NULL);
3421 child_die = die->child;
3422 while (child_die && child_die->tag)
3424 if (child_die->tag == DW_TAG_subrange_type)
3426 read_subrange_type (child_die, cu);
3428 if (child_die->type != NULL)
3430 /* The range type was succesfully read. Save it for
3431 the array type creation. */
3432 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3434 range_types = (struct type **)
3435 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3436 * sizeof (struct type *));
3438 make_cleanup (free_current_contents, &range_types);
3440 range_types[ndim++] = child_die->type;
3443 child_die = sibling_die (child_die);
3446 /* Dwarf2 dimensions are output from left to right, create the
3447 necessary array types in backwards order. */
3448 type = element_type;
3450 type = create_array_type (NULL, type, range_types[ndim]);
3452 /* Understand Dwarf2 support for vector types (like they occur on
3453 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3454 array type. This is not part of the Dwarf2/3 standard yet, but a
3455 custom vendor extension. The main difference between a regular
3456 array and the vector variant is that vectors are passed by value
3458 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
3460 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3462 do_cleanups (back_to);
3464 /* Install the type in the die. */
3468 /* First cut: install each common block member as a global variable. */
3471 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3473 struct die_info *child_die;
3474 struct attribute *attr;
3476 CORE_ADDR base = (CORE_ADDR) 0;
3478 attr = dwarf2_attr (die, DW_AT_location, cu);
3481 /* Support the .debug_loc offsets */
3482 if (attr_form_is_block (attr))
3484 base = decode_locdesc (DW_BLOCK (attr), cu);
3486 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3488 dwarf2_complex_location_expr_complaint ();
3492 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3493 "common block member");
3496 if (die->child != NULL)
3498 child_die = die->child;
3499 while (child_die && child_die->tag)
3501 sym = new_symbol (child_die, NULL, cu);
3502 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
3505 SYMBOL_VALUE_ADDRESS (sym) =
3506 base + decode_locdesc (DW_BLOCK (attr), cu);
3507 add_symbol_to_list (sym, &global_symbols);
3509 child_die = sibling_die (child_die);
3514 /* Read a C++ namespace. */
3517 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3519 struct objfile *objfile = cu->objfile;
3520 const char *previous_prefix = processing_current_prefix;
3523 struct die_info *current_die;
3525 name = namespace_name (die, &is_anonymous, cu);
3527 /* Now build the name of the current namespace. */
3529 if (previous_prefix[0] == '\0')
3531 processing_current_prefix = name;
3535 /* We need temp_name around because processing_current_prefix
3536 is a const char *. */
3537 char *temp_name = alloca (strlen (previous_prefix)
3538 + 2 + strlen(name) + 1);
3539 strcpy (temp_name, previous_prefix);
3540 strcat (temp_name, "::");
3541 strcat (temp_name, name);
3543 processing_current_prefix = temp_name;
3546 /* Add a symbol associated to this if we haven't seen the namespace
3547 before. Also, add a using directive if it's an anonymous
3550 if (dwarf2_extension (die, cu) == NULL)
3554 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3555 this cast will hopefully become unnecessary. */
3556 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3557 (char *) processing_current_prefix,
3559 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3561 new_symbol (die, type, cu);
3565 cp_add_using_directive (processing_current_prefix,
3566 strlen (previous_prefix),
3567 strlen (processing_current_prefix));
3570 if (die->child != NULL)
3572 struct die_info *child_die = die->child;
3574 while (child_die && child_die->tag)
3576 process_die (child_die, cu);
3577 child_die = sibling_die (child_die);
3581 processing_current_prefix = previous_prefix;
3584 /* Return the name of the namespace represented by DIE. Set
3585 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3589 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
3591 struct die_info *current_die;
3592 const char *name = NULL;
3594 /* Loop through the extensions until we find a name. */
3596 for (current_die = die;
3597 current_die != NULL;
3598 current_die = dwarf2_extension (die, cu))
3600 name = dwarf2_name (current_die, cu);
3605 /* Is it an anonymous namespace? */
3607 *is_anonymous = (name == NULL);
3609 name = "(anonymous namespace)";
3614 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3615 the user defined type vector. */
3618 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3620 struct comp_unit_head *cu_header = &cu->header;
3622 struct attribute *attr_byte_size;
3623 struct attribute *attr_address_class;
3624 int byte_size, addr_class;
3631 type = lookup_pointer_type (die_type (die, cu));
3633 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
3635 byte_size = DW_UNSND (attr_byte_size);
3637 byte_size = cu_header->addr_size;
3639 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
3640 if (attr_address_class)
3641 addr_class = DW_UNSND (attr_address_class);
3643 addr_class = DW_ADDR_none;
3645 /* If the pointer size or address class is different than the
3646 default, create a type variant marked as such and set the
3647 length accordingly. */
3648 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3650 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3654 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
3655 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
3656 type = make_type_with_address_space (type, type_flags);
3658 else if (TYPE_LENGTH (type) != byte_size)
3660 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
3663 /* Should we also complain about unhandled address classes? */
3667 TYPE_LENGTH (type) = byte_size;
3671 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3672 the user defined type vector. */
3675 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
3677 struct objfile *objfile = cu->objfile;
3679 struct type *to_type;
3680 struct type *domain;
3687 type = alloc_type (objfile);
3688 to_type = die_type (die, cu);
3689 domain = die_containing_type (die, cu);
3690 smash_to_member_type (type, domain, to_type);
3695 /* Extract all information from a DW_TAG_reference_type DIE and add to
3696 the user defined type vector. */
3699 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
3701 struct comp_unit_head *cu_header = &cu->header;
3703 struct attribute *attr;
3710 type = lookup_reference_type (die_type (die, cu));
3711 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3714 TYPE_LENGTH (type) = DW_UNSND (attr);
3718 TYPE_LENGTH (type) = cu_header->addr_size;
3724 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
3726 struct type *base_type;
3733 base_type = die_type (die, cu);
3734 die->type = make_cvr_type (1, TYPE_VOLATILE (base_type),
3735 TYPE_RESTRICT (base_type), base_type, 0);
3739 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
3741 struct type *base_type;
3748 base_type = die_type (die, cu);
3749 die->type = make_cvr_type (TYPE_CONST (base_type), 1,
3750 TYPE_RESTRICT (base_type), base_type, 0);
3754 read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu)
3756 struct type *base_type;
3763 base_type = die_type (die, cu);
3764 die->type = make_cvr_type (TYPE_CONST (base_type), TYPE_VOLATILE (base_type),
3768 /* Extract all information from a DW_TAG_string_type DIE and add to
3769 the user defined type vector. It isn't really a user defined type,
3770 but it behaves like one, with other DIE's using an AT_user_def_type
3771 attribute to reference it. */
3774 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3776 struct objfile *objfile = cu->objfile;
3777 struct type *type, *range_type, *index_type, *char_type;
3778 struct attribute *attr;
3779 unsigned int length;
3786 attr = dwarf2_attr (die, DW_AT_string_length, cu);
3789 length = DW_UNSND (attr);
3793 /* check for the DW_AT_byte_size attribute */
3794 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3797 length = DW_UNSND (attr);
3804 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3805 range_type = create_range_type (NULL, index_type, 1, length);
3806 if (cu->language == language_fortran)
3808 /* Need to create a unique string type for bounds
3810 type = create_string_type (0, range_type);
3814 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
3815 type = create_string_type (char_type, range_type);
3820 /* Handle DIES due to C code like:
3824 int (*funcp)(int a, long l);
3828 ('funcp' generates a DW_TAG_subroutine_type DIE)
3832 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
3834 struct type *type; /* Type that this function returns */
3835 struct type *ftype; /* Function that returns above type */
3836 struct attribute *attr;
3838 /* Decode the type that this subroutine returns */
3843 type = die_type (die, cu);
3844 ftype = lookup_function_type (type);
3846 /* All functions in C++ have prototypes. */
3847 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
3848 if ((attr && (DW_UNSND (attr) != 0))
3849 || cu->language == language_cplus)
3850 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
3852 if (die->child != NULL)
3854 struct die_info *child_die;
3858 /* Count the number of parameters.
3859 FIXME: GDB currently ignores vararg functions, but knows about
3860 vararg member functions. */
3861 child_die = die->child;
3862 while (child_die && child_die->tag)
3864 if (child_die->tag == DW_TAG_formal_parameter)
3866 else if (child_die->tag == DW_TAG_unspecified_parameters)
3867 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
3868 child_die = sibling_die (child_die);
3871 /* Allocate storage for parameters and fill them in. */
3872 TYPE_NFIELDS (ftype) = nparams;
3873 TYPE_FIELDS (ftype) = (struct field *)
3874 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
3876 child_die = die->child;
3877 while (child_die && child_die->tag)
3879 if (child_die->tag == DW_TAG_formal_parameter)
3881 /* Dwarf2 has no clean way to discern C++ static and non-static
3882 member functions. G++ helps GDB by marking the first
3883 parameter for non-static member functions (which is the
3884 this pointer) as artificial. We pass this information
3885 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3886 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
3888 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
3890 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
3891 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
3894 child_die = sibling_die (child_die);
3902 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
3904 struct objfile *objfile = cu->objfile;
3905 struct attribute *attr;
3910 attr = dwarf2_attr (die, DW_AT_name, cu);
3911 if (attr && DW_STRING (attr))
3913 name = DW_STRING (attr);
3915 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
3916 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
3920 /* Find a representation of a given base type and install
3921 it in the TYPE field of the die. */
3924 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
3926 struct objfile *objfile = cu->objfile;
3928 struct attribute *attr;
3929 int encoding = 0, size = 0;
3931 /* If we've already decoded this die, this is a no-op. */
3937 attr = dwarf2_attr (die, DW_AT_encoding, cu);
3940 encoding = DW_UNSND (attr);
3942 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3945 size = DW_UNSND (attr);
3947 attr = dwarf2_attr (die, DW_AT_name, cu);
3948 if (attr && DW_STRING (attr))
3950 enum type_code code = TYPE_CODE_INT;
3955 case DW_ATE_address:
3956 /* Turn DW_ATE_address into a void * pointer. */
3957 code = TYPE_CODE_PTR;
3958 type_flags |= TYPE_FLAG_UNSIGNED;
3960 case DW_ATE_boolean:
3961 code = TYPE_CODE_BOOL;
3962 type_flags |= TYPE_FLAG_UNSIGNED;
3964 case DW_ATE_complex_float:
3965 code = TYPE_CODE_COMPLEX;
3968 code = TYPE_CODE_FLT;
3971 case DW_ATE_signed_char:
3973 case DW_ATE_unsigned:
3974 case DW_ATE_unsigned_char:
3975 type_flags |= TYPE_FLAG_UNSIGNED;
3978 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
3979 dwarf_type_encoding_name (encoding));
3982 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
3983 if (encoding == DW_ATE_address)
3984 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
3986 else if (encoding == DW_ATE_complex_float)
3989 TYPE_TARGET_TYPE (type)
3990 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
3991 else if (size == 16)
3992 TYPE_TARGET_TYPE (type)
3993 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
3995 TYPE_TARGET_TYPE (type)
3996 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4001 type = dwarf_base_type (encoding, size, cu);
4006 /* Read the given DW_AT_subrange DIE. */
4009 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4011 struct type *base_type;
4012 struct type *range_type;
4013 struct attribute *attr;
4017 /* If we have already decoded this die, then nothing more to do. */
4021 base_type = die_type (die, cu);
4022 if (base_type == NULL)
4024 complaint (&symfile_complaints,
4025 "DW_AT_type missing from DW_TAG_subrange_type");
4029 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4030 base_type = alloc_type (NULL);
4032 if (cu->language == language_fortran)
4034 /* FORTRAN implies a lower bound of 1, if not given. */
4038 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4040 low = dwarf2_get_attr_constant_value (attr, 0);
4042 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4045 if (attr->form == DW_FORM_block1)
4047 /* GCC encodes arrays with unspecified or dynamic length
4048 with a DW_FORM_block1 attribute.
4049 FIXME: GDB does not yet know how to handle dynamic
4050 arrays properly, treat them as arrays with unspecified
4053 FIXME: jimb/2003-09-22: GDB does not really know
4054 how to handle arrays of unspecified length
4055 either; we just represent them as zero-length
4056 arrays. Choose an appropriate upper bound given
4057 the lower bound we've computed above. */
4061 high = dwarf2_get_attr_constant_value (attr, 1);
4064 range_type = create_range_type (NULL, base_type, low, high);
4066 attr = dwarf2_attr (die, DW_AT_name, cu);
4067 if (attr && DW_STRING (attr))
4068 TYPE_NAME (range_type) = DW_STRING (attr);
4070 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4072 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4074 die->type = range_type;
4078 /* Read a whole compilation unit into a linked list of dies. */
4080 static struct die_info *
4081 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4083 /* Reset die reference table; we are
4084 building new ones now. */
4085 dwarf2_empty_hash_tables ();
4087 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4090 /* Read a single die and all its descendents. Set the die's sibling
4091 field to NULL; set other fields in the die correctly, and set all
4092 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4093 location of the info_ptr after reading all of those dies. PARENT
4094 is the parent of the die in question. */
4096 static struct die_info *
4097 read_die_and_children (char *info_ptr, bfd *abfd,
4098 struct dwarf2_cu *cu,
4099 char **new_info_ptr,
4100 struct die_info *parent)
4102 struct die_info *die;
4106 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4107 store_in_ref_table (die->offset, die);
4111 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4117 *new_info_ptr = cur_ptr;
4120 die->sibling = NULL;
4121 die->parent = parent;
4125 /* Read a die, all of its descendents, and all of its siblings; set
4126 all of the fields of all of the dies correctly. Arguments are as
4127 in read_die_and_children. */
4129 static struct die_info *
4130 read_die_and_siblings (char *info_ptr, bfd *abfd,
4131 struct dwarf2_cu *cu,
4132 char **new_info_ptr,
4133 struct die_info *parent)
4135 struct die_info *first_die, *last_sibling;
4139 first_die = last_sibling = NULL;
4143 struct die_info *die
4144 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4152 last_sibling->sibling = die;
4157 *new_info_ptr = cur_ptr;
4167 /* Free a linked list of dies. */
4170 free_die_list (struct die_info *dies)
4172 struct die_info *die, *next;
4177 if (die->child != NULL)
4178 free_die_list (die->child);
4179 next = die->sibling;
4187 do_free_die_list_cleanup (void *dies)
4189 free_die_list (dies);
4192 static struct cleanup *
4193 make_cleanup_free_die_list (struct die_info *dies)
4195 return make_cleanup (do_free_die_list_cleanup, dies);
4199 /* Read the contents of the section at OFFSET and of size SIZE from the
4200 object file specified by OBJFILE into the objfile_obstack and return it. */
4203 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4205 bfd *abfd = objfile->obfd;
4207 bfd_size_type size = bfd_get_section_size (sectp);
4212 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4214 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4218 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4219 || bfd_bread (buf, size, abfd) != size)
4220 error ("Dwarf Error: Can't read DWARF data from '%s'",
4221 bfd_get_filename (abfd));
4226 /* In DWARF version 2, the description of the debugging information is
4227 stored in a separate .debug_abbrev section. Before we read any
4228 dies from a section we read in all abbreviations and install them
4232 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4234 struct comp_unit_head *cu_header = &cu->header;
4236 struct abbrev_info *cur_abbrev;
4237 unsigned int abbrev_number, bytes_read, abbrev_name;
4238 unsigned int abbrev_form, hash_number;
4240 /* Initialize dwarf2 abbrevs */
4241 memset (cu_header->dwarf2_abbrevs, 0,
4242 ABBREV_HASH_SIZE*sizeof (struct abbrev_info *));
4244 abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset;
4245 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4246 abbrev_ptr += bytes_read;
4248 /* loop until we reach an abbrev number of 0 */
4249 while (abbrev_number)
4251 cur_abbrev = dwarf_alloc_abbrev ();
4253 /* read in abbrev header */
4254 cur_abbrev->number = abbrev_number;
4255 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4256 abbrev_ptr += bytes_read;
4257 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4260 /* now read in declarations */
4261 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4262 abbrev_ptr += bytes_read;
4263 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4264 abbrev_ptr += bytes_read;
4267 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
4269 cur_abbrev->attrs = (struct attr_abbrev *)
4270 xrealloc (cur_abbrev->attrs,
4271 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
4272 * sizeof (struct attr_abbrev));
4274 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
4275 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4276 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4277 abbrev_ptr += bytes_read;
4278 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4279 abbrev_ptr += bytes_read;
4282 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4283 cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number];
4284 cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev;
4286 /* Get next abbreviation.
4287 Under Irix6 the abbreviations for a compilation unit are not
4288 always properly terminated with an abbrev number of 0.
4289 Exit loop if we encounter an abbreviation which we have
4290 already read (which means we are about to read the abbreviations
4291 for the next compile unit) or if the end of the abbreviation
4292 table is reached. */
4293 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
4294 >= dwarf_abbrev_size)
4296 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4297 abbrev_ptr += bytes_read;
4298 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4303 /* Empty the abbrev table for a new compilation unit. */
4306 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table)
4309 struct abbrev_info *abbrev, *next;
4310 struct abbrev_info **abbrevs;
4312 abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table;
4314 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
4317 abbrev = abbrevs[i];
4320 next = abbrev->next;
4321 xfree (abbrev->attrs);
4329 /* Lookup an abbrev_info structure in the abbrev hash table. */
4331 static struct abbrev_info *
4332 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4334 struct comp_unit_head *cu_header = &cu->header;
4335 unsigned int hash_number;
4336 struct abbrev_info *abbrev;
4338 hash_number = number % ABBREV_HASH_SIZE;
4339 abbrev = cu_header->dwarf2_abbrevs[hash_number];
4343 if (abbrev->number == number)
4346 abbrev = abbrev->next;
4351 /* Read a minimal amount of information into the minimal die structure. */
4354 read_partial_die (struct partial_die_info *part_die, bfd *abfd,
4355 char *info_ptr, struct dwarf2_cu *cu)
4357 unsigned int abbrev_number, bytes_read, i;
4358 struct abbrev_info *abbrev;
4359 struct attribute attr;
4360 struct attribute spec_attr;
4361 int found_spec_attr = 0;
4362 int has_low_pc_attr = 0;
4363 int has_high_pc_attr = 0;
4365 *part_die = zeroed_partial_die;
4366 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4367 info_ptr += bytes_read;
4371 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4374 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
4375 bfd_get_filename (abfd));
4377 part_die->offset = info_ptr - dwarf_info_buffer;
4378 part_die->tag = abbrev->tag;
4379 part_die->has_children = abbrev->has_children;
4380 part_die->abbrev = abbrev_number;
4382 for (i = 0; i < abbrev->num_attrs; ++i)
4384 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4386 /* Store the data if it is of an attribute we want to keep in a
4387 partial symbol table. */
4392 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4393 if (part_die->name == NULL)
4394 part_die->name = DW_STRING (&attr);
4396 case DW_AT_MIPS_linkage_name:
4397 part_die->name = DW_STRING (&attr);
4400 has_low_pc_attr = 1;
4401 part_die->lowpc = DW_ADDR (&attr);
4404 has_high_pc_attr = 1;
4405 part_die->highpc = DW_ADDR (&attr);
4407 case DW_AT_location:
4408 /* Support the .debug_loc offsets */
4409 if (attr_form_is_block (&attr))
4411 part_die->locdesc = DW_BLOCK (&attr);
4413 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4415 dwarf2_complex_location_expr_complaint ();
4419 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4420 "partial symbol information");
4423 case DW_AT_language:
4424 part_die->language = DW_UNSND (&attr);
4426 case DW_AT_external:
4427 part_die->is_external = DW_UNSND (&attr);
4429 case DW_AT_declaration:
4430 part_die->is_declaration = DW_UNSND (&attr);
4433 part_die->has_type = 1;
4435 case DW_AT_abstract_origin:
4436 case DW_AT_specification:
4437 found_spec_attr = 1;
4441 /* Ignore absolute siblings, they might point outside of
4442 the current compile unit. */
4443 if (attr.form == DW_FORM_ref_addr)
4444 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
4447 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr, cu);
4454 /* If we found a reference attribute and the die has no name, try
4455 to find a name in the referred to die. */
4457 if (found_spec_attr && part_die->name == NULL)
4459 struct partial_die_info spec_die;
4462 spec_ptr = dwarf_info_buffer
4463 + dwarf2_get_ref_die_offset (&spec_attr, cu);
4464 read_partial_die (&spec_die, abfd, spec_ptr, cu);
4467 part_die->name = spec_die.name;
4469 /* Copy DW_AT_external attribute if it is set. */
4470 if (spec_die.is_external)
4471 part_die->is_external = spec_die.is_external;
4475 /* When using the GNU linker, .gnu.linkonce. sections are used to
4476 eliminate duplicate copies of functions and vtables and such.
4477 The linker will arbitrarily choose one and discard the others.
4478 The AT_*_pc values for such functions refer to local labels in
4479 these sections. If the section from that file was discarded, the
4480 labels are not in the output, so the relocs get a value of 0.
4481 If this is a discarded function, mark the pc bounds as invalid,
4482 so that GDB will ignore it. */
4483 if (has_low_pc_attr && has_high_pc_attr
4484 && part_die->lowpc < part_die->highpc
4485 && (part_die->lowpc != 0
4486 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
4487 part_die->has_pc_info = 1;
4491 /* Read the die from the .debug_info section buffer. Set DIEP to
4492 point to a newly allocated die with its information, except for its
4493 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4494 whether the die has children or not. */
4497 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
4498 struct dwarf2_cu *cu, int *has_children)
4500 unsigned int abbrev_number, bytes_read, i, offset;
4501 struct abbrev_info *abbrev;
4502 struct die_info *die;
4504 offset = info_ptr - dwarf_info_buffer;
4505 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4506 info_ptr += bytes_read;
4509 die = dwarf_alloc_die ();
4511 die->abbrev = abbrev_number;
4518 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4521 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4523 bfd_get_filename (abfd));
4525 die = dwarf_alloc_die ();
4526 die->offset = offset;
4527 die->tag = abbrev->tag;
4528 die->abbrev = abbrev_number;
4531 die->num_attrs = abbrev->num_attrs;
4532 die->attrs = (struct attribute *)
4533 xmalloc (die->num_attrs * sizeof (struct attribute));
4535 for (i = 0; i < abbrev->num_attrs; ++i)
4537 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
4538 abfd, info_ptr, cu);
4542 *has_children = abbrev->has_children;
4546 /* Read an attribute value described by an attribute form. */
4549 read_attribute_value (struct attribute *attr, unsigned form,
4550 bfd *abfd, char *info_ptr,
4551 struct dwarf2_cu *cu)
4553 struct comp_unit_head *cu_header = &cu->header;
4554 unsigned int bytes_read;
4555 struct dwarf_block *blk;
4561 case DW_FORM_ref_addr:
4562 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
4563 info_ptr += bytes_read;
4565 case DW_FORM_block2:
4566 blk = dwarf_alloc_block ();
4567 blk->size = read_2_bytes (abfd, info_ptr);
4569 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4570 info_ptr += blk->size;
4571 DW_BLOCK (attr) = blk;
4573 case DW_FORM_block4:
4574 blk = dwarf_alloc_block ();
4575 blk->size = read_4_bytes (abfd, info_ptr);
4577 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4578 info_ptr += blk->size;
4579 DW_BLOCK (attr) = blk;
4582 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4586 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4590 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4593 case DW_FORM_string:
4594 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
4595 info_ptr += bytes_read;
4598 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
4600 info_ptr += bytes_read;
4603 blk = dwarf_alloc_block ();
4604 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4605 info_ptr += bytes_read;
4606 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4607 info_ptr += blk->size;
4608 DW_BLOCK (attr) = blk;
4610 case DW_FORM_block1:
4611 blk = dwarf_alloc_block ();
4612 blk->size = read_1_byte (abfd, info_ptr);
4614 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4615 info_ptr += blk->size;
4616 DW_BLOCK (attr) = blk;
4619 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4623 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4626 case DW_FORM_flag_present:
4627 DW_UNSND (attr) = 1;
4630 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
4631 info_ptr += bytes_read;
4634 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4635 info_ptr += bytes_read;
4638 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4642 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4646 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4650 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4653 case DW_FORM_ref_udata:
4654 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4655 info_ptr += bytes_read;
4657 case DW_FORM_indirect:
4658 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4659 info_ptr += bytes_read;
4660 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
4663 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4664 dwarf_form_name (form),
4665 bfd_get_filename (abfd));
4670 /* Read an attribute described by an abbreviated attribute. */
4673 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
4674 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
4676 attr->name = abbrev->name;
4677 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
4680 /* read dwarf information from a buffer */
4683 read_1_byte (bfd *abfd, char *buf)
4685 return bfd_get_8 (abfd, (bfd_byte *) buf);
4689 read_1_signed_byte (bfd *abfd, char *buf)
4691 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
4695 read_2_bytes (bfd *abfd, char *buf)
4697 return bfd_get_16 (abfd, (bfd_byte *) buf);
4701 read_2_signed_bytes (bfd *abfd, char *buf)
4703 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4707 read_4_bytes (bfd *abfd, char *buf)
4709 return bfd_get_32 (abfd, (bfd_byte *) buf);
4713 read_4_signed_bytes (bfd *abfd, char *buf)
4715 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4718 static unsigned long
4719 read_8_bytes (bfd *abfd, char *buf)
4721 return bfd_get_64 (abfd, (bfd_byte *) buf);
4725 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
4727 struct comp_unit_head *cu_header = &cu->header;
4728 CORE_ADDR retval = 0;
4730 if (cu_header->signed_addr_p)
4732 switch (cu_header->addr_size)
4735 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4738 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4741 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
4744 internal_error (__FILE__, __LINE__,
4745 "read_address: bad switch, signed [in module %s]",
4746 bfd_get_filename (abfd));
4751 switch (cu_header->addr_size)
4754 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
4757 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4760 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4763 internal_error (__FILE__, __LINE__,
4764 "read_address: bad switch, unsigned [in module %s]",
4765 bfd_get_filename (abfd));
4769 *bytes_read = cu_header->addr_size;
4773 /* Read the initial length from a section. The (draft) DWARF 3
4774 specification allows the initial length to take up either 4 bytes
4775 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4776 bytes describe the length and all offsets will be 8 bytes in length
4779 An older, non-standard 64-bit format is also handled by this
4780 function. The older format in question stores the initial length
4781 as an 8-byte quantity without an escape value. Lengths greater
4782 than 2^32 aren't very common which means that the initial 4 bytes
4783 is almost always zero. Since a length value of zero doesn't make
4784 sense for the 32-bit format, this initial zero can be considered to
4785 be an escape value which indicates the presence of the older 64-bit
4786 format. As written, the code can't detect (old format) lengths
4787 greater than 4GB. If it becomes necessary to handle lengths somewhat
4788 larger than 4GB, we could allow other small values (such as the
4789 non-sensical values of 1, 2, and 3) to also be used as escape values
4790 indicating the presence of the old format.
4792 The value returned via bytes_read should be used to increment
4793 the relevant pointer after calling read_initial_length().
4795 As a side effect, this function sets the fields initial_length_size
4796 and offset_size in cu_header to the values appropriate for the
4797 length field. (The format of the initial length field determines
4798 the width of file offsets to be fetched later with fetch_offset().)
4800 [ Note: read_initial_length() and read_offset() are based on the
4801 document entitled "DWARF Debugging Information Format", revision
4802 3, draft 8, dated November 19, 2001. This document was obtained
4805 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4807 This document is only a draft and is subject to change. (So beware.)
4809 Details regarding the older, non-standard 64-bit format were
4810 determined empirically by examining 64-bit ELF files produced
4811 by the SGI toolchain on an IRIX 6.5 machine.
4813 - Kevin, July 16, 2002
4817 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
4822 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4824 if (retval == 0xffffffff)
4826 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
4828 if (cu_header != NULL)
4830 cu_header->initial_length_size = 12;
4831 cu_header->offset_size = 8;
4834 else if (retval == 0)
4836 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4838 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4840 if (cu_header != NULL)
4842 cu_header->initial_length_size = 8;
4843 cu_header->offset_size = 8;
4849 if (cu_header != NULL)
4851 cu_header->initial_length_size = 4;
4852 cu_header->offset_size = 4;
4859 /* Read an offset from the data stream. The size of the offset is
4860 given by cu_header->offset_size. */
4863 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
4868 switch (cu_header->offset_size)
4871 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4875 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4879 internal_error (__FILE__, __LINE__,
4880 "read_offset: bad switch [in module %s]",
4881 bfd_get_filename (abfd));
4888 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
4890 /* If the size of a host char is 8 bits, we can return a pointer
4891 to the buffer, otherwise we have to copy the data to a buffer
4892 allocated on the temporary obstack. */
4893 gdb_assert (HOST_CHAR_BIT == 8);
4898 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4900 /* If the size of a host char is 8 bits, we can return a pointer
4901 to the string, otherwise we have to copy the string to a buffer
4902 allocated on the temporary obstack. */
4903 gdb_assert (HOST_CHAR_BIT == 8);
4906 *bytes_read_ptr = 1;
4909 *bytes_read_ptr = strlen (buf) + 1;
4914 read_indirect_string (bfd *abfd, char *buf,
4915 const struct comp_unit_head *cu_header,
4916 unsigned int *bytes_read_ptr)
4918 LONGEST str_offset = read_offset (abfd, buf, cu_header,
4919 (int *) bytes_read_ptr);
4921 if (dwarf_str_buffer == NULL)
4923 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4924 bfd_get_filename (abfd));
4927 if (str_offset >= dwarf_str_size)
4929 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4930 bfd_get_filename (abfd));
4933 gdb_assert (HOST_CHAR_BIT == 8);
4934 if (dwarf_str_buffer[str_offset] == '\0')
4936 return dwarf_str_buffer + str_offset;
4939 static unsigned long
4940 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4942 unsigned long result;
4943 unsigned int num_read;
4953 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4956 result |= ((unsigned long)(byte & 127) << shift);
4957 if ((byte & 128) == 0)
4963 *bytes_read_ptr = num_read;
4968 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4971 int i, shift, size, num_read;
4981 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4984 result |= ((long)(byte & 127) << shift);
4986 if ((byte & 128) == 0)
4991 if ((shift < size) && (byte & 0x40))
4993 result |= -(1 << shift);
4995 *bytes_read_ptr = num_read;
5000 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
5006 cu->language = language_c;
5008 case DW_LANG_C_plus_plus:
5009 cu->language = language_cplus;
5011 case DW_LANG_Fortran77:
5012 case DW_LANG_Fortran90:
5013 case DW_LANG_Fortran95:
5014 cu->language = language_fortran;
5016 case DW_LANG_Mips_Assembler:
5017 cu->language = language_asm;
5020 cu->language = language_java;
5024 case DW_LANG_Cobol74:
5025 case DW_LANG_Cobol85:
5026 case DW_LANG_Pascal83:
5027 case DW_LANG_Modula2:
5029 cu->language = language_minimal;
5032 cu->language_defn = language_def (cu->language);
5035 /* Return the named attribute or NULL if not there. */
5037 static struct attribute *
5038 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
5041 struct attribute *spec = NULL;
5043 for (i = 0; i < die->num_attrs; ++i)
5045 if (die->attrs[i].name == name)
5047 return &die->attrs[i];
5049 if (die->attrs[i].name == DW_AT_specification
5050 || die->attrs[i].name == DW_AT_abstract_origin)
5051 spec = &die->attrs[i];
5055 struct die_info *ref_die =
5056 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
5059 return dwarf2_attr (ref_die, name, cu);
5066 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5068 return (dwarf2_attr (die, DW_AT_declaration, cu)
5069 && ! dwarf2_attr (die, DW_AT_specification, cu));
5072 /* Return the die giving the specification for DIE, if there is
5075 static struct die_info *
5076 die_specification (struct die_info *die, struct dwarf2_cu *cu)
5078 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
5080 if (spec_attr == NULL)
5083 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
5086 /* Free the line_header structure *LH, and any arrays and strings it
5089 free_line_header (struct line_header *lh)
5091 if (lh->standard_opcode_lengths)
5092 xfree (lh->standard_opcode_lengths);
5094 /* Remember that all the lh->file_names[i].name pointers are
5095 pointers into debug_line_buffer, and don't need to be freed. */
5097 xfree (lh->file_names);
5099 /* Similarly for the include directory names. */
5100 if (lh->include_dirs)
5101 xfree (lh->include_dirs);
5107 /* Add an entry to LH's include directory table. */
5109 add_include_dir (struct line_header *lh, char *include_dir)
5111 /* Grow the array if necessary. */
5112 if (lh->include_dirs_size == 0)
5114 lh->include_dirs_size = 1; /* for testing */
5115 lh->include_dirs = xmalloc (lh->include_dirs_size
5116 * sizeof (*lh->include_dirs));
5118 else if (lh->num_include_dirs >= lh->include_dirs_size)
5120 lh->include_dirs_size *= 2;
5121 lh->include_dirs = xrealloc (lh->include_dirs,
5122 (lh->include_dirs_size
5123 * sizeof (*lh->include_dirs)));
5126 lh->include_dirs[lh->num_include_dirs++] = include_dir;
5130 /* Add an entry to LH's file name table. */
5132 add_file_name (struct line_header *lh,
5134 unsigned int dir_index,
5135 unsigned int mod_time,
5136 unsigned int length)
5138 struct file_entry *fe;
5140 /* Grow the array if necessary. */
5141 if (lh->file_names_size == 0)
5143 lh->file_names_size = 1; /* for testing */
5144 lh->file_names = xmalloc (lh->file_names_size
5145 * sizeof (*lh->file_names));
5147 else if (lh->num_file_names >= lh->file_names_size)
5149 lh->file_names_size *= 2;
5150 lh->file_names = xrealloc (lh->file_names,
5151 (lh->file_names_size
5152 * sizeof (*lh->file_names)));
5155 fe = &lh->file_names[lh->num_file_names++];
5157 fe->dir_index = dir_index;
5158 fe->mod_time = mod_time;
5159 fe->length = length;
5163 /* Read the statement program header starting at OFFSET in
5164 dwarf_line_buffer, according to the endianness of ABFD. Return a
5165 pointer to a struct line_header, allocated using xmalloc.
5167 NOTE: the strings in the include directory and file name tables of
5168 the returned object point into debug_line_buffer, and must not be
5170 static struct line_header *
5171 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5172 struct dwarf2_cu *cu)
5174 struct cleanup *back_to;
5175 struct line_header *lh;
5179 char *cur_dir, *cur_file;
5181 if (dwarf_line_buffer == NULL)
5183 complaint (&symfile_complaints, "missing .debug_line section");
5187 /* Make sure that at least there's room for the total_length field. That
5188 could be 12 bytes long, but we're just going to fudge that. */
5189 if (offset + 4 >= dwarf_line_size)
5191 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5195 lh = xmalloc (sizeof (*lh));
5196 memset (lh, 0, sizeof (*lh));
5197 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5200 line_ptr = dwarf_line_buffer + offset;
5202 /* read in the header */
5203 lh->total_length = read_initial_length (abfd, line_ptr, &cu->header, &bytes_read);
5204 line_ptr += bytes_read;
5205 if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size)
5207 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5210 lh->statement_program_end = line_ptr + lh->total_length;
5211 lh->version = read_2_bytes (abfd, line_ptr);
5213 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5214 line_ptr += bytes_read;
5215 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5217 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5219 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5221 lh->line_range = read_1_byte (abfd, line_ptr);
5223 lh->opcode_base = read_1_byte (abfd, line_ptr);
5225 lh->standard_opcode_lengths
5226 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5228 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5229 for (i = 1; i < lh->opcode_base; ++i)
5231 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5235 /* Read directory table */
5236 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5238 line_ptr += bytes_read;
5239 add_include_dir (lh, cur_dir);
5241 line_ptr += bytes_read;
5243 /* Read file name table */
5244 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5246 unsigned int dir_index, mod_time, length;
5248 line_ptr += bytes_read;
5249 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5250 line_ptr += bytes_read;
5251 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5252 line_ptr += bytes_read;
5253 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5254 line_ptr += bytes_read;
5256 add_file_name (lh, cur_file, dir_index, mod_time, length);
5258 line_ptr += bytes_read;
5259 lh->statement_program_start = line_ptr;
5261 if (line_ptr > dwarf_line_buffer + dwarf_line_size)
5262 complaint (&symfile_complaints,
5263 "line number info header doesn't fit in `.debug_line' section");
5265 discard_cleanups (back_to);
5269 /* This function exists to work around a bug in certain compilers
5270 (particularly GCC 2.95), in which the first line number marker of a
5271 function does not show up until after the prologue, right before
5272 the second line number marker. This function shifts ADDRESS down
5273 to the beginning of the function if necessary, and is called on
5274 addresses passed to record_line. */
5277 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
5279 struct function_range *fn;
5281 /* Find the function_range containing address. */
5286 cu->cached_fn = cu->first_fn;
5290 if (fn->lowpc <= address && fn->highpc > address)
5296 while (fn && fn != cu->cached_fn)
5297 if (fn->lowpc <= address && fn->highpc > address)
5307 if (address != fn->lowpc)
5308 complaint (&symfile_complaints,
5309 "misplaced first line number at 0x%lx for '%s'",
5310 (unsigned long) address, fn->name);
5315 /* Decode the line number information for the compilation unit whose
5316 line number info is at OFFSET in the .debug_line section.
5317 The compilation directory of the file is passed in COMP_DIR. */
5320 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5321 struct dwarf2_cu *cu)
5325 unsigned int bytes_read;
5326 unsigned char op_code, extended_op, adj_opcode;
5328 struct objfile *objfile = cu->objfile;
5330 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5332 line_ptr = lh->statement_program_start;
5333 line_end = lh->statement_program_end;
5335 /* Read the statement sequences until there's nothing left. */
5336 while (line_ptr < line_end)
5338 /* state machine registers */
5339 CORE_ADDR address = 0;
5340 unsigned int file = 1;
5341 unsigned int line = 1;
5342 unsigned int column = 0;
5343 int is_stmt = lh->default_is_stmt;
5344 int basic_block = 0;
5345 int end_sequence = 0;
5347 /* Start a subfile for the current file of the state machine. */
5348 if (lh->num_file_names >= file)
5350 /* lh->include_dirs and lh->file_names are 0-based, but the
5351 directory and file name numbers in the statement program
5353 struct file_entry *fe = &lh->file_names[file - 1];
5356 dir = lh->include_dirs[fe->dir_index - 1];
5359 dwarf2_start_subfile (fe->name, dir);
5362 /* Decode the table. */
5363 while (!end_sequence)
5365 op_code = read_1_byte (abfd, line_ptr);
5368 if (op_code >= lh->opcode_base)
5369 { /* Special operand. */
5370 adj_opcode = op_code - lh->opcode_base;
5371 address += (adj_opcode / lh->line_range)
5372 * lh->minimum_instruction_length;
5373 line += lh->line_base + (adj_opcode % lh->line_range);
5374 /* append row to matrix using current values */
5375 record_line (current_subfile, line,
5376 check_cu_functions (address, cu));
5379 else switch (op_code)
5381 case DW_LNS_extended_op:
5382 line_ptr += 1; /* ignore length */
5383 extended_op = read_1_byte (abfd, line_ptr);
5385 switch (extended_op)
5387 case DW_LNE_end_sequence:
5389 record_line (current_subfile, 0, address);
5391 case DW_LNE_set_address:
5392 address = read_address (abfd, line_ptr, cu, &bytes_read);
5393 line_ptr += bytes_read;
5394 address += baseaddr;
5396 case DW_LNE_define_file:
5399 unsigned int dir_index, mod_time, length;
5401 cur_file = read_string (abfd, line_ptr, &bytes_read);
5402 line_ptr += bytes_read;
5404 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5405 line_ptr += bytes_read;
5407 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5408 line_ptr += bytes_read;
5410 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5411 line_ptr += bytes_read;
5412 add_file_name (lh, cur_file, dir_index, mod_time, length);
5416 complaint (&symfile_complaints,
5417 "mangled .debug_line section");
5422 record_line (current_subfile, line,
5423 check_cu_functions (address, cu));
5426 case DW_LNS_advance_pc:
5427 address += lh->minimum_instruction_length
5428 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5429 line_ptr += bytes_read;
5431 case DW_LNS_advance_line:
5432 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
5433 line_ptr += bytes_read;
5435 case DW_LNS_set_file:
5437 /* lh->include_dirs and lh->file_names are 0-based,
5438 but the directory and file name numbers in the
5439 statement program are 1-based. */
5440 struct file_entry *fe;
5442 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5443 line_ptr += bytes_read;
5444 fe = &lh->file_names[file - 1];
5446 dir = lh->include_dirs[fe->dir_index - 1];
5449 dwarf2_start_subfile (fe->name, dir);
5452 case DW_LNS_set_column:
5453 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5454 line_ptr += bytes_read;
5456 case DW_LNS_negate_stmt:
5457 is_stmt = (!is_stmt);
5459 case DW_LNS_set_basic_block:
5462 /* Add to the address register of the state machine the
5463 address increment value corresponding to special opcode
5464 255. Ie, this value is scaled by the minimum instruction
5465 length since special opcode 255 would have scaled the
5467 case DW_LNS_const_add_pc:
5468 address += (lh->minimum_instruction_length
5469 * ((255 - lh->opcode_base) / lh->line_range));
5471 case DW_LNS_fixed_advance_pc:
5472 address += read_2_bytes (abfd, line_ptr);
5476 { /* Unknown standard opcode, ignore it. */
5478 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
5480 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5481 line_ptr += bytes_read;
5489 /* Start a subfile for DWARF. FILENAME is the name of the file and
5490 DIRNAME the name of the source directory which contains FILENAME
5491 or NULL if not known.
5492 This routine tries to keep line numbers from identical absolute and
5493 relative file names in a common subfile.
5495 Using the `list' example from the GDB testsuite, which resides in
5496 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5497 of /srcdir/list0.c yields the following debugging information for list0.c:
5499 DW_AT_name: /srcdir/list0.c
5500 DW_AT_comp_dir: /compdir
5501 files.files[0].name: list0.h
5502 files.files[0].dir: /srcdir
5503 files.files[1].name: list0.c
5504 files.files[1].dir: /srcdir
5506 The line number information for list0.c has to end up in a single
5507 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5510 dwarf2_start_subfile (char *filename, char *dirname)
5512 /* If the filename isn't absolute, try to match an existing subfile
5513 with the full pathname. */
5515 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
5517 struct subfile *subfile;
5518 char *fullname = concat (dirname, "/", filename, NULL);
5520 for (subfile = subfiles; subfile; subfile = subfile->next)
5522 if (FILENAME_CMP (subfile->name, fullname) == 0)
5524 current_subfile = subfile;
5531 start_subfile (filename, dirname);
5535 var_decode_location (struct attribute *attr, struct symbol *sym,
5536 struct dwarf2_cu *cu)
5538 struct objfile *objfile = cu->objfile;
5539 struct comp_unit_head *cu_header = &cu->header;
5541 /* NOTE drow/2003-01-30: There used to be a comment and some special
5542 code here to turn a symbol with DW_AT_external and a
5543 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5544 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5545 with some versions of binutils) where shared libraries could have
5546 relocations against symbols in their debug information - the
5547 minimal symbol would have the right address, but the debug info
5548 would not. It's no longer necessary, because we will explicitly
5549 apply relocations when we read in the debug information now. */
5551 /* A DW_AT_location attribute with no contents indicates that a
5552 variable has been optimized away. */
5553 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
5555 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
5559 /* Handle one degenerate form of location expression specially, to
5560 preserve GDB's previous behavior when section offsets are
5561 specified. If this is just a DW_OP_addr then mark this symbol
5564 if (attr_form_is_block (attr)
5565 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
5566 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
5570 SYMBOL_VALUE_ADDRESS (sym) =
5571 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
5572 fixup_symbol_section (sym, objfile);
5573 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
5574 SYMBOL_SECTION (sym));
5575 SYMBOL_CLASS (sym) = LOC_STATIC;
5579 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5580 expression evaluator, and use LOC_COMPUTED only when necessary
5581 (i.e. when the value of a register or memory location is
5582 referenced, or a thread-local block, etc.). Then again, it might
5583 not be worthwhile. I'm assuming that it isn't unless performance
5584 or memory numbers show me otherwise. */
5586 dwarf2_symbol_mark_computed (attr, sym, cu);
5587 SYMBOL_CLASS (sym) = LOC_COMPUTED;
5590 /* Given a pointer to a DWARF information entry, figure out if we need
5591 to make a symbol table entry for it, and if so, create a new entry
5592 and return a pointer to it.
5593 If TYPE is NULL, determine symbol type from the die, otherwise
5594 used the passed type. */
5596 static struct symbol *
5597 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5599 struct objfile *objfile = cu->objfile;
5600 struct symbol *sym = NULL;
5602 struct attribute *attr = NULL;
5603 struct attribute *attr2 = NULL;
5606 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5608 if (die->tag != DW_TAG_namespace)
5609 name = dwarf2_linkage_name (die, cu);
5611 name = TYPE_NAME (type);
5615 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
5616 sizeof (struct symbol));
5617 OBJSTAT (objfile, n_syms++);
5618 memset (sym, 0, sizeof (struct symbol));
5620 /* Cache this symbol's name and the name's demangled form (if any). */
5621 SYMBOL_LANGUAGE (sym) = cu->language;
5622 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
5624 /* Default assumptions.
5625 Use the passed type or decode it from the die. */
5626 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5627 SYMBOL_CLASS (sym) = LOC_STATIC;
5629 SYMBOL_TYPE (sym) = type;
5631 SYMBOL_TYPE (sym) = die_type (die, cu);
5632 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
5635 SYMBOL_LINE (sym) = DW_UNSND (attr);
5640 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5643 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
5645 SYMBOL_CLASS (sym) = LOC_LABEL;
5647 case DW_TAG_subprogram:
5648 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5650 SYMBOL_CLASS (sym) = LOC_BLOCK;
5651 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5652 if (attr2 && (DW_UNSND (attr2) != 0))
5654 add_symbol_to_list (sym, &global_symbols);
5658 add_symbol_to_list (sym, cu->list_in_scope);
5661 case DW_TAG_variable:
5662 /* Compilation with minimal debug info may result in variables
5663 with missing type entries. Change the misleading `void' type
5664 to something sensible. */
5665 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
5666 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
5667 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
5668 "<variable, no debug info>",
5670 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5673 dwarf2_const_value (attr, sym, cu);
5674 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5675 if (attr2 && (DW_UNSND (attr2) != 0))
5676 add_symbol_to_list (sym, &global_symbols);
5678 add_symbol_to_list (sym, cu->list_in_scope);
5681 attr = dwarf2_attr (die, DW_AT_location, cu);
5684 var_decode_location (attr, sym, cu);
5685 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5686 if (attr2 && (DW_UNSND (attr2) != 0))
5687 add_symbol_to_list (sym, &global_symbols);
5689 add_symbol_to_list (sym, cu->list_in_scope);
5693 /* We do not know the address of this symbol.
5694 If it is an external symbol and we have type information
5695 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5696 The address of the variable will then be determined from
5697 the minimal symbol table whenever the variable is
5699 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5700 if (attr2 && (DW_UNSND (attr2) != 0)
5701 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
5703 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
5704 add_symbol_to_list (sym, &global_symbols);
5708 case DW_TAG_formal_parameter:
5709 attr = dwarf2_attr (die, DW_AT_location, cu);
5712 var_decode_location (attr, sym, cu);
5713 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5714 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
5715 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
5717 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5720 dwarf2_const_value (attr, sym, cu);
5722 add_symbol_to_list (sym, cu->list_in_scope);
5724 case DW_TAG_unspecified_parameters:
5725 /* From varargs functions; gdb doesn't seem to have any
5726 interest in this information, so just ignore it for now.
5729 case DW_TAG_class_type:
5730 case DW_TAG_structure_type:
5731 case DW_TAG_union_type:
5732 case DW_TAG_enumeration_type:
5733 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5734 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5736 /* Make sure that the symbol includes appropriate enclosing
5737 classes/namespaces in its name. These are calculated in
5738 read_structure_type, and the correct name is saved in
5741 if (cu->language == language_cplus)
5743 struct type *type = SYMBOL_TYPE (sym);
5745 if (TYPE_TAG_NAME (type) != NULL)
5747 /* FIXME: carlton/2003-11-10: Should this use
5748 SYMBOL_SET_NAMES instead? (The same problem also
5749 arises a further down in the function.) */
5750 SYMBOL_LINKAGE_NAME (sym)
5751 = obsavestring (TYPE_TAG_NAME (type),
5752 strlen (TYPE_TAG_NAME (type)),
5753 &objfile->objfile_obstack);
5758 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5759 really ever be static objects: otherwise, if you try
5760 to, say, break of a class's method and you're in a file
5761 which doesn't mention that class, it won't work unless
5762 the check for all static symbols in lookup_symbol_aux
5763 saves you. See the OtherFileClass tests in
5764 gdb.c++/namespace.exp. */
5766 struct pending **list_to_add;
5768 list_to_add = (cu->list_in_scope == &file_symbols
5769 && cu->language == language_cplus
5770 ? &global_symbols : cu->list_in_scope);
5772 add_symbol_to_list (sym, list_to_add);
5774 /* The semantics of C++ state that "struct foo { ... }" also
5775 defines a typedef for "foo". Synthesize a typedef symbol so
5776 that "ptype foo" works as expected. */
5777 if (cu->language == language_cplus)
5779 struct symbol *typedef_sym = (struct symbol *)
5780 obstack_alloc (&objfile->objfile_obstack,
5781 sizeof (struct symbol));
5782 *typedef_sym = *sym;
5783 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
5784 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
5785 TYPE_NAME (SYMBOL_TYPE (sym)) =
5786 obsavestring (SYMBOL_NATURAL_NAME (sym),
5787 strlen (SYMBOL_NATURAL_NAME (sym)),
5788 &objfile->objfile_obstack);
5789 add_symbol_to_list (typedef_sym, list_to_add);
5793 case DW_TAG_typedef:
5794 if (processing_has_namespace_info
5795 && processing_current_prefix[0] != '\0')
5797 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
5798 processing_current_prefix,
5802 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5803 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5804 add_symbol_to_list (sym, cu->list_in_scope);
5806 case DW_TAG_base_type:
5807 case DW_TAG_subrange_type:
5808 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5809 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5810 add_symbol_to_list (sym, cu->list_in_scope);
5812 case DW_TAG_enumerator:
5813 if (processing_has_namespace_info
5814 && processing_current_prefix[0] != '\0')
5816 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
5817 processing_current_prefix,
5821 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5824 dwarf2_const_value (attr, sym, cu);
5827 /* NOTE: carlton/2003-11-10: See comment above in the
5828 DW_TAG_class_type, etc. block. */
5830 struct pending **list_to_add;
5832 list_to_add = (cu->list_in_scope == &file_symbols
5833 && cu->language == language_cplus
5834 ? &global_symbols : cu->list_in_scope);
5836 add_symbol_to_list (sym, list_to_add);
5839 case DW_TAG_namespace:
5840 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5841 add_symbol_to_list (sym, &global_symbols);
5844 /* Not a tag we recognize. Hopefully we aren't processing
5845 trash data, but since we must specifically ignore things
5846 we don't recognize, there is nothing else we should do at
5848 complaint (&symfile_complaints, "unsupported tag: '%s'",
5849 dwarf_tag_name (die->tag));
5856 /* Copy constant value from an attribute to a symbol. */
5859 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
5860 struct dwarf2_cu *cu)
5862 struct objfile *objfile = cu->objfile;
5863 struct comp_unit_head *cu_header = &cu->header;
5864 struct dwarf_block *blk;
5869 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
5870 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5871 cu_header->addr_size,
5872 TYPE_LENGTH (SYMBOL_TYPE
5874 SYMBOL_VALUE_BYTES (sym) = (char *)
5875 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
5876 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5877 it's body - store_unsigned_integer. */
5878 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
5880 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5882 case DW_FORM_block1:
5883 case DW_FORM_block2:
5884 case DW_FORM_block4:
5886 blk = DW_BLOCK (attr);
5887 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
5888 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5890 TYPE_LENGTH (SYMBOL_TYPE
5892 SYMBOL_VALUE_BYTES (sym) = (char *)
5893 obstack_alloc (&objfile->objfile_obstack, blk->size);
5894 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
5895 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5898 /* The DW_AT_const_value attributes are supposed to carry the
5899 symbol's value "represented as it would be on the target
5900 architecture." By the time we get here, it's already been
5901 converted to host endianness, so we just need to sign- or
5902 zero-extend it as appropriate. */
5904 dwarf2_const_value_data (attr, sym, 8);
5907 dwarf2_const_value_data (attr, sym, 16);
5910 dwarf2_const_value_data (attr, sym, 32);
5913 dwarf2_const_value_data (attr, sym, 64);
5917 SYMBOL_VALUE (sym) = DW_SND (attr);
5918 SYMBOL_CLASS (sym) = LOC_CONST;
5922 SYMBOL_VALUE (sym) = DW_UNSND (attr);
5923 SYMBOL_CLASS (sym) = LOC_CONST;
5927 complaint (&symfile_complaints,
5928 "unsupported const value attribute form: '%s'",
5929 dwarf_form_name (attr->form));
5930 SYMBOL_VALUE (sym) = 0;
5931 SYMBOL_CLASS (sym) = LOC_CONST;
5937 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5938 or zero-extend it as appropriate for the symbol's type. */
5940 dwarf2_const_value_data (struct attribute *attr,
5944 LONGEST l = DW_UNSND (attr);
5946 if (bits < sizeof (l) * 8)
5948 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
5949 l &= ((LONGEST) 1 << bits) - 1;
5951 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
5954 SYMBOL_VALUE (sym) = l;
5955 SYMBOL_CLASS (sym) = LOC_CONST;
5959 /* Return the type of the die in question using its DW_AT_type attribute. */
5961 static struct type *
5962 die_type (struct die_info *die, struct dwarf2_cu *cu)
5965 struct attribute *type_attr;
5966 struct die_info *type_die;
5969 type_attr = dwarf2_attr (die, DW_AT_type, cu);
5972 /* A missing DW_AT_type represents a void type. */
5973 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
5977 ref = dwarf2_get_ref_die_offset (type_attr, cu);
5978 type_die = follow_die_ref (ref);
5981 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5982 ref, cu->objfile->name);
5986 type = tag_type_to_type (type_die, cu);
5989 dump_die (type_die);
5990 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5996 /* Return the containing type of the die in question using its
5997 DW_AT_containing_type attribute. */
5999 static struct type *
6000 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
6002 struct type *type = NULL;
6003 struct attribute *type_attr;
6004 struct die_info *type_die = NULL;
6007 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
6010 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6011 type_die = follow_die_ref (ref);
6014 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
6018 type = tag_type_to_type (type_die, cu);
6023 dump_die (type_die);
6024 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6031 static struct type *
6032 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
6034 struct die_info *die;
6037 die = follow_die_ref (offset);
6040 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
6043 type = tag_type_to_type (die, cu);
6048 static struct type *
6049 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
6057 read_type_die (die, cu);
6061 error ("Dwarf Error: Cannot find type of die [in module %s]",
6069 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6071 char *prefix = determine_prefix (die, cu);
6072 const char *old_prefix = processing_current_prefix;
6073 struct cleanup *back_to = make_cleanup (xfree, prefix);
6074 processing_current_prefix = prefix;
6078 case DW_TAG_class_type:
6079 case DW_TAG_structure_type:
6080 case DW_TAG_union_type:
6081 read_structure_type (die, cu);
6083 case DW_TAG_enumeration_type:
6084 read_enumeration_type (die, cu);
6086 case DW_TAG_subprogram:
6087 case DW_TAG_subroutine_type:
6088 read_subroutine_type (die, cu);
6090 case DW_TAG_array_type:
6091 read_array_type (die, cu);
6093 case DW_TAG_pointer_type:
6094 read_tag_pointer_type (die, cu);
6096 case DW_TAG_ptr_to_member_type:
6097 read_tag_ptr_to_member_type (die, cu);
6099 case DW_TAG_reference_type:
6100 read_tag_reference_type (die, cu);
6102 case DW_TAG_const_type:
6103 read_tag_const_type (die, cu);
6105 case DW_TAG_volatile_type:
6106 read_tag_volatile_type (die, cu);
6108 case DW_TAG_restrict_type:
6109 read_tag_restrict_type (die, cu);
6111 case DW_TAG_string_type:
6112 read_tag_string_type (die, cu);
6114 case DW_TAG_typedef:
6115 read_typedef (die, cu);
6117 case DW_TAG_subrange_type:
6118 read_subrange_type (die, cu);
6120 case DW_TAG_base_type:
6121 read_base_type (die, cu);
6124 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
6125 dwarf_tag_name (die->tag));
6129 processing_current_prefix = old_prefix;
6130 do_cleanups (back_to);
6133 /* Return the name of the namespace/class that DIE is defined within,
6134 or "" if we can't tell. The caller should xfree the result. */
6136 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6137 therein) for an example of how to use this function to deal with
6138 DW_AT_specification. */
6141 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6143 struct die_info *parent;
6145 if (cu->language != language_cplus)
6148 parent = die->parent;
6152 return xstrdup ("");
6156 switch (parent->tag) {
6157 case DW_TAG_namespace:
6159 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6160 before doing this check? */
6161 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6163 return xstrdup (TYPE_TAG_NAME (parent->type));
6168 char *parent_prefix = determine_prefix (parent, cu);
6169 char *retval = typename_concat (parent_prefix,
6170 namespace_name (parent, &dummy,
6172 xfree (parent_prefix);
6177 case DW_TAG_class_type:
6178 case DW_TAG_structure_type:
6180 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6182 return xstrdup (TYPE_TAG_NAME (parent->type));
6186 const char *old_prefix = processing_current_prefix;
6187 char *new_prefix = determine_prefix (parent, cu);
6190 processing_current_prefix = new_prefix;
6191 retval = determine_class_name (parent, cu);
6192 processing_current_prefix = old_prefix;
6199 return determine_prefix (parent, cu);
6204 /* Return a newly-allocated string formed by concatenating PREFIX,
6205 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6206 string, just return a copy of SUFFIX. */
6209 typename_concat (const char *prefix, const char *suffix)
6211 if (prefix == NULL || prefix[0] == '\0')
6212 return xstrdup (suffix);
6215 char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1);
6217 strcpy (retval, prefix);
6218 strcat (retval, "::");
6219 strcat (retval, suffix);
6225 static struct type *
6226 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6228 struct objfile *objfile = cu->objfile;
6230 /* FIXME - this should not produce a new (struct type *)
6231 every time. It should cache base types. */
6235 case DW_ATE_address:
6236 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
6238 case DW_ATE_boolean:
6239 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
6241 case DW_ATE_complex_float:
6244 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
6248 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
6254 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
6258 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
6265 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6268 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
6272 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6276 case DW_ATE_signed_char:
6277 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6279 case DW_ATE_unsigned:
6283 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6286 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
6290 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
6294 case DW_ATE_unsigned_char:
6295 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6298 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6305 copy_die (struct die_info *old_die)
6307 struct die_info *new_die;
6310 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
6311 memset (new_die, 0, sizeof (struct die_info));
6313 new_die->tag = old_die->tag;
6314 new_die->has_children = old_die->has_children;
6315 new_die->abbrev = old_die->abbrev;
6316 new_die->offset = old_die->offset;
6317 new_die->type = NULL;
6319 num_attrs = old_die->num_attrs;
6320 new_die->num_attrs = num_attrs;
6321 new_die->attrs = (struct attribute *)
6322 xmalloc (num_attrs * sizeof (struct attribute));
6324 for (i = 0; i < old_die->num_attrs; ++i)
6326 new_die->attrs[i].name = old_die->attrs[i].name;
6327 new_die->attrs[i].form = old_die->attrs[i].form;
6328 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
6331 new_die->next = NULL;
6336 /* Return sibling of die, NULL if no sibling. */
6338 static struct die_info *
6339 sibling_die (struct die_info *die)
6341 return die->sibling;
6344 /* Get linkage name of a die, return NULL if not found. */
6347 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
6349 struct attribute *attr;
6351 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
6352 if (attr && DW_STRING (attr))
6353 return DW_STRING (attr);
6354 attr = dwarf2_attr (die, DW_AT_name, cu);
6355 if (attr && DW_STRING (attr))
6356 return DW_STRING (attr);
6360 /* Get name of a die, return NULL if not found. */
6363 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
6365 struct attribute *attr;
6367 attr = dwarf2_attr (die, DW_AT_name, cu);
6368 if (attr && DW_STRING (attr))
6369 return DW_STRING (attr);
6373 /* Return the die that this die in an extension of, or NULL if there
6376 static struct die_info *
6377 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
6379 struct attribute *attr;
6380 struct die_info *extension_die;
6383 attr = dwarf2_attr (die, DW_AT_extension, cu);
6387 ref = dwarf2_get_ref_die_offset (attr, cu);
6388 extension_die = follow_die_ref (ref);
6391 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
6394 return extension_die;
6397 /* Convert a DIE tag into its string name. */
6400 dwarf_tag_name (unsigned tag)
6404 case DW_TAG_padding:
6405 return "DW_TAG_padding";
6406 case DW_TAG_array_type:
6407 return "DW_TAG_array_type";
6408 case DW_TAG_class_type:
6409 return "DW_TAG_class_type";
6410 case DW_TAG_entry_point:
6411 return "DW_TAG_entry_point";
6412 case DW_TAG_enumeration_type:
6413 return "DW_TAG_enumeration_type";
6414 case DW_TAG_formal_parameter:
6415 return "DW_TAG_formal_parameter";
6416 case DW_TAG_imported_declaration:
6417 return "DW_TAG_imported_declaration";
6419 return "DW_TAG_label";
6420 case DW_TAG_lexical_block:
6421 return "DW_TAG_lexical_block";
6423 return "DW_TAG_member";
6424 case DW_TAG_pointer_type:
6425 return "DW_TAG_pointer_type";
6426 case DW_TAG_reference_type:
6427 return "DW_TAG_reference_type";
6428 case DW_TAG_compile_unit:
6429 return "DW_TAG_compile_unit";
6430 case DW_TAG_string_type:
6431 return "DW_TAG_string_type";
6432 case DW_TAG_structure_type:
6433 return "DW_TAG_structure_type";
6434 case DW_TAG_subroutine_type:
6435 return "DW_TAG_subroutine_type";
6436 case DW_TAG_typedef:
6437 return "DW_TAG_typedef";
6438 case DW_TAG_union_type:
6439 return "DW_TAG_union_type";
6440 case DW_TAG_unspecified_parameters:
6441 return "DW_TAG_unspecified_parameters";
6442 case DW_TAG_variant:
6443 return "DW_TAG_variant";
6444 case DW_TAG_common_block:
6445 return "DW_TAG_common_block";
6446 case DW_TAG_common_inclusion:
6447 return "DW_TAG_common_inclusion";
6448 case DW_TAG_inheritance:
6449 return "DW_TAG_inheritance";
6450 case DW_TAG_inlined_subroutine:
6451 return "DW_TAG_inlined_subroutine";
6453 return "DW_TAG_module";
6454 case DW_TAG_ptr_to_member_type:
6455 return "DW_TAG_ptr_to_member_type";
6456 case DW_TAG_set_type:
6457 return "DW_TAG_set_type";
6458 case DW_TAG_subrange_type:
6459 return "DW_TAG_subrange_type";
6460 case DW_TAG_with_stmt:
6461 return "DW_TAG_with_stmt";
6462 case DW_TAG_access_declaration:
6463 return "DW_TAG_access_declaration";
6464 case DW_TAG_base_type:
6465 return "DW_TAG_base_type";
6466 case DW_TAG_catch_block:
6467 return "DW_TAG_catch_block";
6468 case DW_TAG_const_type:
6469 return "DW_TAG_const_type";
6470 case DW_TAG_constant:
6471 return "DW_TAG_constant";
6472 case DW_TAG_enumerator:
6473 return "DW_TAG_enumerator";
6474 case DW_TAG_file_type:
6475 return "DW_TAG_file_type";
6477 return "DW_TAG_friend";
6478 case DW_TAG_namelist:
6479 return "DW_TAG_namelist";
6480 case DW_TAG_namelist_item:
6481 return "DW_TAG_namelist_item";
6482 case DW_TAG_packed_type:
6483 return "DW_TAG_packed_type";
6484 case DW_TAG_subprogram:
6485 return "DW_TAG_subprogram";
6486 case DW_TAG_template_type_param:
6487 return "DW_TAG_template_type_param";
6488 case DW_TAG_template_value_param:
6489 return "DW_TAG_template_value_param";
6490 case DW_TAG_thrown_type:
6491 return "DW_TAG_thrown_type";
6492 case DW_TAG_try_block:
6493 return "DW_TAG_try_block";
6494 case DW_TAG_variant_part:
6495 return "DW_TAG_variant_part";
6496 case DW_TAG_variable:
6497 return "DW_TAG_variable";
6498 case DW_TAG_volatile_type:
6499 return "DW_TAG_volatile_type";
6500 case DW_TAG_dwarf_procedure:
6501 return "DW_TAG_dwarf_procedure";
6502 case DW_TAG_restrict_type:
6503 return "DW_TAG_restrict_type";
6504 case DW_TAG_interface_type:
6505 return "DW_TAG_interface_type";
6506 case DW_TAG_namespace:
6507 return "DW_TAG_namespace";
6508 case DW_TAG_imported_module:
6509 return "DW_TAG_imported_module";
6510 case DW_TAG_unspecified_type:
6511 return "DW_TAG_unspecified_type";
6512 case DW_TAG_partial_unit:
6513 return "DW_TAG_partial_unit";
6514 case DW_TAG_imported_unit:
6515 return "DW_TAG_imported_unit";
6516 case DW_TAG_MIPS_loop:
6517 return "DW_TAG_MIPS_loop";
6518 case DW_TAG_format_label:
6519 return "DW_TAG_format_label";
6520 case DW_TAG_function_template:
6521 return "DW_TAG_function_template";
6522 case DW_TAG_class_template:
6523 return "DW_TAG_class_template";
6525 return "DW_TAG_<unknown>";
6529 /* Convert a DWARF attribute code into its string name. */
6532 dwarf_attr_name (unsigned attr)
6537 return "DW_AT_sibling";
6538 case DW_AT_location:
6539 return "DW_AT_location";
6541 return "DW_AT_name";
6542 case DW_AT_ordering:
6543 return "DW_AT_ordering";
6544 case DW_AT_subscr_data:
6545 return "DW_AT_subscr_data";
6546 case DW_AT_byte_size:
6547 return "DW_AT_byte_size";
6548 case DW_AT_bit_offset:
6549 return "DW_AT_bit_offset";
6550 case DW_AT_bit_size:
6551 return "DW_AT_bit_size";
6552 case DW_AT_element_list:
6553 return "DW_AT_element_list";
6554 case DW_AT_stmt_list:
6555 return "DW_AT_stmt_list";
6557 return "DW_AT_low_pc";
6559 return "DW_AT_high_pc";
6560 case DW_AT_language:
6561 return "DW_AT_language";
6563 return "DW_AT_member";
6565 return "DW_AT_discr";
6566 case DW_AT_discr_value:
6567 return "DW_AT_discr_value";
6568 case DW_AT_visibility:
6569 return "DW_AT_visibility";
6571 return "DW_AT_import";
6572 case DW_AT_string_length:
6573 return "DW_AT_string_length";
6574 case DW_AT_common_reference:
6575 return "DW_AT_common_reference";
6576 case DW_AT_comp_dir:
6577 return "DW_AT_comp_dir";
6578 case DW_AT_const_value:
6579 return "DW_AT_const_value";
6580 case DW_AT_containing_type:
6581 return "DW_AT_containing_type";
6582 case DW_AT_default_value:
6583 return "DW_AT_default_value";
6585 return "DW_AT_inline";
6586 case DW_AT_is_optional:
6587 return "DW_AT_is_optional";
6588 case DW_AT_lower_bound:
6589 return "DW_AT_lower_bound";
6590 case DW_AT_producer:
6591 return "DW_AT_producer";
6592 case DW_AT_prototyped:
6593 return "DW_AT_prototyped";
6594 case DW_AT_return_addr:
6595 return "DW_AT_return_addr";
6596 case DW_AT_start_scope:
6597 return "DW_AT_start_scope";
6598 case DW_AT_stride_size:
6599 return "DW_AT_stride_size";
6600 case DW_AT_upper_bound:
6601 return "DW_AT_upper_bound";
6602 case DW_AT_abstract_origin:
6603 return "DW_AT_abstract_origin";
6604 case DW_AT_accessibility:
6605 return "DW_AT_accessibility";
6606 case DW_AT_address_class:
6607 return "DW_AT_address_class";
6608 case DW_AT_artificial:
6609 return "DW_AT_artificial";
6610 case DW_AT_base_types:
6611 return "DW_AT_base_types";
6612 case DW_AT_calling_convention:
6613 return "DW_AT_calling_convention";
6615 return "DW_AT_count";
6616 case DW_AT_data_member_location:
6617 return "DW_AT_data_member_location";
6618 case DW_AT_decl_column:
6619 return "DW_AT_decl_column";
6620 case DW_AT_decl_file:
6621 return "DW_AT_decl_file";
6622 case DW_AT_decl_line:
6623 return "DW_AT_decl_line";
6624 case DW_AT_declaration:
6625 return "DW_AT_declaration";
6626 case DW_AT_discr_list:
6627 return "DW_AT_discr_list";
6628 case DW_AT_encoding:
6629 return "DW_AT_encoding";
6630 case DW_AT_external:
6631 return "DW_AT_external";
6632 case DW_AT_frame_base:
6633 return "DW_AT_frame_base";
6635 return "DW_AT_friend";
6636 case DW_AT_identifier_case:
6637 return "DW_AT_identifier_case";
6638 case DW_AT_macro_info:
6639 return "DW_AT_macro_info";
6640 case DW_AT_namelist_items:
6641 return "DW_AT_namelist_items";
6642 case DW_AT_priority:
6643 return "DW_AT_priority";
6645 return "DW_AT_segment";
6646 case DW_AT_specification:
6647 return "DW_AT_specification";
6648 case DW_AT_static_link:
6649 return "DW_AT_static_link";
6651 return "DW_AT_type";
6652 case DW_AT_use_location:
6653 return "DW_AT_use_location";
6654 case DW_AT_variable_parameter:
6655 return "DW_AT_variable_parameter";
6656 case DW_AT_virtuality:
6657 return "DW_AT_virtuality";
6658 case DW_AT_vtable_elem_location:
6659 return "DW_AT_vtable_elem_location";
6660 case DW_AT_allocated:
6661 return "DW_AT_allocated";
6662 case DW_AT_associated:
6663 return "DW_AT_associated";
6664 case DW_AT_data_location:
6665 return "DW_AT_data_location";
6667 return "DW_AT_stride";
6668 case DW_AT_entry_pc:
6669 return "DW_AT_entry_pc";
6670 case DW_AT_use_UTF8:
6671 return "DW_AT_use_UTF8";
6672 case DW_AT_extension:
6673 return "DW_AT_extension";
6675 return "DW_AT_ranges";
6676 case DW_AT_trampoline:
6677 return "DW_AT_trampoline";
6678 case DW_AT_call_column:
6679 return "DW_AT_call_column";
6680 case DW_AT_call_file:
6681 return "DW_AT_call_file";
6682 case DW_AT_call_line:
6683 return "DW_AT_call_line";
6685 case DW_AT_MIPS_fde:
6686 return "DW_AT_MIPS_fde";
6687 case DW_AT_MIPS_loop_begin:
6688 return "DW_AT_MIPS_loop_begin";
6689 case DW_AT_MIPS_tail_loop_begin:
6690 return "DW_AT_MIPS_tail_loop_begin";
6691 case DW_AT_MIPS_epilog_begin:
6692 return "DW_AT_MIPS_epilog_begin";
6693 case DW_AT_MIPS_loop_unroll_factor:
6694 return "DW_AT_MIPS_loop_unroll_factor";
6695 case DW_AT_MIPS_software_pipeline_depth:
6696 return "DW_AT_MIPS_software_pipeline_depth";
6698 case DW_AT_MIPS_linkage_name:
6699 return "DW_AT_MIPS_linkage_name";
6701 case DW_AT_sf_names:
6702 return "DW_AT_sf_names";
6703 case DW_AT_src_info:
6704 return "DW_AT_src_info";
6705 case DW_AT_mac_info:
6706 return "DW_AT_mac_info";
6707 case DW_AT_src_coords:
6708 return "DW_AT_src_coords";
6709 case DW_AT_body_begin:
6710 return "DW_AT_body_begin";
6711 case DW_AT_body_end:
6712 return "DW_AT_body_end";
6713 case DW_AT_GNU_vector:
6714 return "DW_AT_GNU_vector";
6716 return "DW_AT_<unknown>";
6720 /* Convert a DWARF value form code into its string name. */
6723 dwarf_form_name (unsigned form)
6728 return "DW_FORM_addr";
6729 case DW_FORM_block2:
6730 return "DW_FORM_block2";
6731 case DW_FORM_block4:
6732 return "DW_FORM_block4";
6734 return "DW_FORM_data2";
6736 return "DW_FORM_data4";
6738 return "DW_FORM_data8";
6739 case DW_FORM_string:
6740 return "DW_FORM_string";
6742 return "DW_FORM_block";
6743 case DW_FORM_block1:
6744 return "DW_FORM_block1";
6746 return "DW_FORM_data1";
6748 return "DW_FORM_flag";
6750 return "DW_FORM_sdata";
6752 return "DW_FORM_strp";
6754 return "DW_FORM_udata";
6755 case DW_FORM_ref_addr:
6756 return "DW_FORM_ref_addr";
6758 return "DW_FORM_ref1";
6760 return "DW_FORM_ref2";
6762 return "DW_FORM_ref4";
6764 return "DW_FORM_ref8";
6765 case DW_FORM_ref_udata:
6766 return "DW_FORM_ref_udata";
6767 case DW_FORM_indirect:
6768 return "DW_FORM_indirect";
6770 return "DW_FORM_<unknown>";
6774 /* Convert a DWARF stack opcode into its string name. */
6777 dwarf_stack_op_name (unsigned op)
6782 return "DW_OP_addr";
6784 return "DW_OP_deref";
6786 return "DW_OP_const1u";
6788 return "DW_OP_const1s";
6790 return "DW_OP_const2u";
6792 return "DW_OP_const2s";
6794 return "DW_OP_const4u";
6796 return "DW_OP_const4s";
6798 return "DW_OP_const8u";
6800 return "DW_OP_const8s";
6802 return "DW_OP_constu";
6804 return "DW_OP_consts";
6808 return "DW_OP_drop";
6810 return "DW_OP_over";
6812 return "DW_OP_pick";
6814 return "DW_OP_swap";
6818 return "DW_OP_xderef";
6826 return "DW_OP_minus";
6838 return "DW_OP_plus";
6839 case DW_OP_plus_uconst:
6840 return "DW_OP_plus_uconst";
6846 return "DW_OP_shra";
6864 return "DW_OP_skip";
6866 return "DW_OP_lit0";
6868 return "DW_OP_lit1";
6870 return "DW_OP_lit2";
6872 return "DW_OP_lit3";
6874 return "DW_OP_lit4";
6876 return "DW_OP_lit5";
6878 return "DW_OP_lit6";
6880 return "DW_OP_lit7";
6882 return "DW_OP_lit8";
6884 return "DW_OP_lit9";
6886 return "DW_OP_lit10";
6888 return "DW_OP_lit11";
6890 return "DW_OP_lit12";
6892 return "DW_OP_lit13";
6894 return "DW_OP_lit14";
6896 return "DW_OP_lit15";
6898 return "DW_OP_lit16";
6900 return "DW_OP_lit17";
6902 return "DW_OP_lit18";
6904 return "DW_OP_lit19";
6906 return "DW_OP_lit20";
6908 return "DW_OP_lit21";
6910 return "DW_OP_lit22";
6912 return "DW_OP_lit23";
6914 return "DW_OP_lit24";
6916 return "DW_OP_lit25";
6918 return "DW_OP_lit26";
6920 return "DW_OP_lit27";
6922 return "DW_OP_lit28";
6924 return "DW_OP_lit29";
6926 return "DW_OP_lit30";
6928 return "DW_OP_lit31";
6930 return "DW_OP_reg0";
6932 return "DW_OP_reg1";
6934 return "DW_OP_reg2";
6936 return "DW_OP_reg3";
6938 return "DW_OP_reg4";
6940 return "DW_OP_reg5";
6942 return "DW_OP_reg6";
6944 return "DW_OP_reg7";
6946 return "DW_OP_reg8";
6948 return "DW_OP_reg9";
6950 return "DW_OP_reg10";
6952 return "DW_OP_reg11";
6954 return "DW_OP_reg12";
6956 return "DW_OP_reg13";
6958 return "DW_OP_reg14";
6960 return "DW_OP_reg15";
6962 return "DW_OP_reg16";
6964 return "DW_OP_reg17";
6966 return "DW_OP_reg18";
6968 return "DW_OP_reg19";
6970 return "DW_OP_reg20";
6972 return "DW_OP_reg21";
6974 return "DW_OP_reg22";
6976 return "DW_OP_reg23";
6978 return "DW_OP_reg24";
6980 return "DW_OP_reg25";
6982 return "DW_OP_reg26";
6984 return "DW_OP_reg27";
6986 return "DW_OP_reg28";
6988 return "DW_OP_reg29";
6990 return "DW_OP_reg30";
6992 return "DW_OP_reg31";
6994 return "DW_OP_breg0";
6996 return "DW_OP_breg1";
6998 return "DW_OP_breg2";
7000 return "DW_OP_breg3";
7002 return "DW_OP_breg4";
7004 return "DW_OP_breg5";
7006 return "DW_OP_breg6";
7008 return "DW_OP_breg7";
7010 return "DW_OP_breg8";
7012 return "DW_OP_breg9";
7014 return "DW_OP_breg10";
7016 return "DW_OP_breg11";
7018 return "DW_OP_breg12";
7020 return "DW_OP_breg13";
7022 return "DW_OP_breg14";
7024 return "DW_OP_breg15";
7026 return "DW_OP_breg16";
7028 return "DW_OP_breg17";
7030 return "DW_OP_breg18";
7032 return "DW_OP_breg19";
7034 return "DW_OP_breg20";
7036 return "DW_OP_breg21";
7038 return "DW_OP_breg22";
7040 return "DW_OP_breg23";
7042 return "DW_OP_breg24";
7044 return "DW_OP_breg25";
7046 return "DW_OP_breg26";
7048 return "DW_OP_breg27";
7050 return "DW_OP_breg28";
7052 return "DW_OP_breg29";
7054 return "DW_OP_breg30";
7056 return "DW_OP_breg31";
7058 return "DW_OP_regx";
7060 return "DW_OP_fbreg";
7062 return "DW_OP_bregx";
7064 return "DW_OP_piece";
7065 case DW_OP_deref_size:
7066 return "DW_OP_deref_size";
7067 case DW_OP_xderef_size:
7068 return "DW_OP_xderef_size";
7071 /* DWARF 3 extensions. */
7072 case DW_OP_push_object_address:
7073 return "DW_OP_push_object_address";
7075 return "DW_OP_call2";
7077 return "DW_OP_call4";
7078 case DW_OP_call_ref:
7079 return "DW_OP_call_ref";
7080 /* GNU extensions. */
7081 case DW_OP_GNU_push_tls_address:
7082 return "DW_OP_GNU_push_tls_address";
7084 return "OP_<unknown>";
7089 dwarf_bool_name (unsigned mybool)
7097 /* Convert a DWARF type code into its string name. */
7100 dwarf_type_encoding_name (unsigned enc)
7104 case DW_ATE_address:
7105 return "DW_ATE_address";
7106 case DW_ATE_boolean:
7107 return "DW_ATE_boolean";
7108 case DW_ATE_complex_float:
7109 return "DW_ATE_complex_float";
7111 return "DW_ATE_float";
7113 return "DW_ATE_signed";
7114 case DW_ATE_signed_char:
7115 return "DW_ATE_signed_char";
7116 case DW_ATE_unsigned:
7117 return "DW_ATE_unsigned";
7118 case DW_ATE_unsigned_char:
7119 return "DW_ATE_unsigned_char";
7120 case DW_ATE_imaginary_float:
7121 return "DW_ATE_imaginary_float";
7123 return "DW_ATE_<unknown>";
7127 /* Convert a DWARF call frame info operation to its string name. */
7131 dwarf_cfi_name (unsigned cfi_opc)
7135 case DW_CFA_advance_loc:
7136 return "DW_CFA_advance_loc";
7138 return "DW_CFA_offset";
7139 case DW_CFA_restore:
7140 return "DW_CFA_restore";
7142 return "DW_CFA_nop";
7143 case DW_CFA_set_loc:
7144 return "DW_CFA_set_loc";
7145 case DW_CFA_advance_loc1:
7146 return "DW_CFA_advance_loc1";
7147 case DW_CFA_advance_loc2:
7148 return "DW_CFA_advance_loc2";
7149 case DW_CFA_advance_loc4:
7150 return "DW_CFA_advance_loc4";
7151 case DW_CFA_offset_extended:
7152 return "DW_CFA_offset_extended";
7153 case DW_CFA_restore_extended:
7154 return "DW_CFA_restore_extended";
7155 case DW_CFA_undefined:
7156 return "DW_CFA_undefined";
7157 case DW_CFA_same_value:
7158 return "DW_CFA_same_value";
7159 case DW_CFA_register:
7160 return "DW_CFA_register";
7161 case DW_CFA_remember_state:
7162 return "DW_CFA_remember_state";
7163 case DW_CFA_restore_state:
7164 return "DW_CFA_restore_state";
7165 case DW_CFA_def_cfa:
7166 return "DW_CFA_def_cfa";
7167 case DW_CFA_def_cfa_register:
7168 return "DW_CFA_def_cfa_register";
7169 case DW_CFA_def_cfa_offset:
7170 return "DW_CFA_def_cfa_offset";
7173 case DW_CFA_def_cfa_expression:
7174 return "DW_CFA_def_cfa_expression";
7175 case DW_CFA_expression:
7176 return "DW_CFA_expression";
7177 case DW_CFA_offset_extended_sf:
7178 return "DW_CFA_offset_extended_sf";
7179 case DW_CFA_def_cfa_sf:
7180 return "DW_CFA_def_cfa_sf";
7181 case DW_CFA_def_cfa_offset_sf:
7182 return "DW_CFA_def_cfa_offset_sf";
7184 /* SGI/MIPS specific */
7185 case DW_CFA_MIPS_advance_loc8:
7186 return "DW_CFA_MIPS_advance_loc8";
7188 /* GNU extensions */
7189 case DW_CFA_GNU_window_save:
7190 return "DW_CFA_GNU_window_save";
7191 case DW_CFA_GNU_args_size:
7192 return "DW_CFA_GNU_args_size";
7193 case DW_CFA_GNU_negative_offset_extended:
7194 return "DW_CFA_GNU_negative_offset_extended";
7197 return "DW_CFA_<unknown>";
7203 dump_die (struct die_info *die)
7207 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7208 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7209 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7210 dwarf_bool_name (die->child != NULL));
7212 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7213 for (i = 0; i < die->num_attrs; ++i)
7215 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7216 dwarf_attr_name (die->attrs[i].name),
7217 dwarf_form_name (die->attrs[i].form));
7218 switch (die->attrs[i].form)
7220 case DW_FORM_ref_addr:
7222 fprintf_unfiltered (gdb_stderr, "address: ");
7223 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7225 case DW_FORM_block2:
7226 case DW_FORM_block4:
7228 case DW_FORM_block1:
7229 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7240 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7242 case DW_FORM_string:
7244 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7245 DW_STRING (&die->attrs[i])
7246 ? DW_STRING (&die->attrs[i]) : "");
7249 if (DW_UNSND (&die->attrs[i]))
7250 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7252 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7254 case DW_FORM_flag_present:
7255 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7257 case DW_FORM_indirect:
7258 /* the reader will have reduced the indirect form to
7259 the "base form" so this form should not occur */
7260 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7263 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7264 die->attrs[i].form);
7266 fprintf_unfiltered (gdb_stderr, "\n");
7271 dump_die_list (struct die_info *die)
7276 if (die->child != NULL)
7277 dump_die_list (die->child);
7278 if (die->sibling != NULL)
7279 dump_die_list (die->sibling);
7284 store_in_ref_table (unsigned int offset, struct die_info *die)
7287 struct die_info *old;
7289 h = (offset % REF_HASH_SIZE);
7290 old = die_ref_table[h];
7291 die->next_ref = old;
7292 die_ref_table[h] = die;
7297 dwarf2_empty_hash_tables (void)
7299 memset (die_ref_table, 0, sizeof (die_ref_table));
7303 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
7305 unsigned int result = 0;
7309 case DW_FORM_ref_addr:
7310 result = DW_ADDR (attr);
7316 case DW_FORM_ref_udata:
7317 result = cu->header.offset + DW_UNSND (attr);
7320 complaint (&symfile_complaints,
7321 "unsupported die ref attribute form: '%s'",
7322 dwarf_form_name (attr->form));
7327 /* Return the constant value held by the given attribute. Return -1
7328 if the value held by the attribute is not constant. */
7331 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7333 if (attr->form == DW_FORM_sdata)
7334 return DW_SND (attr);
7335 else if (attr->form == DW_FORM_udata
7336 || attr->form == DW_FORM_data1
7337 || attr->form == DW_FORM_data2
7338 || attr->form == DW_FORM_data4
7339 || attr->form == DW_FORM_data8)
7340 return DW_UNSND (attr);
7343 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
7344 dwarf_form_name (attr->form));
7345 return default_value;
7349 static struct die_info *
7350 follow_die_ref (unsigned int offset)
7352 struct die_info *die;
7355 h = (offset % REF_HASH_SIZE);
7356 die = die_ref_table[h];
7359 if (die->offset == offset)
7363 die = die->next_ref;
7368 static struct type *
7369 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
7370 struct dwarf2_cu *cu)
7372 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
7374 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7375 typeid, objfile->name);
7378 /* Look for this particular type in the fundamental type vector. If
7379 one is not found, create and install one appropriate for the
7380 current language and the current target machine. */
7382 if (cu->ftypes[typeid] == NULL)
7384 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
7387 return (cu->ftypes[typeid]);
7390 /* Decode simple location descriptions.
7391 Given a pointer to a dwarf block that defines a location, compute
7392 the location and return the value.
7394 NOTE drow/2003-11-18: This function is called in two situations
7395 now: for the address of static or global variables (partial symbols
7396 only) and for offsets into structures which are expected to be
7397 (more or less) constant. The partial symbol case should go away,
7398 and only the constant case should remain. That will let this
7399 function complain more accurately. A few special modes are allowed
7400 without complaint for global variables (for instance, global
7401 register values and thread-local values).
7403 A location description containing no operations indicates that the
7404 object is optimized out. The return value is 0 for that case.
7405 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7406 callers will only want a very basic result and this can become a
7409 When the result is a register number, the global isreg flag is set,
7410 otherwise it is cleared.
7412 Note that stack[0] is unused except as a default error return.
7413 Note that stack overflow is not yet handled. */
7416 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
7418 struct objfile *objfile = cu->objfile;
7419 struct comp_unit_head *cu_header = &cu->header;
7421 int size = blk->size;
7422 char *data = blk->data;
7423 CORE_ADDR stack[64];
7425 unsigned int bytes_read, unsnd;
7470 stack[++stacki] = op - DW_OP_lit0;
7506 stack[++stacki] = op - DW_OP_reg0;
7508 dwarf2_complex_location_expr_complaint ();
7513 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7515 stack[++stacki] = unsnd;
7517 dwarf2_complex_location_expr_complaint ();
7521 stack[++stacki] = read_address (objfile->obfd, &data[i],
7527 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
7532 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
7537 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
7542 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
7547 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
7552 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
7557 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
7563 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
7568 stack[stacki + 1] = stack[stacki];
7573 stack[stacki - 1] += stack[stacki];
7577 case DW_OP_plus_uconst:
7578 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7583 stack[stacki - 1] -= stack[stacki];
7588 /* If we're not the last op, then we definitely can't encode
7589 this using GDB's address_class enum. This is valid for partial
7590 global symbols, although the variable's address will be bogus
7593 dwarf2_complex_location_expr_complaint ();
7596 case DW_OP_GNU_push_tls_address:
7597 /* The top of the stack has the offset from the beginning
7598 of the thread control block at which the variable is located. */
7599 /* Nothing should follow this operator, so the top of stack would
7601 /* This is valid for partial global symbols, but the variable's
7602 address will be bogus in the psymtab. */
7604 dwarf2_complex_location_expr_complaint ();
7608 complaint (&symfile_complaints, "unsupported stack op: '%s'",
7609 dwarf_stack_op_name (op));
7610 return (stack[stacki]);
7613 return (stack[stacki]);
7616 /* memory allocation interface */
7619 dwarf2_free_tmp_obstack (void *ignore)
7621 obstack_free (&dwarf2_tmp_obstack, NULL);
7624 static struct dwarf_block *
7625 dwarf_alloc_block (void)
7627 struct dwarf_block *blk;
7629 blk = (struct dwarf_block *)
7630 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
7634 static struct abbrev_info *
7635 dwarf_alloc_abbrev (void)
7637 struct abbrev_info *abbrev;
7639 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
7640 memset (abbrev, 0, sizeof (struct abbrev_info));
7644 static struct die_info *
7645 dwarf_alloc_die (void)
7647 struct die_info *die;
7649 die = (struct die_info *) xmalloc (sizeof (struct die_info));
7650 memset (die, 0, sizeof (struct die_info));
7655 /* Macro support. */
7658 /* Return the full name of file number I in *LH's file name table.
7659 Use COMP_DIR as the name of the current directory of the
7660 compilation. The result is allocated using xmalloc; the caller is
7661 responsible for freeing it. */
7663 file_full_name (int file, struct line_header *lh, const char *comp_dir)
7665 struct file_entry *fe = &lh->file_names[file - 1];
7667 if (IS_ABSOLUTE_PATH (fe->name))
7668 return xstrdup (fe->name);
7676 dir = lh->include_dirs[fe->dir_index - 1];
7682 dir_len = strlen (dir);
7683 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
7684 strcpy (full_name, dir);
7685 full_name[dir_len] = '/';
7686 strcpy (full_name + dir_len + 1, fe->name);
7690 return xstrdup (fe->name);
7695 static struct macro_source_file *
7696 macro_start_file (int file, int line,
7697 struct macro_source_file *current_file,
7698 const char *comp_dir,
7699 struct line_header *lh, struct objfile *objfile)
7701 /* The full name of this source file. */
7702 char *full_name = file_full_name (file, lh, comp_dir);
7704 /* We don't create a macro table for this compilation unit
7705 at all until we actually get a filename. */
7706 if (! pending_macros)
7707 pending_macros = new_macro_table (&objfile->objfile_obstack,
7708 objfile->macro_cache);
7711 /* If we have no current file, then this must be the start_file
7712 directive for the compilation unit's main source file. */
7713 current_file = macro_set_main (pending_macros, full_name);
7715 current_file = macro_include (current_file, line, full_name);
7719 return current_file;
7723 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7724 followed by a null byte. */
7726 copy_string (const char *buf, int len)
7728 char *s = xmalloc (len + 1);
7729 memcpy (s, buf, len);
7737 consume_improper_spaces (const char *p, const char *body)
7741 complaint (&symfile_complaints,
7742 "macro definition contains spaces in formal argument list:\n`%s'",
7754 parse_macro_definition (struct macro_source_file *file, int line,
7759 /* The body string takes one of two forms. For object-like macro
7760 definitions, it should be:
7762 <macro name> " " <definition>
7764 For function-like macro definitions, it should be:
7766 <macro name> "() " <definition>
7768 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7770 Spaces may appear only where explicitly indicated, and in the
7773 The Dwarf 2 spec says that an object-like macro's name is always
7774 followed by a space, but versions of GCC around March 2002 omit
7775 the space when the macro's definition is the empty string.
7777 The Dwarf 2 spec says that there should be no spaces between the
7778 formal arguments in a function-like macro's formal argument list,
7779 but versions of GCC around March 2002 include spaces after the
7783 /* Find the extent of the macro name. The macro name is terminated
7784 by either a space or null character (for an object-like macro) or
7785 an opening paren (for a function-like macro). */
7786 for (p = body; *p; p++)
7787 if (*p == ' ' || *p == '(')
7790 if (*p == ' ' || *p == '\0')
7792 /* It's an object-like macro. */
7793 int name_len = p - body;
7794 char *name = copy_string (body, name_len);
7795 const char *replacement;
7798 replacement = body + name_len + 1;
7801 dwarf2_macro_malformed_definition_complaint (body);
7802 replacement = body + name_len;
7805 macro_define_object (file, line, name, replacement);
7811 /* It's a function-like macro. */
7812 char *name = copy_string (body, p - body);
7815 char **argv = xmalloc (argv_size * sizeof (*argv));
7819 p = consume_improper_spaces (p, body);
7821 /* Parse the formal argument list. */
7822 while (*p && *p != ')')
7824 /* Find the extent of the current argument name. */
7825 const char *arg_start = p;
7827 while (*p && *p != ',' && *p != ')' && *p != ' ')
7830 if (! *p || p == arg_start)
7831 dwarf2_macro_malformed_definition_complaint (body);
7834 /* Make sure argv has room for the new argument. */
7835 if (argc >= argv_size)
7838 argv = xrealloc (argv, argv_size * sizeof (*argv));
7841 argv[argc++] = copy_string (arg_start, p - arg_start);
7844 p = consume_improper_spaces (p, body);
7846 /* Consume the comma, if present. */
7851 p = consume_improper_spaces (p, body);
7860 /* Perfectly formed definition, no complaints. */
7861 macro_define_function (file, line, name,
7862 argc, (const char **) argv,
7864 else if (*p == '\0')
7866 /* Complain, but do define it. */
7867 dwarf2_macro_malformed_definition_complaint (body);
7868 macro_define_function (file, line, name,
7869 argc, (const char **) argv,
7873 /* Just complain. */
7874 dwarf2_macro_malformed_definition_complaint (body);
7877 /* Just complain. */
7878 dwarf2_macro_malformed_definition_complaint (body);
7884 for (i = 0; i < argc; i++)
7890 dwarf2_macro_malformed_definition_complaint (body);
7895 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7896 char *comp_dir, bfd *abfd,
7897 struct dwarf2_cu *cu)
7899 char *mac_ptr, *mac_end;
7900 struct macro_source_file *current_file = 0;
7902 if (dwarf_macinfo_buffer == NULL)
7904 complaint (&symfile_complaints, "missing .debug_macinfo section");
7908 mac_ptr = dwarf_macinfo_buffer + offset;
7909 mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size;
7913 enum dwarf_macinfo_record_type macinfo_type;
7915 /* Do we at least have room for a macinfo type byte? */
7916 if (mac_ptr >= mac_end)
7918 dwarf2_macros_too_long_complaint ();
7922 macinfo_type = read_1_byte (abfd, mac_ptr);
7925 switch (macinfo_type)
7927 /* A zero macinfo type indicates the end of the macro
7932 case DW_MACINFO_define:
7933 case DW_MACINFO_undef:
7939 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7940 mac_ptr += bytes_read;
7941 body = read_string (abfd, mac_ptr, &bytes_read);
7942 mac_ptr += bytes_read;
7945 complaint (&symfile_complaints,
7946 "debug info gives macro %s outside of any file: %s",
7948 DW_MACINFO_define ? "definition" : macinfo_type ==
7949 DW_MACINFO_undef ? "undefinition" :
7950 "something-or-other", body);
7953 if (macinfo_type == DW_MACINFO_define)
7954 parse_macro_definition (current_file, line, body);
7955 else if (macinfo_type == DW_MACINFO_undef)
7956 macro_undef (current_file, line, body);
7961 case DW_MACINFO_start_file:
7966 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7967 mac_ptr += bytes_read;
7968 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7969 mac_ptr += bytes_read;
7971 current_file = macro_start_file (file, line,
7972 current_file, comp_dir,
7977 case DW_MACINFO_end_file:
7979 complaint (&symfile_complaints,
7980 "macro debug info has an unmatched `close_file' directive");
7983 current_file = current_file->included_by;
7986 enum dwarf_macinfo_record_type next_type;
7988 /* GCC circa March 2002 doesn't produce the zero
7989 type byte marking the end of the compilation
7990 unit. Complain if it's not there, but exit no
7993 /* Do we at least have room for a macinfo type byte? */
7994 if (mac_ptr >= mac_end)
7996 dwarf2_macros_too_long_complaint ();
8000 /* We don't increment mac_ptr here, so this is just
8002 next_type = read_1_byte (abfd, mac_ptr);
8004 complaint (&symfile_complaints,
8005 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8012 case DW_MACINFO_vendor_ext:
8018 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8019 mac_ptr += bytes_read;
8020 string = read_string (abfd, mac_ptr, &bytes_read);
8021 mac_ptr += bytes_read;
8023 /* We don't recognize any vendor extensions. */
8030 /* Check if the attribute's form is a DW_FORM_block*
8031 if so return true else false. */
8033 attr_form_is_block (struct attribute *attr)
8035 return (attr == NULL ? 0 :
8036 attr->form == DW_FORM_block1
8037 || attr->form == DW_FORM_block2
8038 || attr->form == DW_FORM_block4
8039 || attr->form == DW_FORM_block);
8043 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
8044 struct dwarf2_cu *cu)
8046 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
8048 struct dwarf2_loclist_baton *baton;
8050 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8051 sizeof (struct dwarf2_loclist_baton));
8052 baton->objfile = cu->objfile;
8054 /* We don't know how long the location list is, but make sure we
8055 don't run off the edge of the section. */
8056 baton->size = dwarf_loc_size - DW_UNSND (attr);
8057 baton->data = dwarf_loc_buffer + DW_UNSND (attr);
8058 baton->base_address = cu->header.base_address;
8059 if (cu->header.base_known == 0)
8060 complaint (&symfile_complaints,
8061 "Location list used without specifying the CU base address.");
8063 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
8064 SYMBOL_LOCATION_BATON (sym) = baton;
8068 struct dwarf2_locexpr_baton *baton;
8070 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8071 sizeof (struct dwarf2_locexpr_baton));
8072 baton->objfile = cu->objfile;
8074 if (attr_form_is_block (attr))
8076 /* Note that we're just copying the block's data pointer
8077 here, not the actual data. We're still pointing into the
8078 dwarf_info_buffer for SYM's objfile; right now we never
8079 release that buffer, but when we do clean up properly
8080 this may need to change. */
8081 baton->size = DW_BLOCK (attr)->size;
8082 baton->data = DW_BLOCK (attr)->data;
8086 dwarf2_invalid_attrib_class_complaint ("location description",
8087 SYMBOL_NATURAL_NAME (sym));
8092 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
8093 SYMBOL_LOCATION_BATON (sym) = baton;