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_unspecified_type (struct die_info *, struct dwarf2_cu *);
830 static void read_tag_ptr_to_member_type (struct die_info *,
833 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
835 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
837 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
839 static void read_tag_restrict_type (struct die_info *, struct dwarf2_cu *);
841 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
843 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
845 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
847 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
850 struct die_info *parent);
852 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
855 struct die_info *parent);
857 static void free_die_list (struct die_info *);
859 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
861 static void process_die (struct die_info *, struct dwarf2_cu *);
863 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
865 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
867 static struct die_info *dwarf2_extension (struct die_info *die,
870 static char *dwarf_tag_name (unsigned int);
872 static char *dwarf_attr_name (unsigned int);
874 static char *dwarf_form_name (unsigned int);
876 static char *dwarf_stack_op_name (unsigned int);
878 static char *dwarf_bool_name (unsigned int);
880 static char *dwarf_type_encoding_name (unsigned int);
883 static char *dwarf_cfi_name (unsigned int);
885 struct die_info *copy_die (struct die_info *);
888 static struct die_info *sibling_die (struct die_info *);
890 static void dump_die (struct die_info *);
892 static void dump_die_list (struct die_info *);
894 static void store_in_ref_table (unsigned int, struct die_info *);
896 static void dwarf2_empty_hash_tables (void);
898 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
901 static int dwarf2_get_attr_constant_value (struct attribute *, int);
903 static struct die_info *follow_die_ref (unsigned int);
905 static struct type *dwarf2_fundamental_type (struct objfile *, int,
908 /* memory allocation interface */
910 static void dwarf2_free_tmp_obstack (void *);
912 static struct dwarf_block *dwarf_alloc_block (void);
914 static struct abbrev_info *dwarf_alloc_abbrev (void);
916 static struct die_info *dwarf_alloc_die (void);
918 static void initialize_cu_func_list (struct dwarf2_cu *);
920 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
923 static void dwarf_decode_macros (struct line_header *, unsigned int,
924 char *, bfd *, struct dwarf2_cu *);
926 static int attr_form_is_block (struct attribute *);
929 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
930 struct dwarf2_cu *cu);
932 /* Try to locate the sections we need for DWARF 2 debugging
933 information and return true if we have enough to do something. */
936 dwarf2_has_info (bfd *abfd)
938 dwarf_info_section = 0;
939 dwarf_abbrev_section = 0;
940 dwarf_line_section = 0;
941 dwarf_str_section = 0;
942 dwarf_macinfo_section = 0;
943 dwarf_frame_section = 0;
944 dwarf_eh_frame_section = 0;
945 dwarf_ranges_section = 0;
946 dwarf_loc_section = 0;
948 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
949 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
952 /* This function is mapped across the sections and remembers the
953 offset and size of each of the debugging sections we are interested
957 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
959 if (strcmp (sectp->name, INFO_SECTION) == 0)
961 dwarf_info_size = bfd_get_section_size (sectp);
962 dwarf_info_section = sectp;
964 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
966 dwarf_abbrev_size = bfd_get_section_size (sectp);
967 dwarf_abbrev_section = sectp;
969 else if (strcmp (sectp->name, LINE_SECTION) == 0)
971 dwarf_line_size = bfd_get_section_size (sectp);
972 dwarf_line_section = sectp;
974 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
976 dwarf_pubnames_size = bfd_get_section_size (sectp);
977 dwarf_pubnames_section = sectp;
979 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
981 dwarf_aranges_size = bfd_get_section_size (sectp);
982 dwarf_aranges_section = sectp;
984 else if (strcmp (sectp->name, LOC_SECTION) == 0)
986 dwarf_loc_size = bfd_get_section_size (sectp);
987 dwarf_loc_section = sectp;
989 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
991 dwarf_macinfo_size = bfd_get_section_size (sectp);
992 dwarf_macinfo_section = sectp;
994 else if (strcmp (sectp->name, STR_SECTION) == 0)
996 dwarf_str_size = bfd_get_section_size (sectp);
997 dwarf_str_section = sectp;
999 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
1001 dwarf_frame_size = bfd_get_section_size (sectp);
1002 dwarf_frame_section = sectp;
1004 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1006 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1007 if (aflag & SEC_HAS_CONTENTS)
1009 dwarf_eh_frame_size = bfd_get_section_size (sectp);
1010 dwarf_eh_frame_section = sectp;
1013 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1015 dwarf_ranges_size = bfd_get_section_size (sectp);
1016 dwarf_ranges_section = sectp;
1020 /* Build a partial symbol table. */
1023 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1026 /* We definitely need the .debug_info and .debug_abbrev sections */
1028 dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1029 dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1031 if (dwarf_line_section)
1032 dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1034 dwarf_line_buffer = NULL;
1036 if (dwarf_str_section)
1037 dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1039 dwarf_str_buffer = NULL;
1041 if (dwarf_macinfo_section)
1042 dwarf_macinfo_buffer = dwarf2_read_section (objfile,
1043 dwarf_macinfo_section);
1045 dwarf_macinfo_buffer = NULL;
1047 if (dwarf_ranges_section)
1048 dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1050 dwarf_ranges_buffer = NULL;
1052 if (dwarf_loc_section)
1053 dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1055 dwarf_loc_buffer = NULL;
1058 || (objfile->global_psymbols.size == 0
1059 && objfile->static_psymbols.size == 0))
1061 init_psymbol_list (objfile, 1024);
1065 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1067 /* Things are significantly easier if we have .debug_aranges and
1068 .debug_pubnames sections */
1070 dwarf2_build_psymtabs_easy (objfile, mainline);
1074 /* only test this case for now */
1076 /* In this case we have to work a bit harder */
1077 dwarf2_build_psymtabs_hard (objfile, mainline);
1082 /* Build the partial symbol table from the information in the
1083 .debug_pubnames and .debug_aranges sections. */
1086 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1088 bfd *abfd = objfile->obfd;
1089 char *aranges_buffer, *pubnames_buffer;
1090 char *aranges_ptr, *pubnames_ptr;
1091 unsigned int entry_length, version, info_offset, info_size;
1093 pubnames_buffer = dwarf2_read_section (objfile,
1094 dwarf_pubnames_section);
1095 pubnames_ptr = pubnames_buffer;
1096 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
1098 struct comp_unit_head cu_header;
1101 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1103 pubnames_ptr += bytes_read;
1104 version = read_1_byte (abfd, pubnames_ptr);
1106 info_offset = read_4_bytes (abfd, pubnames_ptr);
1108 info_size = read_4_bytes (abfd, pubnames_ptr);
1112 aranges_buffer = dwarf2_read_section (objfile,
1113 dwarf_aranges_section);
1118 /* Read in the comp unit header information from the debug_info at
1122 read_comp_unit_head (struct comp_unit_head *cu_header,
1123 char *info_ptr, bfd *abfd)
1127 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1129 info_ptr += bytes_read;
1130 cu_header->version = read_2_bytes (abfd, info_ptr);
1132 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1134 info_ptr += bytes_read;
1135 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1137 signed_addr = bfd_get_sign_extend_vma (abfd);
1138 if (signed_addr < 0)
1139 internal_error (__FILE__, __LINE__,
1140 "read_comp_unit_head: dwarf from non elf file");
1141 cu_header->signed_addr_p = signed_addr;
1145 /* Build the partial symbol table by doing a quick pass through the
1146 .debug_info and .debug_abbrev sections. */
1149 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1151 /* Instead of reading this into a big buffer, we should probably use
1152 mmap() on architectures that support it. (FIXME) */
1153 bfd *abfd = objfile->obfd;
1154 char *info_ptr, *abbrev_ptr;
1155 char *beg_of_comp_unit;
1156 struct partial_die_info comp_unit_die;
1157 struct partial_symtab *pst;
1158 struct cleanup *back_to;
1159 CORE_ADDR lowpc, highpc, baseaddr;
1161 info_ptr = dwarf_info_buffer;
1162 abbrev_ptr = dwarf_abbrev_buffer;
1164 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1165 the partial symbol scan, like attribute values.
1167 We could reduce our peak memory consumption during partial symbol
1168 table construction by freeing stuff from this obstack more often
1169 --- say, after processing each compilation unit, or each die ---
1170 but it turns out that this saves almost nothing. For an
1171 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1172 on dwarf2_tmp_obstack. Some investigation showed:
1174 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1175 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1176 all fixed-length values not requiring dynamic allocation.
1178 2) 30% of the attributes used the form DW_FORM_string. For
1179 DW_FORM_string, read_attribute simply hands back a pointer to
1180 the null-terminated string in dwarf_info_buffer, so no dynamic
1181 allocation is needed there either.
1183 3) The remaining 1% of the attributes all used DW_FORM_block1.
1184 75% of those were DW_AT_frame_base location lists for
1185 functions; the rest were DW_AT_location attributes, probably
1186 for the global variables.
1188 Anyway, what this all means is that the memory the dwarf2
1189 reader uses as temporary space reading partial symbols is about
1190 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1192 obstack_init (&dwarf2_tmp_obstack);
1193 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1195 /* Since the objects we're extracting from dwarf_info_buffer vary in
1196 length, only the individual functions to extract them (like
1197 read_comp_unit_head and read_partial_die) can really know whether
1198 the buffer is large enough to hold another complete object.
1200 At the moment, they don't actually check that. If
1201 dwarf_info_buffer holds just one extra byte after the last
1202 compilation unit's dies, then read_comp_unit_head will happily
1203 read off the end of the buffer. read_partial_die is similarly
1204 casual. Those functions should be fixed.
1206 For this loop condition, simply checking whether there's any data
1207 left at all should be sufficient. */
1208 while (info_ptr < dwarf_info_buffer + dwarf_info_size)
1210 struct dwarf2_cu cu;
1211 beg_of_comp_unit = info_ptr;
1213 cu.objfile = objfile;
1214 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1216 if (cu.header.version != 2)
1218 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));
1221 if (cu.header.abbrev_offset >= dwarf_abbrev_size)
1223 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1224 (long) cu.header.abbrev_offset,
1225 (long) (beg_of_comp_unit - dwarf_info_buffer),
1226 bfd_get_filename (abfd));
1229 if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size
1230 > dwarf_info_buffer + dwarf_info_size)
1232 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1233 (long) cu.header.length,
1234 (long) (beg_of_comp_unit - dwarf_info_buffer),
1235 bfd_get_filename (abfd));
1238 /* Complete the cu_header */
1239 cu.header.offset = beg_of_comp_unit - dwarf_info_buffer;
1240 cu.header.first_die_ptr = info_ptr;
1241 cu.header.cu_head_ptr = beg_of_comp_unit;
1243 cu.list_in_scope = &file_symbols;
1245 /* Read the abbrevs for this compilation unit into a table */
1246 dwarf2_read_abbrevs (abfd, &cu);
1247 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1249 /* Read the compilation unit die */
1250 info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr,
1253 /* Set the language we're debugging */
1254 set_cu_language (comp_unit_die.language, &cu);
1256 /* Allocate a new partial symbol table structure */
1257 pst = start_psymtab_common (objfile, objfile->section_offsets,
1258 comp_unit_die.name ? comp_unit_die.name : "",
1259 comp_unit_die.lowpc,
1260 objfile->global_psymbols.next,
1261 objfile->static_psymbols.next);
1263 pst->read_symtab_private = (char *)
1264 obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
1265 DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
1266 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
1267 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
1268 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
1269 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
1270 DWARF_LINE_SIZE (pst) = dwarf_line_size;
1271 DWARF_STR_BUFFER (pst) = dwarf_str_buffer;
1272 DWARF_STR_SIZE (pst) = dwarf_str_size;
1273 DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer;
1274 DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size;
1275 DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer;
1276 DWARF_RANGES_SIZE (pst) = dwarf_ranges_size;
1277 DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer;
1278 DWARF_LOC_SIZE (pst) = dwarf_loc_size;
1279 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1281 /* Store the function that reads in the rest of the symbol table */
1282 pst->read_symtab = dwarf2_psymtab_to_symtab;
1284 /* Check if comp unit has_children.
1285 If so, read the rest of the partial symbols from this comp unit.
1286 If not, there's no more debug_info for this comp unit. */
1287 if (comp_unit_die.has_children)
1289 lowpc = ((CORE_ADDR) -1);
1290 highpc = ((CORE_ADDR) 0);
1292 info_ptr = scan_partial_symbols (info_ptr, &lowpc, &highpc,
1295 /* If we didn't find a lowpc, set it to highpc to avoid
1296 complaints from `maint check'. */
1297 if (lowpc == ((CORE_ADDR) -1))
1300 /* If the compilation unit didn't have an explicit address range,
1301 then use the information extracted from its child dies. */
1302 if (! comp_unit_die.has_pc_info)
1304 comp_unit_die.lowpc = lowpc;
1305 comp_unit_die.highpc = highpc;
1308 pst->textlow = comp_unit_die.lowpc + baseaddr;
1309 pst->texthigh = comp_unit_die.highpc + baseaddr;
1311 pst->n_global_syms = objfile->global_psymbols.next -
1312 (objfile->global_psymbols.list + pst->globals_offset);
1313 pst->n_static_syms = objfile->static_psymbols.next -
1314 (objfile->static_psymbols.list + pst->statics_offset);
1315 sort_pst_symbols (pst);
1317 /* If there is already a psymtab or symtab for a file of this
1318 name, remove it. (If there is a symtab, more drastic things
1319 also happen.) This happens in VxWorks. */
1320 free_named_symtabs (pst->filename);
1322 info_ptr = beg_of_comp_unit + cu.header.length
1323 + cu.header.initial_length_size;
1325 do_cleanups (back_to);
1328 /* Read in all interesting dies to the end of the compilation unit or
1329 to the end of the current namespace. NAMESPACE is NULL if we
1330 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1331 it's the name of the current namespace. In particular, it's the
1332 empty string if we're currently in the global namespace but have
1333 previously encountered a DW_TAG_namespace. */
1336 scan_partial_symbols (char *info_ptr, CORE_ADDR *lowpc,
1337 CORE_ADDR *highpc, struct dwarf2_cu *cu,
1338 const char *namespace)
1340 struct objfile *objfile = cu->objfile;
1341 bfd *abfd = objfile->obfd;
1342 struct partial_die_info pdi;
1344 /* Now, march along the PDI's, descending into ones which have
1345 interesting children but skipping the children of the other ones,
1346 until we reach the end of the compilation unit. */
1350 /* This flag tells whether or not info_ptr has gotten updated
1352 int info_ptr_updated = 0;
1354 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1356 /* Anonymous namespaces have no name but have interesting
1357 children, so we need to look at them. Ditto for anonymous
1360 if (pdi.name != NULL || pdi.tag == DW_TAG_namespace
1361 || pdi.tag == DW_TAG_enumeration_type)
1365 case DW_TAG_subprogram:
1366 if (pdi.has_pc_info)
1368 if (pdi.lowpc < *lowpc)
1372 if (pdi.highpc > *highpc)
1374 *highpc = pdi.highpc;
1376 if (!pdi.is_declaration)
1378 add_partial_symbol (&pdi, cu, namespace);
1382 case DW_TAG_variable:
1383 case DW_TAG_typedef:
1384 case DW_TAG_union_type:
1385 if (!pdi.is_declaration)
1387 add_partial_symbol (&pdi, cu, namespace);
1390 case DW_TAG_class_type:
1391 case DW_TAG_structure_type:
1392 if (!pdi.is_declaration)
1394 info_ptr = add_partial_structure (&pdi, info_ptr, cu,
1396 info_ptr_updated = 1;
1399 case DW_TAG_enumeration_type:
1400 if (!pdi.is_declaration)
1402 info_ptr = add_partial_enumeration (&pdi, info_ptr, cu,
1404 info_ptr_updated = 1;
1407 case DW_TAG_base_type:
1408 case DW_TAG_subrange_type:
1409 /* File scope base type definitions are added to the partial
1411 add_partial_symbol (&pdi, cu, namespace);
1413 case DW_TAG_namespace:
1414 /* We've hit a DW_TAG_namespace entry, so we know this
1415 file has been compiled using a compiler that
1416 generates them; update NAMESPACE to reflect that. */
1417 if (namespace == NULL)
1419 info_ptr = add_partial_namespace (&pdi, info_ptr, lowpc, highpc,
1421 info_ptr_updated = 1;
1431 /* If the die has a sibling, skip to the sibling, unless another
1432 function has already updated info_ptr for us. */
1434 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1435 or not we want to update this depends on enough stuff (not
1436 only pdi.tag but also whether or not pdi.name is NULL) that
1437 this seems like the easiest way to handle the issue. */
1439 if (!info_ptr_updated)
1440 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1447 add_partial_symbol (struct partial_die_info *pdi,
1448 struct dwarf2_cu *cu, const char *namespace)
1450 struct objfile *objfile = cu->objfile;
1452 char *actual_name = pdi->name;
1453 const struct partial_symbol *psym = NULL;
1456 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1458 /* If we're not in the global namespace and if the namespace name
1459 isn't encoded in a mangled actual_name, add it. */
1461 if (pdi_needs_namespace (pdi->tag, namespace))
1463 actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1);
1464 strcpy (actual_name, namespace);
1465 strcat (actual_name, "::");
1466 strcat (actual_name, pdi->name);
1471 case DW_TAG_subprogram:
1472 if (pdi->is_external)
1474 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1475 mst_text, objfile); */
1476 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1477 VAR_DOMAIN, LOC_BLOCK,
1478 &objfile->global_psymbols,
1479 0, pdi->lowpc + baseaddr,
1480 cu->language, objfile);
1484 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1485 mst_file_text, objfile); */
1486 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1487 VAR_DOMAIN, LOC_BLOCK,
1488 &objfile->static_psymbols,
1489 0, pdi->lowpc + baseaddr,
1490 cu->language, objfile);
1493 case DW_TAG_variable:
1494 if (pdi->is_external)
1497 Don't enter into the minimal symbol tables as there is
1498 a minimal symbol table entry from the ELF symbols already.
1499 Enter into partial symbol table if it has a location
1500 descriptor or a type.
1501 If the location descriptor is missing, new_symbol will create
1502 a LOC_UNRESOLVED symbol, the address of the variable will then
1503 be determined from the minimal symbol table whenever the variable
1505 The address for the partial symbol table entry is not
1506 used by GDB, but it comes in handy for debugging partial symbol
1510 addr = decode_locdesc (pdi->locdesc, cu);
1511 if (pdi->locdesc || pdi->has_type)
1512 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1513 VAR_DOMAIN, LOC_STATIC,
1514 &objfile->global_psymbols,
1516 cu->language, objfile);
1520 /* Static Variable. Skip symbols without location descriptors. */
1521 if (pdi->locdesc == NULL)
1523 addr = decode_locdesc (pdi->locdesc, cu);
1524 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1525 mst_file_data, objfile); */
1526 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1527 VAR_DOMAIN, LOC_STATIC,
1528 &objfile->static_psymbols,
1530 cu->language, objfile);
1533 case DW_TAG_typedef:
1534 case DW_TAG_base_type:
1535 case DW_TAG_subrange_type:
1536 add_psymbol_to_list (actual_name, strlen (actual_name),
1537 VAR_DOMAIN, LOC_TYPEDEF,
1538 &objfile->static_psymbols,
1539 0, (CORE_ADDR) 0, cu->language, objfile);
1541 case DW_TAG_class_type:
1542 case DW_TAG_structure_type:
1543 case DW_TAG_union_type:
1544 case DW_TAG_enumeration_type:
1545 /* Skip aggregate types without children, these are external
1547 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1548 static vs. global. */
1549 if (pdi->has_children == 0)
1551 add_psymbol_to_list (actual_name, strlen (actual_name),
1552 STRUCT_DOMAIN, LOC_TYPEDEF,
1553 cu->language == language_cplus
1554 ? &objfile->global_psymbols
1555 : &objfile->static_psymbols,
1556 0, (CORE_ADDR) 0, cu->language, objfile);
1558 if (cu->language == language_cplus)
1560 /* For C++, these implicitly act as typedefs as well. */
1561 add_psymbol_to_list (actual_name, strlen (actual_name),
1562 VAR_DOMAIN, LOC_TYPEDEF,
1563 &objfile->global_psymbols,
1564 0, (CORE_ADDR) 0, cu->language, objfile);
1567 case DW_TAG_enumerator:
1568 add_psymbol_to_list (actual_name, strlen (actual_name),
1569 VAR_DOMAIN, LOC_CONST,
1570 cu->language == language_cplus
1571 ? &objfile->global_psymbols
1572 : &objfile->static_psymbols,
1573 0, (CORE_ADDR) 0, cu->language, objfile);
1579 /* Check to see if we should scan the name for possible namespace
1580 info. Only do this if this is C++, if we don't have namespace
1581 debugging info in the file, if the psym is of an appropriate type
1582 (otherwise we'll have psym == NULL), and if we actually had a
1583 mangled name to begin with. */
1585 if (cu->language == language_cplus
1586 && namespace == NULL
1588 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1589 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1593 /* Determine whether a die of type TAG living in the C++ namespace
1594 NAMESPACE needs to have the name of the namespace prepended to the
1595 name listed in the die. */
1598 pdi_needs_namespace (enum dwarf_tag tag, const char *namespace)
1600 if (namespace == NULL || namespace[0] == '\0')
1605 case DW_TAG_typedef:
1606 case DW_TAG_class_type:
1607 case DW_TAG_structure_type:
1608 case DW_TAG_union_type:
1609 case DW_TAG_enumeration_type:
1610 case DW_TAG_enumerator:
1617 /* Read a partial die corresponding to a namespace; also, add a symbol
1618 corresponding to that namespace to the symbol table. NAMESPACE is
1619 the name of the enclosing namespace. */
1622 add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
1623 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1624 struct dwarf2_cu *cu, const char *namespace)
1626 struct objfile *objfile = cu->objfile;
1627 const char *new_name = pdi->name;
1630 /* Calculate the full name of the namespace that we just entered. */
1632 if (new_name == NULL)
1633 new_name = "(anonymous namespace)";
1634 full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1);
1635 strcpy (full_name, namespace);
1636 if (*namespace != '\0')
1637 strcat (full_name, "::");
1638 strcat (full_name, new_name);
1640 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1641 to add_partial_symbol, because we don't have a way to pass in the
1642 full name to that function; that might be a flaw in
1643 add_partial_symbol's interface. */
1645 add_psymbol_to_list (full_name, strlen (full_name),
1646 VAR_DOMAIN, LOC_TYPEDEF,
1647 &objfile->global_psymbols,
1648 0, 0, cu->language, objfile);
1650 /* Now scan partial symbols in that namespace. */
1652 if (pdi->has_children)
1653 info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name);
1658 /* Read a partial die corresponding to a class or structure. */
1661 add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
1662 struct dwarf2_cu *cu,
1663 const char *namespace)
1665 bfd *abfd = cu->objfile->obfd;
1666 char *actual_class_name = NULL;
1668 if (cu->language == language_cplus
1669 && (namespace == NULL || namespace[0] == '\0')
1670 && struct_pdi->name != NULL
1671 && struct_pdi->has_children)
1673 /* See if we can figure out if the class lives in a namespace
1674 (or is nested within another class.) We do this by looking
1675 for a member function; its demangled name will contain
1676 namespace info, if there is any. */
1678 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1679 what template types look like, because the demangler
1680 frequently doesn't give the same name as the debug info. We
1681 could fix this by only using the demangled name to get the
1682 prefix (but see comment in read_structure_type). */
1684 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1685 the appropriate debug information, so it would be nice to be
1686 able to avoid this hack. But NAMESPACE may not be the
1687 namespace where this class was defined: NAMESPACE reflects
1688 where STRUCT_PDI occurs in the tree of dies, but because of
1689 DW_AT_specification, that may not actually tell us where the
1690 class is defined. (See the comment in read_func_scope for an
1691 example of how this could occur.)
1693 Unfortunately, our current partial symtab data structures are
1694 completely unable to deal with DW_AT_specification. So, for
1695 now, the best thing to do is to get nesting information from
1696 places other than the tree structure of dies if there's any
1697 chance that a DW_AT_specification is involved. :-( */
1699 char *next_child = info_ptr;
1703 struct partial_die_info child_pdi;
1705 next_child = read_partial_die (&child_pdi, abfd, next_child,
1709 if (child_pdi.tag == DW_TAG_subprogram)
1711 actual_class_name = class_name_from_physname (child_pdi.name);
1712 if (actual_class_name != NULL)
1713 struct_pdi->name = actual_class_name;
1718 next_child = locate_pdi_sibling (&child_pdi, next_child,
1724 add_partial_symbol (struct_pdi, cu, namespace);
1725 xfree (actual_class_name);
1727 return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu);
1730 /* Read a partial die corresponding to an enumeration type. */
1733 add_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr,
1734 struct dwarf2_cu *cu, const char *namespace)
1736 struct objfile *objfile = cu->objfile;
1737 bfd *abfd = objfile->obfd;
1738 struct partial_die_info pdi;
1740 if (enum_pdi->name != NULL)
1741 add_partial_symbol (enum_pdi, cu, namespace);
1745 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1748 if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL)
1749 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1751 add_partial_symbol (&pdi, cu, namespace);
1757 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1761 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
1762 bfd *abfd, struct dwarf2_cu *cu)
1764 /* Do we know the sibling already? */
1766 if (orig_pdi->sibling)
1767 return orig_pdi->sibling;
1769 /* Are there any children to deal with? */
1771 if (!orig_pdi->has_children)
1774 /* Okay, we don't know the sibling, but we have children that we
1775 want to skip. So read children until we run into one without a
1776 tag; return whatever follows it. */
1780 struct partial_die_info pdi;
1782 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1787 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1791 /* Expand this partial symbol table into a full symbol table. */
1794 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
1796 /* FIXME: This is barely more than a stub. */
1801 warning ("bug: psymtab for %s is already read in.", pst->filename);
1807 printf_filtered ("Reading in symbols for %s...", pst->filename);
1808 gdb_flush (gdb_stdout);
1811 psymtab_to_symtab_1 (pst);
1813 /* Finish up the debug error message. */
1815 printf_filtered ("done.\n");
1821 psymtab_to_symtab_1 (struct partial_symtab *pst)
1823 struct objfile *objfile = pst->objfile;
1824 bfd *abfd = objfile->obfd;
1825 struct dwarf2_cu cu;
1826 struct die_info *dies;
1827 unsigned long offset;
1828 CORE_ADDR lowpc, highpc;
1829 struct die_info *child_die;
1831 struct symtab *symtab;
1832 struct cleanup *back_to;
1833 struct attribute *attr;
1836 /* Set local variables from the partial symbol table info. */
1837 offset = DWARF_INFO_OFFSET (pst);
1838 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1839 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1840 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1841 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1842 dwarf_line_size = DWARF_LINE_SIZE (pst);
1843 dwarf_str_buffer = DWARF_STR_BUFFER (pst);
1844 dwarf_str_size = DWARF_STR_SIZE (pst);
1845 dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst);
1846 dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst);
1847 dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst);
1848 dwarf_ranges_size = DWARF_RANGES_SIZE (pst);
1849 dwarf_loc_buffer = DWARF_LOC_BUFFER (pst);
1850 dwarf_loc_size = DWARF_LOC_SIZE (pst);
1851 info_ptr = dwarf_info_buffer + offset;
1852 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1854 /* We're in the global namespace. */
1855 processing_current_prefix = "";
1857 obstack_init (&dwarf2_tmp_obstack);
1858 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1861 make_cleanup (really_free_pendings, NULL);
1863 cu.objfile = objfile;
1865 /* read in the comp_unit header */
1866 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1868 /* Read the abbrevs for this compilation unit */
1869 dwarf2_read_abbrevs (abfd, &cu);
1870 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1872 cu.header.offset = offset;
1874 cu.list_in_scope = &file_symbols;
1876 dies = read_comp_unit (info_ptr, abfd, &cu);
1878 make_cleanup_free_die_list (dies);
1880 /* Find the base address of the compilation unit for range lists and
1881 location lists. It will normally be specified by DW_AT_low_pc.
1882 In DWARF-3 draft 4, the base address could be overridden by
1883 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1884 compilation units with discontinuous ranges. */
1886 cu.header.base_known = 0;
1887 cu.header.base_address = 0;
1889 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
1892 cu.header.base_address = DW_ADDR (attr);
1893 cu.header.base_known = 1;
1897 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
1900 cu.header.base_address = DW_ADDR (attr);
1901 cu.header.base_known = 1;
1905 /* Do line number decoding in read_file_scope () */
1906 process_die (dies, &cu);
1908 /* Some compilers don't define a DW_AT_high_pc attribute for the
1909 compilation unit. If the DW_AT_high_pc is missing, synthesize
1910 it, by scanning the DIE's below the compilation unit. */
1911 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
1913 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
1915 /* Set symtab language to language from DW_AT_language.
1916 If the compilation is from a C file generated by language preprocessors,
1917 do not set the language if it was already deduced by start_subfile. */
1919 && !(cu.language == language_c && symtab->language != language_c))
1921 symtab->language = cu.language;
1923 pst->symtab = symtab;
1926 do_cleanups (back_to);
1929 /* Process a die and its children. */
1932 process_die (struct die_info *die, struct dwarf2_cu *cu)
1936 case DW_TAG_padding:
1938 case DW_TAG_compile_unit:
1939 read_file_scope (die, cu);
1941 case DW_TAG_subprogram:
1942 read_subroutine_type (die, cu);
1943 read_func_scope (die, cu);
1945 case DW_TAG_inlined_subroutine:
1946 /* FIXME: These are ignored for now.
1947 They could be used to set breakpoints on all inlined instances
1948 of a function and make GDB `next' properly over inlined functions. */
1950 case DW_TAG_lexical_block:
1951 case DW_TAG_try_block:
1952 case DW_TAG_catch_block:
1953 read_lexical_block_scope (die, cu);
1955 case DW_TAG_class_type:
1956 case DW_TAG_structure_type:
1957 case DW_TAG_union_type:
1958 read_structure_type (die, cu);
1959 process_structure_scope (die, cu);
1961 case DW_TAG_enumeration_type:
1962 read_enumeration_type (die, cu);
1963 process_enumeration_scope (die, cu);
1966 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
1967 a symbol or process any children. Therefore it doesn't do anything
1968 that won't be done on-demand by read_type_die. */
1969 case DW_TAG_subroutine_type:
1970 read_subroutine_type (die, cu);
1972 case DW_TAG_array_type:
1973 read_array_type (die, cu);
1975 case DW_TAG_pointer_type:
1976 read_tag_pointer_type (die, cu);
1978 case DW_TAG_ptr_to_member_type:
1979 read_tag_ptr_to_member_type (die, cu);
1981 case DW_TAG_reference_type:
1982 case DW_TAG_rvalue_reference_type:
1983 read_tag_reference_type (die, cu);
1985 case DW_TAG_string_type:
1986 read_tag_string_type (die, cu);
1990 case DW_TAG_base_type:
1991 read_base_type (die, cu);
1992 /* Add a typedef symbol for the type definition, if it has a
1994 new_symbol (die, die->type, cu);
1996 case DW_TAG_subrange_type:
1997 read_subrange_type (die, cu);
1998 /* Add a typedef symbol for the type definition, if it has a
2000 new_symbol (die, die->type, cu);
2002 case DW_TAG_common_block:
2003 read_common_block (die, cu);
2005 case DW_TAG_common_inclusion:
2007 case DW_TAG_namespace:
2008 processing_has_namespace_info = 1;
2009 read_namespace (die, cu);
2011 case DW_TAG_imported_declaration:
2012 case DW_TAG_imported_module:
2013 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2014 information contained in these. DW_TAG_imported_declaration
2015 dies shouldn't have children; DW_TAG_imported_module dies
2016 shouldn't in the C++ case, but conceivably could in the
2017 Fortran case, so we'll have to replace this gdb_assert if
2018 Fortran compilers start generating that info. */
2019 processing_has_namespace_info = 1;
2020 gdb_assert (die->child == NULL);
2023 new_symbol (die, NULL, cu);
2029 initialize_cu_func_list (struct dwarf2_cu *cu)
2031 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2035 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2037 struct objfile *objfile = cu->objfile;
2038 struct comp_unit_head *cu_header = &cu->header;
2039 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2040 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2041 CORE_ADDR highpc = ((CORE_ADDR) 0);
2042 struct attribute *attr;
2043 char *name = "<unknown>";
2044 char *comp_dir = NULL;
2045 struct die_info *child_die;
2046 bfd *abfd = objfile->obfd;
2047 struct line_header *line_header = 0;
2050 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2052 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2054 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2055 from finish_block. */
2056 if (lowpc == ((CORE_ADDR) -1))
2061 attr = dwarf2_attr (die, DW_AT_name, cu);
2064 name = DW_STRING (attr);
2066 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2069 comp_dir = DW_STRING (attr);
2072 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2073 directory, get rid of it. */
2074 char *cp = strchr (comp_dir, ':');
2076 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2081 if (objfile->ei.entry_point >= lowpc &&
2082 objfile->ei.entry_point < highpc)
2084 objfile->ei.deprecated_entry_file_lowpc = lowpc;
2085 objfile->ei.deprecated_entry_file_highpc = highpc;
2088 attr = dwarf2_attr (die, DW_AT_language, cu);
2091 set_cu_language (DW_UNSND (attr), cu);
2094 /* We assume that we're processing GCC output. */
2095 processing_gcc_compilation = 2;
2097 /* FIXME:Do something here. */
2098 if (dip->at_producer != NULL)
2100 handle_producer (dip->at_producer);
2104 /* The compilation unit may be in a different language or objfile,
2105 zero out all remembered fundamental types. */
2106 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2108 start_symtab (name, comp_dir, lowpc);
2109 record_debugformat ("DWARF 2");
2111 initialize_cu_func_list (cu);
2113 /* Process all dies in compilation unit. */
2114 if (die->child != NULL)
2116 child_die = die->child;
2117 while (child_die && child_die->tag)
2119 process_die (child_die, cu);
2120 child_die = sibling_die (child_die);
2124 /* Decode line number information if present. */
2125 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2128 unsigned int line_offset = DW_UNSND (attr);
2129 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2132 make_cleanup ((make_cleanup_ftype *) free_line_header,
2133 (void *) line_header);
2134 dwarf_decode_lines (line_header, comp_dir, abfd, cu);
2138 /* Decode macro information, if present. Dwarf 2 macro information
2139 refers to information in the line number info statement program
2140 header, so we can only read it if we've read the header
2142 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2143 if (attr && line_header)
2145 unsigned int macro_offset = DW_UNSND (attr);
2146 dwarf_decode_macros (line_header, macro_offset,
2147 comp_dir, abfd, cu);
2149 do_cleanups (back_to);
2153 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2154 struct dwarf2_cu *cu)
2156 struct function_range *thisfn;
2158 thisfn = (struct function_range *)
2159 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range));
2160 thisfn->name = name;
2161 thisfn->lowpc = lowpc;
2162 thisfn->highpc = highpc;
2163 thisfn->seen_line = 0;
2164 thisfn->next = NULL;
2166 if (cu->last_fn == NULL)
2167 cu->first_fn = thisfn;
2169 cu->last_fn->next = thisfn;
2171 cu->last_fn = thisfn;
2175 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2177 struct objfile *objfile = cu->objfile;
2178 struct context_stack *new;
2181 struct die_info *child_die;
2182 struct attribute *attr;
2184 const char *previous_prefix = processing_current_prefix;
2185 struct cleanup *back_to = NULL;
2188 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2190 name = dwarf2_linkage_name (die, cu);
2192 /* Ignore functions with missing or empty names and functions with
2193 missing or invalid low and high pc attributes. */
2194 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2197 if (cu->language == language_cplus)
2199 struct die_info *spec_die = die_specification (die, cu);
2201 /* NOTE: carlton/2004-01-23: We have to be careful in the
2202 presence of DW_AT_specification. For example, with GCC 3.4,
2207 // Definition of N::foo.
2211 then we'll have a tree of DIEs like this:
2213 1: DW_TAG_compile_unit
2214 2: DW_TAG_namespace // N
2215 3: DW_TAG_subprogram // declaration of N::foo
2216 4: DW_TAG_subprogram // definition of N::foo
2217 DW_AT_specification // refers to die #3
2219 Thus, when processing die #4, we have to pretend that we're
2220 in the context of its DW_AT_specification, namely the contex
2223 if (spec_die != NULL)
2225 char *specification_prefix = determine_prefix (spec_die, cu);
2226 processing_current_prefix = specification_prefix;
2227 back_to = make_cleanup (xfree, specification_prefix);
2234 /* Record the function range for dwarf_decode_lines. */
2235 add_to_cu_func_list (name, lowpc, highpc, cu);
2237 if (objfile->ei.entry_point >= lowpc &&
2238 objfile->ei.entry_point < highpc)
2240 objfile->ei.entry_func_lowpc = lowpc;
2241 objfile->ei.entry_func_highpc = highpc;
2244 new = push_context (0, lowpc);
2245 new->name = new_symbol (die, die->type, cu);
2247 /* If there is a location expression for DW_AT_frame_base, record
2249 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2251 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2252 expression is being recorded directly in the function's symbol
2253 and not in a separate frame-base object. I guess this hack is
2254 to avoid adding some sort of frame-base adjunct/annex to the
2255 function's symbol :-(. The problem with doing this is that it
2256 results in a function symbol with a location expression that
2257 has nothing to do with the location of the function, ouch! The
2258 relationship should be: a function's symbol has-a frame base; a
2259 frame-base has-a location expression. */
2260 dwarf2_symbol_mark_computed (attr, new->name, cu);
2262 cu->list_in_scope = &local_symbols;
2264 if (die->child != NULL)
2266 child_die = die->child;
2267 while (child_die && child_die->tag)
2269 process_die (child_die, cu);
2270 child_die = sibling_die (child_die);
2274 new = pop_context ();
2275 /* Make a block for the local symbols within. */
2276 finish_block (new->name, &local_symbols, new->old_blocks,
2277 lowpc, highpc, objfile);
2279 /* In C++, we can have functions nested inside functions (e.g., when
2280 a function declares a class that has methods). This means that
2281 when we finish processing a function scope, we may need to go
2282 back to building a containing block's symbol lists. */
2283 local_symbols = new->locals;
2284 param_symbols = new->params;
2286 /* If we've finished processing a top-level function, subsequent
2287 symbols go in the file symbol list. */
2288 if (outermost_context_p ())
2289 cu->list_in_scope = &file_symbols;
2291 processing_current_prefix = previous_prefix;
2292 if (back_to != NULL)
2293 do_cleanups (back_to);
2296 /* Process all the DIES contained within a lexical block scope. Start
2297 a new scope, process the dies, and then close the scope. */
2300 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2302 struct objfile *objfile = cu->objfile;
2303 struct context_stack *new;
2304 CORE_ADDR lowpc, highpc;
2305 struct die_info *child_die;
2308 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2310 /* Ignore blocks with missing or invalid low and high pc attributes. */
2311 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2312 as multiple lexical blocks? Handling children in a sane way would
2313 be nasty. Might be easier to properly extend generic blocks to
2315 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2320 push_context (0, lowpc);
2321 if (die->child != NULL)
2323 child_die = die->child;
2324 while (child_die && child_die->tag)
2326 process_die (child_die, cu);
2327 child_die = sibling_die (child_die);
2330 new = pop_context ();
2332 if (local_symbols != NULL)
2334 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2337 local_symbols = new->locals;
2340 /* Get low and high pc attributes from a die. Return 1 if the attributes
2341 are present and valid, otherwise, return 0. Return -1 if the range is
2342 discontinuous, i.e. derived from DW_AT_ranges information. */
2344 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2345 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2347 struct objfile *objfile = cu->objfile;
2348 struct comp_unit_head *cu_header = &cu->header;
2349 struct attribute *attr;
2350 bfd *obfd = objfile->obfd;
2355 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2358 high = DW_ADDR (attr);
2359 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2361 low = DW_ADDR (attr);
2363 /* Found high w/o low attribute. */
2366 /* Found consecutive range of addresses. */
2371 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2374 unsigned int addr_size = cu_header->addr_size;
2375 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2376 /* Value of the DW_AT_ranges attribute is the offset in the
2377 .debug_ranges section. */
2378 unsigned int offset = DW_UNSND (attr);
2379 /* Base address selection entry. */
2387 found_base = cu_header->base_known;
2388 base = cu_header->base_address;
2390 if (offset >= dwarf_ranges_size)
2392 complaint (&symfile_complaints,
2393 "Offset %d out of bounds for DW_AT_ranges attribute",
2397 buffer = dwarf_ranges_buffer + offset;
2399 /* Read in the largest possible address. */
2400 marker = read_address (obfd, buffer, cu, &dummy);
2401 if ((marker & mask) == mask)
2403 /* If we found the largest possible address, then
2404 read the base address. */
2405 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2406 buffer += 2 * addr_size;
2407 offset += 2 * addr_size;
2415 CORE_ADDR range_beginning, range_end;
2417 range_beginning = read_address (obfd, buffer, cu, &dummy);
2418 buffer += addr_size;
2419 range_end = read_address (obfd, buffer, cu, &dummy);
2420 buffer += addr_size;
2421 offset += 2 * addr_size;
2423 /* An end of list marker is a pair of zero addresses. */
2424 if (range_beginning == 0 && range_end == 0)
2425 /* Found the end of list entry. */
2428 /* Each base address selection entry is a pair of 2 values.
2429 The first is the largest possible address, the second is
2430 the base address. Check for a base address here. */
2431 if ((range_beginning & mask) == mask)
2433 /* If we found the largest possible address, then
2434 read the base address. */
2435 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2442 /* We have no valid base address for the ranges
2444 complaint (&symfile_complaints,
2445 "Invalid .debug_ranges data (no base address)");
2449 range_beginning += base;
2452 /* FIXME: This is recording everything as a low-high
2453 segment of consecutive addresses. We should have a
2454 data structure for discontiguous block ranges
2458 low = range_beginning;
2464 if (range_beginning < low)
2465 low = range_beginning;
2466 if (range_end > high)
2472 /* If the first entry is an end-of-list marker, the range
2473 describes an empty scope, i.e. no instructions. */
2483 /* When using the GNU linker, .gnu.linkonce. sections are used to
2484 eliminate duplicate copies of functions and vtables and such.
2485 The linker will arbitrarily choose one and discard the others.
2486 The AT_*_pc values for such functions refer to local labels in
2487 these sections. If the section from that file was discarded, the
2488 labels are not in the output, so the relocs get a value of 0.
2489 If this is a discarded function, mark the pc bounds as invalid,
2490 so that GDB will ignore it. */
2491 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2499 /* Get the low and high pc's represented by the scope DIE, and store
2500 them in *LOWPC and *HIGHPC. If the correct values can't be
2501 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2504 get_scope_pc_bounds (struct die_info *die,
2505 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2506 struct dwarf2_cu *cu)
2508 CORE_ADDR best_low = (CORE_ADDR) -1;
2509 CORE_ADDR best_high = (CORE_ADDR) 0;
2510 CORE_ADDR current_low, current_high;
2512 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
2514 best_low = current_low;
2515 best_high = current_high;
2519 struct die_info *child = die->child;
2521 while (child && child->tag)
2523 switch (child->tag) {
2524 case DW_TAG_subprogram:
2525 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
2527 best_low = min (best_low, current_low);
2528 best_high = max (best_high, current_high);
2531 case DW_TAG_namespace:
2532 /* FIXME: carlton/2004-01-16: Should we do this for
2533 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2534 that current GCC's always emit the DIEs corresponding
2535 to definitions of methods of classes as children of a
2536 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2537 the DIEs giving the declarations, which could be
2538 anywhere). But I don't see any reason why the
2539 standards says that they have to be there. */
2540 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
2542 if (current_low != ((CORE_ADDR) -1))
2544 best_low = min (best_low, current_low);
2545 best_high = max (best_high, current_high);
2553 child = sibling_die (child);
2558 *highpc = best_high;
2561 /* Add an aggregate field to the field list. */
2564 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2565 struct dwarf2_cu *cu)
2567 struct objfile *objfile = cu->objfile;
2568 struct nextfield *new_field;
2569 struct attribute *attr;
2571 char *fieldname = "";
2573 /* Allocate a new field list entry and link it in. */
2574 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2575 make_cleanup (xfree, new_field);
2576 memset (new_field, 0, sizeof (struct nextfield));
2577 new_field->next = fip->fields;
2578 fip->fields = new_field;
2581 /* Handle accessibility and virtuality of field.
2582 The default accessibility for members is public, the default
2583 accessibility for inheritance is private. */
2584 if (die->tag != DW_TAG_inheritance)
2585 new_field->accessibility = DW_ACCESS_public;
2587 new_field->accessibility = DW_ACCESS_private;
2588 new_field->virtuality = DW_VIRTUALITY_none;
2590 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2592 new_field->accessibility = DW_UNSND (attr);
2593 if (new_field->accessibility != DW_ACCESS_public)
2594 fip->non_public_fields = 1;
2595 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
2597 new_field->virtuality = DW_UNSND (attr);
2599 fp = &new_field->field;
2601 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
2603 /* Data member other than a C++ static data member. */
2605 /* Get type of field. */
2606 fp->type = die_type (die, cu);
2608 FIELD_STATIC_KIND (*fp) = 0;
2610 /* Get bit size of field (zero if none). */
2611 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
2614 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2618 FIELD_BITSIZE (*fp) = 0;
2621 /* Get bit offset of field. */
2622 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2625 FIELD_BITPOS (*fp) =
2626 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2629 FIELD_BITPOS (*fp) = 0;
2630 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
2633 if (BITS_BIG_ENDIAN)
2635 /* For big endian bits, the DW_AT_bit_offset gives the
2636 additional bit offset from the MSB of the containing
2637 anonymous object to the MSB of the field. We don't
2638 have to do anything special since we don't need to
2639 know the size of the anonymous object. */
2640 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2644 /* For little endian bits, compute the bit offset to the
2645 MSB of the anonymous object, subtract off the number of
2646 bits from the MSB of the field to the MSB of the
2647 object, and then subtract off the number of bits of
2648 the field itself. The result is the bit offset of
2649 the LSB of the field. */
2651 int bit_offset = DW_UNSND (attr);
2653 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2656 /* The size of the anonymous object containing
2657 the bit field is explicit, so use the
2658 indicated size (in bytes). */
2659 anonymous_size = DW_UNSND (attr);
2663 /* The size of the anonymous object containing
2664 the bit field must be inferred from the type
2665 attribute of the data member containing the
2667 anonymous_size = TYPE_LENGTH (fp->type);
2669 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2670 - bit_offset - FIELD_BITSIZE (*fp);
2674 /* Get name of field. */
2675 attr = dwarf2_attr (die, DW_AT_name, cu);
2676 if (attr && DW_STRING (attr))
2677 fieldname = DW_STRING (attr);
2678 fp->name = obsavestring (fieldname, strlen (fieldname),
2679 &objfile->objfile_obstack);
2681 /* Change accessibility for artificial fields (e.g. virtual table
2682 pointer or virtual base class pointer) to private. */
2683 if (dwarf2_attr (die, DW_AT_artificial, cu))
2685 new_field->accessibility = DW_ACCESS_private;
2686 fip->non_public_fields = 1;
2689 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2691 /* C++ static member. */
2693 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2694 is a declaration, but all versions of G++ as of this writing
2695 (so through at least 3.2.1) incorrectly generate
2696 DW_TAG_variable tags. */
2700 /* Get name of field. */
2701 attr = dwarf2_attr (die, DW_AT_name, cu);
2702 if (attr && DW_STRING (attr))
2703 fieldname = DW_STRING (attr);
2707 /* Get physical name. */
2708 physname = dwarf2_linkage_name (die, cu);
2710 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
2711 &objfile->objfile_obstack));
2712 FIELD_TYPE (*fp) = die_type (die, cu);
2713 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
2714 &objfile->objfile_obstack);
2716 else if (die->tag == DW_TAG_inheritance)
2718 /* C++ base class field. */
2719 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2721 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
2723 FIELD_BITSIZE (*fp) = 0;
2724 FIELD_STATIC_KIND (*fp) = 0;
2725 FIELD_TYPE (*fp) = die_type (die, cu);
2726 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
2727 fip->nbaseclasses++;
2731 /* Create the vector of fields, and attach it to the type. */
2734 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
2735 struct dwarf2_cu *cu)
2737 int nfields = fip->nfields;
2739 /* Record the field count, allocate space for the array of fields,
2740 and create blank accessibility bitfields if necessary. */
2741 TYPE_NFIELDS (type) = nfields;
2742 TYPE_FIELDS (type) = (struct field *)
2743 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2744 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2746 if (fip->non_public_fields)
2748 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2750 TYPE_FIELD_PRIVATE_BITS (type) =
2751 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2752 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2754 TYPE_FIELD_PROTECTED_BITS (type) =
2755 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2756 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2758 TYPE_FIELD_IGNORE_BITS (type) =
2759 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2760 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2763 /* If the type has baseclasses, allocate and clear a bit vector for
2764 TYPE_FIELD_VIRTUAL_BITS. */
2765 if (fip->nbaseclasses)
2767 int num_bytes = B_BYTES (fip->nbaseclasses);
2770 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2771 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2772 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2773 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
2774 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
2777 /* Copy the saved-up fields into the field vector. Start from the head
2778 of the list, adding to the tail of the field array, so that they end
2779 up in the same order in the array in which they were added to the list. */
2780 while (nfields-- > 0)
2782 TYPE_FIELD (type, nfields) = fip->fields->field;
2783 switch (fip->fields->accessibility)
2785 case DW_ACCESS_private:
2786 SET_TYPE_FIELD_PRIVATE (type, nfields);
2789 case DW_ACCESS_protected:
2790 SET_TYPE_FIELD_PROTECTED (type, nfields);
2793 case DW_ACCESS_public:
2797 /* Unknown accessibility. Complain and treat it as public. */
2799 complaint (&symfile_complaints, "unsupported accessibility %d",
2800 fip->fields->accessibility);
2804 if (nfields < fip->nbaseclasses)
2806 switch (fip->fields->virtuality)
2808 case DW_VIRTUALITY_virtual:
2809 case DW_VIRTUALITY_pure_virtual:
2810 SET_TYPE_FIELD_VIRTUAL (type, nfields);
2814 fip->fields = fip->fields->next;
2818 /* Add a member function to the proper fieldlist. */
2821 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
2822 struct type *type, struct dwarf2_cu *cu)
2824 struct objfile *objfile = cu->objfile;
2825 struct attribute *attr;
2826 struct fnfieldlist *flp;
2828 struct fn_field *fnp;
2831 struct nextfnfield *new_fnfield;
2833 /* Get name of member function. */
2834 attr = dwarf2_attr (die, DW_AT_name, cu);
2835 if (attr && DW_STRING (attr))
2836 fieldname = DW_STRING (attr);
2840 /* Get the mangled name. */
2841 physname = dwarf2_linkage_name (die, cu);
2843 /* Look up member function name in fieldlist. */
2844 for (i = 0; i < fip->nfnfields; i++)
2846 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
2850 /* Create new list element if necessary. */
2851 if (i < fip->nfnfields)
2852 flp = &fip->fnfieldlists[i];
2855 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2857 fip->fnfieldlists = (struct fnfieldlist *)
2858 xrealloc (fip->fnfieldlists,
2859 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2860 * sizeof (struct fnfieldlist));
2861 if (fip->nfnfields == 0)
2862 make_cleanup (free_current_contents, &fip->fnfieldlists);
2864 flp = &fip->fnfieldlists[fip->nfnfields];
2865 flp->name = fieldname;
2871 /* Create a new member function field and chain it to the field list
2873 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2874 make_cleanup (xfree, new_fnfield);
2875 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2876 new_fnfield->next = flp->head;
2877 flp->head = new_fnfield;
2880 /* Fill in the member function field info. */
2881 fnp = &new_fnfield->fnfield;
2882 fnp->physname = obsavestring (physname, strlen (physname),
2883 &objfile->objfile_obstack);
2884 fnp->type = alloc_type (objfile);
2885 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2887 int nparams = TYPE_NFIELDS (die->type);
2889 /* TYPE is the domain of this method, and DIE->TYPE is the type
2890 of the method itself (TYPE_CODE_METHOD). */
2891 smash_to_method_type (fnp->type, type,
2892 TYPE_TARGET_TYPE (die->type),
2893 TYPE_FIELDS (die->type),
2894 TYPE_NFIELDS (die->type),
2895 TYPE_VARARGS (die->type));
2897 /* Handle static member functions.
2898 Dwarf2 has no clean way to discern C++ static and non-static
2899 member functions. G++ helps GDB by marking the first
2900 parameter for non-static member functions (which is the
2901 this pointer) as artificial. We obtain this information
2902 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2903 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2904 fnp->voffset = VOFFSET_STATIC;
2907 complaint (&symfile_complaints, "member function type missing for '%s'",
2910 /* Get fcontext from DW_AT_containing_type if present. */
2911 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
2912 fnp->fcontext = die_containing_type (die, cu);
2914 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2915 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2917 /* Get accessibility. */
2918 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2921 switch (DW_UNSND (attr))
2923 case DW_ACCESS_private:
2924 fnp->is_private = 1;
2926 case DW_ACCESS_protected:
2927 fnp->is_protected = 1;
2932 /* Check for artificial methods. */
2933 attr = dwarf2_attr (die, DW_AT_artificial, cu);
2934 if (attr && DW_UNSND (attr) != 0)
2935 fnp->is_artificial = 1;
2937 /* Get index in virtual function table if it is a virtual member function. */
2938 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
2941 /* Support the .debug_loc offsets */
2942 if (attr_form_is_block (attr))
2944 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
2946 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
2948 dwarf2_complex_location_expr_complaint ();
2952 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2958 /* Create the vector of member function fields, and attach it to the type. */
2961 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
2962 struct dwarf2_cu *cu)
2964 struct fnfieldlist *flp;
2965 int total_length = 0;
2968 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2969 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2970 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2972 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2974 struct nextfnfield *nfp = flp->head;
2975 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2978 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2979 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2980 fn_flp->fn_fields = (struct fn_field *)
2981 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2982 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2983 fn_flp->fn_fields[k] = nfp->fnfield;
2985 total_length += flp->length;
2988 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2989 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2992 /* Called when we find the DIE that starts a structure or union scope
2993 (definition) to process all dies that define the members of the
2996 NOTE: we need to call struct_type regardless of whether or not the
2997 DIE has an at_name attribute, since it might be an anonymous
2998 structure or union. This gets the type entered into our set of
3001 However, if the structure is incomplete (an opaque struct/union)
3002 then suppress creating a symbol table entry for it since gdb only
3003 wants to find the one with the complete definition. Note that if
3004 it is complete, we just call new_symbol, which does it's own
3005 checking about whether the struct/union is anonymous or not (and
3006 suppresses creating a symbol table entry itself). */
3009 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3011 struct objfile *objfile = cu->objfile;
3013 struct attribute *attr;
3014 const char *previous_prefix = processing_current_prefix;
3015 struct cleanup *back_to = NULL;
3020 type = alloc_type (objfile);
3022 INIT_CPLUS_SPECIFIC (type);
3023 attr = dwarf2_attr (die, DW_AT_name, cu);
3024 if (attr && DW_STRING (attr))
3026 if (cu->language == language_cplus)
3028 char *new_prefix = determine_class_name (die, cu);
3029 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3030 strlen (new_prefix),
3031 &objfile->objfile_obstack);
3032 back_to = make_cleanup (xfree, new_prefix);
3033 processing_current_prefix = new_prefix;
3037 TYPE_TAG_NAME (type) = DW_STRING (attr);
3041 if (die->tag == DW_TAG_structure_type)
3043 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3045 else if (die->tag == DW_TAG_union_type)
3047 TYPE_CODE (type) = TYPE_CODE_UNION;
3051 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3053 TYPE_CODE (type) = TYPE_CODE_CLASS;
3056 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3059 TYPE_LENGTH (type) = DW_UNSND (attr);
3063 TYPE_LENGTH (type) = 0;
3066 /* We need to add the type field to the die immediately so we don't
3067 infinitely recurse when dealing with pointers to the structure
3068 type within the structure itself. */
3071 if (die->child != NULL && ! die_is_declaration (die, cu))
3073 struct field_info fi;
3074 struct die_info *child_die;
3075 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3077 memset (&fi, 0, sizeof (struct field_info));
3079 child_die = die->child;
3081 while (child_die && child_die->tag)
3083 if (child_die->tag == DW_TAG_member
3084 || child_die->tag == DW_TAG_variable)
3086 /* NOTE: carlton/2002-11-05: A C++ static data member
3087 should be a DW_TAG_member that is a declaration, but
3088 all versions of G++ as of this writing (so through at
3089 least 3.2.1) incorrectly generate DW_TAG_variable
3090 tags for them instead. */
3091 dwarf2_add_field (&fi, child_die, cu);
3093 else if (child_die->tag == DW_TAG_subprogram)
3095 /* C++ member function. */
3096 read_type_die (child_die, cu);
3097 dwarf2_add_member_fn (&fi, child_die, type, cu);
3099 else if (child_die->tag == DW_TAG_inheritance)
3101 /* C++ base class field. */
3102 dwarf2_add_field (&fi, child_die, cu);
3104 child_die = sibling_die (child_die);
3107 /* Attach fields and member functions to the type. */
3109 dwarf2_attach_fields_to_type (&fi, type, cu);
3112 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3114 /* Get the type which refers to the base class (possibly this
3115 class itself) which contains the vtable pointer for the current
3116 class from the DW_AT_containing_type attribute. */
3118 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3120 struct type *t = die_containing_type (die, cu);
3122 TYPE_VPTR_BASETYPE (type) = t;
3125 static const char vptr_name[] =
3126 {'_', 'v', 'p', 't', 'r', '\0'};
3129 /* Our own class provides vtbl ptr. */
3130 for (i = TYPE_NFIELDS (t) - 1;
3131 i >= TYPE_N_BASECLASSES (t);
3134 char *fieldname = TYPE_FIELD_NAME (t, i);
3136 if ((strncmp (fieldname, vptr_name,
3137 strlen (vptr_name) - 1)
3139 && is_cplus_marker (fieldname[strlen (vptr_name)]))
3141 TYPE_VPTR_FIELDNO (type) = i;
3146 /* Complain if virtual function table field not found. */
3147 if (i < TYPE_N_BASECLASSES (t))
3148 complaint (&symfile_complaints,
3149 "virtual function table pointer not found when defining class '%s'",
3150 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3155 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3160 do_cleanups (back_to);
3164 /* No children, must be stub. */
3165 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3168 processing_current_prefix = previous_prefix;
3169 if (back_to != NULL)
3170 do_cleanups (back_to);
3174 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3176 struct objfile *objfile = cu->objfile;
3177 const char *previous_prefix = processing_current_prefix;
3178 struct die_info *child_die = die->child;
3180 if (TYPE_TAG_NAME (die->type) != NULL)
3181 processing_current_prefix = TYPE_TAG_NAME (die->type);
3183 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3184 snapshots) has been known to create a die giving a declaration
3185 for a class that has, as a child, a die giving a definition for a
3186 nested class. So we have to process our children even if the
3187 current die is a declaration. Normally, of course, a declaration
3188 won't have any children at all. */
3190 while (child_die != NULL && child_die->tag)
3192 if (child_die->tag == DW_TAG_member
3193 || child_die->tag == DW_TAG_variable
3194 || child_die->tag == DW_TAG_inheritance)
3199 process_die (child_die, cu);
3201 child_die = sibling_die (child_die);
3204 if (die->child != NULL && ! die_is_declaration (die, cu))
3205 new_symbol (die, die->type, cu);
3207 processing_current_prefix = previous_prefix;
3210 /* Given a DW_AT_enumeration_type die, set its type. We do not
3211 complete the type's fields yet, or create any symbols. */
3214 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3216 struct objfile *objfile = cu->objfile;
3218 struct attribute *attr;
3223 type = alloc_type (objfile);
3225 TYPE_CODE (type) = TYPE_CODE_ENUM;
3226 attr = dwarf2_attr (die, DW_AT_name, cu);
3227 if (attr && DW_STRING (attr))
3229 const char *name = DW_STRING (attr);
3231 if (processing_has_namespace_info)
3233 TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack,
3234 processing_current_prefix,
3235 processing_current_prefix[0] == '\0'
3241 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
3242 &objfile->objfile_obstack);
3246 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3249 TYPE_LENGTH (type) = DW_UNSND (attr);
3253 TYPE_LENGTH (type) = 0;
3259 /* Determine the name of the type represented by DIE, which should be
3260 a named C++ compound type. Return the name in question; the caller
3261 is responsible for xfree()'ing it. */
3264 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3266 struct cleanup *back_to = NULL;
3267 struct die_info *spec_die = die_specification (die, cu);
3268 char *new_prefix = NULL;
3270 /* If this is the definition of a class that is declared by another
3271 die, then processing_current_prefix may not be accurate; see
3272 read_func_scope for a similar example. */
3273 if (spec_die != NULL)
3275 char *specification_prefix = determine_prefix (spec_die, cu);
3276 processing_current_prefix = specification_prefix;
3277 back_to = make_cleanup (xfree, specification_prefix);
3280 /* If we don't have namespace debug info, guess the name by trying
3281 to demangle the names of members, just like we did in
3282 add_partial_structure. */
3283 if (!processing_has_namespace_info)
3285 struct die_info *child;
3287 for (child = die->child;
3288 child != NULL && child->tag != 0;
3289 child = sibling_die (child))
3291 if (child->tag == DW_TAG_subprogram)
3293 new_prefix = class_name_from_physname (dwarf2_linkage_name
3296 if (new_prefix != NULL)
3302 if (new_prefix == NULL)
3304 const char *name = dwarf2_name (die, cu);
3305 new_prefix = typename_concat (processing_current_prefix,
3306 name ? name : "<<anonymous>>");
3309 if (back_to != NULL)
3310 do_cleanups (back_to);
3315 /* Given a pointer to a die which begins an enumeration, process all
3316 the dies that define the members of the enumeration, and create the
3317 symbol for the enumeration type.
3319 NOTE: We reverse the order of the element list. */
3322 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3324 struct objfile *objfile = cu->objfile;
3325 struct die_info *child_die;
3326 struct field *fields;
3327 struct attribute *attr;
3330 int unsigned_enum = 1;
3334 if (die->child != NULL)
3336 child_die = die->child;
3337 while (child_die && child_die->tag)
3339 if (child_die->tag != DW_TAG_enumerator)
3341 process_die (child_die, cu);
3345 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3348 sym = new_symbol (child_die, die->type, cu);
3349 if (SYMBOL_VALUE (sym) < 0)
3352 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3354 fields = (struct field *)
3356 (num_fields + DW_FIELD_ALLOC_CHUNK)
3357 * sizeof (struct field));
3360 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3361 FIELD_TYPE (fields[num_fields]) = NULL;
3362 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3363 FIELD_BITSIZE (fields[num_fields]) = 0;
3364 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3370 child_die = sibling_die (child_die);
3375 TYPE_NFIELDS (die->type) = num_fields;
3376 TYPE_FIELDS (die->type) = (struct field *)
3377 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
3378 memcpy (TYPE_FIELDS (die->type), fields,
3379 sizeof (struct field) * num_fields);
3383 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
3386 new_symbol (die, die->type, cu);
3389 /* Extract all information from a DW_TAG_array_type DIE and put it in
3390 the DIE's type field. For now, this only handles one dimensional
3394 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3396 struct objfile *objfile = cu->objfile;
3397 struct die_info *child_die;
3398 struct type *type = NULL;
3399 struct type *element_type, *range_type, *index_type;
3400 struct type **range_types = NULL;
3401 struct attribute *attr;
3403 struct cleanup *back_to;
3405 /* Return if we've already decoded this type. */
3411 element_type = die_type (die, cu);
3413 /* Irix 6.2 native cc creates array types without children for
3414 arrays with unspecified length. */
3415 if (die->child == NULL)
3417 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3418 range_type = create_range_type (NULL, index_type, 0, -1);
3419 die->type = create_array_type (NULL, element_type, range_type);
3423 back_to = make_cleanup (null_cleanup, NULL);
3424 child_die = die->child;
3425 while (child_die && child_die->tag)
3427 if (child_die->tag == DW_TAG_subrange_type)
3429 read_subrange_type (child_die, cu);
3431 if (child_die->type != NULL)
3433 /* The range type was succesfully read. Save it for
3434 the array type creation. */
3435 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3437 range_types = (struct type **)
3438 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3439 * sizeof (struct type *));
3441 make_cleanup (free_current_contents, &range_types);
3443 range_types[ndim++] = child_die->type;
3446 child_die = sibling_die (child_die);
3449 /* Dwarf2 dimensions are output from left to right, create the
3450 necessary array types in backwards order. */
3451 type = element_type;
3453 type = create_array_type (NULL, type, range_types[ndim]);
3455 /* Understand Dwarf2 support for vector types (like they occur on
3456 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3457 array type. This is not part of the Dwarf2/3 standard yet, but a
3458 custom vendor extension. The main difference between a regular
3459 array and the vector variant is that vectors are passed by value
3461 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
3463 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3465 do_cleanups (back_to);
3467 /* Install the type in the die. */
3471 /* First cut: install each common block member as a global variable. */
3474 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3476 struct die_info *child_die;
3477 struct attribute *attr;
3479 CORE_ADDR base = (CORE_ADDR) 0;
3481 attr = dwarf2_attr (die, DW_AT_location, cu);
3484 /* Support the .debug_loc offsets */
3485 if (attr_form_is_block (attr))
3487 base = decode_locdesc (DW_BLOCK (attr), cu);
3489 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3491 dwarf2_complex_location_expr_complaint ();
3495 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3496 "common block member");
3499 if (die->child != NULL)
3501 child_die = die->child;
3502 while (child_die && child_die->tag)
3504 sym = new_symbol (child_die, NULL, cu);
3505 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
3508 SYMBOL_VALUE_ADDRESS (sym) =
3509 base + decode_locdesc (DW_BLOCK (attr), cu);
3510 add_symbol_to_list (sym, &global_symbols);
3512 child_die = sibling_die (child_die);
3517 /* Read a C++ namespace. */
3520 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3522 struct objfile *objfile = cu->objfile;
3523 const char *previous_prefix = processing_current_prefix;
3526 struct die_info *current_die;
3528 name = namespace_name (die, &is_anonymous, cu);
3530 /* Now build the name of the current namespace. */
3532 if (previous_prefix[0] == '\0')
3534 processing_current_prefix = name;
3538 /* We need temp_name around because processing_current_prefix
3539 is a const char *. */
3540 char *temp_name = alloca (strlen (previous_prefix)
3541 + 2 + strlen(name) + 1);
3542 strcpy (temp_name, previous_prefix);
3543 strcat (temp_name, "::");
3544 strcat (temp_name, name);
3546 processing_current_prefix = temp_name;
3549 /* Add a symbol associated to this if we haven't seen the namespace
3550 before. Also, add a using directive if it's an anonymous
3553 if (dwarf2_extension (die, cu) == NULL)
3557 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3558 this cast will hopefully become unnecessary. */
3559 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3560 (char *) processing_current_prefix,
3562 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3564 new_symbol (die, type, cu);
3568 cp_add_using_directive (processing_current_prefix,
3569 strlen (previous_prefix),
3570 strlen (processing_current_prefix));
3573 if (die->child != NULL)
3575 struct die_info *child_die = die->child;
3577 while (child_die && child_die->tag)
3579 process_die (child_die, cu);
3580 child_die = sibling_die (child_die);
3584 processing_current_prefix = previous_prefix;
3587 /* Return the name of the namespace represented by DIE. Set
3588 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3592 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
3594 struct die_info *current_die;
3595 const char *name = NULL;
3597 /* Loop through the extensions until we find a name. */
3599 for (current_die = die;
3600 current_die != NULL;
3601 current_die = dwarf2_extension (die, cu))
3603 name = dwarf2_name (current_die, cu);
3608 /* Is it an anonymous namespace? */
3610 *is_anonymous = (name == NULL);
3612 name = "(anonymous namespace)";
3617 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3618 the user defined type vector. */
3621 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3623 struct comp_unit_head *cu_header = &cu->header;
3625 struct attribute *attr_byte_size;
3626 struct attribute *attr_address_class;
3627 int byte_size, addr_class;
3634 type = lookup_pointer_type (die_type (die, cu));
3636 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
3638 byte_size = DW_UNSND (attr_byte_size);
3640 byte_size = cu_header->addr_size;
3642 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
3643 if (attr_address_class)
3644 addr_class = DW_UNSND (attr_address_class);
3646 addr_class = DW_ADDR_none;
3648 /* If the pointer size or address class is different than the
3649 default, create a type variant marked as such and set the
3650 length accordingly. */
3651 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3653 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3657 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
3658 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
3659 type = make_type_with_address_space (type, type_flags);
3661 else if (TYPE_LENGTH (type) != byte_size)
3663 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
3666 /* Should we also complain about unhandled address classes? */
3670 TYPE_LENGTH (type) = byte_size;
3674 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3675 the user defined type vector. */
3678 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
3680 struct objfile *objfile = cu->objfile;
3682 struct type *to_type;
3683 struct type *domain;
3690 type = alloc_type (objfile);
3691 to_type = die_type (die, cu);
3692 domain = die_containing_type (die, cu);
3693 smash_to_member_type (type, domain, to_type);
3698 /* Extract all information from a DW_TAG_reference_type DIE and add to
3699 the user defined type vector. */
3702 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
3704 struct comp_unit_head *cu_header = &cu->header;
3706 struct attribute *attr;
3713 type = lookup_reference_type (die_type (die, cu));
3714 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3717 TYPE_LENGTH (type) = DW_UNSND (attr);
3721 TYPE_LENGTH (type) = cu_header->addr_size;
3727 read_tag_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
3729 struct objfile *objfile = cu->objfile;
3731 struct attribute *attr;
3738 type = alloc_type (objfile);
3739 TYPE_LENGTH (type) = 0;
3740 attr = dwarf2_attr (die, DW_AT_name, cu);
3741 if (attr && DW_STRING (attr))
3742 TYPE_NAME (type) = DW_STRING (attr);
3748 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
3750 struct type *base_type;
3757 base_type = die_type (die, cu);
3758 die->type = make_cvr_type (1, TYPE_VOLATILE (base_type),
3759 TYPE_RESTRICT (base_type), base_type, 0);
3763 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
3765 struct type *base_type;
3772 base_type = die_type (die, cu);
3773 die->type = make_cvr_type (TYPE_CONST (base_type), 1,
3774 TYPE_RESTRICT (base_type), base_type, 0);
3778 read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu)
3780 struct type *base_type;
3787 base_type = die_type (die, cu);
3788 die->type = make_cvr_type (TYPE_CONST (base_type), TYPE_VOLATILE (base_type),
3792 /* Extract all information from a DW_TAG_string_type DIE and add to
3793 the user defined type vector. It isn't really a user defined type,
3794 but it behaves like one, with other DIE's using an AT_user_def_type
3795 attribute to reference it. */
3798 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3800 struct objfile *objfile = cu->objfile;
3801 struct type *type, *range_type, *index_type, *char_type;
3802 struct attribute *attr;
3803 unsigned int length;
3810 attr = dwarf2_attr (die, DW_AT_string_length, cu);
3813 length = DW_UNSND (attr);
3817 /* check for the DW_AT_byte_size attribute */
3818 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3821 length = DW_UNSND (attr);
3828 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3829 range_type = create_range_type (NULL, index_type, 1, length);
3830 if (cu->language == language_fortran)
3832 /* Need to create a unique string type for bounds
3834 type = create_string_type (0, range_type);
3838 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
3839 type = create_string_type (char_type, range_type);
3844 /* Handle DIES due to C code like:
3848 int (*funcp)(int a, long l);
3852 ('funcp' generates a DW_TAG_subroutine_type DIE)
3856 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
3858 struct type *type; /* Type that this function returns */
3859 struct type *ftype; /* Function that returns above type */
3860 struct attribute *attr;
3862 /* Decode the type that this subroutine returns */
3867 type = die_type (die, cu);
3868 ftype = lookup_function_type (type);
3870 /* All functions in C++ have prototypes. */
3871 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
3872 if ((attr && (DW_UNSND (attr) != 0))
3873 || cu->language == language_cplus)
3874 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
3876 if (die->child != NULL)
3878 struct die_info *child_die;
3882 /* Count the number of parameters.
3883 FIXME: GDB currently ignores vararg functions, but knows about
3884 vararg member functions. */
3885 child_die = die->child;
3886 while (child_die && child_die->tag)
3888 if (child_die->tag == DW_TAG_formal_parameter)
3890 else if (child_die->tag == DW_TAG_unspecified_parameters)
3891 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
3892 child_die = sibling_die (child_die);
3895 /* Allocate storage for parameters and fill them in. */
3896 TYPE_NFIELDS (ftype) = nparams;
3897 TYPE_FIELDS (ftype) = (struct field *)
3898 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
3900 child_die = die->child;
3901 while (child_die && child_die->tag)
3903 if (child_die->tag == DW_TAG_formal_parameter)
3905 /* Dwarf2 has no clean way to discern C++ static and non-static
3906 member functions. G++ helps GDB by marking the first
3907 parameter for non-static member functions (which is the
3908 this pointer) as artificial. We pass this information
3909 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3910 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
3912 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
3914 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
3915 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
3918 child_die = sibling_die (child_die);
3926 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
3928 struct objfile *objfile = cu->objfile;
3929 struct attribute *attr;
3934 attr = dwarf2_attr (die, DW_AT_name, cu);
3935 if (attr && DW_STRING (attr))
3937 name = DW_STRING (attr);
3939 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
3940 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
3944 /* Find a representation of a given base type and install
3945 it in the TYPE field of the die. */
3948 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
3950 struct objfile *objfile = cu->objfile;
3952 struct attribute *attr;
3953 int encoding = 0, size = 0;
3955 /* If we've already decoded this die, this is a no-op. */
3961 attr = dwarf2_attr (die, DW_AT_encoding, cu);
3964 encoding = DW_UNSND (attr);
3966 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3969 size = DW_UNSND (attr);
3971 attr = dwarf2_attr (die, DW_AT_name, cu);
3972 if (attr && DW_STRING (attr))
3974 enum type_code code = TYPE_CODE_INT;
3979 case DW_ATE_address:
3980 /* Turn DW_ATE_address into a void * pointer. */
3981 code = TYPE_CODE_PTR;
3982 type_flags |= TYPE_FLAG_UNSIGNED;
3984 case DW_ATE_boolean:
3985 code = TYPE_CODE_BOOL;
3986 type_flags |= TYPE_FLAG_UNSIGNED;
3988 case DW_ATE_complex_float:
3989 code = TYPE_CODE_COMPLEX;
3992 code = TYPE_CODE_FLT;
3995 case DW_ATE_signed_char:
3997 case DW_ATE_unsigned:
3998 case DW_ATE_unsigned_char:
3999 type_flags |= TYPE_FLAG_UNSIGNED;
4002 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
4003 dwarf_type_encoding_name (encoding));
4006 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
4007 if (encoding == DW_ATE_address)
4008 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
4010 else if (encoding == DW_ATE_complex_float)
4013 TYPE_TARGET_TYPE (type)
4014 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
4015 else if (size == 16)
4016 TYPE_TARGET_TYPE (type)
4017 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
4019 TYPE_TARGET_TYPE (type)
4020 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4025 type = dwarf_base_type (encoding, size, cu);
4030 /* Read the given DW_AT_subrange DIE. */
4033 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4035 struct type *base_type;
4036 struct type *range_type;
4037 struct attribute *attr;
4041 /* If we have already decoded this die, then nothing more to do. */
4045 base_type = die_type (die, cu);
4046 if (base_type == NULL)
4048 complaint (&symfile_complaints,
4049 "DW_AT_type missing from DW_TAG_subrange_type");
4053 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4054 base_type = alloc_type (NULL);
4056 if (cu->language == language_fortran)
4058 /* FORTRAN implies a lower bound of 1, if not given. */
4062 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4064 low = dwarf2_get_attr_constant_value (attr, 0);
4066 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4069 if (attr->form == DW_FORM_block1)
4071 /* GCC encodes arrays with unspecified or dynamic length
4072 with a DW_FORM_block1 attribute.
4073 FIXME: GDB does not yet know how to handle dynamic
4074 arrays properly, treat them as arrays with unspecified
4077 FIXME: jimb/2003-09-22: GDB does not really know
4078 how to handle arrays of unspecified length
4079 either; we just represent them as zero-length
4080 arrays. Choose an appropriate upper bound given
4081 the lower bound we've computed above. */
4085 high = dwarf2_get_attr_constant_value (attr, 1);
4088 range_type = create_range_type (NULL, base_type, low, high);
4090 attr = dwarf2_attr (die, DW_AT_name, cu);
4091 if (attr && DW_STRING (attr))
4092 TYPE_NAME (range_type) = DW_STRING (attr);
4094 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4096 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4098 die->type = range_type;
4102 /* Read a whole compilation unit into a linked list of dies. */
4104 static struct die_info *
4105 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4107 /* Reset die reference table; we are
4108 building new ones now. */
4109 dwarf2_empty_hash_tables ();
4111 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4114 /* Read a single die and all its descendents. Set the die's sibling
4115 field to NULL; set other fields in the die correctly, and set all
4116 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4117 location of the info_ptr after reading all of those dies. PARENT
4118 is the parent of the die in question. */
4120 static struct die_info *
4121 read_die_and_children (char *info_ptr, bfd *abfd,
4122 struct dwarf2_cu *cu,
4123 char **new_info_ptr,
4124 struct die_info *parent)
4126 struct die_info *die;
4130 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4131 store_in_ref_table (die->offset, die);
4135 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4141 *new_info_ptr = cur_ptr;
4144 die->sibling = NULL;
4145 die->parent = parent;
4149 /* Read a die, all of its descendents, and all of its siblings; set
4150 all of the fields of all of the dies correctly. Arguments are as
4151 in read_die_and_children. */
4153 static struct die_info *
4154 read_die_and_siblings (char *info_ptr, bfd *abfd,
4155 struct dwarf2_cu *cu,
4156 char **new_info_ptr,
4157 struct die_info *parent)
4159 struct die_info *first_die, *last_sibling;
4163 first_die = last_sibling = NULL;
4167 struct die_info *die
4168 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4176 last_sibling->sibling = die;
4181 *new_info_ptr = cur_ptr;
4191 /* Free a linked list of dies. */
4194 free_die_list (struct die_info *dies)
4196 struct die_info *die, *next;
4201 if (die->child != NULL)
4202 free_die_list (die->child);
4203 next = die->sibling;
4211 do_free_die_list_cleanup (void *dies)
4213 free_die_list (dies);
4216 static struct cleanup *
4217 make_cleanup_free_die_list (struct die_info *dies)
4219 return make_cleanup (do_free_die_list_cleanup, dies);
4223 /* Read the contents of the section at OFFSET and of size SIZE from the
4224 object file specified by OBJFILE into the objfile_obstack and return it. */
4227 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4229 bfd *abfd = objfile->obfd;
4231 bfd_size_type size = bfd_get_section_size (sectp);
4236 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4238 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4242 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4243 || bfd_bread (buf, size, abfd) != size)
4244 error ("Dwarf Error: Can't read DWARF data from '%s'",
4245 bfd_get_filename (abfd));
4250 /* In DWARF version 2, the description of the debugging information is
4251 stored in a separate .debug_abbrev section. Before we read any
4252 dies from a section we read in all abbreviations and install them
4256 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4258 struct comp_unit_head *cu_header = &cu->header;
4260 struct abbrev_info *cur_abbrev;
4261 unsigned int abbrev_number, bytes_read, abbrev_name;
4262 unsigned int abbrev_form, hash_number;
4264 /* Initialize dwarf2 abbrevs */
4265 memset (cu_header->dwarf2_abbrevs, 0,
4266 ABBREV_HASH_SIZE*sizeof (struct abbrev_info *));
4268 abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset;
4269 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4270 abbrev_ptr += bytes_read;
4272 /* loop until we reach an abbrev number of 0 */
4273 while (abbrev_number)
4275 cur_abbrev = dwarf_alloc_abbrev ();
4277 /* read in abbrev header */
4278 cur_abbrev->number = abbrev_number;
4279 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4280 abbrev_ptr += bytes_read;
4281 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4284 /* now read in declarations */
4285 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4286 abbrev_ptr += bytes_read;
4287 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4288 abbrev_ptr += bytes_read;
4291 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
4293 cur_abbrev->attrs = (struct attr_abbrev *)
4294 xrealloc (cur_abbrev->attrs,
4295 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
4296 * sizeof (struct attr_abbrev));
4298 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
4299 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4300 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4301 abbrev_ptr += bytes_read;
4302 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4303 abbrev_ptr += bytes_read;
4306 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4307 cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number];
4308 cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev;
4310 /* Get next abbreviation.
4311 Under Irix6 the abbreviations for a compilation unit are not
4312 always properly terminated with an abbrev number of 0.
4313 Exit loop if we encounter an abbreviation which we have
4314 already read (which means we are about to read the abbreviations
4315 for the next compile unit) or if the end of the abbreviation
4316 table is reached. */
4317 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
4318 >= dwarf_abbrev_size)
4320 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4321 abbrev_ptr += bytes_read;
4322 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4327 /* Empty the abbrev table for a new compilation unit. */
4330 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table)
4333 struct abbrev_info *abbrev, *next;
4334 struct abbrev_info **abbrevs;
4336 abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table;
4338 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
4341 abbrev = abbrevs[i];
4344 next = abbrev->next;
4345 xfree (abbrev->attrs);
4353 /* Lookup an abbrev_info structure in the abbrev hash table. */
4355 static struct abbrev_info *
4356 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4358 struct comp_unit_head *cu_header = &cu->header;
4359 unsigned int hash_number;
4360 struct abbrev_info *abbrev;
4362 hash_number = number % ABBREV_HASH_SIZE;
4363 abbrev = cu_header->dwarf2_abbrevs[hash_number];
4367 if (abbrev->number == number)
4370 abbrev = abbrev->next;
4375 /* Read a minimal amount of information into the minimal die structure. */
4378 read_partial_die (struct partial_die_info *part_die, bfd *abfd,
4379 char *info_ptr, struct dwarf2_cu *cu)
4381 unsigned int abbrev_number, bytes_read, i;
4382 struct abbrev_info *abbrev;
4383 struct attribute attr;
4384 struct attribute spec_attr;
4385 int found_spec_attr = 0;
4386 int has_low_pc_attr = 0;
4387 int has_high_pc_attr = 0;
4389 *part_die = zeroed_partial_die;
4390 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4391 info_ptr += bytes_read;
4395 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4398 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
4399 bfd_get_filename (abfd));
4401 part_die->offset = info_ptr - dwarf_info_buffer;
4402 part_die->tag = abbrev->tag;
4403 part_die->has_children = abbrev->has_children;
4404 part_die->abbrev = abbrev_number;
4406 for (i = 0; i < abbrev->num_attrs; ++i)
4408 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4410 /* Store the data if it is of an attribute we want to keep in a
4411 partial symbol table. */
4416 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4417 if (part_die->name == NULL)
4418 part_die->name = DW_STRING (&attr);
4420 case DW_AT_MIPS_linkage_name:
4421 part_die->name = DW_STRING (&attr);
4424 has_low_pc_attr = 1;
4425 part_die->lowpc = DW_ADDR (&attr);
4428 has_high_pc_attr = 1;
4429 part_die->highpc = DW_ADDR (&attr);
4431 case DW_AT_location:
4432 /* Support the .debug_loc offsets */
4433 if (attr_form_is_block (&attr))
4435 part_die->locdesc = DW_BLOCK (&attr);
4437 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4439 dwarf2_complex_location_expr_complaint ();
4443 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4444 "partial symbol information");
4447 case DW_AT_language:
4448 part_die->language = DW_UNSND (&attr);
4450 case DW_AT_external:
4451 part_die->is_external = DW_UNSND (&attr);
4453 case DW_AT_declaration:
4454 part_die->is_declaration = DW_UNSND (&attr);
4457 part_die->has_type = 1;
4459 case DW_AT_abstract_origin:
4460 case DW_AT_specification:
4461 found_spec_attr = 1;
4465 /* Ignore absolute siblings, they might point outside of
4466 the current compile unit. */
4467 if (attr.form == DW_FORM_ref_addr)
4468 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
4471 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr, cu);
4478 /* If we found a reference attribute and the die has no name, try
4479 to find a name in the referred to die. */
4481 if (found_spec_attr && part_die->name == NULL)
4483 struct partial_die_info spec_die;
4486 spec_ptr = dwarf_info_buffer
4487 + dwarf2_get_ref_die_offset (&spec_attr, cu);
4488 read_partial_die (&spec_die, abfd, spec_ptr, cu);
4491 part_die->name = spec_die.name;
4493 /* Copy DW_AT_external attribute if it is set. */
4494 if (spec_die.is_external)
4495 part_die->is_external = spec_die.is_external;
4499 /* When using the GNU linker, .gnu.linkonce. sections are used to
4500 eliminate duplicate copies of functions and vtables and such.
4501 The linker will arbitrarily choose one and discard the others.
4502 The AT_*_pc values for such functions refer to local labels in
4503 these sections. If the section from that file was discarded, the
4504 labels are not in the output, so the relocs get a value of 0.
4505 If this is a discarded function, mark the pc bounds as invalid,
4506 so that GDB will ignore it. */
4507 if (has_low_pc_attr && has_high_pc_attr
4508 && part_die->lowpc < part_die->highpc
4509 && (part_die->lowpc != 0
4510 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
4511 part_die->has_pc_info = 1;
4515 /* Read the die from the .debug_info section buffer. Set DIEP to
4516 point to a newly allocated die with its information, except for its
4517 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4518 whether the die has children or not. */
4521 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
4522 struct dwarf2_cu *cu, int *has_children)
4524 unsigned int abbrev_number, bytes_read, i, offset;
4525 struct abbrev_info *abbrev;
4526 struct die_info *die;
4528 offset = info_ptr - dwarf_info_buffer;
4529 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4530 info_ptr += bytes_read;
4533 die = dwarf_alloc_die ();
4535 die->abbrev = abbrev_number;
4542 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4545 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4547 bfd_get_filename (abfd));
4549 die = dwarf_alloc_die ();
4550 die->offset = offset;
4551 die->tag = abbrev->tag;
4552 die->abbrev = abbrev_number;
4555 die->num_attrs = abbrev->num_attrs;
4556 die->attrs = (struct attribute *)
4557 xmalloc (die->num_attrs * sizeof (struct attribute));
4559 for (i = 0; i < abbrev->num_attrs; ++i)
4561 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
4562 abfd, info_ptr, cu);
4566 *has_children = abbrev->has_children;
4570 /* Read an attribute value described by an attribute form. */
4573 read_attribute_value (struct attribute *attr, unsigned form,
4574 bfd *abfd, char *info_ptr,
4575 struct dwarf2_cu *cu)
4577 struct comp_unit_head *cu_header = &cu->header;
4578 unsigned int bytes_read;
4579 struct dwarf_block *blk;
4585 case DW_FORM_ref_addr:
4586 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
4587 info_ptr += bytes_read;
4589 case DW_FORM_block2:
4590 blk = dwarf_alloc_block ();
4591 blk->size = read_2_bytes (abfd, info_ptr);
4593 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4594 info_ptr += blk->size;
4595 DW_BLOCK (attr) = blk;
4597 case DW_FORM_block4:
4598 blk = dwarf_alloc_block ();
4599 blk->size = read_4_bytes (abfd, info_ptr);
4601 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4602 info_ptr += blk->size;
4603 DW_BLOCK (attr) = blk;
4606 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4610 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4614 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4617 case DW_FORM_string:
4618 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
4619 info_ptr += bytes_read;
4622 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
4624 info_ptr += bytes_read;
4627 blk = dwarf_alloc_block ();
4628 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4629 info_ptr += bytes_read;
4630 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4631 info_ptr += blk->size;
4632 DW_BLOCK (attr) = blk;
4634 case DW_FORM_block1:
4635 blk = dwarf_alloc_block ();
4636 blk->size = read_1_byte (abfd, info_ptr);
4638 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4639 info_ptr += blk->size;
4640 DW_BLOCK (attr) = blk;
4643 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4647 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4650 case DW_FORM_flag_present:
4651 DW_UNSND (attr) = 1;
4654 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
4655 info_ptr += bytes_read;
4658 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4659 info_ptr += bytes_read;
4662 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4666 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4670 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4674 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4677 case DW_FORM_ref_udata:
4678 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4679 info_ptr += bytes_read;
4681 case DW_FORM_indirect:
4682 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4683 info_ptr += bytes_read;
4684 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
4687 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4688 dwarf_form_name (form),
4689 bfd_get_filename (abfd));
4694 /* Read an attribute described by an abbreviated attribute. */
4697 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
4698 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
4700 attr->name = abbrev->name;
4701 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
4704 /* read dwarf information from a buffer */
4707 read_1_byte (bfd *abfd, char *buf)
4709 return bfd_get_8 (abfd, (bfd_byte *) buf);
4713 read_1_signed_byte (bfd *abfd, char *buf)
4715 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
4719 read_2_bytes (bfd *abfd, char *buf)
4721 return bfd_get_16 (abfd, (bfd_byte *) buf);
4725 read_2_signed_bytes (bfd *abfd, char *buf)
4727 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4731 read_4_bytes (bfd *abfd, char *buf)
4733 return bfd_get_32 (abfd, (bfd_byte *) buf);
4737 read_4_signed_bytes (bfd *abfd, char *buf)
4739 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4742 static unsigned long
4743 read_8_bytes (bfd *abfd, char *buf)
4745 return bfd_get_64 (abfd, (bfd_byte *) buf);
4749 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
4751 struct comp_unit_head *cu_header = &cu->header;
4752 CORE_ADDR retval = 0;
4754 if (cu_header->signed_addr_p)
4756 switch (cu_header->addr_size)
4759 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4762 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4765 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
4768 internal_error (__FILE__, __LINE__,
4769 "read_address: bad switch, signed [in module %s]",
4770 bfd_get_filename (abfd));
4775 switch (cu_header->addr_size)
4778 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
4781 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4784 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4787 internal_error (__FILE__, __LINE__,
4788 "read_address: bad switch, unsigned [in module %s]",
4789 bfd_get_filename (abfd));
4793 *bytes_read = cu_header->addr_size;
4797 /* Read the initial length from a section. The (draft) DWARF 3
4798 specification allows the initial length to take up either 4 bytes
4799 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4800 bytes describe the length and all offsets will be 8 bytes in length
4803 An older, non-standard 64-bit format is also handled by this
4804 function. The older format in question stores the initial length
4805 as an 8-byte quantity without an escape value. Lengths greater
4806 than 2^32 aren't very common which means that the initial 4 bytes
4807 is almost always zero. Since a length value of zero doesn't make
4808 sense for the 32-bit format, this initial zero can be considered to
4809 be an escape value which indicates the presence of the older 64-bit
4810 format. As written, the code can't detect (old format) lengths
4811 greater than 4GB. If it becomes necessary to handle lengths somewhat
4812 larger than 4GB, we could allow other small values (such as the
4813 non-sensical values of 1, 2, and 3) to also be used as escape values
4814 indicating the presence of the old format.
4816 The value returned via bytes_read should be used to increment
4817 the relevant pointer after calling read_initial_length().
4819 As a side effect, this function sets the fields initial_length_size
4820 and offset_size in cu_header to the values appropriate for the
4821 length field. (The format of the initial length field determines
4822 the width of file offsets to be fetched later with fetch_offset().)
4824 [ Note: read_initial_length() and read_offset() are based on the
4825 document entitled "DWARF Debugging Information Format", revision
4826 3, draft 8, dated November 19, 2001. This document was obtained
4829 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4831 This document is only a draft and is subject to change. (So beware.)
4833 Details regarding the older, non-standard 64-bit format were
4834 determined empirically by examining 64-bit ELF files produced
4835 by the SGI toolchain on an IRIX 6.5 machine.
4837 - Kevin, July 16, 2002
4841 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
4846 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4848 if (retval == 0xffffffff)
4850 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
4852 if (cu_header != NULL)
4854 cu_header->initial_length_size = 12;
4855 cu_header->offset_size = 8;
4858 else if (retval == 0)
4860 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4862 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4864 if (cu_header != NULL)
4866 cu_header->initial_length_size = 8;
4867 cu_header->offset_size = 8;
4873 if (cu_header != NULL)
4875 cu_header->initial_length_size = 4;
4876 cu_header->offset_size = 4;
4883 /* Read an offset from the data stream. The size of the offset is
4884 given by cu_header->offset_size. */
4887 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
4892 switch (cu_header->offset_size)
4895 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4899 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4903 internal_error (__FILE__, __LINE__,
4904 "read_offset: bad switch [in module %s]",
4905 bfd_get_filename (abfd));
4912 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
4914 /* If the size of a host char is 8 bits, we can return a pointer
4915 to the buffer, otherwise we have to copy the data to a buffer
4916 allocated on the temporary obstack. */
4917 gdb_assert (HOST_CHAR_BIT == 8);
4922 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4924 /* If the size of a host char is 8 bits, we can return a pointer
4925 to the string, otherwise we have to copy the string to a buffer
4926 allocated on the temporary obstack. */
4927 gdb_assert (HOST_CHAR_BIT == 8);
4930 *bytes_read_ptr = 1;
4933 *bytes_read_ptr = strlen (buf) + 1;
4938 read_indirect_string (bfd *abfd, char *buf,
4939 const struct comp_unit_head *cu_header,
4940 unsigned int *bytes_read_ptr)
4942 LONGEST str_offset = read_offset (abfd, buf, cu_header,
4943 (int *) bytes_read_ptr);
4945 if (dwarf_str_buffer == NULL)
4947 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4948 bfd_get_filename (abfd));
4951 if (str_offset >= dwarf_str_size)
4953 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4954 bfd_get_filename (abfd));
4957 gdb_assert (HOST_CHAR_BIT == 8);
4958 if (dwarf_str_buffer[str_offset] == '\0')
4960 return dwarf_str_buffer + str_offset;
4963 static unsigned long
4964 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4966 unsigned long result;
4967 unsigned int num_read;
4977 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4980 result |= ((unsigned long)(byte & 127) << shift);
4981 if ((byte & 128) == 0)
4987 *bytes_read_ptr = num_read;
4992 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4995 int i, shift, size, num_read;
5005 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5008 result |= ((long)(byte & 127) << shift);
5010 if ((byte & 128) == 0)
5015 if ((shift < size) && (byte & 0x40))
5017 result |= -(1 << shift);
5019 *bytes_read_ptr = num_read;
5024 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
5030 cu->language = language_c;
5032 case DW_LANG_C_plus_plus:
5033 cu->language = language_cplus;
5035 case DW_LANG_Fortran77:
5036 case DW_LANG_Fortran90:
5037 case DW_LANG_Fortran95:
5038 cu->language = language_fortran;
5040 case DW_LANG_Mips_Assembler:
5041 cu->language = language_asm;
5044 cu->language = language_java;
5048 case DW_LANG_Cobol74:
5049 case DW_LANG_Cobol85:
5050 case DW_LANG_Pascal83:
5051 case DW_LANG_Modula2:
5053 cu->language = language_minimal;
5056 cu->language_defn = language_def (cu->language);
5059 /* Return the named attribute or NULL if not there. */
5061 static struct attribute *
5062 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
5065 struct attribute *spec = NULL;
5067 for (i = 0; i < die->num_attrs; ++i)
5069 if (die->attrs[i].name == name)
5071 return &die->attrs[i];
5073 if (die->attrs[i].name == DW_AT_specification
5074 || die->attrs[i].name == DW_AT_abstract_origin)
5075 spec = &die->attrs[i];
5079 struct die_info *ref_die =
5080 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
5083 return dwarf2_attr (ref_die, name, cu);
5090 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5092 return (dwarf2_attr (die, DW_AT_declaration, cu)
5093 && ! dwarf2_attr (die, DW_AT_specification, cu));
5096 /* Return the die giving the specification for DIE, if there is
5099 static struct die_info *
5100 die_specification (struct die_info *die, struct dwarf2_cu *cu)
5102 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
5104 if (spec_attr == NULL)
5107 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
5110 /* Free the line_header structure *LH, and any arrays and strings it
5113 free_line_header (struct line_header *lh)
5115 if (lh->standard_opcode_lengths)
5116 xfree (lh->standard_opcode_lengths);
5118 /* Remember that all the lh->file_names[i].name pointers are
5119 pointers into debug_line_buffer, and don't need to be freed. */
5121 xfree (lh->file_names);
5123 /* Similarly for the include directory names. */
5124 if (lh->include_dirs)
5125 xfree (lh->include_dirs);
5131 /* Add an entry to LH's include directory table. */
5133 add_include_dir (struct line_header *lh, char *include_dir)
5135 /* Grow the array if necessary. */
5136 if (lh->include_dirs_size == 0)
5138 lh->include_dirs_size = 1; /* for testing */
5139 lh->include_dirs = xmalloc (lh->include_dirs_size
5140 * sizeof (*lh->include_dirs));
5142 else if (lh->num_include_dirs >= lh->include_dirs_size)
5144 lh->include_dirs_size *= 2;
5145 lh->include_dirs = xrealloc (lh->include_dirs,
5146 (lh->include_dirs_size
5147 * sizeof (*lh->include_dirs)));
5150 lh->include_dirs[lh->num_include_dirs++] = include_dir;
5154 /* Add an entry to LH's file name table. */
5156 add_file_name (struct line_header *lh,
5158 unsigned int dir_index,
5159 unsigned int mod_time,
5160 unsigned int length)
5162 struct file_entry *fe;
5164 /* Grow the array if necessary. */
5165 if (lh->file_names_size == 0)
5167 lh->file_names_size = 1; /* for testing */
5168 lh->file_names = xmalloc (lh->file_names_size
5169 * sizeof (*lh->file_names));
5171 else if (lh->num_file_names >= lh->file_names_size)
5173 lh->file_names_size *= 2;
5174 lh->file_names = xrealloc (lh->file_names,
5175 (lh->file_names_size
5176 * sizeof (*lh->file_names)));
5179 fe = &lh->file_names[lh->num_file_names++];
5181 fe->dir_index = dir_index;
5182 fe->mod_time = mod_time;
5183 fe->length = length;
5187 /* Read the statement program header starting at OFFSET in
5188 dwarf_line_buffer, according to the endianness of ABFD. Return a
5189 pointer to a struct line_header, allocated using xmalloc.
5191 NOTE: the strings in the include directory and file name tables of
5192 the returned object point into debug_line_buffer, and must not be
5194 static struct line_header *
5195 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5196 struct dwarf2_cu *cu)
5198 struct cleanup *back_to;
5199 struct line_header *lh;
5203 char *cur_dir, *cur_file;
5205 if (dwarf_line_buffer == NULL)
5207 complaint (&symfile_complaints, "missing .debug_line section");
5211 /* Make sure that at least there's room for the total_length field. That
5212 could be 12 bytes long, but we're just going to fudge that. */
5213 if (offset + 4 >= dwarf_line_size)
5215 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5219 lh = xmalloc (sizeof (*lh));
5220 memset (lh, 0, sizeof (*lh));
5221 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5224 line_ptr = dwarf_line_buffer + offset;
5226 /* read in the header */
5227 lh->total_length = read_initial_length (abfd, line_ptr, &cu->header, &bytes_read);
5228 line_ptr += bytes_read;
5229 if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size)
5231 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5234 lh->statement_program_end = line_ptr + lh->total_length;
5235 lh->version = read_2_bytes (abfd, line_ptr);
5237 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5238 line_ptr += bytes_read;
5239 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5241 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5243 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5245 lh->line_range = read_1_byte (abfd, line_ptr);
5247 lh->opcode_base = read_1_byte (abfd, line_ptr);
5249 lh->standard_opcode_lengths
5250 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5252 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5253 for (i = 1; i < lh->opcode_base; ++i)
5255 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5259 /* Read directory table */
5260 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5262 line_ptr += bytes_read;
5263 add_include_dir (lh, cur_dir);
5265 line_ptr += bytes_read;
5267 /* Read file name table */
5268 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5270 unsigned int dir_index, mod_time, length;
5272 line_ptr += bytes_read;
5273 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5274 line_ptr += bytes_read;
5275 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5276 line_ptr += bytes_read;
5277 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5278 line_ptr += bytes_read;
5280 add_file_name (lh, cur_file, dir_index, mod_time, length);
5282 line_ptr += bytes_read;
5283 lh->statement_program_start = line_ptr;
5285 if (line_ptr > dwarf_line_buffer + dwarf_line_size)
5286 complaint (&symfile_complaints,
5287 "line number info header doesn't fit in `.debug_line' section");
5289 discard_cleanups (back_to);
5293 /* This function exists to work around a bug in certain compilers
5294 (particularly GCC 2.95), in which the first line number marker of a
5295 function does not show up until after the prologue, right before
5296 the second line number marker. This function shifts ADDRESS down
5297 to the beginning of the function if necessary, and is called on
5298 addresses passed to record_line. */
5301 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
5303 struct function_range *fn;
5305 /* Find the function_range containing address. */
5310 cu->cached_fn = cu->first_fn;
5314 if (fn->lowpc <= address && fn->highpc > address)
5320 while (fn && fn != cu->cached_fn)
5321 if (fn->lowpc <= address && fn->highpc > address)
5331 if (address != fn->lowpc)
5332 complaint (&symfile_complaints,
5333 "misplaced first line number at 0x%lx for '%s'",
5334 (unsigned long) address, fn->name);
5339 /* Decode the line number information for the compilation unit whose
5340 line number info is at OFFSET in the .debug_line section.
5341 The compilation directory of the file is passed in COMP_DIR. */
5344 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5345 struct dwarf2_cu *cu)
5349 unsigned int bytes_read;
5350 unsigned char op_code, extended_op, adj_opcode;
5352 struct objfile *objfile = cu->objfile;
5354 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5356 line_ptr = lh->statement_program_start;
5357 line_end = lh->statement_program_end;
5359 /* Read the statement sequences until there's nothing left. */
5360 while (line_ptr < line_end)
5362 /* state machine registers */
5363 CORE_ADDR address = 0;
5364 unsigned int file = 1;
5365 unsigned int line = 1;
5366 unsigned int column = 0;
5367 int is_stmt = lh->default_is_stmt;
5368 int basic_block = 0;
5369 int end_sequence = 0;
5371 /* Start a subfile for the current file of the state machine. */
5372 if (lh->num_file_names >= file)
5374 /* lh->include_dirs and lh->file_names are 0-based, but the
5375 directory and file name numbers in the statement program
5377 struct file_entry *fe = &lh->file_names[file - 1];
5380 dir = lh->include_dirs[fe->dir_index - 1];
5383 dwarf2_start_subfile (fe->name, dir);
5386 /* Decode the table. */
5387 while (!end_sequence)
5389 op_code = read_1_byte (abfd, line_ptr);
5392 if (op_code >= lh->opcode_base)
5393 { /* Special operand. */
5394 adj_opcode = op_code - lh->opcode_base;
5395 address += (adj_opcode / lh->line_range)
5396 * lh->minimum_instruction_length;
5397 line += lh->line_base + (adj_opcode % lh->line_range);
5398 /* append row to matrix using current values */
5399 record_line (current_subfile, line,
5400 check_cu_functions (address, cu));
5403 else switch (op_code)
5405 case DW_LNS_extended_op:
5406 line_ptr += 1; /* ignore length */
5407 extended_op = read_1_byte (abfd, line_ptr);
5409 switch (extended_op)
5411 case DW_LNE_end_sequence:
5413 record_line (current_subfile, 0, address);
5415 case DW_LNE_set_address:
5416 address = read_address (abfd, line_ptr, cu, &bytes_read);
5417 line_ptr += bytes_read;
5418 address += baseaddr;
5420 case DW_LNE_define_file:
5423 unsigned int dir_index, mod_time, length;
5425 cur_file = read_string (abfd, line_ptr, &bytes_read);
5426 line_ptr += bytes_read;
5428 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5429 line_ptr += bytes_read;
5431 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5432 line_ptr += bytes_read;
5434 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5435 line_ptr += bytes_read;
5436 add_file_name (lh, cur_file, dir_index, mod_time, length);
5440 complaint (&symfile_complaints,
5441 "mangled .debug_line section");
5446 record_line (current_subfile, line,
5447 check_cu_functions (address, cu));
5450 case DW_LNS_advance_pc:
5451 address += lh->minimum_instruction_length
5452 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5453 line_ptr += bytes_read;
5455 case DW_LNS_advance_line:
5456 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
5457 line_ptr += bytes_read;
5459 case DW_LNS_set_file:
5461 /* lh->include_dirs and lh->file_names are 0-based,
5462 but the directory and file name numbers in the
5463 statement program are 1-based. */
5464 struct file_entry *fe;
5466 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5467 line_ptr += bytes_read;
5468 fe = &lh->file_names[file - 1];
5470 dir = lh->include_dirs[fe->dir_index - 1];
5473 dwarf2_start_subfile (fe->name, dir);
5476 case DW_LNS_set_column:
5477 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5478 line_ptr += bytes_read;
5480 case DW_LNS_negate_stmt:
5481 is_stmt = (!is_stmt);
5483 case DW_LNS_set_basic_block:
5486 /* Add to the address register of the state machine the
5487 address increment value corresponding to special opcode
5488 255. Ie, this value is scaled by the minimum instruction
5489 length since special opcode 255 would have scaled the
5491 case DW_LNS_const_add_pc:
5492 address += (lh->minimum_instruction_length
5493 * ((255 - lh->opcode_base) / lh->line_range));
5495 case DW_LNS_fixed_advance_pc:
5496 address += read_2_bytes (abfd, line_ptr);
5500 { /* Unknown standard opcode, ignore it. */
5502 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
5504 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5505 line_ptr += bytes_read;
5513 /* Start a subfile for DWARF. FILENAME is the name of the file and
5514 DIRNAME the name of the source directory which contains FILENAME
5515 or NULL if not known.
5516 This routine tries to keep line numbers from identical absolute and
5517 relative file names in a common subfile.
5519 Using the `list' example from the GDB testsuite, which resides in
5520 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5521 of /srcdir/list0.c yields the following debugging information for list0.c:
5523 DW_AT_name: /srcdir/list0.c
5524 DW_AT_comp_dir: /compdir
5525 files.files[0].name: list0.h
5526 files.files[0].dir: /srcdir
5527 files.files[1].name: list0.c
5528 files.files[1].dir: /srcdir
5530 The line number information for list0.c has to end up in a single
5531 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5534 dwarf2_start_subfile (char *filename, char *dirname)
5536 /* If the filename isn't absolute, try to match an existing subfile
5537 with the full pathname. */
5539 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
5541 struct subfile *subfile;
5542 char *fullname = concat (dirname, "/", filename, NULL);
5544 for (subfile = subfiles; subfile; subfile = subfile->next)
5546 if (FILENAME_CMP (subfile->name, fullname) == 0)
5548 current_subfile = subfile;
5555 start_subfile (filename, dirname);
5559 var_decode_location (struct attribute *attr, struct symbol *sym,
5560 struct dwarf2_cu *cu)
5562 struct objfile *objfile = cu->objfile;
5563 struct comp_unit_head *cu_header = &cu->header;
5565 /* NOTE drow/2003-01-30: There used to be a comment and some special
5566 code here to turn a symbol with DW_AT_external and a
5567 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5568 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5569 with some versions of binutils) where shared libraries could have
5570 relocations against symbols in their debug information - the
5571 minimal symbol would have the right address, but the debug info
5572 would not. It's no longer necessary, because we will explicitly
5573 apply relocations when we read in the debug information now. */
5575 /* A DW_AT_location attribute with no contents indicates that a
5576 variable has been optimized away. */
5577 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
5579 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
5583 /* Handle one degenerate form of location expression specially, to
5584 preserve GDB's previous behavior when section offsets are
5585 specified. If this is just a DW_OP_addr then mark this symbol
5588 if (attr_form_is_block (attr)
5589 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
5590 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
5594 SYMBOL_VALUE_ADDRESS (sym) =
5595 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
5596 fixup_symbol_section (sym, objfile);
5597 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
5598 SYMBOL_SECTION (sym));
5599 SYMBOL_CLASS (sym) = LOC_STATIC;
5603 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5604 expression evaluator, and use LOC_COMPUTED only when necessary
5605 (i.e. when the value of a register or memory location is
5606 referenced, or a thread-local block, etc.). Then again, it might
5607 not be worthwhile. I'm assuming that it isn't unless performance
5608 or memory numbers show me otherwise. */
5610 dwarf2_symbol_mark_computed (attr, sym, cu);
5611 SYMBOL_CLASS (sym) = LOC_COMPUTED;
5614 /* Given a pointer to a DWARF information entry, figure out if we need
5615 to make a symbol table entry for it, and if so, create a new entry
5616 and return a pointer to it.
5617 If TYPE is NULL, determine symbol type from the die, otherwise
5618 used the passed type. */
5620 static struct symbol *
5621 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5623 struct objfile *objfile = cu->objfile;
5624 struct symbol *sym = NULL;
5626 struct attribute *attr = NULL;
5627 struct attribute *attr2 = NULL;
5630 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5632 if (die->tag != DW_TAG_namespace)
5633 name = dwarf2_linkage_name (die, cu);
5635 name = TYPE_NAME (type);
5639 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
5640 sizeof (struct symbol));
5641 OBJSTAT (objfile, n_syms++);
5642 memset (sym, 0, sizeof (struct symbol));
5644 /* Cache this symbol's name and the name's demangled form (if any). */
5645 SYMBOL_LANGUAGE (sym) = cu->language;
5646 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
5648 /* Default assumptions.
5649 Use the passed type or decode it from the die. */
5650 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5651 SYMBOL_CLASS (sym) = LOC_STATIC;
5653 SYMBOL_TYPE (sym) = type;
5655 SYMBOL_TYPE (sym) = die_type (die, cu);
5656 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
5659 SYMBOL_LINE (sym) = DW_UNSND (attr);
5664 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5667 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
5669 SYMBOL_CLASS (sym) = LOC_LABEL;
5671 case DW_TAG_subprogram:
5672 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5674 SYMBOL_CLASS (sym) = LOC_BLOCK;
5675 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5676 if (attr2 && (DW_UNSND (attr2) != 0))
5678 add_symbol_to_list (sym, &global_symbols);
5682 add_symbol_to_list (sym, cu->list_in_scope);
5685 case DW_TAG_variable:
5686 /* Compilation with minimal debug info may result in variables
5687 with missing type entries. Change the misleading `void' type
5688 to something sensible. */
5689 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
5690 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
5691 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
5692 "<variable, no debug info>",
5694 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5697 dwarf2_const_value (attr, sym, cu);
5698 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5699 if (attr2 && (DW_UNSND (attr2) != 0))
5700 add_symbol_to_list (sym, &global_symbols);
5702 add_symbol_to_list (sym, cu->list_in_scope);
5705 attr = dwarf2_attr (die, DW_AT_location, cu);
5708 var_decode_location (attr, sym, cu);
5709 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5710 if (attr2 && (DW_UNSND (attr2) != 0))
5711 add_symbol_to_list (sym, &global_symbols);
5713 add_symbol_to_list (sym, cu->list_in_scope);
5717 /* We do not know the address of this symbol.
5718 If it is an external symbol and we have type information
5719 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5720 The address of the variable will then be determined from
5721 the minimal symbol table whenever the variable is
5723 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5724 if (attr2 && (DW_UNSND (attr2) != 0)
5725 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
5727 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
5728 add_symbol_to_list (sym, &global_symbols);
5732 case DW_TAG_formal_parameter:
5733 attr = dwarf2_attr (die, DW_AT_location, cu);
5736 var_decode_location (attr, sym, cu);
5737 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5738 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
5739 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
5741 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5744 dwarf2_const_value (attr, sym, cu);
5746 add_symbol_to_list (sym, cu->list_in_scope);
5748 case DW_TAG_unspecified_parameters:
5749 /* From varargs functions; gdb doesn't seem to have any
5750 interest in this information, so just ignore it for now.
5753 case DW_TAG_class_type:
5754 case DW_TAG_structure_type:
5755 case DW_TAG_union_type:
5756 case DW_TAG_enumeration_type:
5757 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5758 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5760 /* Make sure that the symbol includes appropriate enclosing
5761 classes/namespaces in its name. These are calculated in
5762 read_structure_type, and the correct name is saved in
5765 if (cu->language == language_cplus)
5767 struct type *type = SYMBOL_TYPE (sym);
5769 if (TYPE_TAG_NAME (type) != NULL)
5771 /* FIXME: carlton/2003-11-10: Should this use
5772 SYMBOL_SET_NAMES instead? (The same problem also
5773 arises a further down in the function.) */
5774 SYMBOL_LINKAGE_NAME (sym)
5775 = obsavestring (TYPE_TAG_NAME (type),
5776 strlen (TYPE_TAG_NAME (type)),
5777 &objfile->objfile_obstack);
5782 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5783 really ever be static objects: otherwise, if you try
5784 to, say, break of a class's method and you're in a file
5785 which doesn't mention that class, it won't work unless
5786 the check for all static symbols in lookup_symbol_aux
5787 saves you. See the OtherFileClass tests in
5788 gdb.c++/namespace.exp. */
5790 struct pending **list_to_add;
5792 list_to_add = (cu->list_in_scope == &file_symbols
5793 && cu->language == language_cplus
5794 ? &global_symbols : cu->list_in_scope);
5796 add_symbol_to_list (sym, list_to_add);
5798 /* The semantics of C++ state that "struct foo { ... }" also
5799 defines a typedef for "foo". Synthesize a typedef symbol so
5800 that "ptype foo" works as expected. */
5801 if (cu->language == language_cplus)
5803 struct symbol *typedef_sym = (struct symbol *)
5804 obstack_alloc (&objfile->objfile_obstack,
5805 sizeof (struct symbol));
5806 *typedef_sym = *sym;
5807 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
5808 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
5809 TYPE_NAME (SYMBOL_TYPE (sym)) =
5810 obsavestring (SYMBOL_NATURAL_NAME (sym),
5811 strlen (SYMBOL_NATURAL_NAME (sym)),
5812 &objfile->objfile_obstack);
5813 add_symbol_to_list (typedef_sym, list_to_add);
5817 case DW_TAG_typedef:
5818 if (processing_has_namespace_info
5819 && processing_current_prefix[0] != '\0')
5821 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
5822 processing_current_prefix,
5826 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5827 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5828 add_symbol_to_list (sym, cu->list_in_scope);
5830 case DW_TAG_base_type:
5831 case DW_TAG_subrange_type:
5832 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5833 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5834 add_symbol_to_list (sym, cu->list_in_scope);
5836 case DW_TAG_enumerator:
5837 if (processing_has_namespace_info
5838 && processing_current_prefix[0] != '\0')
5840 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
5841 processing_current_prefix,
5845 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5848 dwarf2_const_value (attr, sym, cu);
5851 /* NOTE: carlton/2003-11-10: See comment above in the
5852 DW_TAG_class_type, etc. block. */
5854 struct pending **list_to_add;
5856 list_to_add = (cu->list_in_scope == &file_symbols
5857 && cu->language == language_cplus
5858 ? &global_symbols : cu->list_in_scope);
5860 add_symbol_to_list (sym, list_to_add);
5863 case DW_TAG_namespace:
5864 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5865 add_symbol_to_list (sym, &global_symbols);
5868 /* Not a tag we recognize. Hopefully we aren't processing
5869 trash data, but since we must specifically ignore things
5870 we don't recognize, there is nothing else we should do at
5872 complaint (&symfile_complaints, "unsupported tag: '%s'",
5873 dwarf_tag_name (die->tag));
5880 /* Copy constant value from an attribute to a symbol. */
5883 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
5884 struct dwarf2_cu *cu)
5886 struct objfile *objfile = cu->objfile;
5887 struct comp_unit_head *cu_header = &cu->header;
5888 struct dwarf_block *blk;
5893 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
5894 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5895 cu_header->addr_size,
5896 TYPE_LENGTH (SYMBOL_TYPE
5898 SYMBOL_VALUE_BYTES (sym) = (char *)
5899 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
5900 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5901 it's body - store_unsigned_integer. */
5902 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
5904 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5906 case DW_FORM_block1:
5907 case DW_FORM_block2:
5908 case DW_FORM_block4:
5910 blk = DW_BLOCK (attr);
5911 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
5912 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5914 TYPE_LENGTH (SYMBOL_TYPE
5916 SYMBOL_VALUE_BYTES (sym) = (char *)
5917 obstack_alloc (&objfile->objfile_obstack, blk->size);
5918 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
5919 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5922 /* The DW_AT_const_value attributes are supposed to carry the
5923 symbol's value "represented as it would be on the target
5924 architecture." By the time we get here, it's already been
5925 converted to host endianness, so we just need to sign- or
5926 zero-extend it as appropriate. */
5928 dwarf2_const_value_data (attr, sym, 8);
5931 dwarf2_const_value_data (attr, sym, 16);
5934 dwarf2_const_value_data (attr, sym, 32);
5937 dwarf2_const_value_data (attr, sym, 64);
5941 SYMBOL_VALUE (sym) = DW_SND (attr);
5942 SYMBOL_CLASS (sym) = LOC_CONST;
5946 SYMBOL_VALUE (sym) = DW_UNSND (attr);
5947 SYMBOL_CLASS (sym) = LOC_CONST;
5951 complaint (&symfile_complaints,
5952 "unsupported const value attribute form: '%s'",
5953 dwarf_form_name (attr->form));
5954 SYMBOL_VALUE (sym) = 0;
5955 SYMBOL_CLASS (sym) = LOC_CONST;
5961 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5962 or zero-extend it as appropriate for the symbol's type. */
5964 dwarf2_const_value_data (struct attribute *attr,
5968 LONGEST l = DW_UNSND (attr);
5970 if (bits < sizeof (l) * 8)
5972 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
5973 l &= ((LONGEST) 1 << bits) - 1;
5975 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
5978 SYMBOL_VALUE (sym) = l;
5979 SYMBOL_CLASS (sym) = LOC_CONST;
5983 /* Return the type of the die in question using its DW_AT_type attribute. */
5985 static struct type *
5986 die_type (struct die_info *die, struct dwarf2_cu *cu)
5989 struct attribute *type_attr;
5990 struct die_info *type_die;
5993 type_attr = dwarf2_attr (die, DW_AT_type, cu);
5996 /* A missing DW_AT_type represents a void type. */
5997 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
6001 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6002 type_die = follow_die_ref (ref);
6005 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6006 ref, cu->objfile->name);
6010 type = tag_type_to_type (type_die, cu);
6013 dump_die (type_die);
6014 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6020 /* Return the containing type of the die in question using its
6021 DW_AT_containing_type attribute. */
6023 static struct type *
6024 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
6026 struct type *type = NULL;
6027 struct attribute *type_attr;
6028 struct die_info *type_die = NULL;
6031 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
6034 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6035 type_die = follow_die_ref (ref);
6038 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
6042 type = tag_type_to_type (type_die, cu);
6047 dump_die (type_die);
6048 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6055 static struct type *
6056 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
6058 struct die_info *die;
6061 die = follow_die_ref (offset);
6064 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
6067 type = tag_type_to_type (die, cu);
6072 static struct type *
6073 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
6081 read_type_die (die, cu);
6085 error ("Dwarf Error: Cannot find type of die 0x%x [in module %s]",
6086 die->tag, cu->objfile->name);
6093 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6095 char *prefix = determine_prefix (die, cu);
6096 const char *old_prefix = processing_current_prefix;
6097 struct cleanup *back_to = make_cleanup (xfree, prefix);
6098 processing_current_prefix = prefix;
6102 case DW_TAG_class_type:
6103 case DW_TAG_structure_type:
6104 case DW_TAG_union_type:
6105 read_structure_type (die, cu);
6107 case DW_TAG_enumeration_type:
6108 read_enumeration_type (die, cu);
6110 case DW_TAG_subprogram:
6111 case DW_TAG_subroutine_type:
6112 read_subroutine_type (die, cu);
6114 case DW_TAG_array_type:
6115 read_array_type (die, cu);
6117 case DW_TAG_pointer_type:
6118 read_tag_pointer_type (die, cu);
6120 case DW_TAG_unspecified_type:
6121 read_tag_unspecified_type (die, cu);
6123 case DW_TAG_ptr_to_member_type:
6124 read_tag_ptr_to_member_type (die, cu);
6126 case DW_TAG_reference_type:
6127 case DW_TAG_rvalue_reference_type:
6128 read_tag_reference_type (die, cu);
6130 case DW_TAG_const_type:
6131 read_tag_const_type (die, cu);
6133 case DW_TAG_volatile_type:
6134 read_tag_volatile_type (die, cu);
6136 case DW_TAG_restrict_type:
6137 read_tag_restrict_type (die, cu);
6139 case DW_TAG_string_type:
6140 read_tag_string_type (die, cu);
6142 case DW_TAG_typedef:
6143 read_typedef (die, cu);
6145 case DW_TAG_subrange_type:
6146 read_subrange_type (die, cu);
6148 case DW_TAG_base_type:
6149 read_base_type (die, cu);
6152 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
6153 dwarf_tag_name (die->tag));
6157 processing_current_prefix = old_prefix;
6158 do_cleanups (back_to);
6161 /* Return the name of the namespace/class that DIE is defined within,
6162 or "" if we can't tell. The caller should xfree the result. */
6164 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6165 therein) for an example of how to use this function to deal with
6166 DW_AT_specification. */
6169 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6171 struct die_info *parent;
6173 if (cu->language != language_cplus)
6176 parent = die->parent;
6180 return xstrdup ("");
6184 switch (parent->tag) {
6185 case DW_TAG_namespace:
6187 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6188 before doing this check? */
6189 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6191 return xstrdup (TYPE_TAG_NAME (parent->type));
6196 char *parent_prefix = determine_prefix (parent, cu);
6197 char *retval = typename_concat (parent_prefix,
6198 namespace_name (parent, &dummy,
6200 xfree (parent_prefix);
6205 case DW_TAG_class_type:
6206 case DW_TAG_structure_type:
6208 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6210 return xstrdup (TYPE_TAG_NAME (parent->type));
6214 const char *old_prefix = processing_current_prefix;
6215 char *new_prefix = determine_prefix (parent, cu);
6218 processing_current_prefix = new_prefix;
6219 retval = determine_class_name (parent, cu);
6220 processing_current_prefix = old_prefix;
6227 return determine_prefix (parent, cu);
6232 /* Return a newly-allocated string formed by concatenating PREFIX,
6233 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6234 string, just return a copy of SUFFIX. */
6237 typename_concat (const char *prefix, const char *suffix)
6239 if (prefix == NULL || prefix[0] == '\0')
6240 return xstrdup (suffix);
6243 char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1);
6245 strcpy (retval, prefix);
6246 strcat (retval, "::");
6247 strcat (retval, suffix);
6253 static struct type *
6254 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6256 struct objfile *objfile = cu->objfile;
6258 /* FIXME - this should not produce a new (struct type *)
6259 every time. It should cache base types. */
6263 case DW_ATE_address:
6264 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
6266 case DW_ATE_boolean:
6267 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
6269 case DW_ATE_complex_float:
6272 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
6276 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
6282 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
6286 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
6293 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6296 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
6300 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6304 case DW_ATE_signed_char:
6305 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6307 case DW_ATE_unsigned:
6311 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6314 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
6318 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
6322 case DW_ATE_unsigned_char:
6323 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6326 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6333 copy_die (struct die_info *old_die)
6335 struct die_info *new_die;
6338 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
6339 memset (new_die, 0, sizeof (struct die_info));
6341 new_die->tag = old_die->tag;
6342 new_die->has_children = old_die->has_children;
6343 new_die->abbrev = old_die->abbrev;
6344 new_die->offset = old_die->offset;
6345 new_die->type = NULL;
6347 num_attrs = old_die->num_attrs;
6348 new_die->num_attrs = num_attrs;
6349 new_die->attrs = (struct attribute *)
6350 xmalloc (num_attrs * sizeof (struct attribute));
6352 for (i = 0; i < old_die->num_attrs; ++i)
6354 new_die->attrs[i].name = old_die->attrs[i].name;
6355 new_die->attrs[i].form = old_die->attrs[i].form;
6356 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
6359 new_die->next = NULL;
6364 /* Return sibling of die, NULL if no sibling. */
6366 static struct die_info *
6367 sibling_die (struct die_info *die)
6369 return die->sibling;
6372 /* Get linkage name of a die, return NULL if not found. */
6375 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
6377 struct attribute *attr;
6379 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
6380 if (attr && DW_STRING (attr))
6381 return DW_STRING (attr);
6382 attr = dwarf2_attr (die, DW_AT_name, cu);
6383 if (attr && DW_STRING (attr))
6384 return DW_STRING (attr);
6388 /* Get name of a die, return NULL if not found. */
6391 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
6393 struct attribute *attr;
6395 attr = dwarf2_attr (die, DW_AT_name, cu);
6396 if (attr && DW_STRING (attr))
6397 return DW_STRING (attr);
6401 /* Return the die that this die in an extension of, or NULL if there
6404 static struct die_info *
6405 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
6407 struct attribute *attr;
6408 struct die_info *extension_die;
6411 attr = dwarf2_attr (die, DW_AT_extension, cu);
6415 ref = dwarf2_get_ref_die_offset (attr, cu);
6416 extension_die = follow_die_ref (ref);
6419 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
6422 return extension_die;
6425 /* Convert a DIE tag into its string name. */
6428 dwarf_tag_name (unsigned tag)
6432 case DW_TAG_padding:
6433 return "DW_TAG_padding";
6434 case DW_TAG_array_type:
6435 return "DW_TAG_array_type";
6436 case DW_TAG_class_type:
6437 return "DW_TAG_class_type";
6438 case DW_TAG_entry_point:
6439 return "DW_TAG_entry_point";
6440 case DW_TAG_enumeration_type:
6441 return "DW_TAG_enumeration_type";
6442 case DW_TAG_formal_parameter:
6443 return "DW_TAG_formal_parameter";
6444 case DW_TAG_imported_declaration:
6445 return "DW_TAG_imported_declaration";
6447 return "DW_TAG_label";
6448 case DW_TAG_lexical_block:
6449 return "DW_TAG_lexical_block";
6451 return "DW_TAG_member";
6452 case DW_TAG_pointer_type:
6453 return "DW_TAG_pointer_type";
6454 case DW_TAG_reference_type:
6455 return "DW_TAG_reference_type";
6456 case DW_TAG_rvalue_reference_type:
6457 return "DW_TAG_rvalue_reference_type";
6458 case DW_TAG_compile_unit:
6459 return "DW_TAG_compile_unit";
6460 case DW_TAG_string_type:
6461 return "DW_TAG_string_type";
6462 case DW_TAG_structure_type:
6463 return "DW_TAG_structure_type";
6464 case DW_TAG_subroutine_type:
6465 return "DW_TAG_subroutine_type";
6466 case DW_TAG_typedef:
6467 return "DW_TAG_typedef";
6468 case DW_TAG_union_type:
6469 return "DW_TAG_union_type";
6470 case DW_TAG_unspecified_parameters:
6471 return "DW_TAG_unspecified_parameters";
6472 case DW_TAG_variant:
6473 return "DW_TAG_variant";
6474 case DW_TAG_common_block:
6475 return "DW_TAG_common_block";
6476 case DW_TAG_common_inclusion:
6477 return "DW_TAG_common_inclusion";
6478 case DW_TAG_inheritance:
6479 return "DW_TAG_inheritance";
6480 case DW_TAG_inlined_subroutine:
6481 return "DW_TAG_inlined_subroutine";
6483 return "DW_TAG_module";
6484 case DW_TAG_ptr_to_member_type:
6485 return "DW_TAG_ptr_to_member_type";
6486 case DW_TAG_set_type:
6487 return "DW_TAG_set_type";
6488 case DW_TAG_subrange_type:
6489 return "DW_TAG_subrange_type";
6490 case DW_TAG_with_stmt:
6491 return "DW_TAG_with_stmt";
6492 case DW_TAG_access_declaration:
6493 return "DW_TAG_access_declaration";
6494 case DW_TAG_base_type:
6495 return "DW_TAG_base_type";
6496 case DW_TAG_catch_block:
6497 return "DW_TAG_catch_block";
6498 case DW_TAG_const_type:
6499 return "DW_TAG_const_type";
6500 case DW_TAG_constant:
6501 return "DW_TAG_constant";
6502 case DW_TAG_enumerator:
6503 return "DW_TAG_enumerator";
6504 case DW_TAG_file_type:
6505 return "DW_TAG_file_type";
6507 return "DW_TAG_friend";
6508 case DW_TAG_namelist:
6509 return "DW_TAG_namelist";
6510 case DW_TAG_namelist_item:
6511 return "DW_TAG_namelist_item";
6512 case DW_TAG_packed_type:
6513 return "DW_TAG_packed_type";
6514 case DW_TAG_subprogram:
6515 return "DW_TAG_subprogram";
6516 case DW_TAG_template_type_param:
6517 return "DW_TAG_template_type_param";
6518 case DW_TAG_template_value_param:
6519 return "DW_TAG_template_value_param";
6520 case DW_TAG_thrown_type:
6521 return "DW_TAG_thrown_type";
6522 case DW_TAG_try_block:
6523 return "DW_TAG_try_block";
6524 case DW_TAG_variant_part:
6525 return "DW_TAG_variant_part";
6526 case DW_TAG_variable:
6527 return "DW_TAG_variable";
6528 case DW_TAG_volatile_type:
6529 return "DW_TAG_volatile_type";
6530 case DW_TAG_dwarf_procedure:
6531 return "DW_TAG_dwarf_procedure";
6532 case DW_TAG_restrict_type:
6533 return "DW_TAG_restrict_type";
6534 case DW_TAG_interface_type:
6535 return "DW_TAG_interface_type";
6536 case DW_TAG_namespace:
6537 return "DW_TAG_namespace";
6538 case DW_TAG_imported_module:
6539 return "DW_TAG_imported_module";
6540 case DW_TAG_unspecified_type:
6541 return "DW_TAG_unspecified_type";
6542 case DW_TAG_partial_unit:
6543 return "DW_TAG_partial_unit";
6544 case DW_TAG_imported_unit:
6545 return "DW_TAG_imported_unit";
6546 case DW_TAG_MIPS_loop:
6547 return "DW_TAG_MIPS_loop";
6548 case DW_TAG_format_label:
6549 return "DW_TAG_format_label";
6550 case DW_TAG_function_template:
6551 return "DW_TAG_function_template";
6552 case DW_TAG_class_template:
6553 return "DW_TAG_class_template";
6555 return "DW_TAG_<unknown>";
6559 /* Convert a DWARF attribute code into its string name. */
6562 dwarf_attr_name (unsigned attr)
6567 return "DW_AT_sibling";
6568 case DW_AT_location:
6569 return "DW_AT_location";
6571 return "DW_AT_name";
6572 case DW_AT_ordering:
6573 return "DW_AT_ordering";
6574 case DW_AT_subscr_data:
6575 return "DW_AT_subscr_data";
6576 case DW_AT_byte_size:
6577 return "DW_AT_byte_size";
6578 case DW_AT_bit_offset:
6579 return "DW_AT_bit_offset";
6580 case DW_AT_bit_size:
6581 return "DW_AT_bit_size";
6582 case DW_AT_element_list:
6583 return "DW_AT_element_list";
6584 case DW_AT_stmt_list:
6585 return "DW_AT_stmt_list";
6587 return "DW_AT_low_pc";
6589 return "DW_AT_high_pc";
6590 case DW_AT_language:
6591 return "DW_AT_language";
6593 return "DW_AT_member";
6595 return "DW_AT_discr";
6596 case DW_AT_discr_value:
6597 return "DW_AT_discr_value";
6598 case DW_AT_visibility:
6599 return "DW_AT_visibility";
6601 return "DW_AT_import";
6602 case DW_AT_string_length:
6603 return "DW_AT_string_length";
6604 case DW_AT_common_reference:
6605 return "DW_AT_common_reference";
6606 case DW_AT_comp_dir:
6607 return "DW_AT_comp_dir";
6608 case DW_AT_const_value:
6609 return "DW_AT_const_value";
6610 case DW_AT_containing_type:
6611 return "DW_AT_containing_type";
6612 case DW_AT_default_value:
6613 return "DW_AT_default_value";
6615 return "DW_AT_inline";
6616 case DW_AT_is_optional:
6617 return "DW_AT_is_optional";
6618 case DW_AT_lower_bound:
6619 return "DW_AT_lower_bound";
6620 case DW_AT_producer:
6621 return "DW_AT_producer";
6622 case DW_AT_prototyped:
6623 return "DW_AT_prototyped";
6624 case DW_AT_return_addr:
6625 return "DW_AT_return_addr";
6626 case DW_AT_start_scope:
6627 return "DW_AT_start_scope";
6628 case DW_AT_stride_size:
6629 return "DW_AT_stride_size";
6630 case DW_AT_upper_bound:
6631 return "DW_AT_upper_bound";
6632 case DW_AT_abstract_origin:
6633 return "DW_AT_abstract_origin";
6634 case DW_AT_accessibility:
6635 return "DW_AT_accessibility";
6636 case DW_AT_address_class:
6637 return "DW_AT_address_class";
6638 case DW_AT_artificial:
6639 return "DW_AT_artificial";
6640 case DW_AT_base_types:
6641 return "DW_AT_base_types";
6642 case DW_AT_calling_convention:
6643 return "DW_AT_calling_convention";
6645 return "DW_AT_count";
6646 case DW_AT_data_member_location:
6647 return "DW_AT_data_member_location";
6648 case DW_AT_decl_column:
6649 return "DW_AT_decl_column";
6650 case DW_AT_decl_file:
6651 return "DW_AT_decl_file";
6652 case DW_AT_decl_line:
6653 return "DW_AT_decl_line";
6654 case DW_AT_declaration:
6655 return "DW_AT_declaration";
6656 case DW_AT_discr_list:
6657 return "DW_AT_discr_list";
6658 case DW_AT_encoding:
6659 return "DW_AT_encoding";
6660 case DW_AT_external:
6661 return "DW_AT_external";
6662 case DW_AT_frame_base:
6663 return "DW_AT_frame_base";
6665 return "DW_AT_friend";
6666 case DW_AT_identifier_case:
6667 return "DW_AT_identifier_case";
6668 case DW_AT_macro_info:
6669 return "DW_AT_macro_info";
6670 case DW_AT_namelist_items:
6671 return "DW_AT_namelist_items";
6672 case DW_AT_priority:
6673 return "DW_AT_priority";
6675 return "DW_AT_segment";
6676 case DW_AT_specification:
6677 return "DW_AT_specification";
6678 case DW_AT_static_link:
6679 return "DW_AT_static_link";
6681 return "DW_AT_type";
6682 case DW_AT_use_location:
6683 return "DW_AT_use_location";
6684 case DW_AT_variable_parameter:
6685 return "DW_AT_variable_parameter";
6686 case DW_AT_virtuality:
6687 return "DW_AT_virtuality";
6688 case DW_AT_vtable_elem_location:
6689 return "DW_AT_vtable_elem_location";
6690 case DW_AT_allocated:
6691 return "DW_AT_allocated";
6692 case DW_AT_associated:
6693 return "DW_AT_associated";
6694 case DW_AT_data_location:
6695 return "DW_AT_data_location";
6697 return "DW_AT_stride";
6698 case DW_AT_entry_pc:
6699 return "DW_AT_entry_pc";
6700 case DW_AT_use_UTF8:
6701 return "DW_AT_use_UTF8";
6702 case DW_AT_extension:
6703 return "DW_AT_extension";
6705 return "DW_AT_ranges";
6706 case DW_AT_trampoline:
6707 return "DW_AT_trampoline";
6708 case DW_AT_call_column:
6709 return "DW_AT_call_column";
6710 case DW_AT_call_file:
6711 return "DW_AT_call_file";
6712 case DW_AT_call_line:
6713 return "DW_AT_call_line";
6715 case DW_AT_MIPS_fde:
6716 return "DW_AT_MIPS_fde";
6717 case DW_AT_MIPS_loop_begin:
6718 return "DW_AT_MIPS_loop_begin";
6719 case DW_AT_MIPS_tail_loop_begin:
6720 return "DW_AT_MIPS_tail_loop_begin";
6721 case DW_AT_MIPS_epilog_begin:
6722 return "DW_AT_MIPS_epilog_begin";
6723 case DW_AT_MIPS_loop_unroll_factor:
6724 return "DW_AT_MIPS_loop_unroll_factor";
6725 case DW_AT_MIPS_software_pipeline_depth:
6726 return "DW_AT_MIPS_software_pipeline_depth";
6728 case DW_AT_MIPS_linkage_name:
6729 return "DW_AT_MIPS_linkage_name";
6731 case DW_AT_sf_names:
6732 return "DW_AT_sf_names";
6733 case DW_AT_src_info:
6734 return "DW_AT_src_info";
6735 case DW_AT_mac_info:
6736 return "DW_AT_mac_info";
6737 case DW_AT_src_coords:
6738 return "DW_AT_src_coords";
6739 case DW_AT_body_begin:
6740 return "DW_AT_body_begin";
6741 case DW_AT_body_end:
6742 return "DW_AT_body_end";
6743 case DW_AT_GNU_vector:
6744 return "DW_AT_GNU_vector";
6746 return "DW_AT_<unknown>";
6750 /* Convert a DWARF value form code into its string name. */
6753 dwarf_form_name (unsigned form)
6758 return "DW_FORM_addr";
6759 case DW_FORM_block2:
6760 return "DW_FORM_block2";
6761 case DW_FORM_block4:
6762 return "DW_FORM_block4";
6764 return "DW_FORM_data2";
6766 return "DW_FORM_data4";
6768 return "DW_FORM_data8";
6769 case DW_FORM_string:
6770 return "DW_FORM_string";
6772 return "DW_FORM_block";
6773 case DW_FORM_block1:
6774 return "DW_FORM_block1";
6776 return "DW_FORM_data1";
6778 return "DW_FORM_flag";
6780 return "DW_FORM_sdata";
6782 return "DW_FORM_strp";
6784 return "DW_FORM_udata";
6785 case DW_FORM_ref_addr:
6786 return "DW_FORM_ref_addr";
6788 return "DW_FORM_ref1";
6790 return "DW_FORM_ref2";
6792 return "DW_FORM_ref4";
6794 return "DW_FORM_ref8";
6795 case DW_FORM_ref_udata:
6796 return "DW_FORM_ref_udata";
6797 case DW_FORM_indirect:
6798 return "DW_FORM_indirect";
6800 return "DW_FORM_<unknown>";
6804 /* Convert a DWARF stack opcode into its string name. */
6807 dwarf_stack_op_name (unsigned op)
6812 return "DW_OP_addr";
6814 return "DW_OP_deref";
6816 return "DW_OP_const1u";
6818 return "DW_OP_const1s";
6820 return "DW_OP_const2u";
6822 return "DW_OP_const2s";
6824 return "DW_OP_const4u";
6826 return "DW_OP_const4s";
6828 return "DW_OP_const8u";
6830 return "DW_OP_const8s";
6832 return "DW_OP_constu";
6834 return "DW_OP_consts";
6838 return "DW_OP_drop";
6840 return "DW_OP_over";
6842 return "DW_OP_pick";
6844 return "DW_OP_swap";
6848 return "DW_OP_xderef";
6856 return "DW_OP_minus";
6868 return "DW_OP_plus";
6869 case DW_OP_plus_uconst:
6870 return "DW_OP_plus_uconst";
6876 return "DW_OP_shra";
6894 return "DW_OP_skip";
6896 return "DW_OP_lit0";
6898 return "DW_OP_lit1";
6900 return "DW_OP_lit2";
6902 return "DW_OP_lit3";
6904 return "DW_OP_lit4";
6906 return "DW_OP_lit5";
6908 return "DW_OP_lit6";
6910 return "DW_OP_lit7";
6912 return "DW_OP_lit8";
6914 return "DW_OP_lit9";
6916 return "DW_OP_lit10";
6918 return "DW_OP_lit11";
6920 return "DW_OP_lit12";
6922 return "DW_OP_lit13";
6924 return "DW_OP_lit14";
6926 return "DW_OP_lit15";
6928 return "DW_OP_lit16";
6930 return "DW_OP_lit17";
6932 return "DW_OP_lit18";
6934 return "DW_OP_lit19";
6936 return "DW_OP_lit20";
6938 return "DW_OP_lit21";
6940 return "DW_OP_lit22";
6942 return "DW_OP_lit23";
6944 return "DW_OP_lit24";
6946 return "DW_OP_lit25";
6948 return "DW_OP_lit26";
6950 return "DW_OP_lit27";
6952 return "DW_OP_lit28";
6954 return "DW_OP_lit29";
6956 return "DW_OP_lit30";
6958 return "DW_OP_lit31";
6960 return "DW_OP_reg0";
6962 return "DW_OP_reg1";
6964 return "DW_OP_reg2";
6966 return "DW_OP_reg3";
6968 return "DW_OP_reg4";
6970 return "DW_OP_reg5";
6972 return "DW_OP_reg6";
6974 return "DW_OP_reg7";
6976 return "DW_OP_reg8";
6978 return "DW_OP_reg9";
6980 return "DW_OP_reg10";
6982 return "DW_OP_reg11";
6984 return "DW_OP_reg12";
6986 return "DW_OP_reg13";
6988 return "DW_OP_reg14";
6990 return "DW_OP_reg15";
6992 return "DW_OP_reg16";
6994 return "DW_OP_reg17";
6996 return "DW_OP_reg18";
6998 return "DW_OP_reg19";
7000 return "DW_OP_reg20";
7002 return "DW_OP_reg21";
7004 return "DW_OP_reg22";
7006 return "DW_OP_reg23";
7008 return "DW_OP_reg24";
7010 return "DW_OP_reg25";
7012 return "DW_OP_reg26";
7014 return "DW_OP_reg27";
7016 return "DW_OP_reg28";
7018 return "DW_OP_reg29";
7020 return "DW_OP_reg30";
7022 return "DW_OP_reg31";
7024 return "DW_OP_breg0";
7026 return "DW_OP_breg1";
7028 return "DW_OP_breg2";
7030 return "DW_OP_breg3";
7032 return "DW_OP_breg4";
7034 return "DW_OP_breg5";
7036 return "DW_OP_breg6";
7038 return "DW_OP_breg7";
7040 return "DW_OP_breg8";
7042 return "DW_OP_breg9";
7044 return "DW_OP_breg10";
7046 return "DW_OP_breg11";
7048 return "DW_OP_breg12";
7050 return "DW_OP_breg13";
7052 return "DW_OP_breg14";
7054 return "DW_OP_breg15";
7056 return "DW_OP_breg16";
7058 return "DW_OP_breg17";
7060 return "DW_OP_breg18";
7062 return "DW_OP_breg19";
7064 return "DW_OP_breg20";
7066 return "DW_OP_breg21";
7068 return "DW_OP_breg22";
7070 return "DW_OP_breg23";
7072 return "DW_OP_breg24";
7074 return "DW_OP_breg25";
7076 return "DW_OP_breg26";
7078 return "DW_OP_breg27";
7080 return "DW_OP_breg28";
7082 return "DW_OP_breg29";
7084 return "DW_OP_breg30";
7086 return "DW_OP_breg31";
7088 return "DW_OP_regx";
7090 return "DW_OP_fbreg";
7092 return "DW_OP_bregx";
7094 return "DW_OP_piece";
7095 case DW_OP_deref_size:
7096 return "DW_OP_deref_size";
7097 case DW_OP_xderef_size:
7098 return "DW_OP_xderef_size";
7101 /* DWARF 3 extensions. */
7102 case DW_OP_push_object_address:
7103 return "DW_OP_push_object_address";
7105 return "DW_OP_call2";
7107 return "DW_OP_call4";
7108 case DW_OP_call_ref:
7109 return "DW_OP_call_ref";
7110 /* GNU extensions. */
7111 case DW_OP_GNU_push_tls_address:
7112 return "DW_OP_GNU_push_tls_address";
7114 return "OP_<unknown>";
7119 dwarf_bool_name (unsigned mybool)
7127 /* Convert a DWARF type code into its string name. */
7130 dwarf_type_encoding_name (unsigned enc)
7134 case DW_ATE_address:
7135 return "DW_ATE_address";
7136 case DW_ATE_boolean:
7137 return "DW_ATE_boolean";
7138 case DW_ATE_complex_float:
7139 return "DW_ATE_complex_float";
7141 return "DW_ATE_float";
7143 return "DW_ATE_signed";
7144 case DW_ATE_signed_char:
7145 return "DW_ATE_signed_char";
7146 case DW_ATE_unsigned:
7147 return "DW_ATE_unsigned";
7148 case DW_ATE_unsigned_char:
7149 return "DW_ATE_unsigned_char";
7150 case DW_ATE_imaginary_float:
7151 return "DW_ATE_imaginary_float";
7153 return "DW_ATE_<unknown>";
7157 /* Convert a DWARF call frame info operation to its string name. */
7161 dwarf_cfi_name (unsigned cfi_opc)
7165 case DW_CFA_advance_loc:
7166 return "DW_CFA_advance_loc";
7168 return "DW_CFA_offset";
7169 case DW_CFA_restore:
7170 return "DW_CFA_restore";
7172 return "DW_CFA_nop";
7173 case DW_CFA_set_loc:
7174 return "DW_CFA_set_loc";
7175 case DW_CFA_advance_loc1:
7176 return "DW_CFA_advance_loc1";
7177 case DW_CFA_advance_loc2:
7178 return "DW_CFA_advance_loc2";
7179 case DW_CFA_advance_loc4:
7180 return "DW_CFA_advance_loc4";
7181 case DW_CFA_offset_extended:
7182 return "DW_CFA_offset_extended";
7183 case DW_CFA_restore_extended:
7184 return "DW_CFA_restore_extended";
7185 case DW_CFA_undefined:
7186 return "DW_CFA_undefined";
7187 case DW_CFA_same_value:
7188 return "DW_CFA_same_value";
7189 case DW_CFA_register:
7190 return "DW_CFA_register";
7191 case DW_CFA_remember_state:
7192 return "DW_CFA_remember_state";
7193 case DW_CFA_restore_state:
7194 return "DW_CFA_restore_state";
7195 case DW_CFA_def_cfa:
7196 return "DW_CFA_def_cfa";
7197 case DW_CFA_def_cfa_register:
7198 return "DW_CFA_def_cfa_register";
7199 case DW_CFA_def_cfa_offset:
7200 return "DW_CFA_def_cfa_offset";
7203 case DW_CFA_def_cfa_expression:
7204 return "DW_CFA_def_cfa_expression";
7205 case DW_CFA_expression:
7206 return "DW_CFA_expression";
7207 case DW_CFA_offset_extended_sf:
7208 return "DW_CFA_offset_extended_sf";
7209 case DW_CFA_def_cfa_sf:
7210 return "DW_CFA_def_cfa_sf";
7211 case DW_CFA_def_cfa_offset_sf:
7212 return "DW_CFA_def_cfa_offset_sf";
7214 /* SGI/MIPS specific */
7215 case DW_CFA_MIPS_advance_loc8:
7216 return "DW_CFA_MIPS_advance_loc8";
7218 /* GNU extensions */
7219 case DW_CFA_GNU_window_save:
7220 return "DW_CFA_GNU_window_save";
7221 case DW_CFA_GNU_args_size:
7222 return "DW_CFA_GNU_args_size";
7223 case DW_CFA_GNU_negative_offset_extended:
7224 return "DW_CFA_GNU_negative_offset_extended";
7227 return "DW_CFA_<unknown>";
7233 dump_die (struct die_info *die)
7237 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7238 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7239 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7240 dwarf_bool_name (die->child != NULL));
7242 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7243 for (i = 0; i < die->num_attrs; ++i)
7245 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7246 dwarf_attr_name (die->attrs[i].name),
7247 dwarf_form_name (die->attrs[i].form));
7248 switch (die->attrs[i].form)
7250 case DW_FORM_ref_addr:
7252 fprintf_unfiltered (gdb_stderr, "address: ");
7253 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7255 case DW_FORM_block2:
7256 case DW_FORM_block4:
7258 case DW_FORM_block1:
7259 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7270 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7272 case DW_FORM_string:
7274 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7275 DW_STRING (&die->attrs[i])
7276 ? DW_STRING (&die->attrs[i]) : "");
7279 if (DW_UNSND (&die->attrs[i]))
7280 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7282 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7284 case DW_FORM_flag_present:
7285 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7287 case DW_FORM_indirect:
7288 /* the reader will have reduced the indirect form to
7289 the "base form" so this form should not occur */
7290 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7293 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7294 die->attrs[i].form);
7296 fprintf_unfiltered (gdb_stderr, "\n");
7301 dump_die_list (struct die_info *die)
7306 if (die->child != NULL)
7307 dump_die_list (die->child);
7308 if (die->sibling != NULL)
7309 dump_die_list (die->sibling);
7314 store_in_ref_table (unsigned int offset, struct die_info *die)
7317 struct die_info *old;
7319 h = (offset % REF_HASH_SIZE);
7320 old = die_ref_table[h];
7321 die->next_ref = old;
7322 die_ref_table[h] = die;
7327 dwarf2_empty_hash_tables (void)
7329 memset (die_ref_table, 0, sizeof (die_ref_table));
7333 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
7335 unsigned int result = 0;
7339 case DW_FORM_ref_addr:
7340 result = DW_ADDR (attr);
7346 case DW_FORM_ref_udata:
7347 result = cu->header.offset + DW_UNSND (attr);
7350 complaint (&symfile_complaints,
7351 "unsupported die ref attribute form: '%s'",
7352 dwarf_form_name (attr->form));
7357 /* Return the constant value held by the given attribute. Return -1
7358 if the value held by the attribute is not constant. */
7361 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7363 if (attr->form == DW_FORM_sdata)
7364 return DW_SND (attr);
7365 else if (attr->form == DW_FORM_udata
7366 || attr->form == DW_FORM_data1
7367 || attr->form == DW_FORM_data2
7368 || attr->form == DW_FORM_data4
7369 || attr->form == DW_FORM_data8)
7370 return DW_UNSND (attr);
7373 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
7374 dwarf_form_name (attr->form));
7375 return default_value;
7379 static struct die_info *
7380 follow_die_ref (unsigned int offset)
7382 struct die_info *die;
7385 h = (offset % REF_HASH_SIZE);
7386 die = die_ref_table[h];
7389 if (die->offset == offset)
7393 die = die->next_ref;
7398 static struct type *
7399 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
7400 struct dwarf2_cu *cu)
7402 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
7404 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7405 typeid, objfile->name);
7408 /* Look for this particular type in the fundamental type vector. If
7409 one is not found, create and install one appropriate for the
7410 current language and the current target machine. */
7412 if (cu->ftypes[typeid] == NULL)
7414 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
7417 return (cu->ftypes[typeid]);
7420 /* Decode simple location descriptions.
7421 Given a pointer to a dwarf block that defines a location, compute
7422 the location and return the value.
7424 NOTE drow/2003-11-18: This function is called in two situations
7425 now: for the address of static or global variables (partial symbols
7426 only) and for offsets into structures which are expected to be
7427 (more or less) constant. The partial symbol case should go away,
7428 and only the constant case should remain. That will let this
7429 function complain more accurately. A few special modes are allowed
7430 without complaint for global variables (for instance, global
7431 register values and thread-local values).
7433 A location description containing no operations indicates that the
7434 object is optimized out. The return value is 0 for that case.
7435 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7436 callers will only want a very basic result and this can become a
7439 When the result is a register number, the global isreg flag is set,
7440 otherwise it is cleared.
7442 Note that stack[0] is unused except as a default error return.
7443 Note that stack overflow is not yet handled. */
7446 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
7448 struct objfile *objfile = cu->objfile;
7449 struct comp_unit_head *cu_header = &cu->header;
7451 int size = blk->size;
7452 char *data = blk->data;
7453 CORE_ADDR stack[64];
7455 unsigned int bytes_read, unsnd;
7500 stack[++stacki] = op - DW_OP_lit0;
7536 stack[++stacki] = op - DW_OP_reg0;
7538 dwarf2_complex_location_expr_complaint ();
7543 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7545 stack[++stacki] = unsnd;
7547 dwarf2_complex_location_expr_complaint ();
7551 stack[++stacki] = read_address (objfile->obfd, &data[i],
7557 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
7562 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
7567 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
7572 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
7577 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
7582 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
7587 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
7593 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
7598 stack[stacki + 1] = stack[stacki];
7603 stack[stacki - 1] += stack[stacki];
7607 case DW_OP_plus_uconst:
7608 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7613 stack[stacki - 1] -= stack[stacki];
7618 /* If we're not the last op, then we definitely can't encode
7619 this using GDB's address_class enum. This is valid for partial
7620 global symbols, although the variable's address will be bogus
7623 dwarf2_complex_location_expr_complaint ();
7626 case DW_OP_GNU_push_tls_address:
7627 /* The top of the stack has the offset from the beginning
7628 of the thread control block at which the variable is located. */
7629 /* Nothing should follow this operator, so the top of stack would
7631 /* This is valid for partial global symbols, but the variable's
7632 address will be bogus in the psymtab. */
7634 dwarf2_complex_location_expr_complaint ();
7638 complaint (&symfile_complaints, "unsupported stack op: '%s'",
7639 dwarf_stack_op_name (op));
7640 return (stack[stacki]);
7643 return (stack[stacki]);
7646 /* memory allocation interface */
7649 dwarf2_free_tmp_obstack (void *ignore)
7651 obstack_free (&dwarf2_tmp_obstack, NULL);
7654 static struct dwarf_block *
7655 dwarf_alloc_block (void)
7657 struct dwarf_block *blk;
7659 blk = (struct dwarf_block *)
7660 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
7664 static struct abbrev_info *
7665 dwarf_alloc_abbrev (void)
7667 struct abbrev_info *abbrev;
7669 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
7670 memset (abbrev, 0, sizeof (struct abbrev_info));
7674 static struct die_info *
7675 dwarf_alloc_die (void)
7677 struct die_info *die;
7679 die = (struct die_info *) xmalloc (sizeof (struct die_info));
7680 memset (die, 0, sizeof (struct die_info));
7685 /* Macro support. */
7688 /* Return the full name of file number I in *LH's file name table.
7689 Use COMP_DIR as the name of the current directory of the
7690 compilation. The result is allocated using xmalloc; the caller is
7691 responsible for freeing it. */
7693 file_full_name (int file, struct line_header *lh, const char *comp_dir)
7695 struct file_entry *fe = &lh->file_names[file - 1];
7697 if (IS_ABSOLUTE_PATH (fe->name))
7698 return xstrdup (fe->name);
7706 dir = lh->include_dirs[fe->dir_index - 1];
7712 dir_len = strlen (dir);
7713 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
7714 strcpy (full_name, dir);
7715 full_name[dir_len] = '/';
7716 strcpy (full_name + dir_len + 1, fe->name);
7720 return xstrdup (fe->name);
7725 static struct macro_source_file *
7726 macro_start_file (int file, int line,
7727 struct macro_source_file *current_file,
7728 const char *comp_dir,
7729 struct line_header *lh, struct objfile *objfile)
7731 /* The full name of this source file. */
7732 char *full_name = file_full_name (file, lh, comp_dir);
7734 /* We don't create a macro table for this compilation unit
7735 at all until we actually get a filename. */
7736 if (! pending_macros)
7737 pending_macros = new_macro_table (&objfile->objfile_obstack,
7738 objfile->macro_cache);
7741 /* If we have no current file, then this must be the start_file
7742 directive for the compilation unit's main source file. */
7743 current_file = macro_set_main (pending_macros, full_name);
7745 current_file = macro_include (current_file, line, full_name);
7749 return current_file;
7753 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7754 followed by a null byte. */
7756 copy_string (const char *buf, int len)
7758 char *s = xmalloc (len + 1);
7759 memcpy (s, buf, len);
7767 consume_improper_spaces (const char *p, const char *body)
7771 complaint (&symfile_complaints,
7772 "macro definition contains spaces in formal argument list:\n`%s'",
7784 parse_macro_definition (struct macro_source_file *file, int line,
7789 /* The body string takes one of two forms. For object-like macro
7790 definitions, it should be:
7792 <macro name> " " <definition>
7794 For function-like macro definitions, it should be:
7796 <macro name> "() " <definition>
7798 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7800 Spaces may appear only where explicitly indicated, and in the
7803 The Dwarf 2 spec says that an object-like macro's name is always
7804 followed by a space, but versions of GCC around March 2002 omit
7805 the space when the macro's definition is the empty string.
7807 The Dwarf 2 spec says that there should be no spaces between the
7808 formal arguments in a function-like macro's formal argument list,
7809 but versions of GCC around March 2002 include spaces after the
7813 /* Find the extent of the macro name. The macro name is terminated
7814 by either a space or null character (for an object-like macro) or
7815 an opening paren (for a function-like macro). */
7816 for (p = body; *p; p++)
7817 if (*p == ' ' || *p == '(')
7820 if (*p == ' ' || *p == '\0')
7822 /* It's an object-like macro. */
7823 int name_len = p - body;
7824 char *name = copy_string (body, name_len);
7825 const char *replacement;
7828 replacement = body + name_len + 1;
7831 dwarf2_macro_malformed_definition_complaint (body);
7832 replacement = body + name_len;
7835 macro_define_object (file, line, name, replacement);
7841 /* It's a function-like macro. */
7842 char *name = copy_string (body, p - body);
7845 char **argv = xmalloc (argv_size * sizeof (*argv));
7849 p = consume_improper_spaces (p, body);
7851 /* Parse the formal argument list. */
7852 while (*p && *p != ')')
7854 /* Find the extent of the current argument name. */
7855 const char *arg_start = p;
7857 while (*p && *p != ',' && *p != ')' && *p != ' ')
7860 if (! *p || p == arg_start)
7861 dwarf2_macro_malformed_definition_complaint (body);
7864 /* Make sure argv has room for the new argument. */
7865 if (argc >= argv_size)
7868 argv = xrealloc (argv, argv_size * sizeof (*argv));
7871 argv[argc++] = copy_string (arg_start, p - arg_start);
7874 p = consume_improper_spaces (p, body);
7876 /* Consume the comma, if present. */
7881 p = consume_improper_spaces (p, body);
7890 /* Perfectly formed definition, no complaints. */
7891 macro_define_function (file, line, name,
7892 argc, (const char **) argv,
7894 else if (*p == '\0')
7896 /* Complain, but do define it. */
7897 dwarf2_macro_malformed_definition_complaint (body);
7898 macro_define_function (file, line, name,
7899 argc, (const char **) argv,
7903 /* Just complain. */
7904 dwarf2_macro_malformed_definition_complaint (body);
7907 /* Just complain. */
7908 dwarf2_macro_malformed_definition_complaint (body);
7914 for (i = 0; i < argc; i++)
7920 dwarf2_macro_malformed_definition_complaint (body);
7925 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7926 char *comp_dir, bfd *abfd,
7927 struct dwarf2_cu *cu)
7929 char *mac_ptr, *mac_end;
7930 struct macro_source_file *current_file = 0;
7932 if (dwarf_macinfo_buffer == NULL)
7934 complaint (&symfile_complaints, "missing .debug_macinfo section");
7938 mac_ptr = dwarf_macinfo_buffer + offset;
7939 mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size;
7943 enum dwarf_macinfo_record_type macinfo_type;
7945 /* Do we at least have room for a macinfo type byte? */
7946 if (mac_ptr >= mac_end)
7948 dwarf2_macros_too_long_complaint ();
7952 macinfo_type = read_1_byte (abfd, mac_ptr);
7955 switch (macinfo_type)
7957 /* A zero macinfo type indicates the end of the macro
7962 case DW_MACINFO_define:
7963 case DW_MACINFO_undef:
7969 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7970 mac_ptr += bytes_read;
7971 body = read_string (abfd, mac_ptr, &bytes_read);
7972 mac_ptr += bytes_read;
7975 complaint (&symfile_complaints,
7976 "debug info gives macro %s outside of any file: %s",
7978 DW_MACINFO_define ? "definition" : macinfo_type ==
7979 DW_MACINFO_undef ? "undefinition" :
7980 "something-or-other", body);
7983 if (macinfo_type == DW_MACINFO_define)
7984 parse_macro_definition (current_file, line, body);
7985 else if (macinfo_type == DW_MACINFO_undef)
7986 macro_undef (current_file, line, body);
7991 case DW_MACINFO_start_file:
7996 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7997 mac_ptr += bytes_read;
7998 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7999 mac_ptr += bytes_read;
8001 current_file = macro_start_file (file, line,
8002 current_file, comp_dir,
8007 case DW_MACINFO_end_file:
8009 complaint (&symfile_complaints,
8010 "macro debug info has an unmatched `close_file' directive");
8013 current_file = current_file->included_by;
8016 enum dwarf_macinfo_record_type next_type;
8018 /* GCC circa March 2002 doesn't produce the zero
8019 type byte marking the end of the compilation
8020 unit. Complain if it's not there, but exit no
8023 /* Do we at least have room for a macinfo type byte? */
8024 if (mac_ptr >= mac_end)
8026 dwarf2_macros_too_long_complaint ();
8030 /* We don't increment mac_ptr here, so this is just
8032 next_type = read_1_byte (abfd, mac_ptr);
8034 complaint (&symfile_complaints,
8035 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8042 case DW_MACINFO_vendor_ext:
8048 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8049 mac_ptr += bytes_read;
8050 string = read_string (abfd, mac_ptr, &bytes_read);
8051 mac_ptr += bytes_read;
8053 /* We don't recognize any vendor extensions. */
8060 /* Check if the attribute's form is a DW_FORM_block*
8061 if so return true else false. */
8063 attr_form_is_block (struct attribute *attr)
8065 return (attr == NULL ? 0 :
8066 attr->form == DW_FORM_block1
8067 || attr->form == DW_FORM_block2
8068 || attr->form == DW_FORM_block4
8069 || attr->form == DW_FORM_block);
8073 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
8074 struct dwarf2_cu *cu)
8076 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
8078 struct dwarf2_loclist_baton *baton;
8080 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8081 sizeof (struct dwarf2_loclist_baton));
8082 baton->objfile = cu->objfile;
8084 /* We don't know how long the location list is, but make sure we
8085 don't run off the edge of the section. */
8086 baton->size = dwarf_loc_size - DW_UNSND (attr);
8087 baton->data = dwarf_loc_buffer + DW_UNSND (attr);
8088 baton->base_address = cu->header.base_address;
8089 if (cu->header.base_known == 0)
8090 complaint (&symfile_complaints,
8091 "Location list used without specifying the CU base address.");
8093 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
8094 SYMBOL_LOCATION_BATON (sym) = baton;
8098 struct dwarf2_locexpr_baton *baton;
8100 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8101 sizeof (struct dwarf2_locexpr_baton));
8102 baton->objfile = cu->objfile;
8104 if (attr_form_is_block (attr))
8106 /* Note that we're just copying the block's data pointer
8107 here, not the actual data. We're still pointing into the
8108 dwarf_info_buffer for SYM's objfile; right now we never
8109 release that buffer, but when we do clean up properly
8110 this may need to change. */
8111 baton->size = DW_BLOCK (attr)->size;
8112 baton->data = DW_BLOCK (attr)->data;
8116 dwarf2_invalid_attrib_class_complaint ("location description",
8117 SYMBOL_NATURAL_NAME (sym));
8122 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
8123 SYMBOL_LOCATION_BATON (sym) = baton;