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.
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. */
36 #include "elf/dwarf2.h"
39 #include "expression.h"
40 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
45 #include "dwarf2expr.h"
46 #include "dwarf2loc.h"
47 #include "cp-support.h"
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
54 #ifndef DWARF2_REG_TO_REGNUM
55 #define DWARF2_REG_TO_REGNUM(REG) (REG)
59 /* .debug_info header for a compilation unit
60 Because of alignment constraints, this structure has padding and cannot
61 be mapped directly onto the beginning of the .debug_info section. */
62 typedef struct comp_unit_header
64 unsigned int length; /* length of the .debug_info
66 unsigned short version; /* version number -- 2 for DWARF
68 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
69 unsigned char addr_size; /* byte size of an address -- 4 */
72 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
75 /* .debug_pubnames header
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct pubnames_header
80 unsigned int length; /* length of the .debug_pubnames
82 unsigned char version; /* version number -- 2 for DWARF
84 unsigned int info_offset; /* offset into .debug_info section */
85 unsigned int info_size; /* byte size of .debug_info section
89 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct aranges_header
96 unsigned int length; /* byte len of the .debug_aranges
98 unsigned short version; /* version number -- 2 for DWARF
100 unsigned int info_offset; /* offset into .debug_info section */
101 unsigned char addr_size; /* byte size of an address */
102 unsigned char seg_size; /* byte size of segment descriptor */
105 #define _ACTUAL_ARANGES_HEADER_SIZE 12
107 /* .debug_line statement program prologue
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct statement_prologue
112 unsigned int total_length; /* byte length of the statement
114 unsigned short version; /* version number -- 2 for DWARF
116 unsigned int prologue_length; /* # bytes between prologue &
118 unsigned char minimum_instruction_length; /* byte size of
120 unsigned char default_is_stmt; /* initial value of is_stmt
123 unsigned char line_range;
124 unsigned char opcode_base; /* number assigned to first special
126 unsigned char *standard_opcode_lengths;
130 /* offsets and sizes of debugging sections */
132 static unsigned int dwarf_info_size;
133 static unsigned int dwarf_abbrev_size;
134 static unsigned int dwarf_line_size;
135 static unsigned int dwarf_pubnames_size;
136 static unsigned int dwarf_aranges_size;
137 static unsigned int dwarf_loc_size;
138 static unsigned int dwarf_macinfo_size;
139 static unsigned int dwarf_str_size;
140 static unsigned int dwarf_ranges_size;
141 unsigned int dwarf_frame_size;
142 unsigned int dwarf_eh_frame_size;
144 static asection *dwarf_info_section;
145 static asection *dwarf_abbrev_section;
146 static asection *dwarf_line_section;
147 static asection *dwarf_pubnames_section;
148 static asection *dwarf_aranges_section;
149 static asection *dwarf_loc_section;
150 static asection *dwarf_macinfo_section;
151 static asection *dwarf_str_section;
152 static asection *dwarf_ranges_section;
153 asection *dwarf_frame_section;
154 asection *dwarf_eh_frame_section;
156 /* names of the debugging sections */
158 #define INFO_SECTION ".debug_info"
159 #define ABBREV_SECTION ".debug_abbrev"
160 #define LINE_SECTION ".debug_line"
161 #define PUBNAMES_SECTION ".debug_pubnames"
162 #define ARANGES_SECTION ".debug_aranges"
163 #define LOC_SECTION ".debug_loc"
164 #define MACINFO_SECTION ".debug_macinfo"
165 #define STR_SECTION ".debug_str"
166 #define RANGES_SECTION ".debug_ranges"
167 #define FRAME_SECTION ".debug_frame"
168 #define EH_FRAME_SECTION ".eh_frame"
170 /* local data types */
172 /* We hold several abbreviation tables in memory at the same time. */
173 #ifndef ABBREV_HASH_SIZE
174 #define ABBREV_HASH_SIZE 121
177 /* The data in a compilation unit header, after target2host
178 translation, looks like this. */
179 struct comp_unit_head
181 unsigned long length;
183 unsigned int abbrev_offset;
184 unsigned char addr_size;
185 unsigned char signed_addr_p;
186 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
187 unsigned int initial_length_size; /* size of the length field; either
190 /* Offset to the first byte of this compilation unit header in the
191 * .debug_info section, for resolving relative reference dies. */
195 /* Pointer to this compilation unit header in the .debug_info
200 /* Pointer to the first die of this compilatio unit. This will
201 * be the first byte following the compilation unit header. */
205 /* Pointer to the next compilation unit header in the program. */
207 struct comp_unit_head *next;
209 /* DWARF abbreviation table associated with this compilation unit */
211 struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
213 /* Base address of this compilation unit. */
215 CORE_ADDR base_address;
217 /* Non-zero if base_address has been set. */
222 /* Internal state when decoding a particular compilation unit. */
225 /* The objfile containing this compilation unit. */
226 struct objfile *objfile;
228 /* The header of the compilation unit.
230 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
231 should be moved to the dwarf2_cu structure; for instance the abbrevs
233 struct comp_unit_head header;
235 struct function_range *first_fn, *last_fn, *cached_fn;
237 /* The language we are debugging. */
238 enum language language;
239 const struct language_defn *language_defn;
241 /* The generic symbol table building routines have separate lists for
242 file scope symbols and all all other scopes (local scopes). So
243 we need to select the right one to pass to add_symbol_to_list().
244 We do it by keeping a pointer to the correct list in list_in_scope.
246 FIXME: The original dwarf code just treated the file scope as the
247 first local scope, and all other local scopes as nested local
248 scopes, and worked fine. Check to see if we really need to
249 distinguish these in buildsym.c. */
250 struct pending **list_in_scope;
252 /* Maintain an array of referenced fundamental types for the current
253 compilation unit being read. For DWARF version 1, we have to construct
254 the fundamental types on the fly, since no information about the
255 fundamental types is supplied. Each such fundamental type is created by
256 calling a language dependent routine to create the type, and then a
257 pointer to that type is then placed in the array at the index specified
258 by it's FT_<TYPENAME> value. The array has a fixed size set by the
259 FT_NUM_MEMBERS compile time constant, which is the number of predefined
260 fundamental types gdb knows how to construct. */
261 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
264 /* The line number information for a compilation unit (found in the
265 .debug_line section) begins with a "statement program header",
266 which contains the following information. */
269 unsigned int total_length;
270 unsigned short version;
271 unsigned int header_length;
272 unsigned char minimum_instruction_length;
273 unsigned char default_is_stmt;
275 unsigned char line_range;
276 unsigned char opcode_base;
278 /* standard_opcode_lengths[i] is the number of operands for the
279 standard opcode whose value is i. This means that
280 standard_opcode_lengths[0] is unused, and the last meaningful
281 element is standard_opcode_lengths[opcode_base - 1]. */
282 unsigned char *standard_opcode_lengths;
284 /* The include_directories table. NOTE! These strings are not
285 allocated with xmalloc; instead, they are pointers into
286 debug_line_buffer. If you try to free them, `free' will get
288 unsigned int num_include_dirs, include_dirs_size;
291 /* The file_names table. NOTE! These strings are not allocated
292 with xmalloc; instead, they are pointers into debug_line_buffer.
293 Don't try to free them directly. */
294 unsigned int num_file_names, file_names_size;
298 unsigned int dir_index;
299 unsigned int mod_time;
303 /* The start and end of the statement program following this
304 header. These point into dwarf_line_buffer. */
305 char *statement_program_start, *statement_program_end;
308 /* When we construct a partial symbol table entry we only
309 need this much information. */
310 struct partial_die_info
313 unsigned char has_children;
314 unsigned char is_external;
315 unsigned char is_declaration;
316 unsigned char has_type;
323 struct dwarf_block *locdesc;
324 unsigned int language;
328 /* This data structure holds the information of an abbrev. */
331 unsigned int number; /* number identifying abbrev */
332 enum dwarf_tag tag; /* dwarf tag */
333 int has_children; /* boolean */
334 unsigned int num_attrs; /* number of attributes */
335 struct attr_abbrev *attrs; /* an array of attribute descriptions */
336 struct abbrev_info *next; /* next in chain */
341 enum dwarf_attribute name;
342 enum dwarf_form form;
345 /* This data structure holds a complete die structure. */
348 enum dwarf_tag tag; /* Tag indicating type of die */
349 unsigned int abbrev; /* Abbrev number */
350 unsigned int offset; /* Offset in .debug_info section */
351 unsigned int num_attrs; /* Number of attributes */
352 struct attribute *attrs; /* An array of attributes */
353 struct die_info *next_ref; /* Next die in ref hash table */
355 /* The dies in a compilation unit form an n-ary tree. PARENT
356 points to this die's parent; CHILD points to the first child of
357 this node; and all the children of a given node are chained
358 together via their SIBLING fields, terminated by a die whose
360 struct die_info *child; /* Its first child, if any. */
361 struct die_info *sibling; /* Its next sibling, if any. */
362 struct die_info *parent; /* Its parent, if any. */
364 struct type *type; /* Cached type information */
367 /* Attributes have a name and a value */
370 enum dwarf_attribute name;
371 enum dwarf_form form;
375 struct dwarf_block *blk;
383 struct function_range
386 CORE_ADDR lowpc, highpc;
388 struct function_range *next;
391 /* Get at parts of an attribute structure */
393 #define DW_STRING(attr) ((attr)->u.str)
394 #define DW_UNSND(attr) ((attr)->u.unsnd)
395 #define DW_BLOCK(attr) ((attr)->u.blk)
396 #define DW_SND(attr) ((attr)->u.snd)
397 #define DW_ADDR(attr) ((attr)->u.addr)
399 /* Blocks are a bunch of untyped bytes. */
406 #ifndef ATTR_ALLOC_CHUNK
407 #define ATTR_ALLOC_CHUNK 4
410 /* A hash table of die offsets for following references. */
411 #ifndef REF_HASH_SIZE
412 #define REF_HASH_SIZE 1021
415 static struct die_info *die_ref_table[REF_HASH_SIZE];
417 /* Obstack for allocating temporary storage used during symbol reading. */
418 static struct obstack dwarf2_tmp_obstack;
420 /* Allocate fields for structs, unions and enums in this size. */
421 #ifndef DW_FIELD_ALLOC_CHUNK
422 #define DW_FIELD_ALLOC_CHUNK 4
425 /* Actually data from the sections. */
426 static char *dwarf_info_buffer;
427 static char *dwarf_abbrev_buffer;
428 static char *dwarf_line_buffer;
429 static char *dwarf_str_buffer;
430 static char *dwarf_macinfo_buffer;
431 static char *dwarf_ranges_buffer;
432 static char *dwarf_loc_buffer;
434 /* A zeroed version of a partial die for initialization purposes. */
435 static struct partial_die_info zeroed_partial_die;
437 /* FIXME: decode_locdesc sets these variables to describe the location
438 to the caller. These ought to be a structure or something. If
439 none of the flags are set, the object lives at the address returned
440 by decode_locdesc. */
442 static int isreg; /* Object lives in register.
443 decode_locdesc's return value is
444 the register number. */
446 /* We put a pointer to this structure in the read_symtab_private field
448 The complete dwarf information for an objfile is kept in the
449 psymbol_obstack, so that absolute die references can be handled.
450 Most of the information in this structure is related to an entire
451 object file and could be passed via the sym_private field of the objfile.
452 It is however conceivable that dwarf2 might not be the only type
453 of symbols read from an object file. */
457 /* Pointer to start of dwarf info buffer for the objfile. */
459 char *dwarf_info_buffer;
461 /* Offset in dwarf_info_buffer for this compilation unit. */
463 unsigned long dwarf_info_offset;
465 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
467 char *dwarf_abbrev_buffer;
469 /* Size of dwarf abbreviation section for the objfile. */
471 unsigned int dwarf_abbrev_size;
473 /* Pointer to start of dwarf line buffer for the objfile. */
475 char *dwarf_line_buffer;
477 /* Size of dwarf_line_buffer, in bytes. */
479 unsigned int dwarf_line_size;
481 /* Pointer to start of dwarf string buffer for the objfile. */
483 char *dwarf_str_buffer;
485 /* Size of dwarf string section for the objfile. */
487 unsigned int dwarf_str_size;
489 /* Pointer to start of dwarf macro buffer for the objfile. */
491 char *dwarf_macinfo_buffer;
493 /* Size of dwarf macinfo section for the objfile. */
495 unsigned int dwarf_macinfo_size;
497 /* Pointer to start of dwarf ranges buffer for the objfile. */
499 char *dwarf_ranges_buffer;
501 /* Size of dwarf ranges buffer for the objfile. */
503 unsigned int dwarf_ranges_size;
505 /* Pointer to start of dwarf locations buffer for the objfile. */
507 char *dwarf_loc_buffer;
509 /* Size of dwarf locations buffer for the objfile. */
511 unsigned int dwarf_loc_size;
514 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
515 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
516 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
517 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
518 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
519 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
520 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
521 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
522 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
523 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
524 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
525 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
526 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
527 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
528 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
530 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
531 but this would require a corresponding change in unpack_field_as_long
533 static int bits_per_byte = 8;
535 /* The routines that read and process dies for a C struct or C++ class
536 pass lists of data member fields and lists of member function fields
537 in an instance of a field_info structure, as defined below. */
540 /* List of data member and baseclasses fields. */
543 struct nextfield *next;
550 /* Number of fields. */
553 /* Number of baseclasses. */
556 /* Set if the accesibility of one of the fields is not public. */
557 int non_public_fields;
559 /* Member function fields array, entries are allocated in the order they
560 are encountered in the object file. */
563 struct nextfnfield *next;
564 struct fn_field fnfield;
568 /* Member function fieldlist array, contains name of possibly overloaded
569 member function, number of overloaded member functions and a pointer
570 to the head of the member function field chain. */
575 struct nextfnfield *head;
579 /* Number of entries in the fnfieldlists array. */
583 /* Various complaints about symbol reading that don't abort the process */
586 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
588 complaint (&symfile_complaints,
589 "statement list doesn't fit in .debug_line section");
593 dwarf2_complex_location_expr_complaint (void)
595 complaint (&symfile_complaints, "location expression too complex");
599 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
602 complaint (&symfile_complaints,
603 "const value length mismatch for '%s', got %d, expected %d", arg1,
608 dwarf2_macros_too_long_complaint (void)
610 complaint (&symfile_complaints,
611 "macro info runs off end of `.debug_macinfo' section");
615 dwarf2_macro_malformed_definition_complaint (const char *arg1)
617 complaint (&symfile_complaints,
618 "macro debug info contains a malformed macro definition:\n`%s'",
623 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
625 complaint (&symfile_complaints,
626 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
629 /* local function prototypes */
631 static void dwarf2_locate_sections (bfd *, asection *, void *);
634 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
637 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
639 static char *scan_partial_symbols (char *, CORE_ADDR *, CORE_ADDR *,
641 const char *namespace);
643 static void add_partial_symbol (struct partial_die_info *, struct dwarf2_cu *,
644 const char *namespace);
646 static int pdi_needs_namespace (enum dwarf_tag tag, const char *namespace);
648 static char *add_partial_namespace (struct partial_die_info *pdi,
650 CORE_ADDR *lowpc, CORE_ADDR *highpc,
651 struct dwarf2_cu *cu,
652 const char *namespace);
654 static char *add_partial_structure (struct partial_die_info *struct_pdi,
656 struct dwarf2_cu *cu,
657 const char *namespace);
659 static char *add_partial_enumeration (struct partial_die_info *enum_pdi,
661 struct dwarf2_cu *cu,
662 const char *namespace);
664 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
667 struct dwarf2_cu *cu);
669 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
671 static void psymtab_to_symtab_1 (struct partial_symtab *);
673 char *dwarf2_read_section (struct objfile *, asection *);
675 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
677 static void dwarf2_empty_abbrev_table (void *);
679 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
682 static char *read_partial_die (struct partial_die_info *,
683 bfd *, char *, struct dwarf2_cu *);
685 static char *read_full_die (struct die_info **, bfd *, char *,
686 struct dwarf2_cu *, int *);
688 static char *read_attribute (struct attribute *, struct attr_abbrev *,
689 bfd *, char *, struct dwarf2_cu *);
691 static char *read_attribute_value (struct attribute *, unsigned,
692 bfd *, char *, struct dwarf2_cu *);
694 static unsigned int read_1_byte (bfd *, char *);
696 static int read_1_signed_byte (bfd *, char *);
698 static unsigned int read_2_bytes (bfd *, char *);
700 static unsigned int read_4_bytes (bfd *, char *);
702 static unsigned long read_8_bytes (bfd *, char *);
704 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
707 static LONGEST read_initial_length (bfd *, char *,
708 struct comp_unit_head *, int *bytes_read);
710 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
713 static char *read_n_bytes (bfd *, char *, unsigned int);
715 static char *read_string (bfd *, char *, unsigned int *);
717 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
720 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
722 static long read_signed_leb128 (bfd *, char *, unsigned int *);
724 static void set_cu_language (unsigned int, struct dwarf2_cu *);
726 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
729 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
731 static struct die_info *die_specification (struct die_info *die,
734 static void free_line_header (struct line_header *lh);
736 static struct line_header *(dwarf_decode_line_header
737 (unsigned int offset,
738 bfd *abfd, struct dwarf2_cu *cu));
740 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
743 static void dwarf2_start_subfile (char *, char *);
745 static struct symbol *new_symbol (struct die_info *, struct type *,
748 static void dwarf2_const_value (struct attribute *, struct symbol *,
751 static void dwarf2_const_value_data (struct attribute *attr,
755 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
757 static struct type *die_containing_type (struct die_info *,
761 static struct type *type_at_offset (unsigned int, struct objfile *);
764 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
766 static void read_type_die (struct die_info *, struct dwarf2_cu *);
768 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
770 static char *determine_prefix_aux (struct die_info *die, struct dwarf2_cu *);
772 static char *typename_concat (const char *prefix, const char *suffix);
774 static char *class_name (struct die_info *die, struct dwarf2_cu *);
776 static void read_typedef (struct die_info *, struct dwarf2_cu *);
778 static void read_base_type (struct die_info *, struct dwarf2_cu *);
780 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
782 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
784 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
786 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
788 static int dwarf2_get_pc_bounds (struct die_info *,
789 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
791 static void get_scope_pc_bounds (struct die_info *,
792 CORE_ADDR *, CORE_ADDR *,
795 static void dwarf2_add_field (struct field_info *, struct die_info *,
798 static void dwarf2_attach_fields_to_type (struct field_info *,
799 struct type *, struct dwarf2_cu *);
801 static void dwarf2_add_member_fn (struct field_info *,
802 struct die_info *, struct type *,
805 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
806 struct type *, struct dwarf2_cu *);
808 static void read_structure_scope (struct die_info *, struct dwarf2_cu *);
810 static void read_common_block (struct die_info *, struct dwarf2_cu *);
812 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
814 static const char *namespace_name (struct die_info *die,
815 int *is_anonymous, struct dwarf2_cu *);
817 static void read_enumeration (struct die_info *, struct dwarf2_cu *);
819 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
821 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
823 static void read_array_type (struct die_info *, struct dwarf2_cu *);
825 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
827 static void read_tag_ptr_to_member_type (struct die_info *,
830 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
832 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
834 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
836 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
838 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
840 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
842 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
845 struct die_info *parent);
847 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
850 struct die_info *parent);
852 static void free_die_list (struct die_info *);
854 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
856 static void process_die (struct die_info *, struct dwarf2_cu *);
858 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
860 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
862 static struct die_info *dwarf2_extension (struct die_info *die,
865 static char *dwarf_tag_name (unsigned int);
867 static char *dwarf_attr_name (unsigned int);
869 static char *dwarf_form_name (unsigned int);
871 static char *dwarf_stack_op_name (unsigned int);
873 static char *dwarf_bool_name (unsigned int);
875 static char *dwarf_type_encoding_name (unsigned int);
878 static char *dwarf_cfi_name (unsigned int);
880 struct die_info *copy_die (struct die_info *);
883 static struct die_info *sibling_die (struct die_info *);
885 static void dump_die (struct die_info *);
887 static void dump_die_list (struct die_info *);
889 static void store_in_ref_table (unsigned int, struct die_info *);
891 static void dwarf2_empty_hash_tables (void);
893 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
896 static int dwarf2_get_attr_constant_value (struct attribute *, int);
898 static struct die_info *follow_die_ref (unsigned int);
900 static struct type *dwarf2_fundamental_type (struct objfile *, int,
903 /* memory allocation interface */
905 static void dwarf2_free_tmp_obstack (void *);
907 static struct dwarf_block *dwarf_alloc_block (void);
909 static struct abbrev_info *dwarf_alloc_abbrev (void);
911 static struct die_info *dwarf_alloc_die (void);
913 static void initialize_cu_func_list (struct dwarf2_cu *);
915 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
918 static void dwarf_decode_macros (struct line_header *, unsigned int,
919 char *, bfd *, struct dwarf2_cu *);
921 static int attr_form_is_block (struct attribute *);
924 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
925 struct dwarf2_cu *cu);
927 /* Try to locate the sections we need for DWARF 2 debugging
928 information and return true if we have enough to do something. */
931 dwarf2_has_info (bfd *abfd)
933 dwarf_info_section = 0;
934 dwarf_abbrev_section = 0;
935 dwarf_line_section = 0;
936 dwarf_str_section = 0;
937 dwarf_macinfo_section = 0;
938 dwarf_frame_section = 0;
939 dwarf_eh_frame_section = 0;
940 dwarf_ranges_section = 0;
941 dwarf_loc_section = 0;
943 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
944 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
947 /* This function is mapped across the sections and remembers the
948 offset and size of each of the debugging sections we are interested
952 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
954 if (strcmp (sectp->name, INFO_SECTION) == 0)
956 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
957 dwarf_info_section = sectp;
959 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
961 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
962 dwarf_abbrev_section = sectp;
964 else if (strcmp (sectp->name, LINE_SECTION) == 0)
966 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
967 dwarf_line_section = sectp;
969 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
971 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
972 dwarf_pubnames_section = sectp;
974 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
976 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
977 dwarf_aranges_section = sectp;
979 else if (strcmp (sectp->name, LOC_SECTION) == 0)
981 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
982 dwarf_loc_section = sectp;
984 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
986 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
987 dwarf_macinfo_section = sectp;
989 else if (strcmp (sectp->name, STR_SECTION) == 0)
991 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
992 dwarf_str_section = sectp;
994 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
996 dwarf_frame_size = bfd_get_section_size_before_reloc (sectp);
997 dwarf_frame_section = sectp;
999 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1001 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1002 if (aflag & SEC_HAS_CONTENTS)
1004 dwarf_eh_frame_size = bfd_get_section_size_before_reloc (sectp);
1005 dwarf_eh_frame_section = sectp;
1008 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1010 dwarf_ranges_size = bfd_get_section_size_before_reloc (sectp);
1011 dwarf_ranges_section = sectp;
1015 /* Build a partial symbol table. */
1018 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1021 /* We definitely need the .debug_info and .debug_abbrev sections */
1023 dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1024 dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1026 if (dwarf_line_section)
1027 dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1029 dwarf_line_buffer = NULL;
1031 if (dwarf_str_section)
1032 dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1034 dwarf_str_buffer = NULL;
1036 if (dwarf_macinfo_section)
1037 dwarf_macinfo_buffer = dwarf2_read_section (objfile,
1038 dwarf_macinfo_section);
1040 dwarf_macinfo_buffer = NULL;
1042 if (dwarf_ranges_section)
1043 dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1045 dwarf_ranges_buffer = NULL;
1047 if (dwarf_loc_section)
1048 dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1050 dwarf_loc_buffer = NULL;
1053 || (objfile->global_psymbols.size == 0
1054 && objfile->static_psymbols.size == 0))
1056 init_psymbol_list (objfile, 1024);
1060 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1062 /* Things are significantly easier if we have .debug_aranges and
1063 .debug_pubnames sections */
1065 dwarf2_build_psymtabs_easy (objfile, mainline);
1069 /* only test this case for now */
1071 /* In this case we have to work a bit harder */
1072 dwarf2_build_psymtabs_hard (objfile, mainline);
1077 /* Build the partial symbol table from the information in the
1078 .debug_pubnames and .debug_aranges sections. */
1081 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1083 bfd *abfd = objfile->obfd;
1084 char *aranges_buffer, *pubnames_buffer;
1085 char *aranges_ptr, *pubnames_ptr;
1086 unsigned int entry_length, version, info_offset, info_size;
1088 pubnames_buffer = dwarf2_read_section (objfile,
1089 dwarf_pubnames_section);
1090 pubnames_ptr = pubnames_buffer;
1091 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
1093 struct comp_unit_head cu_header;
1096 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1098 pubnames_ptr += bytes_read;
1099 version = read_1_byte (abfd, pubnames_ptr);
1101 info_offset = read_4_bytes (abfd, pubnames_ptr);
1103 info_size = read_4_bytes (abfd, pubnames_ptr);
1107 aranges_buffer = dwarf2_read_section (objfile,
1108 dwarf_aranges_section);
1113 /* Read in the comp unit header information from the debug_info at
1117 read_comp_unit_head (struct comp_unit_head *cu_header,
1118 char *info_ptr, bfd *abfd)
1122 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1124 info_ptr += bytes_read;
1125 cu_header->version = read_2_bytes (abfd, info_ptr);
1127 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1129 info_ptr += bytes_read;
1130 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1132 signed_addr = bfd_get_sign_extend_vma (abfd);
1133 if (signed_addr < 0)
1134 internal_error (__FILE__, __LINE__,
1135 "read_comp_unit_head: dwarf from non elf file");
1136 cu_header->signed_addr_p = signed_addr;
1140 /* Build the partial symbol table by doing a quick pass through the
1141 .debug_info and .debug_abbrev sections. */
1144 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1146 /* Instead of reading this into a big buffer, we should probably use
1147 mmap() on architectures that support it. (FIXME) */
1148 bfd *abfd = objfile->obfd;
1149 char *info_ptr, *abbrev_ptr;
1150 char *beg_of_comp_unit;
1151 struct partial_die_info comp_unit_die;
1152 struct partial_symtab *pst;
1153 struct cleanup *back_to;
1154 CORE_ADDR lowpc, highpc, baseaddr;
1156 info_ptr = dwarf_info_buffer;
1157 abbrev_ptr = dwarf_abbrev_buffer;
1159 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1160 the partial symbol scan, like attribute values.
1162 We could reduce our peak memory consumption during partial symbol
1163 table construction by freeing stuff from this obstack more often
1164 --- say, after processing each compilation unit, or each die ---
1165 but it turns out that this saves almost nothing. For an
1166 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1167 on dwarf2_tmp_obstack. Some investigation showed:
1169 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1170 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1171 all fixed-length values not requiring dynamic allocation.
1173 2) 30% of the attributes used the form DW_FORM_string. For
1174 DW_FORM_string, read_attribute simply hands back a pointer to
1175 the null-terminated string in dwarf_info_buffer, so no dynamic
1176 allocation is needed there either.
1178 3) The remaining 1% of the attributes all used DW_FORM_block1.
1179 75% of those were DW_AT_frame_base location lists for
1180 functions; the rest were DW_AT_location attributes, probably
1181 for the global variables.
1183 Anyway, what this all means is that the memory the dwarf2
1184 reader uses as temporary space reading partial symbols is about
1185 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1187 obstack_init (&dwarf2_tmp_obstack);
1188 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1190 /* Since the objects we're extracting from dwarf_info_buffer vary in
1191 length, only the individual functions to extract them (like
1192 read_comp_unit_head and read_partial_die) can really know whether
1193 the buffer is large enough to hold another complete object.
1195 At the moment, they don't actually check that. If
1196 dwarf_info_buffer holds just one extra byte after the last
1197 compilation unit's dies, then read_comp_unit_head will happily
1198 read off the end of the buffer. read_partial_die is similarly
1199 casual. Those functions should be fixed.
1201 For this loop condition, simply checking whether there's any data
1202 left at all should be sufficient. */
1203 while (info_ptr < dwarf_info_buffer + dwarf_info_size)
1205 struct dwarf2_cu cu;
1206 beg_of_comp_unit = info_ptr;
1208 cu.objfile = objfile;
1209 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1211 if (cu.header.version != 2)
1213 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));
1216 if (cu.header.abbrev_offset >= dwarf_abbrev_size)
1218 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1219 (long) cu.header.abbrev_offset,
1220 (long) (beg_of_comp_unit - dwarf_info_buffer),
1221 bfd_get_filename (abfd));
1224 if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size
1225 > dwarf_info_buffer + dwarf_info_size)
1227 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1228 (long) cu.header.length,
1229 (long) (beg_of_comp_unit - dwarf_info_buffer),
1230 bfd_get_filename (abfd));
1233 /* Complete the cu_header */
1234 cu.header.offset = beg_of_comp_unit - dwarf_info_buffer;
1235 cu.header.first_die_ptr = info_ptr;
1236 cu.header.cu_head_ptr = beg_of_comp_unit;
1238 cu.list_in_scope = &file_symbols;
1240 /* Read the abbrevs for this compilation unit into a table */
1241 dwarf2_read_abbrevs (abfd, &cu);
1242 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1244 /* Read the compilation unit die */
1245 info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr,
1248 /* Set the language we're debugging */
1249 set_cu_language (comp_unit_die.language, &cu);
1251 /* Allocate a new partial symbol table structure */
1252 pst = start_psymtab_common (objfile, objfile->section_offsets,
1253 comp_unit_die.name ? comp_unit_die.name : "",
1254 comp_unit_die.lowpc,
1255 objfile->global_psymbols.next,
1256 objfile->static_psymbols.next);
1258 pst->read_symtab_private = (char *)
1259 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
1260 DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
1261 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
1262 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
1263 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
1264 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
1265 DWARF_LINE_SIZE (pst) = dwarf_line_size;
1266 DWARF_STR_BUFFER (pst) = dwarf_str_buffer;
1267 DWARF_STR_SIZE (pst) = dwarf_str_size;
1268 DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer;
1269 DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size;
1270 DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer;
1271 DWARF_RANGES_SIZE (pst) = dwarf_ranges_size;
1272 DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer;
1273 DWARF_LOC_SIZE (pst) = dwarf_loc_size;
1274 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1276 /* Store the function that reads in the rest of the symbol table */
1277 pst->read_symtab = dwarf2_psymtab_to_symtab;
1279 /* Check if comp unit has_children.
1280 If so, read the rest of the partial symbols from this comp unit.
1281 If not, there's no more debug_info for this comp unit. */
1282 if (comp_unit_die.has_children)
1284 lowpc = ((CORE_ADDR) -1);
1285 highpc = ((CORE_ADDR) 0);
1287 info_ptr = scan_partial_symbols (info_ptr, &lowpc, &highpc,
1290 /* If we didn't find a lowpc, set it to highpc to avoid
1291 complaints from `maint check'. */
1292 if (lowpc == ((CORE_ADDR) -1))
1295 /* If the compilation unit didn't have an explicit address range,
1296 then use the information extracted from its child dies. */
1297 if (! comp_unit_die.has_pc_info)
1299 comp_unit_die.lowpc = lowpc;
1300 comp_unit_die.highpc = highpc;
1303 pst->textlow = comp_unit_die.lowpc + baseaddr;
1304 pst->texthigh = comp_unit_die.highpc + baseaddr;
1306 pst->n_global_syms = objfile->global_psymbols.next -
1307 (objfile->global_psymbols.list + pst->globals_offset);
1308 pst->n_static_syms = objfile->static_psymbols.next -
1309 (objfile->static_psymbols.list + pst->statics_offset);
1310 sort_pst_symbols (pst);
1312 /* If there is already a psymtab or symtab for a file of this
1313 name, remove it. (If there is a symtab, more drastic things
1314 also happen.) This happens in VxWorks. */
1315 free_named_symtabs (pst->filename);
1317 info_ptr = beg_of_comp_unit + cu.header.length
1318 + cu.header.initial_length_size;
1320 do_cleanups (back_to);
1323 /* Read in all interesting dies to the end of the compilation unit or
1324 to the end of the current namespace. NAMESPACE is NULL if we
1325 haven't yet encountered any DW_TAG_namespace entries; otherwise,
1326 it's the name of the current namespace. In particular, it's the
1327 empty string if we're currently in the global namespace but have
1328 previously encountered a DW_TAG_namespace. */
1331 scan_partial_symbols (char *info_ptr, CORE_ADDR *lowpc,
1332 CORE_ADDR *highpc, struct dwarf2_cu *cu,
1333 const char *namespace)
1335 struct objfile *objfile = cu->objfile;
1336 bfd *abfd = objfile->obfd;
1337 struct partial_die_info pdi;
1339 /* Now, march along the PDI's, descending into ones which have
1340 interesting children but skipping the children of the other ones,
1341 until we reach the end of the compilation unit. */
1345 /* This flag tells whether or not info_ptr has gotten updated
1347 int info_ptr_updated = 0;
1349 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1351 /* Anonymous namespaces have no name but have interesting
1352 children, so we need to look at them. Ditto for anonymous
1355 if (pdi.name != NULL || pdi.tag == DW_TAG_namespace
1356 || pdi.tag == DW_TAG_enumeration_type)
1360 case DW_TAG_subprogram:
1361 if (pdi.has_pc_info)
1363 if (pdi.lowpc < *lowpc)
1367 if (pdi.highpc > *highpc)
1369 *highpc = pdi.highpc;
1371 if (!pdi.is_declaration)
1373 add_partial_symbol (&pdi, cu, namespace);
1377 case DW_TAG_variable:
1378 case DW_TAG_typedef:
1379 case DW_TAG_union_type:
1380 if (!pdi.is_declaration)
1382 add_partial_symbol (&pdi, cu, namespace);
1385 case DW_TAG_class_type:
1386 case DW_TAG_structure_type:
1387 if (!pdi.is_declaration)
1389 info_ptr = add_partial_structure (&pdi, info_ptr, cu,
1391 info_ptr_updated = 1;
1394 case DW_TAG_enumeration_type:
1395 if (!pdi.is_declaration)
1397 info_ptr = add_partial_enumeration (&pdi, info_ptr, cu,
1399 info_ptr_updated = 1;
1402 case DW_TAG_base_type:
1403 case DW_TAG_subrange_type:
1404 /* File scope base type definitions are added to the partial
1406 add_partial_symbol (&pdi, cu, namespace);
1408 case DW_TAG_namespace:
1409 /* We've hit a DW_TAG_namespace entry, so we know this
1410 file has been compiled using a compiler that
1411 generates them; update NAMESPACE to reflect that. */
1412 if (namespace == NULL)
1414 info_ptr = add_partial_namespace (&pdi, info_ptr, lowpc, highpc,
1416 info_ptr_updated = 1;
1426 /* If the die has a sibling, skip to the sibling, unless another
1427 function has already updated info_ptr for us. */
1429 /* NOTE: carlton/2003-06-16: This is a bit hackish, but whether
1430 or not we want to update this depends on enough stuff (not
1431 only pdi.tag but also whether or not pdi.name is NULL) that
1432 this seems like the easiest way to handle the issue. */
1434 if (!info_ptr_updated)
1435 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1442 add_partial_symbol (struct partial_die_info *pdi,
1443 struct dwarf2_cu *cu, const char *namespace)
1445 struct objfile *objfile = cu->objfile;
1447 char *actual_name = pdi->name;
1448 const struct partial_symbol *psym = NULL;
1451 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1453 /* If we're not in the global namespace and if the namespace name
1454 isn't encoded in a mangled actual_name, add it. */
1456 if (pdi_needs_namespace (pdi->tag, namespace))
1458 actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1);
1459 strcpy (actual_name, namespace);
1460 strcat (actual_name, "::");
1461 strcat (actual_name, pdi->name);
1466 case DW_TAG_subprogram:
1467 if (pdi->is_external)
1469 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1470 mst_text, objfile); */
1471 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1472 VAR_DOMAIN, LOC_BLOCK,
1473 &objfile->global_psymbols,
1474 0, pdi->lowpc + baseaddr,
1475 cu->language, objfile);
1479 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1480 mst_file_text, objfile); */
1481 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1482 VAR_DOMAIN, LOC_BLOCK,
1483 &objfile->static_psymbols,
1484 0, pdi->lowpc + baseaddr,
1485 cu->language, objfile);
1488 case DW_TAG_variable:
1489 if (pdi->is_external)
1492 Don't enter into the minimal symbol tables as there is
1493 a minimal symbol table entry from the ELF symbols already.
1494 Enter into partial symbol table if it has a location
1495 descriptor or a type.
1496 If the location descriptor is missing, new_symbol will create
1497 a LOC_UNRESOLVED symbol, the address of the variable will then
1498 be determined from the minimal symbol table whenever the variable
1500 The address for the partial symbol table entry is not
1501 used by GDB, but it comes in handy for debugging partial symbol
1505 addr = decode_locdesc (pdi->locdesc, cu);
1506 if (pdi->locdesc || pdi->has_type)
1507 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1508 VAR_DOMAIN, LOC_STATIC,
1509 &objfile->global_psymbols,
1511 cu->language, objfile);
1515 /* Static Variable. Skip symbols without location descriptors. */
1516 if (pdi->locdesc == NULL)
1518 addr = decode_locdesc (pdi->locdesc, cu);
1519 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1520 mst_file_data, objfile); */
1521 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1522 VAR_DOMAIN, LOC_STATIC,
1523 &objfile->static_psymbols,
1525 cu->language, objfile);
1528 case DW_TAG_typedef:
1529 case DW_TAG_base_type:
1530 case DW_TAG_subrange_type:
1531 add_psymbol_to_list (actual_name, strlen (actual_name),
1532 VAR_DOMAIN, LOC_TYPEDEF,
1533 &objfile->static_psymbols,
1534 0, (CORE_ADDR) 0, cu->language, objfile);
1536 case DW_TAG_class_type:
1537 case DW_TAG_structure_type:
1538 case DW_TAG_union_type:
1539 case DW_TAG_enumeration_type:
1540 /* Skip aggregate types without children, these are external
1542 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1543 static vs. global. */
1544 if (pdi->has_children == 0)
1546 add_psymbol_to_list (actual_name, strlen (actual_name),
1547 STRUCT_DOMAIN, LOC_TYPEDEF,
1548 cu->language == language_cplus
1549 ? &objfile->global_psymbols
1550 : &objfile->static_psymbols,
1551 0, (CORE_ADDR) 0, cu->language, objfile);
1553 if (cu->language == language_cplus)
1555 /* For C++, these implicitly act as typedefs as well. */
1556 add_psymbol_to_list (actual_name, strlen (actual_name),
1557 VAR_DOMAIN, LOC_TYPEDEF,
1558 &objfile->global_psymbols,
1559 0, (CORE_ADDR) 0, cu->language, objfile);
1562 case DW_TAG_enumerator:
1563 add_psymbol_to_list (actual_name, strlen (actual_name),
1564 VAR_DOMAIN, LOC_CONST,
1565 cu->language == language_cplus
1566 ? &objfile->static_psymbols
1567 : &objfile->global_psymbols,
1568 0, (CORE_ADDR) 0, cu->language, objfile);
1574 /* Check to see if we should scan the name for possible namespace
1575 info. Only do this if this is C++, if we don't have namespace
1576 debugging info in the file, if the psym is of an appropriate type
1577 (otherwise we'll have psym == NULL), and if we actually had a
1578 mangled name to begin with. */
1580 if (cu->language == language_cplus
1581 && namespace == NULL
1583 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1584 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1588 /* Determine whether a die of type TAG living in the C++ namespace
1589 NAMESPACE needs to have the name of the namespace prepended to the
1590 name listed in the die. */
1593 pdi_needs_namespace (enum dwarf_tag tag, const char *namespace)
1595 if (namespace == NULL || namespace[0] == '\0')
1600 case DW_TAG_typedef:
1601 case DW_TAG_class_type:
1602 case DW_TAG_structure_type:
1603 case DW_TAG_union_type:
1604 case DW_TAG_enumeration_type:
1605 case DW_TAG_enumerator:
1612 /* Read a partial die corresponding to a namespace; also, add a symbol
1613 corresponding to that namespace to the symbol table. NAMESPACE is
1614 the name of the enclosing namespace. */
1617 add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
1618 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1619 struct dwarf2_cu *cu, const char *namespace)
1621 struct objfile *objfile = cu->objfile;
1622 const char *new_name = pdi->name;
1625 /* Calculate the full name of the namespace that we just entered. */
1627 if (new_name == NULL)
1628 new_name = "(anonymous namespace)";
1629 full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1);
1630 strcpy (full_name, namespace);
1631 if (*namespace != '\0')
1632 strcat (full_name, "::");
1633 strcat (full_name, new_name);
1635 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1636 to add_partial_symbol, because we don't have a way to pass in the
1637 full name to that function; that might be a flaw in
1638 add_partial_symbol's interface. */
1640 add_psymbol_to_list (full_name, strlen (full_name),
1641 VAR_DOMAIN, LOC_TYPEDEF,
1642 &objfile->global_psymbols,
1643 0, 0, cu->language, objfile);
1645 /* Now scan partial symbols in that namespace. */
1647 if (pdi->has_children)
1648 info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name);
1653 /* Read a partial die corresponding to a class or structure. */
1656 add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
1657 struct dwarf2_cu *cu,
1658 const char *namespace)
1660 bfd *abfd = cu->objfile->obfd;
1661 char *actual_class_name = NULL;
1663 if (cu->language == language_cplus
1664 && (namespace == NULL || namespace[0] == '\0')
1665 && struct_pdi->name != NULL
1666 && struct_pdi->has_children)
1668 /* See if we can figure out if the class lives in a namespace
1669 (or is nested within another class.) We do this by looking
1670 for a member function; its demangled name will contain
1671 namespace info, if there is any. */
1673 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1674 what template types look like, because the demangler
1675 frequently doesn't give the same name as the debug info. We
1676 could fix this by only using the demangled name to get the
1677 prefix (but see comment in read_structure_scope). */
1679 /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
1680 the appropriate debug information, so it would be nice to be
1681 able to avoid this hack. But NAMESPACE may not be the
1682 namespace where this class was defined: NAMESPACE reflects
1683 where STRUCT_PDI occurs in the tree of dies, but because of
1684 DW_AT_specification, that may not actually tell us where the
1685 class is defined. (See the comment in read_func_scope for an
1686 example of how this could occur.)
1688 Unfortunately, our current partial symtab data structures are
1689 completely unable to deal with DW_AT_specification. So, for
1690 now, the best thing to do is to get nesting information from
1691 places other than the tree structure of dies if there's any
1692 chance that a DW_AT_specification is involved. :-( */
1694 char *next_child = info_ptr;
1698 struct partial_die_info child_pdi;
1700 next_child = read_partial_die (&child_pdi, abfd, next_child,
1704 if (child_pdi.tag == DW_TAG_subprogram)
1706 actual_class_name = class_name_from_physname (child_pdi.name);
1707 if (actual_class_name != NULL)
1708 struct_pdi->name = actual_class_name;
1713 next_child = locate_pdi_sibling (&child_pdi, next_child,
1719 add_partial_symbol (struct_pdi, cu, namespace);
1720 xfree (actual_class_name);
1722 return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu);
1725 /* Read a partial die corresponding to an enumeration type. */
1728 add_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr,
1729 struct dwarf2_cu *cu, const char *namespace)
1731 struct objfile *objfile = cu->objfile;
1732 bfd *abfd = objfile->obfd;
1733 struct partial_die_info pdi;
1735 if (enum_pdi->name != NULL)
1736 add_partial_symbol (enum_pdi, cu, namespace);
1740 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1743 if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL)
1744 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1746 add_partial_symbol (&pdi, cu, namespace);
1752 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1756 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
1757 bfd *abfd, struct dwarf2_cu *cu)
1759 /* Do we know the sibling already? */
1761 if (orig_pdi->sibling)
1762 return orig_pdi->sibling;
1764 /* Are there any children to deal with? */
1766 if (!orig_pdi->has_children)
1769 /* Okay, we don't know the sibling, but we have children that we
1770 want to skip. So read children until we run into one without a
1771 tag; return whatever follows it. */
1775 struct partial_die_info pdi;
1777 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1782 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1786 /* Expand this partial symbol table into a full symbol table. */
1789 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
1791 /* FIXME: This is barely more than a stub. */
1796 warning ("bug: psymtab for %s is already read in.", pst->filename);
1802 printf_filtered ("Reading in symbols for %s...", pst->filename);
1803 gdb_flush (gdb_stdout);
1806 psymtab_to_symtab_1 (pst);
1808 /* Finish up the debug error message. */
1810 printf_filtered ("done.\n");
1816 psymtab_to_symtab_1 (struct partial_symtab *pst)
1818 struct objfile *objfile = pst->objfile;
1819 bfd *abfd = objfile->obfd;
1820 struct dwarf2_cu cu;
1821 struct die_info *dies;
1822 unsigned long offset;
1823 CORE_ADDR lowpc, highpc;
1824 struct die_info *child_die;
1826 struct symtab *symtab;
1827 struct cleanup *back_to;
1828 struct attribute *attr;
1831 /* Set local variables from the partial symbol table info. */
1832 offset = DWARF_INFO_OFFSET (pst);
1833 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1834 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1835 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1836 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1837 dwarf_line_size = DWARF_LINE_SIZE (pst);
1838 dwarf_str_buffer = DWARF_STR_BUFFER (pst);
1839 dwarf_str_size = DWARF_STR_SIZE (pst);
1840 dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst);
1841 dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst);
1842 dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst);
1843 dwarf_ranges_size = DWARF_RANGES_SIZE (pst);
1844 dwarf_loc_buffer = DWARF_LOC_BUFFER (pst);
1845 dwarf_loc_size = DWARF_LOC_SIZE (pst);
1846 info_ptr = dwarf_info_buffer + offset;
1847 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1849 /* We're in the global namespace. */
1850 processing_current_prefix = "";
1852 obstack_init (&dwarf2_tmp_obstack);
1853 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1856 make_cleanup (really_free_pendings, NULL);
1858 cu.objfile = objfile;
1860 /* read in the comp_unit header */
1861 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1863 /* Read the abbrevs for this compilation unit */
1864 dwarf2_read_abbrevs (abfd, &cu);
1865 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1867 cu.header.offset = offset;
1869 cu.list_in_scope = &file_symbols;
1871 dies = read_comp_unit (info_ptr, abfd, &cu);
1873 make_cleanup_free_die_list (dies);
1875 /* Find the base address of the compilation unit for range lists and
1876 location lists. It will normally be specified by DW_AT_low_pc.
1877 In DWARF-3 draft 4, the base address could be overridden by
1878 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1879 compilation units with discontinuous ranges. */
1881 cu.header.base_known = 0;
1882 cu.header.base_address = 0;
1884 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
1887 cu.header.base_address = DW_ADDR (attr);
1888 cu.header.base_known = 1;
1892 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
1895 cu.header.base_address = DW_ADDR (attr);
1896 cu.header.base_known = 1;
1900 /* Do line number decoding in read_file_scope () */
1901 process_die (dies, &cu);
1903 /* Some compilers don't define a DW_AT_high_pc attribute for the
1904 compilation unit. If the DW_AT_high_pc is missing, synthesize
1905 it, by scanning the DIE's below the compilation unit. */
1906 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
1908 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
1910 /* Set symtab language to language from DW_AT_language.
1911 If the compilation is from a C file generated by language preprocessors,
1912 do not set the language if it was already deduced by start_subfile. */
1914 && !(cu.language == language_c && symtab->language != language_c))
1916 symtab->language = cu.language;
1918 pst->symtab = symtab;
1921 do_cleanups (back_to);
1924 /* Process a die and its children. */
1927 process_die (struct die_info *die, struct dwarf2_cu *cu)
1931 case DW_TAG_padding:
1933 case DW_TAG_compile_unit:
1934 read_file_scope (die, cu);
1936 case DW_TAG_subprogram:
1937 read_subroutine_type (die, cu);
1938 read_func_scope (die, cu);
1940 case DW_TAG_inlined_subroutine:
1941 /* FIXME: These are ignored for now.
1942 They could be used to set breakpoints on all inlined instances
1943 of a function and make GDB `next' properly over inlined functions. */
1945 case DW_TAG_lexical_block:
1946 case DW_TAG_try_block:
1947 case DW_TAG_catch_block:
1948 read_lexical_block_scope (die, cu);
1950 case DW_TAG_class_type:
1951 case DW_TAG_structure_type:
1952 case DW_TAG_union_type:
1953 read_structure_scope (die, cu);
1955 case DW_TAG_enumeration_type:
1956 read_enumeration (die, cu);
1958 case DW_TAG_subroutine_type:
1959 read_subroutine_type (die, cu);
1961 case DW_TAG_array_type:
1962 read_array_type (die, cu);
1964 case DW_TAG_pointer_type:
1965 read_tag_pointer_type (die, cu);
1967 case DW_TAG_ptr_to_member_type:
1968 read_tag_ptr_to_member_type (die, cu);
1970 case DW_TAG_reference_type:
1971 read_tag_reference_type (die, cu);
1973 case DW_TAG_string_type:
1974 read_tag_string_type (die, cu);
1976 case DW_TAG_base_type:
1977 read_base_type (die, cu);
1978 if (dwarf2_attr (die, DW_AT_name, cu))
1980 /* Add a typedef symbol for the base type definition. */
1981 new_symbol (die, die->type, cu);
1984 case DW_TAG_subrange_type:
1985 read_subrange_type (die, cu);
1986 if (dwarf2_attr (die, DW_AT_name, cu))
1988 /* Add a typedef symbol for the base type definition. */
1989 new_symbol (die, die->type, cu);
1992 case DW_TAG_common_block:
1993 read_common_block (die, cu);
1995 case DW_TAG_common_inclusion:
1997 case DW_TAG_namespace:
1998 processing_has_namespace_info = 1;
1999 read_namespace (die, cu);
2001 case DW_TAG_imported_declaration:
2002 case DW_TAG_imported_module:
2003 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2004 information contained in these. DW_TAG_imported_declaration
2005 dies shouldn't have children; DW_TAG_imported_module dies
2006 shouldn't in the C++ case, but conceivably could in the
2007 Fortran case, so we'll have to replace this gdb_assert if
2008 Fortran compilers start generating that info. */
2009 processing_has_namespace_info = 1;
2010 gdb_assert (die->child == NULL);
2013 new_symbol (die, NULL, cu);
2019 initialize_cu_func_list (struct dwarf2_cu *cu)
2021 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2025 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2027 struct objfile *objfile = cu->objfile;
2028 struct comp_unit_head *cu_header = &cu->header;
2029 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2030 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2031 CORE_ADDR highpc = ((CORE_ADDR) 0);
2032 struct attribute *attr;
2033 char *name = "<unknown>";
2034 char *comp_dir = NULL;
2035 struct die_info *child_die;
2036 bfd *abfd = objfile->obfd;
2037 struct line_header *line_header = 0;
2040 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2042 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2044 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2045 from finish_block. */
2046 if (lowpc == ((CORE_ADDR) -1))
2051 attr = dwarf2_attr (die, DW_AT_name, cu);
2054 name = DW_STRING (attr);
2056 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2059 comp_dir = DW_STRING (attr);
2062 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2063 directory, get rid of it. */
2064 char *cp = strchr (comp_dir, ':');
2066 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2071 if (objfile->ei.entry_point >= lowpc &&
2072 objfile->ei.entry_point < highpc)
2074 objfile->ei.deprecated_entry_file_lowpc = lowpc;
2075 objfile->ei.deprecated_entry_file_highpc = highpc;
2078 attr = dwarf2_attr (die, DW_AT_language, cu);
2081 set_cu_language (DW_UNSND (attr), cu);
2084 /* We assume that we're processing GCC output. */
2085 processing_gcc_compilation = 2;
2087 /* FIXME:Do something here. */
2088 if (dip->at_producer != NULL)
2090 handle_producer (dip->at_producer);
2094 /* The compilation unit may be in a different language or objfile,
2095 zero out all remembered fundamental types. */
2096 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2098 start_symtab (name, comp_dir, lowpc);
2099 record_debugformat ("DWARF 2");
2101 initialize_cu_func_list (cu);
2103 /* Process all dies in compilation unit. */
2104 if (die->child != NULL)
2106 child_die = die->child;
2107 while (child_die && child_die->tag)
2109 process_die (child_die, cu);
2110 child_die = sibling_die (child_die);
2114 /* Decode line number information if present. */
2115 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2118 unsigned int line_offset = DW_UNSND (attr);
2119 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2122 make_cleanup ((make_cleanup_ftype *) free_line_header,
2123 (void *) line_header);
2124 dwarf_decode_lines (line_header, comp_dir, abfd, cu);
2128 /* Decode macro information, if present. Dwarf 2 macro information
2129 refers to information in the line number info statement program
2130 header, so we can only read it if we've read the header
2132 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2133 if (attr && line_header)
2135 unsigned int macro_offset = DW_UNSND (attr);
2136 dwarf_decode_macros (line_header, macro_offset,
2137 comp_dir, abfd, cu);
2139 do_cleanups (back_to);
2143 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2144 struct dwarf2_cu *cu)
2146 struct function_range *thisfn;
2148 thisfn = (struct function_range *)
2149 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range));
2150 thisfn->name = name;
2151 thisfn->lowpc = lowpc;
2152 thisfn->highpc = highpc;
2153 thisfn->seen_line = 0;
2154 thisfn->next = NULL;
2156 if (cu->last_fn == NULL)
2157 cu->first_fn = thisfn;
2159 cu->last_fn->next = thisfn;
2161 cu->last_fn = thisfn;
2165 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2167 struct objfile *objfile = cu->objfile;
2168 struct context_stack *new;
2171 struct die_info *child_die;
2172 struct attribute *attr;
2174 const char *previous_prefix = processing_current_prefix;
2175 struct cleanup *back_to = NULL;
2178 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2180 name = dwarf2_linkage_name (die, cu);
2182 /* Ignore functions with missing or empty names and functions with
2183 missing or invalid low and high pc attributes. */
2184 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2187 if (cu->language == language_cplus)
2189 struct die_info *spec_die = die_specification (die, cu);
2191 /* NOTE: carlton/2004-01-23: We have to be careful in the
2192 presence of DW_AT_specification. For example, with GCC 3.4,
2197 // Definition of N::foo.
2201 then we'll have a tree of DIEs like this:
2203 1: DW_TAG_compile_unit
2204 2: DW_TAG_namespace // N
2205 3: DW_TAG_subprogram // declaration of N::foo
2206 4: DW_TAG_subprogram // definition of N::foo
2207 DW_AT_specification // refers to die #3
2209 Thus, when processing die #4, we have to pretend that we're
2210 in the context of its DW_AT_specification, namely the contex
2213 if (spec_die != NULL)
2215 char *specification_prefix = determine_prefix (spec_die, cu);
2216 processing_current_prefix = specification_prefix;
2217 back_to = make_cleanup (xfree, specification_prefix);
2224 /* Record the function range for dwarf_decode_lines. */
2225 add_to_cu_func_list (name, lowpc, highpc, cu);
2227 if (objfile->ei.entry_point >= lowpc &&
2228 objfile->ei.entry_point < highpc)
2230 objfile->ei.entry_func_lowpc = lowpc;
2231 objfile->ei.entry_func_highpc = highpc;
2234 new = push_context (0, lowpc);
2235 new->name = new_symbol (die, die->type, cu);
2237 /* If there is a location expression for DW_AT_frame_base, record
2239 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2241 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2242 expression is being recorded directly in the function's symbol
2243 and not in a separate frame-base object. I guess this hack is
2244 to avoid adding some sort of frame-base adjunct/annex to the
2245 function's symbol :-(. The problem with doing this is that it
2246 results in a function symbol with a location expression that
2247 has nothing to do with the location of the function, ouch! The
2248 relationship should be: a function's symbol has-a frame base; a
2249 frame-base has-a location expression. */
2250 dwarf2_symbol_mark_computed (attr, new->name, cu);
2252 cu->list_in_scope = &local_symbols;
2254 if (die->child != NULL)
2256 child_die = die->child;
2257 while (child_die && child_die->tag)
2259 process_die (child_die, cu);
2260 child_die = sibling_die (child_die);
2264 new = pop_context ();
2265 /* Make a block for the local symbols within. */
2266 finish_block (new->name, &local_symbols, new->old_blocks,
2267 lowpc, highpc, objfile);
2269 /* In C++, we can have functions nested inside functions (e.g., when
2270 a function declares a class that has methods). This means that
2271 when we finish processing a function scope, we may need to go
2272 back to building a containing block's symbol lists. */
2273 local_symbols = new->locals;
2274 param_symbols = new->params;
2276 /* If we've finished processing a top-level function, subsequent
2277 symbols go in the file symbol list. */
2278 if (outermost_context_p ())
2279 cu->list_in_scope = &file_symbols;
2281 processing_current_prefix = previous_prefix;
2282 if (back_to != NULL)
2283 do_cleanups (back_to);
2286 /* Process all the DIES contained within a lexical block scope. Start
2287 a new scope, process the dies, and then close the scope. */
2290 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2292 struct objfile *objfile = cu->objfile;
2293 struct context_stack *new;
2294 CORE_ADDR lowpc, highpc;
2295 struct die_info *child_die;
2298 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2300 /* Ignore blocks with missing or invalid low and high pc attributes. */
2301 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2302 as multiple lexical blocks? Handling children in a sane way would
2303 be nasty. Might be easier to properly extend generic blocks to
2305 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2310 push_context (0, lowpc);
2311 if (die->child != NULL)
2313 child_die = die->child;
2314 while (child_die && child_die->tag)
2316 process_die (child_die, cu);
2317 child_die = sibling_die (child_die);
2320 new = pop_context ();
2322 if (local_symbols != NULL)
2324 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2327 local_symbols = new->locals;
2330 /* Get low and high pc attributes from a die. Return 1 if the attributes
2331 are present and valid, otherwise, return 0. Return -1 if the range is
2332 discontinuous, i.e. derived from DW_AT_ranges information. */
2334 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2335 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2337 struct objfile *objfile = cu->objfile;
2338 struct comp_unit_head *cu_header = &cu->header;
2339 struct attribute *attr;
2340 bfd *obfd = objfile->obfd;
2345 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2348 high = DW_ADDR (attr);
2349 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2351 low = DW_ADDR (attr);
2353 /* Found high w/o low attribute. */
2356 /* Found consecutive range of addresses. */
2361 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2364 unsigned int addr_size = cu_header->addr_size;
2365 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2366 /* Value of the DW_AT_ranges attribute is the offset in the
2367 .debug_ranges section. */
2368 unsigned int offset = DW_UNSND (attr);
2369 /* Base address selection entry. */
2377 found_base = cu_header->base_known;
2378 base = cu_header->base_address;
2380 if (offset >= dwarf_ranges_size)
2382 complaint (&symfile_complaints,
2383 "Offset %d out of bounds for DW_AT_ranges attribute",
2387 buffer = dwarf_ranges_buffer + offset;
2389 /* Read in the largest possible address. */
2390 marker = read_address (obfd, buffer, cu, &dummy);
2391 if ((marker & mask) == mask)
2393 /* If we found the largest possible address, then
2394 read the base address. */
2395 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2396 buffer += 2 * addr_size;
2397 offset += 2 * addr_size;
2405 CORE_ADDR range_beginning, range_end;
2407 range_beginning = read_address (obfd, buffer, cu, &dummy);
2408 buffer += addr_size;
2409 range_end = read_address (obfd, buffer, cu, &dummy);
2410 buffer += addr_size;
2411 offset += 2 * addr_size;
2413 /* An end of list marker is a pair of zero addresses. */
2414 if (range_beginning == 0 && range_end == 0)
2415 /* Found the end of list entry. */
2418 /* Each base address selection entry is a pair of 2 values.
2419 The first is the largest possible address, the second is
2420 the base address. Check for a base address here. */
2421 if ((range_beginning & mask) == mask)
2423 /* If we found the largest possible address, then
2424 read the base address. */
2425 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2432 /* We have no valid base address for the ranges
2434 complaint (&symfile_complaints,
2435 "Invalid .debug_ranges data (no base address)");
2439 range_beginning += base;
2442 /* FIXME: This is recording everything as a low-high
2443 segment of consecutive addresses. We should have a
2444 data structure for discontiguous block ranges
2448 low = range_beginning;
2454 if (range_beginning < low)
2455 low = range_beginning;
2456 if (range_end > high)
2462 /* If the first entry is an end-of-list marker, the range
2463 describes an empty scope, i.e. no instructions. */
2473 /* When using the GNU linker, .gnu.linkonce. sections are used to
2474 eliminate duplicate copies of functions and vtables and such.
2475 The linker will arbitrarily choose one and discard the others.
2476 The AT_*_pc values for such functions refer to local labels in
2477 these sections. If the section from that file was discarded, the
2478 labels are not in the output, so the relocs get a value of 0.
2479 If this is a discarded function, mark the pc bounds as invalid,
2480 so that GDB will ignore it. */
2481 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2489 /* Get the low and high pc's represented by the scope DIE, and store
2490 them in *LOWPC and *HIGHPC. If the correct values can't be
2491 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2494 get_scope_pc_bounds (struct die_info *die,
2495 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2496 struct dwarf2_cu *cu)
2498 CORE_ADDR best_low = (CORE_ADDR) -1;
2499 CORE_ADDR best_high = (CORE_ADDR) 0;
2500 CORE_ADDR current_low, current_high;
2502 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
2504 best_low = current_low;
2505 best_high = current_high;
2509 struct die_info *child = die->child;
2511 while (child && child->tag)
2513 switch (child->tag) {
2514 case DW_TAG_subprogram:
2515 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
2517 best_low = min (best_low, current_low);
2518 best_high = max (best_high, current_high);
2521 case DW_TAG_namespace:
2522 /* FIXME: carlton/2004-01-16: Should we do this for
2523 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2524 that current GCC's always emit the DIEs corresponding
2525 to definitions of methods of classes as children of a
2526 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2527 the DIEs giving the declarations, which could be
2528 anywhere). But I don't see any reason why the
2529 standards says that they have to be there. */
2530 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
2532 if (current_low != ((CORE_ADDR) -1))
2534 best_low = min (best_low, current_low);
2535 best_high = max (best_high, current_high);
2543 child = sibling_die (child);
2548 *highpc = best_high;
2551 /* Add an aggregate field to the field list. */
2554 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2555 struct dwarf2_cu *cu)
2557 struct objfile *objfile = cu->objfile;
2558 struct nextfield *new_field;
2559 struct attribute *attr;
2561 char *fieldname = "";
2563 /* Allocate a new field list entry and link it in. */
2564 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2565 make_cleanup (xfree, new_field);
2566 memset (new_field, 0, sizeof (struct nextfield));
2567 new_field->next = fip->fields;
2568 fip->fields = new_field;
2571 /* Handle accessibility and virtuality of field.
2572 The default accessibility for members is public, the default
2573 accessibility for inheritance is private. */
2574 if (die->tag != DW_TAG_inheritance)
2575 new_field->accessibility = DW_ACCESS_public;
2577 new_field->accessibility = DW_ACCESS_private;
2578 new_field->virtuality = DW_VIRTUALITY_none;
2580 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2582 new_field->accessibility = DW_UNSND (attr);
2583 if (new_field->accessibility != DW_ACCESS_public)
2584 fip->non_public_fields = 1;
2585 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
2587 new_field->virtuality = DW_UNSND (attr);
2589 fp = &new_field->field;
2591 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
2593 /* Data member other than a C++ static data member. */
2595 /* Get type of field. */
2596 fp->type = die_type (die, cu);
2598 FIELD_STATIC_KIND (*fp) = 0;
2600 /* Get bit size of field (zero if none). */
2601 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
2604 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2608 FIELD_BITSIZE (*fp) = 0;
2611 /* Get bit offset of field. */
2612 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2615 FIELD_BITPOS (*fp) =
2616 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2619 FIELD_BITPOS (*fp) = 0;
2620 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
2623 if (BITS_BIG_ENDIAN)
2625 /* For big endian bits, the DW_AT_bit_offset gives the
2626 additional bit offset from the MSB of the containing
2627 anonymous object to the MSB of the field. We don't
2628 have to do anything special since we don't need to
2629 know the size of the anonymous object. */
2630 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2634 /* For little endian bits, compute the bit offset to the
2635 MSB of the anonymous object, subtract off the number of
2636 bits from the MSB of the field to the MSB of the
2637 object, and then subtract off the number of bits of
2638 the field itself. The result is the bit offset of
2639 the LSB of the field. */
2641 int bit_offset = DW_UNSND (attr);
2643 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2646 /* The size of the anonymous object containing
2647 the bit field is explicit, so use the
2648 indicated size (in bytes). */
2649 anonymous_size = DW_UNSND (attr);
2653 /* The size of the anonymous object containing
2654 the bit field must be inferred from the type
2655 attribute of the data member containing the
2657 anonymous_size = TYPE_LENGTH (fp->type);
2659 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2660 - bit_offset - FIELD_BITSIZE (*fp);
2664 /* Get name of field. */
2665 attr = dwarf2_attr (die, DW_AT_name, cu);
2666 if (attr && DW_STRING (attr))
2667 fieldname = DW_STRING (attr);
2668 fp->name = obsavestring (fieldname, strlen (fieldname),
2669 &objfile->objfile_obstack);
2671 /* Change accessibility for artificial fields (e.g. virtual table
2672 pointer or virtual base class pointer) to private. */
2673 if (dwarf2_attr (die, DW_AT_artificial, cu))
2675 new_field->accessibility = DW_ACCESS_private;
2676 fip->non_public_fields = 1;
2679 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2681 /* C++ static member. */
2683 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2684 is a declaration, but all versions of G++ as of this writing
2685 (so through at least 3.2.1) incorrectly generate
2686 DW_TAG_variable tags. */
2690 /* Get name of field. */
2691 attr = dwarf2_attr (die, DW_AT_name, cu);
2692 if (attr && DW_STRING (attr))
2693 fieldname = DW_STRING (attr);
2697 /* Get physical name. */
2698 physname = dwarf2_linkage_name (die, cu);
2700 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
2701 &objfile->objfile_obstack));
2702 FIELD_TYPE (*fp) = die_type (die, cu);
2703 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
2704 &objfile->objfile_obstack);
2706 else if (die->tag == DW_TAG_inheritance)
2708 /* C++ base class field. */
2709 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2711 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
2713 FIELD_BITSIZE (*fp) = 0;
2714 FIELD_STATIC_KIND (*fp) = 0;
2715 FIELD_TYPE (*fp) = die_type (die, cu);
2716 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
2717 fip->nbaseclasses++;
2721 /* Create the vector of fields, and attach it to the type. */
2724 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
2725 struct dwarf2_cu *cu)
2727 int nfields = fip->nfields;
2729 /* Record the field count, allocate space for the array of fields,
2730 and create blank accessibility bitfields if necessary. */
2731 TYPE_NFIELDS (type) = nfields;
2732 TYPE_FIELDS (type) = (struct field *)
2733 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2734 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2736 if (fip->non_public_fields)
2738 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2740 TYPE_FIELD_PRIVATE_BITS (type) =
2741 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2742 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2744 TYPE_FIELD_PROTECTED_BITS (type) =
2745 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2746 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2748 TYPE_FIELD_IGNORE_BITS (type) =
2749 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2750 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2753 /* If the type has baseclasses, allocate and clear a bit vector for
2754 TYPE_FIELD_VIRTUAL_BITS. */
2755 if (fip->nbaseclasses)
2757 int num_bytes = B_BYTES (fip->nbaseclasses);
2760 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2761 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2762 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2763 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
2764 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
2767 /* Copy the saved-up fields into the field vector. Start from the head
2768 of the list, adding to the tail of the field array, so that they end
2769 up in the same order in the array in which they were added to the list. */
2770 while (nfields-- > 0)
2772 TYPE_FIELD (type, nfields) = fip->fields->field;
2773 switch (fip->fields->accessibility)
2775 case DW_ACCESS_private:
2776 SET_TYPE_FIELD_PRIVATE (type, nfields);
2779 case DW_ACCESS_protected:
2780 SET_TYPE_FIELD_PROTECTED (type, nfields);
2783 case DW_ACCESS_public:
2787 /* Unknown accessibility. Complain and treat it as public. */
2789 complaint (&symfile_complaints, "unsupported accessibility %d",
2790 fip->fields->accessibility);
2794 if (nfields < fip->nbaseclasses)
2796 switch (fip->fields->virtuality)
2798 case DW_VIRTUALITY_virtual:
2799 case DW_VIRTUALITY_pure_virtual:
2800 SET_TYPE_FIELD_VIRTUAL (type, nfields);
2804 fip->fields = fip->fields->next;
2808 /* Add a member function to the proper fieldlist. */
2811 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
2812 struct type *type, struct dwarf2_cu *cu)
2814 struct objfile *objfile = cu->objfile;
2815 struct attribute *attr;
2816 struct fnfieldlist *flp;
2818 struct fn_field *fnp;
2821 struct nextfnfield *new_fnfield;
2823 /* Get name of member function. */
2824 attr = dwarf2_attr (die, DW_AT_name, cu);
2825 if (attr && DW_STRING (attr))
2826 fieldname = DW_STRING (attr);
2830 /* Get the mangled name. */
2831 physname = dwarf2_linkage_name (die, cu);
2833 /* Look up member function name in fieldlist. */
2834 for (i = 0; i < fip->nfnfields; i++)
2836 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
2840 /* Create new list element if necessary. */
2841 if (i < fip->nfnfields)
2842 flp = &fip->fnfieldlists[i];
2845 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2847 fip->fnfieldlists = (struct fnfieldlist *)
2848 xrealloc (fip->fnfieldlists,
2849 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2850 * sizeof (struct fnfieldlist));
2851 if (fip->nfnfields == 0)
2852 make_cleanup (free_current_contents, &fip->fnfieldlists);
2854 flp = &fip->fnfieldlists[fip->nfnfields];
2855 flp->name = fieldname;
2861 /* Create a new member function field and chain it to the field list
2863 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2864 make_cleanup (xfree, new_fnfield);
2865 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2866 new_fnfield->next = flp->head;
2867 flp->head = new_fnfield;
2870 /* Fill in the member function field info. */
2871 fnp = &new_fnfield->fnfield;
2872 fnp->physname = obsavestring (physname, strlen (physname),
2873 &objfile->objfile_obstack);
2874 fnp->type = alloc_type (objfile);
2875 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2877 int nparams = TYPE_NFIELDS (die->type);
2879 /* TYPE is the domain of this method, and DIE->TYPE is the type
2880 of the method itself (TYPE_CODE_METHOD). */
2881 smash_to_method_type (fnp->type, type,
2882 TYPE_TARGET_TYPE (die->type),
2883 TYPE_FIELDS (die->type),
2884 TYPE_NFIELDS (die->type),
2885 TYPE_VARARGS (die->type));
2887 /* Handle static member functions.
2888 Dwarf2 has no clean way to discern C++ static and non-static
2889 member functions. G++ helps GDB by marking the first
2890 parameter for non-static member functions (which is the
2891 this pointer) as artificial. We obtain this information
2892 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2893 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2894 fnp->voffset = VOFFSET_STATIC;
2897 complaint (&symfile_complaints, "member function type missing for '%s'",
2900 /* Get fcontext from DW_AT_containing_type if present. */
2901 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
2902 fnp->fcontext = die_containing_type (die, cu);
2904 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2905 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2907 /* Get accessibility. */
2908 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2911 switch (DW_UNSND (attr))
2913 case DW_ACCESS_private:
2914 fnp->is_private = 1;
2916 case DW_ACCESS_protected:
2917 fnp->is_protected = 1;
2922 /* Check for artificial methods. */
2923 attr = dwarf2_attr (die, DW_AT_artificial, cu);
2924 if (attr && DW_UNSND (attr) != 0)
2925 fnp->is_artificial = 1;
2927 /* Get index in virtual function table if it is a virtual member function. */
2928 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
2931 /* Support the .debug_loc offsets */
2932 if (attr_form_is_block (attr))
2934 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
2936 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
2938 dwarf2_complex_location_expr_complaint ();
2942 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2948 /* Create the vector of member function fields, and attach it to the type. */
2951 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
2952 struct dwarf2_cu *cu)
2954 struct fnfieldlist *flp;
2955 int total_length = 0;
2958 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2959 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2960 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2962 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2964 struct nextfnfield *nfp = flp->head;
2965 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2968 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2969 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2970 fn_flp->fn_fields = (struct fn_field *)
2971 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2972 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2973 fn_flp->fn_fields[k] = nfp->fnfield;
2975 total_length += flp->length;
2978 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2979 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2982 /* Called when we find the DIE that starts a structure or union scope
2983 (definition) to process all dies that define the members of the
2986 NOTE: we need to call struct_type regardless of whether or not the
2987 DIE has an at_name attribute, since it might be an anonymous
2988 structure or union. This gets the type entered into our set of
2991 However, if the structure is incomplete (an opaque struct/union)
2992 then suppress creating a symbol table entry for it since gdb only
2993 wants to find the one with the complete definition. Note that if
2994 it is complete, we just call new_symbol, which does it's own
2995 checking about whether the struct/union is anonymous or not (and
2996 suppresses creating a symbol table entry itself). */
2999 read_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3001 struct objfile *objfile = cu->objfile;
3003 struct attribute *attr;
3004 const char *name = NULL;
3005 const char *previous_prefix = processing_current_prefix;
3006 struct cleanup *back_to = NULL;
3007 /* This says whether or not we want to try to update the structure's
3008 name to include enclosing namespace/class information, if
3010 int need_to_update_name = 0;
3012 type = alloc_type (objfile);
3014 INIT_CPLUS_SPECIFIC (type);
3015 attr = dwarf2_attr (die, DW_AT_name, cu);
3016 if (attr && DW_STRING (attr))
3018 name = DW_STRING (attr);
3020 if (cu->language == language_cplus)
3022 struct die_info *spec_die = die_specification (die, cu);
3024 if (spec_die != NULL)
3026 char *specification_prefix = determine_prefix (spec_die, cu);
3027 processing_current_prefix = specification_prefix;
3028 back_to = make_cleanup (xfree, specification_prefix);
3032 if (processing_has_namespace_info)
3034 /* FIXME: carlton/2003-11-10: This variable exists only for
3035 const-correctness reasons. When I tried to change
3036 TYPE_TAG_NAME to be a const char *, I ran into a cascade
3037 of changes which would have forced decode_line_1 to take
3039 char *new_prefix = obconcat (&objfile->objfile_obstack,
3040 processing_current_prefix,
3041 processing_current_prefix[0] == '\0'
3044 TYPE_TAG_NAME (type) = new_prefix;
3045 processing_current_prefix = new_prefix;
3049 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
3050 &objfile->objfile_obstack);
3051 need_to_update_name = (cu->language == language_cplus);
3055 if (die->tag == DW_TAG_structure_type)
3057 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3059 else if (die->tag == DW_TAG_union_type)
3061 TYPE_CODE (type) = TYPE_CODE_UNION;
3065 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3067 TYPE_CODE (type) = TYPE_CODE_CLASS;
3070 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3073 TYPE_LENGTH (type) = DW_UNSND (attr);
3077 TYPE_LENGTH (type) = 0;
3080 /* We need to add the type field to the die immediately so we don't
3081 infinitely recurse when dealing with pointers to the structure
3082 type within the structure itself. */
3085 if (die->child != NULL && ! die_is_declaration (die, cu))
3087 struct field_info fi;
3088 struct die_info *child_die;
3089 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3091 memset (&fi, 0, sizeof (struct field_info));
3093 child_die = die->child;
3095 while (child_die && child_die->tag)
3097 if (child_die->tag == DW_TAG_member
3098 || child_die->tag == DW_TAG_variable)
3100 /* NOTE: carlton/2002-11-05: A C++ static data member
3101 should be a DW_TAG_member that is a declaration, but
3102 all versions of G++ as of this writing (so through at
3103 least 3.2.1) incorrectly generate DW_TAG_variable
3104 tags for them instead. */
3105 dwarf2_add_field (&fi, child_die, cu);
3107 else if (child_die->tag == DW_TAG_subprogram)
3109 /* C++ member function. */
3110 process_die (child_die, cu);
3111 dwarf2_add_member_fn (&fi, child_die, type, cu);
3112 if (need_to_update_name)
3114 /* The demangled names of member functions contain
3115 information about enclosing namespaces/classes,
3118 /* FIXME: carlton/2003-11-10: The excessive
3119 demangling here is a bit wasteful, as is the
3120 memory usage for names. */
3122 /* NOTE: carlton/2003-11-10: As commented in
3123 add_partial_structure, the demangler sometimes
3124 prints the type info in a different form from the
3125 debug info. We could solve this by using the
3126 demangled name to get the prefix; if doing so,
3127 however, we'd need to be careful when reading a
3128 class that's nested inside a template class.
3129 That would also cause problems when trying to
3130 determine RTTI information, since we use the
3131 demangler to determine the appropriate class
3133 char *actual_class_name
3134 = class_name_from_physname (dwarf2_linkage_name
3136 if (actual_class_name != NULL
3137 && strcmp (actual_class_name, name) != 0)
3139 TYPE_TAG_NAME (type)
3140 = obsavestring (actual_class_name,
3141 strlen (actual_class_name),
3142 &objfile->objfile_obstack);
3144 xfree (actual_class_name);
3145 need_to_update_name = 0;
3148 else if (child_die->tag == DW_TAG_inheritance)
3150 /* C++ base class field. */
3151 dwarf2_add_field (&fi, child_die, cu);
3155 process_die (child_die, cu);
3157 child_die = sibling_die (child_die);
3160 /* Attach fields and member functions to the type. */
3162 dwarf2_attach_fields_to_type (&fi, type, cu);
3165 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3167 /* Get the type which refers to the base class (possibly this
3168 class itself) which contains the vtable pointer for the current
3169 class from the DW_AT_containing_type attribute. */
3171 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3173 struct type *t = die_containing_type (die, cu);
3175 TYPE_VPTR_BASETYPE (type) = t;
3178 static const char vptr_name[] =
3179 {'_', 'v', 'p', 't', 'r', '\0'};
3182 /* Our own class provides vtbl ptr. */
3183 for (i = TYPE_NFIELDS (t) - 1;
3184 i >= TYPE_N_BASECLASSES (t);
3187 char *fieldname = TYPE_FIELD_NAME (t, i);
3189 if ((strncmp (fieldname, vptr_name,
3190 strlen (vptr_name) - 1)
3192 && is_cplus_marker (fieldname[strlen (vptr_name)]))
3194 TYPE_VPTR_FIELDNO (type) = i;
3199 /* Complain if virtual function table field not found. */
3200 if (i < TYPE_N_BASECLASSES (t))
3201 complaint (&symfile_complaints,
3202 "virtual function table pointer not found when defining class '%s'",
3203 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3208 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3213 new_symbol (die, type, cu);
3215 do_cleanups (back_to);
3219 /* No children, must be stub. */
3220 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3223 processing_current_prefix = previous_prefix;
3224 if (back_to != NULL)
3225 do_cleanups (back_to);
3228 /* Given a pointer to a die which begins an enumeration, process all
3229 the dies that define the members of the enumeration.
3231 This will be much nicer in draft 6 of the DWARF spec when our
3232 members will be dies instead squished into the DW_AT_element_list
3235 NOTE: We reverse the order of the element list. */
3238 read_enumeration (struct die_info *die, struct dwarf2_cu *cu)
3240 struct objfile *objfile = cu->objfile;
3241 struct die_info *child_die;
3243 struct field *fields;
3244 struct attribute *attr;
3247 int unsigned_enum = 1;
3249 type = alloc_type (objfile);
3251 TYPE_CODE (type) = TYPE_CODE_ENUM;
3252 attr = dwarf2_attr (die, DW_AT_name, cu);
3253 if (attr && DW_STRING (attr))
3255 const char *name = DW_STRING (attr);
3257 if (processing_has_namespace_info)
3259 TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack,
3260 processing_current_prefix,
3261 processing_current_prefix[0] == '\0'
3267 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
3268 &objfile->objfile_obstack);
3272 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3275 TYPE_LENGTH (type) = DW_UNSND (attr);
3279 TYPE_LENGTH (type) = 0;
3284 if (die->child != NULL)
3286 child_die = die->child;
3287 while (child_die && child_die->tag)
3289 if (child_die->tag != DW_TAG_enumerator)
3291 process_die (child_die, cu);
3295 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3298 sym = new_symbol (child_die, type, cu);
3299 if (SYMBOL_VALUE (sym) < 0)
3302 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3304 fields = (struct field *)
3306 (num_fields + DW_FIELD_ALLOC_CHUNK)
3307 * sizeof (struct field));
3310 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3311 FIELD_TYPE (fields[num_fields]) = NULL;
3312 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3313 FIELD_BITSIZE (fields[num_fields]) = 0;
3314 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3320 child_die = sibling_die (child_die);
3325 TYPE_NFIELDS (type) = num_fields;
3326 TYPE_FIELDS (type) = (struct field *)
3327 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
3328 memcpy (TYPE_FIELDS (type), fields,
3329 sizeof (struct field) * num_fields);
3333 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
3336 new_symbol (die, type, cu);
3339 /* Extract all information from a DW_TAG_array_type DIE and put it in
3340 the DIE's type field. For now, this only handles one dimensional
3344 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3346 struct objfile *objfile = cu->objfile;
3347 struct die_info *child_die;
3348 struct type *type = NULL;
3349 struct type *element_type, *range_type, *index_type;
3350 struct type **range_types = NULL;
3351 struct attribute *attr;
3353 struct cleanup *back_to;
3355 /* Return if we've already decoded this type. */
3361 element_type = die_type (die, cu);
3363 /* Irix 6.2 native cc creates array types without children for
3364 arrays with unspecified length. */
3365 if (die->child == NULL)
3367 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3368 range_type = create_range_type (NULL, index_type, 0, -1);
3369 die->type = create_array_type (NULL, element_type, range_type);
3373 back_to = make_cleanup (null_cleanup, NULL);
3374 child_die = die->child;
3375 while (child_die && child_die->tag)
3377 if (child_die->tag == DW_TAG_subrange_type)
3379 read_subrange_type (child_die, cu);
3381 if (child_die->type != NULL)
3383 /* The range type was succesfully read. Save it for
3384 the array type creation. */
3385 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3387 range_types = (struct type **)
3388 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3389 * sizeof (struct type *));
3391 make_cleanup (free_current_contents, &range_types);
3393 range_types[ndim++] = child_die->type;
3396 child_die = sibling_die (child_die);
3399 /* Dwarf2 dimensions are output from left to right, create the
3400 necessary array types in backwards order. */
3401 type = element_type;
3403 type = create_array_type (NULL, type, range_types[ndim]);
3405 /* Understand Dwarf2 support for vector types (like they occur on
3406 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3407 array type. This is not part of the Dwarf2/3 standard yet, but a
3408 custom vendor extension. The main difference between a regular
3409 array and the vector variant is that vectors are passed by value
3411 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
3413 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3415 do_cleanups (back_to);
3417 /* Install the type in the die. */
3421 /* First cut: install each common block member as a global variable. */
3424 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3426 struct die_info *child_die;
3427 struct attribute *attr;
3429 CORE_ADDR base = (CORE_ADDR) 0;
3431 attr = dwarf2_attr (die, DW_AT_location, cu);
3434 /* Support the .debug_loc offsets */
3435 if (attr_form_is_block (attr))
3437 base = decode_locdesc (DW_BLOCK (attr), cu);
3439 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3441 dwarf2_complex_location_expr_complaint ();
3445 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3446 "common block member");
3449 if (die->child != NULL)
3451 child_die = die->child;
3452 while (child_die && child_die->tag)
3454 sym = new_symbol (child_die, NULL, cu);
3455 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
3458 SYMBOL_VALUE_ADDRESS (sym) =
3459 base + decode_locdesc (DW_BLOCK (attr), cu);
3460 add_symbol_to_list (sym, &global_symbols);
3462 child_die = sibling_die (child_die);
3467 /* Read a C++ namespace. */
3470 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3472 struct objfile *objfile = cu->objfile;
3473 const char *previous_prefix = processing_current_prefix;
3476 struct die_info *current_die;
3478 name = namespace_name (die, &is_anonymous, cu);
3480 /* Now build the name of the current namespace. */
3482 if (previous_prefix[0] == '\0')
3484 processing_current_prefix = name;
3488 /* We need temp_name around because processing_current_prefix
3489 is a const char *. */
3490 char *temp_name = alloca (strlen (previous_prefix)
3491 + 2 + strlen(name) + 1);
3492 strcpy (temp_name, previous_prefix);
3493 strcat (temp_name, "::");
3494 strcat (temp_name, name);
3496 processing_current_prefix = temp_name;
3499 /* Add a symbol associated to this if we haven't seen the namespace
3500 before. Also, add a using directive if it's an anonymous
3503 if (dwarf2_extension (die, cu) == NULL)
3507 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3508 this cast will hopefully become unnecessary. */
3509 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3510 (char *) processing_current_prefix,
3512 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3514 new_symbol (die, type, cu);
3517 cp_add_using_directive (processing_current_prefix,
3518 strlen (previous_prefix),
3519 strlen (processing_current_prefix));
3522 if (die->child != NULL)
3524 struct die_info *child_die = die->child;
3526 while (child_die && child_die->tag)
3528 process_die (child_die, cu);
3529 child_die = sibling_die (child_die);
3533 processing_current_prefix = previous_prefix;
3536 /* Return the name of the namespace represented by DIE. Set
3537 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3541 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
3543 struct die_info *current_die;
3544 const char *name = NULL;
3546 /* Loop through the extensions until we find a name. */
3548 for (current_die = die;
3549 current_die != NULL;
3550 current_die = dwarf2_extension (die, cu))
3552 name = dwarf2_name (current_die, cu);
3557 /* Is it an anonymous namespace? */
3559 *is_anonymous = (name == NULL);
3561 name = "(anonymous namespace)";
3566 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3567 the user defined type vector. */
3570 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3572 struct comp_unit_head *cu_header = &cu->header;
3574 struct attribute *attr_byte_size;
3575 struct attribute *attr_address_class;
3576 int byte_size, addr_class;
3583 type = lookup_pointer_type (die_type (die, cu));
3585 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
3587 byte_size = DW_UNSND (attr_byte_size);
3589 byte_size = cu_header->addr_size;
3591 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
3592 if (attr_address_class)
3593 addr_class = DW_UNSND (attr_address_class);
3595 addr_class = DW_ADDR_none;
3597 /* If the pointer size or address class is different than the
3598 default, create a type variant marked as such and set the
3599 length accordingly. */
3600 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3602 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3606 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
3607 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
3608 type = make_type_with_address_space (type, type_flags);
3610 else if (TYPE_LENGTH (type) != byte_size)
3612 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
3615 /* Should we also complain about unhandled address classes? */
3619 TYPE_LENGTH (type) = byte_size;
3623 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3624 the user defined type vector. */
3627 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
3629 struct objfile *objfile = cu->objfile;
3631 struct type *to_type;
3632 struct type *domain;
3639 type = alloc_type (objfile);
3640 to_type = die_type (die, cu);
3641 domain = die_containing_type (die, cu);
3642 smash_to_member_type (type, domain, to_type);
3647 /* Extract all information from a DW_TAG_reference_type DIE and add to
3648 the user defined type vector. */
3651 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
3653 struct comp_unit_head *cu_header = &cu->header;
3655 struct attribute *attr;
3662 type = lookup_reference_type (die_type (die, cu));
3663 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3666 TYPE_LENGTH (type) = DW_UNSND (attr);
3670 TYPE_LENGTH (type) = cu_header->addr_size;
3676 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
3678 struct type *base_type;
3685 base_type = die_type (die, cu);
3686 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
3690 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
3692 struct type *base_type;
3699 base_type = die_type (die, cu);
3700 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
3703 /* Extract all information from a DW_TAG_string_type DIE and add to
3704 the user defined type vector. It isn't really a user defined type,
3705 but it behaves like one, with other DIE's using an AT_user_def_type
3706 attribute to reference it. */
3709 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3711 struct objfile *objfile = cu->objfile;
3712 struct type *type, *range_type, *index_type, *char_type;
3713 struct attribute *attr;
3714 unsigned int length;
3721 attr = dwarf2_attr (die, DW_AT_string_length, cu);
3724 length = DW_UNSND (attr);
3728 /* check for the DW_AT_byte_size attribute */
3729 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3732 length = DW_UNSND (attr);
3739 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3740 range_type = create_range_type (NULL, index_type, 1, length);
3741 if (cu->language == language_fortran)
3743 /* Need to create a unique string type for bounds
3745 type = create_string_type (0, range_type);
3749 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
3750 type = create_string_type (char_type, range_type);
3755 /* Handle DIES due to C code like:
3759 int (*funcp)(int a, long l);
3763 ('funcp' generates a DW_TAG_subroutine_type DIE)
3767 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
3769 struct type *type; /* Type that this function returns */
3770 struct type *ftype; /* Function that returns above type */
3771 struct attribute *attr;
3773 /* Decode the type that this subroutine returns */
3778 type = die_type (die, cu);
3779 ftype = lookup_function_type (type);
3781 /* All functions in C++ have prototypes. */
3782 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
3783 if ((attr && (DW_UNSND (attr) != 0))
3784 || cu->language == language_cplus)
3785 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
3787 if (die->child != NULL)
3789 struct die_info *child_die;
3793 /* Count the number of parameters.
3794 FIXME: GDB currently ignores vararg functions, but knows about
3795 vararg member functions. */
3796 child_die = die->child;
3797 while (child_die && child_die->tag)
3799 if (child_die->tag == DW_TAG_formal_parameter)
3801 else if (child_die->tag == DW_TAG_unspecified_parameters)
3802 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
3803 child_die = sibling_die (child_die);
3806 /* Allocate storage for parameters and fill them in. */
3807 TYPE_NFIELDS (ftype) = nparams;
3808 TYPE_FIELDS (ftype) = (struct field *)
3809 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
3811 child_die = die->child;
3812 while (child_die && child_die->tag)
3814 if (child_die->tag == DW_TAG_formal_parameter)
3816 /* Dwarf2 has no clean way to discern C++ static and non-static
3817 member functions. G++ helps GDB by marking the first
3818 parameter for non-static member functions (which is the
3819 this pointer) as artificial. We pass this information
3820 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3821 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
3823 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
3825 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
3826 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
3829 child_die = sibling_die (child_die);
3837 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
3839 struct objfile *objfile = cu->objfile;
3840 struct attribute *attr;
3845 attr = dwarf2_attr (die, DW_AT_name, cu);
3846 if (attr && DW_STRING (attr))
3848 name = DW_STRING (attr);
3850 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
3851 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
3855 /* Find a representation of a given base type and install
3856 it in the TYPE field of the die. */
3859 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
3861 struct objfile *objfile = cu->objfile;
3863 struct attribute *attr;
3864 int encoding = 0, size = 0;
3866 /* If we've already decoded this die, this is a no-op. */
3872 attr = dwarf2_attr (die, DW_AT_encoding, cu);
3875 encoding = DW_UNSND (attr);
3877 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3880 size = DW_UNSND (attr);
3882 attr = dwarf2_attr (die, DW_AT_name, cu);
3883 if (attr && DW_STRING (attr))
3885 enum type_code code = TYPE_CODE_INT;
3890 case DW_ATE_address:
3891 /* Turn DW_ATE_address into a void * pointer. */
3892 code = TYPE_CODE_PTR;
3893 type_flags |= TYPE_FLAG_UNSIGNED;
3895 case DW_ATE_boolean:
3896 code = TYPE_CODE_BOOL;
3897 type_flags |= TYPE_FLAG_UNSIGNED;
3899 case DW_ATE_complex_float:
3900 code = TYPE_CODE_COMPLEX;
3903 code = TYPE_CODE_FLT;
3906 case DW_ATE_signed_char:
3908 case DW_ATE_unsigned:
3909 case DW_ATE_unsigned_char:
3910 type_flags |= TYPE_FLAG_UNSIGNED;
3913 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
3914 dwarf_type_encoding_name (encoding));
3917 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
3918 if (encoding == DW_ATE_address)
3919 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
3921 else if (encoding == DW_ATE_complex_float)
3924 TYPE_TARGET_TYPE (type)
3925 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
3926 else if (size == 16)
3927 TYPE_TARGET_TYPE (type)
3928 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
3930 TYPE_TARGET_TYPE (type)
3931 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
3936 type = dwarf_base_type (encoding, size, cu);
3941 /* Read the given DW_AT_subrange DIE. */
3944 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
3946 struct type *base_type;
3947 struct type *range_type;
3948 struct attribute *attr;
3952 /* If we have already decoded this die, then nothing more to do. */
3956 base_type = die_type (die, cu);
3957 if (base_type == NULL)
3959 complaint (&symfile_complaints,
3960 "DW_AT_type missing from DW_TAG_subrange_type");
3964 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
3965 base_type = alloc_type (NULL);
3967 if (cu->language == language_fortran)
3969 /* FORTRAN implies a lower bound of 1, if not given. */
3973 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
3975 low = dwarf2_get_attr_constant_value (attr, 0);
3977 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
3980 if (attr->form == DW_FORM_block1)
3982 /* GCC encodes arrays with unspecified or dynamic length
3983 with a DW_FORM_block1 attribute.
3984 FIXME: GDB does not yet know how to handle dynamic
3985 arrays properly, treat them as arrays with unspecified
3988 FIXME: jimb/2003-09-22: GDB does not really know
3989 how to handle arrays of unspecified length
3990 either; we just represent them as zero-length
3991 arrays. Choose an appropriate upper bound given
3992 the lower bound we've computed above. */
3996 high = dwarf2_get_attr_constant_value (attr, 1);
3999 range_type = create_range_type (NULL, base_type, low, high);
4001 attr = dwarf2_attr (die, DW_AT_name, cu);
4002 if (attr && DW_STRING (attr))
4003 TYPE_NAME (range_type) = DW_STRING (attr);
4005 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4007 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4009 die->type = range_type;
4013 /* Read a whole compilation unit into a linked list of dies. */
4015 static struct die_info *
4016 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4018 /* Reset die reference table; we are
4019 building new ones now. */
4020 dwarf2_empty_hash_tables ();
4022 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4025 /* Read a single die and all its descendents. Set the die's sibling
4026 field to NULL; set other fields in the die correctly, and set all
4027 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4028 location of the info_ptr after reading all of those dies. PARENT
4029 is the parent of the die in question. */
4031 static struct die_info *
4032 read_die_and_children (char *info_ptr, bfd *abfd,
4033 struct dwarf2_cu *cu,
4034 char **new_info_ptr,
4035 struct die_info *parent)
4037 struct die_info *die;
4041 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4042 store_in_ref_table (die->offset, die);
4046 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4052 *new_info_ptr = cur_ptr;
4055 die->sibling = NULL;
4056 die->parent = parent;
4060 /* Read a die, all of its descendents, and all of its siblings; set
4061 all of the fields of all of the dies correctly. Arguments are as
4062 in read_die_and_children. */
4064 static struct die_info *
4065 read_die_and_siblings (char *info_ptr, bfd *abfd,
4066 struct dwarf2_cu *cu,
4067 char **new_info_ptr,
4068 struct die_info *parent)
4070 struct die_info *first_die, *last_sibling;
4074 first_die = last_sibling = NULL;
4078 struct die_info *die
4079 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4087 last_sibling->sibling = die;
4092 *new_info_ptr = cur_ptr;
4102 /* Free a linked list of dies. */
4105 free_die_list (struct die_info *dies)
4107 struct die_info *die, *next;
4112 if (die->child != NULL)
4113 free_die_list (die->child);
4114 next = die->sibling;
4122 do_free_die_list_cleanup (void *dies)
4124 free_die_list (dies);
4127 static struct cleanup *
4128 make_cleanup_free_die_list (struct die_info *dies)
4130 return make_cleanup (do_free_die_list_cleanup, dies);
4134 /* Read the contents of the section at OFFSET and of size SIZE from the
4135 object file specified by OBJFILE into the psymbol_obstack and return it. */
4138 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4140 bfd *abfd = objfile->obfd;
4142 bfd_size_type size = bfd_get_section_size_before_reloc (sectp);
4147 buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
4149 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4153 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4154 || bfd_bread (buf, size, abfd) != size)
4155 error ("Dwarf Error: Can't read DWARF data from '%s'",
4156 bfd_get_filename (abfd));
4161 /* In DWARF version 2, the description of the debugging information is
4162 stored in a separate .debug_abbrev section. Before we read any
4163 dies from a section we read in all abbreviations and install them
4167 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4169 struct comp_unit_head *cu_header = &cu->header;
4171 struct abbrev_info *cur_abbrev;
4172 unsigned int abbrev_number, bytes_read, abbrev_name;
4173 unsigned int abbrev_form, hash_number;
4175 /* Initialize dwarf2 abbrevs */
4176 memset (cu_header->dwarf2_abbrevs, 0,
4177 ABBREV_HASH_SIZE*sizeof (struct abbrev_info *));
4179 abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset;
4180 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4181 abbrev_ptr += bytes_read;
4183 /* loop until we reach an abbrev number of 0 */
4184 while (abbrev_number)
4186 cur_abbrev = dwarf_alloc_abbrev ();
4188 /* read in abbrev header */
4189 cur_abbrev->number = abbrev_number;
4190 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4191 abbrev_ptr += bytes_read;
4192 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4195 /* now read in declarations */
4196 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4197 abbrev_ptr += bytes_read;
4198 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4199 abbrev_ptr += bytes_read;
4202 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
4204 cur_abbrev->attrs = (struct attr_abbrev *)
4205 xrealloc (cur_abbrev->attrs,
4206 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
4207 * sizeof (struct attr_abbrev));
4209 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
4210 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4211 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4212 abbrev_ptr += bytes_read;
4213 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4214 abbrev_ptr += bytes_read;
4217 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4218 cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number];
4219 cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev;
4221 /* Get next abbreviation.
4222 Under Irix6 the abbreviations for a compilation unit are not
4223 always properly terminated with an abbrev number of 0.
4224 Exit loop if we encounter an abbreviation which we have
4225 already read (which means we are about to read the abbreviations
4226 for the next compile unit) or if the end of the abbreviation
4227 table is reached. */
4228 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
4229 >= dwarf_abbrev_size)
4231 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4232 abbrev_ptr += bytes_read;
4233 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4238 /* Empty the abbrev table for a new compilation unit. */
4241 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table)
4244 struct abbrev_info *abbrev, *next;
4245 struct abbrev_info **abbrevs;
4247 abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table;
4249 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
4252 abbrev = abbrevs[i];
4255 next = abbrev->next;
4256 xfree (abbrev->attrs);
4264 /* Lookup an abbrev_info structure in the abbrev hash table. */
4266 static struct abbrev_info *
4267 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4269 struct comp_unit_head *cu_header = &cu->header;
4270 unsigned int hash_number;
4271 struct abbrev_info *abbrev;
4273 hash_number = number % ABBREV_HASH_SIZE;
4274 abbrev = cu_header->dwarf2_abbrevs[hash_number];
4278 if (abbrev->number == number)
4281 abbrev = abbrev->next;
4286 /* Read a minimal amount of information into the minimal die structure. */
4289 read_partial_die (struct partial_die_info *part_die, bfd *abfd,
4290 char *info_ptr, struct dwarf2_cu *cu)
4292 unsigned int abbrev_number, bytes_read, i;
4293 struct abbrev_info *abbrev;
4294 struct attribute attr;
4295 struct attribute spec_attr;
4296 int found_spec_attr = 0;
4297 int has_low_pc_attr = 0;
4298 int has_high_pc_attr = 0;
4300 *part_die = zeroed_partial_die;
4301 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4302 info_ptr += bytes_read;
4306 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4309 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
4310 bfd_get_filename (abfd));
4312 part_die->offset = info_ptr - dwarf_info_buffer;
4313 part_die->tag = abbrev->tag;
4314 part_die->has_children = abbrev->has_children;
4315 part_die->abbrev = abbrev_number;
4317 for (i = 0; i < abbrev->num_attrs; ++i)
4319 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4321 /* Store the data if it is of an attribute we want to keep in a
4322 partial symbol table. */
4327 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4328 if (part_die->name == NULL)
4329 part_die->name = DW_STRING (&attr);
4331 case DW_AT_MIPS_linkage_name:
4332 part_die->name = DW_STRING (&attr);
4335 has_low_pc_attr = 1;
4336 part_die->lowpc = DW_ADDR (&attr);
4339 has_high_pc_attr = 1;
4340 part_die->highpc = DW_ADDR (&attr);
4342 case DW_AT_location:
4343 /* Support the .debug_loc offsets */
4344 if (attr_form_is_block (&attr))
4346 part_die->locdesc = DW_BLOCK (&attr);
4348 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4350 dwarf2_complex_location_expr_complaint ();
4354 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4355 "partial symbol information");
4358 case DW_AT_language:
4359 part_die->language = DW_UNSND (&attr);
4361 case DW_AT_external:
4362 part_die->is_external = DW_UNSND (&attr);
4364 case DW_AT_declaration:
4365 part_die->is_declaration = DW_UNSND (&attr);
4368 part_die->has_type = 1;
4370 case DW_AT_abstract_origin:
4371 case DW_AT_specification:
4372 found_spec_attr = 1;
4376 /* Ignore absolute siblings, they might point outside of
4377 the current compile unit. */
4378 if (attr.form == DW_FORM_ref_addr)
4379 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
4382 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr, cu);
4389 /* If we found a reference attribute and the die has no name, try
4390 to find a name in the referred to die. */
4392 if (found_spec_attr && part_die->name == NULL)
4394 struct partial_die_info spec_die;
4397 spec_ptr = dwarf_info_buffer
4398 + dwarf2_get_ref_die_offset (&spec_attr, cu);
4399 read_partial_die (&spec_die, abfd, spec_ptr, cu);
4402 part_die->name = spec_die.name;
4404 /* Copy DW_AT_external attribute if it is set. */
4405 if (spec_die.is_external)
4406 part_die->is_external = spec_die.is_external;
4410 /* When using the GNU linker, .gnu.linkonce. sections are used to
4411 eliminate duplicate copies of functions and vtables and such.
4412 The linker will arbitrarily choose one and discard the others.
4413 The AT_*_pc values for such functions refer to local labels in
4414 these sections. If the section from that file was discarded, the
4415 labels are not in the output, so the relocs get a value of 0.
4416 If this is a discarded function, mark the pc bounds as invalid,
4417 so that GDB will ignore it. */
4418 if (has_low_pc_attr && has_high_pc_attr
4419 && part_die->lowpc < part_die->highpc
4420 && (part_die->lowpc != 0
4421 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
4422 part_die->has_pc_info = 1;
4426 /* Read the die from the .debug_info section buffer. Set DIEP to
4427 point to a newly allocated die with its information, except for its
4428 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4429 whether the die has children or not. */
4432 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
4433 struct dwarf2_cu *cu, int *has_children)
4435 unsigned int abbrev_number, bytes_read, i, offset;
4436 struct abbrev_info *abbrev;
4437 struct die_info *die;
4439 offset = info_ptr - dwarf_info_buffer;
4440 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4441 info_ptr += bytes_read;
4444 die = dwarf_alloc_die ();
4446 die->abbrev = abbrev_number;
4453 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4456 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4458 bfd_get_filename (abfd));
4460 die = dwarf_alloc_die ();
4461 die->offset = offset;
4462 die->tag = abbrev->tag;
4463 die->abbrev = abbrev_number;
4466 die->num_attrs = abbrev->num_attrs;
4467 die->attrs = (struct attribute *)
4468 xmalloc (die->num_attrs * sizeof (struct attribute));
4470 for (i = 0; i < abbrev->num_attrs; ++i)
4472 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
4473 abfd, info_ptr, cu);
4477 *has_children = abbrev->has_children;
4481 /* Read an attribute value described by an attribute form. */
4484 read_attribute_value (struct attribute *attr, unsigned form,
4485 bfd *abfd, char *info_ptr,
4486 struct dwarf2_cu *cu)
4488 struct comp_unit_head *cu_header = &cu->header;
4489 unsigned int bytes_read;
4490 struct dwarf_block *blk;
4496 case DW_FORM_ref_addr:
4497 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
4498 info_ptr += bytes_read;
4500 case DW_FORM_block2:
4501 blk = dwarf_alloc_block ();
4502 blk->size = read_2_bytes (abfd, info_ptr);
4504 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4505 info_ptr += blk->size;
4506 DW_BLOCK (attr) = blk;
4508 case DW_FORM_block4:
4509 blk = dwarf_alloc_block ();
4510 blk->size = read_4_bytes (abfd, info_ptr);
4512 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4513 info_ptr += blk->size;
4514 DW_BLOCK (attr) = blk;
4517 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4521 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4525 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4528 case DW_FORM_string:
4529 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
4530 info_ptr += bytes_read;
4533 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
4535 info_ptr += bytes_read;
4538 blk = dwarf_alloc_block ();
4539 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4540 info_ptr += bytes_read;
4541 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4542 info_ptr += blk->size;
4543 DW_BLOCK (attr) = blk;
4545 case DW_FORM_block1:
4546 blk = dwarf_alloc_block ();
4547 blk->size = read_1_byte (abfd, info_ptr);
4549 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4550 info_ptr += blk->size;
4551 DW_BLOCK (attr) = blk;
4554 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4558 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4562 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
4563 info_ptr += bytes_read;
4566 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4567 info_ptr += bytes_read;
4570 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4574 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4578 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4582 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4585 case DW_FORM_ref_udata:
4586 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4587 info_ptr += bytes_read;
4589 case DW_FORM_indirect:
4590 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4591 info_ptr += bytes_read;
4592 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
4595 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4596 dwarf_form_name (form),
4597 bfd_get_filename (abfd));
4602 /* Read an attribute described by an abbreviated attribute. */
4605 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
4606 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
4608 attr->name = abbrev->name;
4609 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
4612 /* read dwarf information from a buffer */
4615 read_1_byte (bfd *abfd, char *buf)
4617 return bfd_get_8 (abfd, (bfd_byte *) buf);
4621 read_1_signed_byte (bfd *abfd, char *buf)
4623 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
4627 read_2_bytes (bfd *abfd, char *buf)
4629 return bfd_get_16 (abfd, (bfd_byte *) buf);
4633 read_2_signed_bytes (bfd *abfd, char *buf)
4635 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4639 read_4_bytes (bfd *abfd, char *buf)
4641 return bfd_get_32 (abfd, (bfd_byte *) buf);
4645 read_4_signed_bytes (bfd *abfd, char *buf)
4647 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4650 static unsigned long
4651 read_8_bytes (bfd *abfd, char *buf)
4653 return bfd_get_64 (abfd, (bfd_byte *) buf);
4657 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
4659 struct comp_unit_head *cu_header = &cu->header;
4660 CORE_ADDR retval = 0;
4662 if (cu_header->signed_addr_p)
4664 switch (cu_header->addr_size)
4667 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4670 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4673 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
4676 internal_error (__FILE__, __LINE__,
4677 "read_address: bad switch, signed [in module %s]",
4678 bfd_get_filename (abfd));
4683 switch (cu_header->addr_size)
4686 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
4689 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4692 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4695 internal_error (__FILE__, __LINE__,
4696 "read_address: bad switch, unsigned [in module %s]",
4697 bfd_get_filename (abfd));
4701 *bytes_read = cu_header->addr_size;
4705 /* Read the initial length from a section. The (draft) DWARF 3
4706 specification allows the initial length to take up either 4 bytes
4707 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4708 bytes describe the length and all offsets will be 8 bytes in length
4711 An older, non-standard 64-bit format is also handled by this
4712 function. The older format in question stores the initial length
4713 as an 8-byte quantity without an escape value. Lengths greater
4714 than 2^32 aren't very common which means that the initial 4 bytes
4715 is almost always zero. Since a length value of zero doesn't make
4716 sense for the 32-bit format, this initial zero can be considered to
4717 be an escape value which indicates the presence of the older 64-bit
4718 format. As written, the code can't detect (old format) lengths
4719 greater than 4GB. If it becomes necessary to handle lengths somewhat
4720 larger than 4GB, we could allow other small values (such as the
4721 non-sensical values of 1, 2, and 3) to also be used as escape values
4722 indicating the presence of the old format.
4724 The value returned via bytes_read should be used to increment
4725 the relevant pointer after calling read_initial_length().
4727 As a side effect, this function sets the fields initial_length_size
4728 and offset_size in cu_header to the values appropriate for the
4729 length field. (The format of the initial length field determines
4730 the width of file offsets to be fetched later with fetch_offset().)
4732 [ Note: read_initial_length() and read_offset() are based on the
4733 document entitled "DWARF Debugging Information Format", revision
4734 3, draft 8, dated November 19, 2001. This document was obtained
4737 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4739 This document is only a draft and is subject to change. (So beware.)
4741 Details regarding the older, non-standard 64-bit format were
4742 determined empirically by examining 64-bit ELF files produced
4743 by the SGI toolchain on an IRIX 6.5 machine.
4745 - Kevin, July 16, 2002
4749 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
4754 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4756 if (retval == 0xffffffff)
4758 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
4760 if (cu_header != NULL)
4762 cu_header->initial_length_size = 12;
4763 cu_header->offset_size = 8;
4766 else if (retval == 0)
4768 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4770 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4772 if (cu_header != NULL)
4774 cu_header->initial_length_size = 8;
4775 cu_header->offset_size = 8;
4781 if (cu_header != NULL)
4783 cu_header->initial_length_size = 4;
4784 cu_header->offset_size = 4;
4791 /* Read an offset from the data stream. The size of the offset is
4792 given by cu_header->offset_size. */
4795 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
4800 switch (cu_header->offset_size)
4803 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4807 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4811 internal_error (__FILE__, __LINE__,
4812 "read_offset: bad switch [in module %s]",
4813 bfd_get_filename (abfd));
4820 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
4822 /* If the size of a host char is 8 bits, we can return a pointer
4823 to the buffer, otherwise we have to copy the data to a buffer
4824 allocated on the temporary obstack. */
4825 gdb_assert (HOST_CHAR_BIT == 8);
4830 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4832 /* If the size of a host char is 8 bits, we can return a pointer
4833 to the string, otherwise we have to copy the string to a buffer
4834 allocated on the temporary obstack. */
4835 gdb_assert (HOST_CHAR_BIT == 8);
4838 *bytes_read_ptr = 1;
4841 *bytes_read_ptr = strlen (buf) + 1;
4846 read_indirect_string (bfd *abfd, char *buf,
4847 const struct comp_unit_head *cu_header,
4848 unsigned int *bytes_read_ptr)
4850 LONGEST str_offset = read_offset (abfd, buf, cu_header,
4851 (int *) bytes_read_ptr);
4853 if (dwarf_str_buffer == NULL)
4855 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4856 bfd_get_filename (abfd));
4859 if (str_offset >= dwarf_str_size)
4861 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4862 bfd_get_filename (abfd));
4865 gdb_assert (HOST_CHAR_BIT == 8);
4866 if (dwarf_str_buffer[str_offset] == '\0')
4868 return dwarf_str_buffer + str_offset;
4871 static unsigned long
4872 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4874 unsigned long result;
4875 unsigned int num_read;
4885 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4888 result |= ((unsigned long)(byte & 127) << shift);
4889 if ((byte & 128) == 0)
4895 *bytes_read_ptr = num_read;
4900 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4903 int i, shift, size, num_read;
4913 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4916 result |= ((long)(byte & 127) << shift);
4918 if ((byte & 128) == 0)
4923 if ((shift < size) && (byte & 0x40))
4925 result |= -(1 << shift);
4927 *bytes_read_ptr = num_read;
4932 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
4938 cu->language = language_c;
4940 case DW_LANG_C_plus_plus:
4941 cu->language = language_cplus;
4943 case DW_LANG_Fortran77:
4944 case DW_LANG_Fortran90:
4945 case DW_LANG_Fortran95:
4946 cu->language = language_fortran;
4948 case DW_LANG_Mips_Assembler:
4949 cu->language = language_asm;
4952 cu->language = language_java;
4956 case DW_LANG_Cobol74:
4957 case DW_LANG_Cobol85:
4958 case DW_LANG_Pascal83:
4959 case DW_LANG_Modula2:
4961 cu->language = language_minimal;
4964 cu->language_defn = language_def (cu->language);
4967 /* Return the named attribute or NULL if not there. */
4969 static struct attribute *
4970 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
4973 struct attribute *spec = NULL;
4975 for (i = 0; i < die->num_attrs; ++i)
4977 if (die->attrs[i].name == name)
4979 return &die->attrs[i];
4981 if (die->attrs[i].name == DW_AT_specification
4982 || die->attrs[i].name == DW_AT_abstract_origin)
4983 spec = &die->attrs[i];
4987 struct die_info *ref_die =
4988 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
4991 return dwarf2_attr (ref_die, name, cu);
4998 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5000 return (dwarf2_attr (die, DW_AT_declaration, cu)
5001 && ! dwarf2_attr (die, DW_AT_specification, cu));
5004 /* Return the die giving the specification for DIE, if there is
5007 static struct die_info *
5008 die_specification (struct die_info *die, struct dwarf2_cu *cu)
5010 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
5012 if (spec_attr == NULL)
5015 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
5018 /* Free the line_header structure *LH, and any arrays and strings it
5021 free_line_header (struct line_header *lh)
5023 if (lh->standard_opcode_lengths)
5024 xfree (lh->standard_opcode_lengths);
5026 /* Remember that all the lh->file_names[i].name pointers are
5027 pointers into debug_line_buffer, and don't need to be freed. */
5029 xfree (lh->file_names);
5031 /* Similarly for the include directory names. */
5032 if (lh->include_dirs)
5033 xfree (lh->include_dirs);
5039 /* Add an entry to LH's include directory table. */
5041 add_include_dir (struct line_header *lh, char *include_dir)
5043 /* Grow the array if necessary. */
5044 if (lh->include_dirs_size == 0)
5046 lh->include_dirs_size = 1; /* for testing */
5047 lh->include_dirs = xmalloc (lh->include_dirs_size
5048 * sizeof (*lh->include_dirs));
5050 else if (lh->num_include_dirs >= lh->include_dirs_size)
5052 lh->include_dirs_size *= 2;
5053 lh->include_dirs = xrealloc (lh->include_dirs,
5054 (lh->include_dirs_size
5055 * sizeof (*lh->include_dirs)));
5058 lh->include_dirs[lh->num_include_dirs++] = include_dir;
5062 /* Add an entry to LH's file name table. */
5064 add_file_name (struct line_header *lh,
5066 unsigned int dir_index,
5067 unsigned int mod_time,
5068 unsigned int length)
5070 struct file_entry *fe;
5072 /* Grow the array if necessary. */
5073 if (lh->file_names_size == 0)
5075 lh->file_names_size = 1; /* for testing */
5076 lh->file_names = xmalloc (lh->file_names_size
5077 * sizeof (*lh->file_names));
5079 else if (lh->num_file_names >= lh->file_names_size)
5081 lh->file_names_size *= 2;
5082 lh->file_names = xrealloc (lh->file_names,
5083 (lh->file_names_size
5084 * sizeof (*lh->file_names)));
5087 fe = &lh->file_names[lh->num_file_names++];
5089 fe->dir_index = dir_index;
5090 fe->mod_time = mod_time;
5091 fe->length = length;
5095 /* Read the statement program header starting at OFFSET in
5096 dwarf_line_buffer, according to the endianness of ABFD. Return a
5097 pointer to a struct line_header, allocated using xmalloc.
5099 NOTE: the strings in the include directory and file name tables of
5100 the returned object point into debug_line_buffer, and must not be
5102 static struct line_header *
5103 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5104 struct dwarf2_cu *cu)
5106 struct cleanup *back_to;
5107 struct line_header *lh;
5111 char *cur_dir, *cur_file;
5113 if (dwarf_line_buffer == NULL)
5115 complaint (&symfile_complaints, "missing .debug_line section");
5119 /* Make sure that at least there's room for the total_length field. That
5120 could be 12 bytes long, but we're just going to fudge that. */
5121 if (offset + 4 >= dwarf_line_size)
5123 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5127 lh = xmalloc (sizeof (*lh));
5128 memset (lh, 0, sizeof (*lh));
5129 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5132 line_ptr = dwarf_line_buffer + offset;
5134 /* read in the header */
5135 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
5136 line_ptr += bytes_read;
5137 if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size)
5139 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5142 lh->statement_program_end = line_ptr + lh->total_length;
5143 lh->version = read_2_bytes (abfd, line_ptr);
5145 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5146 line_ptr += bytes_read;
5147 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5149 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5151 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5153 lh->line_range = read_1_byte (abfd, line_ptr);
5155 lh->opcode_base = read_1_byte (abfd, line_ptr);
5157 lh->standard_opcode_lengths
5158 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5160 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5161 for (i = 1; i < lh->opcode_base; ++i)
5163 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5167 /* Read directory table */
5168 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5170 line_ptr += bytes_read;
5171 add_include_dir (lh, cur_dir);
5173 line_ptr += bytes_read;
5175 /* Read file name table */
5176 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5178 unsigned int dir_index, mod_time, length;
5180 line_ptr += bytes_read;
5181 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5182 line_ptr += bytes_read;
5183 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5184 line_ptr += bytes_read;
5185 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5186 line_ptr += bytes_read;
5188 add_file_name (lh, cur_file, dir_index, mod_time, length);
5190 line_ptr += bytes_read;
5191 lh->statement_program_start = line_ptr;
5193 if (line_ptr > dwarf_line_buffer + dwarf_line_size)
5194 complaint (&symfile_complaints,
5195 "line number info header doesn't fit in `.debug_line' section");
5197 discard_cleanups (back_to);
5201 /* This function exists to work around a bug in certain compilers
5202 (particularly GCC 2.95), in which the first line number marker of a
5203 function does not show up until after the prologue, right before
5204 the second line number marker. This function shifts ADDRESS down
5205 to the beginning of the function if necessary, and is called on
5206 addresses passed to record_line. */
5209 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
5211 struct function_range *fn;
5213 /* Find the function_range containing address. */
5218 cu->cached_fn = cu->first_fn;
5222 if (fn->lowpc <= address && fn->highpc > address)
5228 while (fn && fn != cu->cached_fn)
5229 if (fn->lowpc <= address && fn->highpc > address)
5239 if (address != fn->lowpc)
5240 complaint (&symfile_complaints,
5241 "misplaced first line number at 0x%lx for '%s'",
5242 (unsigned long) address, fn->name);
5247 /* Decode the line number information for the compilation unit whose
5248 line number info is at OFFSET in the .debug_line section.
5249 The compilation directory of the file is passed in COMP_DIR. */
5252 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5253 struct dwarf2_cu *cu)
5257 unsigned int bytes_read;
5258 unsigned char op_code, extended_op, adj_opcode;
5260 struct objfile *objfile = cu->objfile;
5262 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5264 line_ptr = lh->statement_program_start;
5265 line_end = lh->statement_program_end;
5267 /* Read the statement sequences until there's nothing left. */
5268 while (line_ptr < line_end)
5270 /* state machine registers */
5271 CORE_ADDR address = 0;
5272 unsigned int file = 1;
5273 unsigned int line = 1;
5274 unsigned int column = 0;
5275 int is_stmt = lh->default_is_stmt;
5276 int basic_block = 0;
5277 int end_sequence = 0;
5279 /* Start a subfile for the current file of the state machine. */
5280 if (lh->num_file_names >= file)
5282 /* lh->include_dirs and lh->file_names are 0-based, but the
5283 directory and file name numbers in the statement program
5285 struct file_entry *fe = &lh->file_names[file - 1];
5288 dir = lh->include_dirs[fe->dir_index - 1];
5291 dwarf2_start_subfile (fe->name, dir);
5294 /* Decode the table. */
5295 while (!end_sequence)
5297 op_code = read_1_byte (abfd, line_ptr);
5300 if (op_code >= lh->opcode_base)
5301 { /* Special operand. */
5302 adj_opcode = op_code - lh->opcode_base;
5303 address += (adj_opcode / lh->line_range)
5304 * lh->minimum_instruction_length;
5305 line += lh->line_base + (adj_opcode % lh->line_range);
5306 /* append row to matrix using current values */
5307 record_line (current_subfile, line,
5308 check_cu_functions (address, cu));
5311 else switch (op_code)
5313 case DW_LNS_extended_op:
5314 line_ptr += 1; /* ignore length */
5315 extended_op = read_1_byte (abfd, line_ptr);
5317 switch (extended_op)
5319 case DW_LNE_end_sequence:
5321 record_line (current_subfile, 0, address);
5323 case DW_LNE_set_address:
5324 address = read_address (abfd, line_ptr, cu, &bytes_read);
5325 line_ptr += bytes_read;
5326 address += baseaddr;
5328 case DW_LNE_define_file:
5331 unsigned int dir_index, mod_time, length;
5333 cur_file = read_string (abfd, line_ptr, &bytes_read);
5334 line_ptr += bytes_read;
5336 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5337 line_ptr += bytes_read;
5339 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5340 line_ptr += bytes_read;
5342 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5343 line_ptr += bytes_read;
5344 add_file_name (lh, cur_file, dir_index, mod_time, length);
5348 complaint (&symfile_complaints,
5349 "mangled .debug_line section");
5354 record_line (current_subfile, line,
5355 check_cu_functions (address, cu));
5358 case DW_LNS_advance_pc:
5359 address += lh->minimum_instruction_length
5360 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5361 line_ptr += bytes_read;
5363 case DW_LNS_advance_line:
5364 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
5365 line_ptr += bytes_read;
5367 case DW_LNS_set_file:
5369 /* lh->include_dirs and lh->file_names are 0-based,
5370 but the directory and file name numbers in the
5371 statement program are 1-based. */
5372 struct file_entry *fe;
5374 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5375 line_ptr += bytes_read;
5376 fe = &lh->file_names[file - 1];
5378 dir = lh->include_dirs[fe->dir_index - 1];
5381 dwarf2_start_subfile (fe->name, dir);
5384 case DW_LNS_set_column:
5385 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5386 line_ptr += bytes_read;
5388 case DW_LNS_negate_stmt:
5389 is_stmt = (!is_stmt);
5391 case DW_LNS_set_basic_block:
5394 /* Add to the address register of the state machine the
5395 address increment value corresponding to special opcode
5396 255. Ie, this value is scaled by the minimum instruction
5397 length since special opcode 255 would have scaled the
5399 case DW_LNS_const_add_pc:
5400 address += (lh->minimum_instruction_length
5401 * ((255 - lh->opcode_base) / lh->line_range));
5403 case DW_LNS_fixed_advance_pc:
5404 address += read_2_bytes (abfd, line_ptr);
5408 { /* Unknown standard opcode, ignore it. */
5410 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
5412 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5413 line_ptr += bytes_read;
5421 /* Start a subfile for DWARF. FILENAME is the name of the file and
5422 DIRNAME the name of the source directory which contains FILENAME
5423 or NULL if not known.
5424 This routine tries to keep line numbers from identical absolute and
5425 relative file names in a common subfile.
5427 Using the `list' example from the GDB testsuite, which resides in
5428 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5429 of /srcdir/list0.c yields the following debugging information for list0.c:
5431 DW_AT_name: /srcdir/list0.c
5432 DW_AT_comp_dir: /compdir
5433 files.files[0].name: list0.h
5434 files.files[0].dir: /srcdir
5435 files.files[1].name: list0.c
5436 files.files[1].dir: /srcdir
5438 The line number information for list0.c has to end up in a single
5439 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5442 dwarf2_start_subfile (char *filename, char *dirname)
5444 /* If the filename isn't absolute, try to match an existing subfile
5445 with the full pathname. */
5447 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
5449 struct subfile *subfile;
5450 char *fullname = concat (dirname, "/", filename, NULL);
5452 for (subfile = subfiles; subfile; subfile = subfile->next)
5454 if (FILENAME_CMP (subfile->name, fullname) == 0)
5456 current_subfile = subfile;
5463 start_subfile (filename, dirname);
5467 var_decode_location (struct attribute *attr, struct symbol *sym,
5468 struct dwarf2_cu *cu)
5470 struct objfile *objfile = cu->objfile;
5471 struct comp_unit_head *cu_header = &cu->header;
5473 /* NOTE drow/2003-01-30: There used to be a comment and some special
5474 code here to turn a symbol with DW_AT_external and a
5475 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5476 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5477 with some versions of binutils) where shared libraries could have
5478 relocations against symbols in their debug information - the
5479 minimal symbol would have the right address, but the debug info
5480 would not. It's no longer necessary, because we will explicitly
5481 apply relocations when we read in the debug information now. */
5483 /* A DW_AT_location attribute with no contents indicates that a
5484 variable has been optimized away. */
5485 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
5487 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
5491 /* Handle one degenerate form of location expression specially, to
5492 preserve GDB's previous behavior when section offsets are
5493 specified. If this is just a DW_OP_addr then mark this symbol
5496 if (attr_form_is_block (attr)
5497 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
5498 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
5502 SYMBOL_VALUE_ADDRESS (sym) =
5503 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
5504 fixup_symbol_section (sym, objfile);
5505 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
5506 SYMBOL_SECTION (sym));
5507 SYMBOL_CLASS (sym) = LOC_STATIC;
5511 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5512 expression evaluator, and use LOC_COMPUTED only when necessary
5513 (i.e. when the value of a register or memory location is
5514 referenced, or a thread-local block, etc.). Then again, it might
5515 not be worthwhile. I'm assuming that it isn't unless performance
5516 or memory numbers show me otherwise. */
5518 dwarf2_symbol_mark_computed (attr, sym, cu);
5519 SYMBOL_CLASS (sym) = LOC_COMPUTED;
5522 /* Given a pointer to a DWARF information entry, figure out if we need
5523 to make a symbol table entry for it, and if so, create a new entry
5524 and return a pointer to it.
5525 If TYPE is NULL, determine symbol type from the die, otherwise
5526 used the passed type. */
5528 static struct symbol *
5529 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5531 struct objfile *objfile = cu->objfile;
5532 struct symbol *sym = NULL;
5534 struct attribute *attr = NULL;
5535 struct attribute *attr2 = NULL;
5538 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5540 if (die->tag != DW_TAG_namespace)
5541 name = dwarf2_linkage_name (die, cu);
5543 name = TYPE_NAME (type);
5547 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
5548 sizeof (struct symbol));
5549 OBJSTAT (objfile, n_syms++);
5550 memset (sym, 0, sizeof (struct symbol));
5552 /* Cache this symbol's name and the name's demangled form (if any). */
5553 SYMBOL_LANGUAGE (sym) = cu->language;
5554 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
5556 /* Default assumptions.
5557 Use the passed type or decode it from the die. */
5558 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5559 SYMBOL_CLASS (sym) = LOC_STATIC;
5561 SYMBOL_TYPE (sym) = type;
5563 SYMBOL_TYPE (sym) = die_type (die, cu);
5564 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
5567 SYMBOL_LINE (sym) = DW_UNSND (attr);
5572 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
5575 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
5577 SYMBOL_CLASS (sym) = LOC_LABEL;
5579 case DW_TAG_subprogram:
5580 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5582 SYMBOL_CLASS (sym) = LOC_BLOCK;
5583 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5584 if (attr2 && (DW_UNSND (attr2) != 0))
5586 add_symbol_to_list (sym, &global_symbols);
5590 add_symbol_to_list (sym, cu->list_in_scope);
5593 case DW_TAG_variable:
5594 /* Compilation with minimal debug info may result in variables
5595 with missing type entries. Change the misleading `void' type
5596 to something sensible. */
5597 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
5598 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
5599 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
5600 "<variable, no debug info>",
5602 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5605 dwarf2_const_value (attr, sym, cu);
5606 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5607 if (attr2 && (DW_UNSND (attr2) != 0))
5608 add_symbol_to_list (sym, &global_symbols);
5610 add_symbol_to_list (sym, cu->list_in_scope);
5613 attr = dwarf2_attr (die, DW_AT_location, cu);
5616 var_decode_location (attr, sym, cu);
5617 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5618 if (attr2 && (DW_UNSND (attr2) != 0))
5619 add_symbol_to_list (sym, &global_symbols);
5621 add_symbol_to_list (sym, cu->list_in_scope);
5625 /* We do not know the address of this symbol.
5626 If it is an external symbol and we have type information
5627 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5628 The address of the variable will then be determined from
5629 the minimal symbol table whenever the variable is
5631 attr2 = dwarf2_attr (die, DW_AT_external, cu);
5632 if (attr2 && (DW_UNSND (attr2) != 0)
5633 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
5635 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
5636 add_symbol_to_list (sym, &global_symbols);
5640 case DW_TAG_formal_parameter:
5641 attr = dwarf2_attr (die, DW_AT_location, cu);
5644 var_decode_location (attr, sym, cu);
5645 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5646 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
5647 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
5649 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5652 dwarf2_const_value (attr, sym, cu);
5654 add_symbol_to_list (sym, cu->list_in_scope);
5656 case DW_TAG_unspecified_parameters:
5657 /* From varargs functions; gdb doesn't seem to have any
5658 interest in this information, so just ignore it for now.
5661 case DW_TAG_class_type:
5662 case DW_TAG_structure_type:
5663 case DW_TAG_union_type:
5664 case DW_TAG_enumeration_type:
5665 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5666 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5668 /* Make sure that the symbol includes appropriate enclosing
5669 classes/namespaces in its name. These are calculated in
5670 read_structure_scope, and the correct name is saved in
5673 if (cu->language == language_cplus)
5675 struct type *type = SYMBOL_TYPE (sym);
5677 if (TYPE_TAG_NAME (type) != NULL)
5679 /* FIXME: carlton/2003-11-10: Should this use
5680 SYMBOL_SET_NAMES instead? (The same problem also
5681 arises a further down in the function.) */
5682 SYMBOL_LINKAGE_NAME (sym)
5683 = obsavestring (TYPE_TAG_NAME (type),
5684 strlen (TYPE_TAG_NAME (type)),
5685 &objfile->symbol_obstack);
5690 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5691 really ever be static objects: otherwise, if you try
5692 to, say, break of a class's method and you're in a file
5693 which doesn't mention that class, it won't work unless
5694 the check for all static symbols in lookup_symbol_aux
5695 saves you. See the OtherFileClass tests in
5696 gdb.c++/namespace.exp. */
5698 struct pending **list_to_add;
5700 list_to_add = (cu->list_in_scope == &file_symbols
5701 && cu->language == language_cplus
5702 ? &global_symbols : cu->list_in_scope);
5704 add_symbol_to_list (sym, list_to_add);
5706 /* The semantics of C++ state that "struct foo { ... }" also
5707 defines a typedef for "foo". Synthesize a typedef symbol so
5708 that "ptype foo" works as expected. */
5709 if (cu->language == language_cplus)
5711 struct symbol *typedef_sym = (struct symbol *)
5712 obstack_alloc (&objfile->symbol_obstack,
5713 sizeof (struct symbol));
5714 *typedef_sym = *sym;
5715 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
5716 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
5717 TYPE_NAME (SYMBOL_TYPE (sym)) =
5718 obsavestring (SYMBOL_NATURAL_NAME (sym),
5719 strlen (SYMBOL_NATURAL_NAME (sym)),
5720 &objfile->objfile_obstack);
5721 add_symbol_to_list (typedef_sym, list_to_add);
5725 case DW_TAG_typedef:
5726 if (processing_has_namespace_info
5727 && processing_current_prefix[0] != '\0')
5729 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->symbol_obstack,
5730 processing_current_prefix,
5734 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5735 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5736 add_symbol_to_list (sym, cu->list_in_scope);
5738 case DW_TAG_base_type:
5739 case DW_TAG_subrange_type:
5740 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5741 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5742 add_symbol_to_list (sym, cu->list_in_scope);
5744 case DW_TAG_enumerator:
5745 if (processing_has_namespace_info
5746 && processing_current_prefix[0] != '\0')
5748 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->symbol_obstack,
5749 processing_current_prefix,
5753 attr = dwarf2_attr (die, DW_AT_const_value, cu);
5756 dwarf2_const_value (attr, sym, cu);
5759 /* NOTE: carlton/2003-11-10: See comment above in the
5760 DW_TAG_class_type, etc. block. */
5762 struct pending **list_to_add;
5764 list_to_add = (cu->list_in_scope == &file_symbols
5765 && cu->language == language_cplus
5766 ? &global_symbols : cu->list_in_scope);
5768 add_symbol_to_list (sym, list_to_add);
5771 case DW_TAG_namespace:
5772 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5773 add_symbol_to_list (sym, &global_symbols);
5776 /* Not a tag we recognize. Hopefully we aren't processing
5777 trash data, but since we must specifically ignore things
5778 we don't recognize, there is nothing else we should do at
5780 complaint (&symfile_complaints, "unsupported tag: '%s'",
5781 dwarf_tag_name (die->tag));
5788 /* Copy constant value from an attribute to a symbol. */
5791 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
5792 struct dwarf2_cu *cu)
5794 struct objfile *objfile = cu->objfile;
5795 struct comp_unit_head *cu_header = &cu->header;
5796 struct dwarf_block *blk;
5801 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
5802 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5803 cu_header->addr_size,
5804 TYPE_LENGTH (SYMBOL_TYPE
5806 SYMBOL_VALUE_BYTES (sym) = (char *)
5807 obstack_alloc (&objfile->symbol_obstack, cu_header->addr_size);
5808 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5809 it's body - store_unsigned_integer. */
5810 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
5812 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5814 case DW_FORM_block1:
5815 case DW_FORM_block2:
5816 case DW_FORM_block4:
5818 blk = DW_BLOCK (attr);
5819 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
5820 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5822 TYPE_LENGTH (SYMBOL_TYPE
5824 SYMBOL_VALUE_BYTES (sym) = (char *)
5825 obstack_alloc (&objfile->symbol_obstack, blk->size);
5826 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
5827 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5830 /* The DW_AT_const_value attributes are supposed to carry the
5831 symbol's value "represented as it would be on the target
5832 architecture." By the time we get here, it's already been
5833 converted to host endianness, so we just need to sign- or
5834 zero-extend it as appropriate. */
5836 dwarf2_const_value_data (attr, sym, 8);
5839 dwarf2_const_value_data (attr, sym, 16);
5842 dwarf2_const_value_data (attr, sym, 32);
5845 dwarf2_const_value_data (attr, sym, 64);
5849 SYMBOL_VALUE (sym) = DW_SND (attr);
5850 SYMBOL_CLASS (sym) = LOC_CONST;
5854 SYMBOL_VALUE (sym) = DW_UNSND (attr);
5855 SYMBOL_CLASS (sym) = LOC_CONST;
5859 complaint (&symfile_complaints,
5860 "unsupported const value attribute form: '%s'",
5861 dwarf_form_name (attr->form));
5862 SYMBOL_VALUE (sym) = 0;
5863 SYMBOL_CLASS (sym) = LOC_CONST;
5869 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5870 or zero-extend it as appropriate for the symbol's type. */
5872 dwarf2_const_value_data (struct attribute *attr,
5876 LONGEST l = DW_UNSND (attr);
5878 if (bits < sizeof (l) * 8)
5880 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
5881 l &= ((LONGEST) 1 << bits) - 1;
5883 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
5886 SYMBOL_VALUE (sym) = l;
5887 SYMBOL_CLASS (sym) = LOC_CONST;
5891 /* Return the type of the die in question using its DW_AT_type attribute. */
5893 static struct type *
5894 die_type (struct die_info *die, struct dwarf2_cu *cu)
5897 struct attribute *type_attr;
5898 struct die_info *type_die;
5901 type_attr = dwarf2_attr (die, DW_AT_type, cu);
5904 /* A missing DW_AT_type represents a void type. */
5905 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
5909 ref = dwarf2_get_ref_die_offset (type_attr, cu);
5910 type_die = follow_die_ref (ref);
5913 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5914 ref, cu->objfile->name);
5918 type = tag_type_to_type (type_die, cu);
5921 dump_die (type_die);
5922 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5928 /* Return the containing type of the die in question using its
5929 DW_AT_containing_type attribute. */
5931 static struct type *
5932 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
5934 struct type *type = NULL;
5935 struct attribute *type_attr;
5936 struct die_info *type_die = NULL;
5939 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
5942 ref = dwarf2_get_ref_die_offset (type_attr, cu);
5943 type_die = follow_die_ref (ref);
5946 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
5950 type = tag_type_to_type (type_die, cu);
5955 dump_die (type_die);
5956 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5963 static struct type *
5964 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
5966 struct die_info *die;
5969 die = follow_die_ref (offset);
5972 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
5975 type = tag_type_to_type (die, cu);
5980 static struct type *
5981 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
5989 read_type_die (die, cu);
5993 error ("Dwarf Error: Cannot find type of die [in module %s]",
6001 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6003 char *prefix = determine_prefix (die, cu);
6004 const char *old_prefix = processing_current_prefix;
6005 struct cleanup *back_to = make_cleanup (xfree, prefix);
6006 processing_current_prefix = prefix;
6010 case DW_TAG_class_type:
6011 case DW_TAG_structure_type:
6012 case DW_TAG_union_type:
6013 read_structure_scope (die, cu);
6015 case DW_TAG_enumeration_type:
6016 read_enumeration (die, cu);
6018 case DW_TAG_subprogram:
6019 case DW_TAG_subroutine_type:
6020 read_subroutine_type (die, cu);
6022 case DW_TAG_array_type:
6023 read_array_type (die, cu);
6025 case DW_TAG_pointer_type:
6026 read_tag_pointer_type (die, cu);
6028 case DW_TAG_ptr_to_member_type:
6029 read_tag_ptr_to_member_type (die, cu);
6031 case DW_TAG_reference_type:
6032 read_tag_reference_type (die, cu);
6034 case DW_TAG_const_type:
6035 read_tag_const_type (die, cu);
6037 case DW_TAG_volatile_type:
6038 read_tag_volatile_type (die, cu);
6040 case DW_TAG_string_type:
6041 read_tag_string_type (die, cu);
6043 case DW_TAG_typedef:
6044 read_typedef (die, cu);
6046 case DW_TAG_subrange_type:
6047 read_subrange_type (die, cu);
6049 case DW_TAG_base_type:
6050 read_base_type (die, cu);
6053 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
6054 dwarf_tag_name (die->tag));
6058 processing_current_prefix = old_prefix;
6059 do_cleanups (back_to);
6062 /* Return the name of the namespace/class that DIE is defined within,
6063 or "" if we can't tell. The caller should xfree the result. */
6065 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6066 therein) for an example of how to use this function to deal with
6067 DW_AT_specification. */
6070 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6072 char *prefix = determine_prefix_aux (die, cu);
6074 return prefix ? prefix : xstrdup ("");
6077 /* Return the name of the namespace/class that DIE is defined
6078 within, or NULL if we can't tell. The caller should xfree the
6082 determine_prefix_aux (struct die_info *die, struct dwarf2_cu *cu)
6084 struct die_info *parent;
6086 if (cu->language != language_cplus)
6089 parent = die->parent;
6093 return (processing_has_namespace_info ? xstrdup ("") : NULL);
6097 char *parent_prefix = determine_prefix_aux (parent, cu);
6100 switch (parent->tag) {
6101 case DW_TAG_namespace:
6105 retval = typename_concat (parent_prefix,
6106 namespace_name (parent, &dummy, cu));
6109 case DW_TAG_class_type:
6110 case DW_TAG_structure_type:
6112 if (parent_prefix != NULL)
6114 const char *parent_name = dwarf2_name (parent, cu);
6116 if (parent_name != NULL)
6117 retval = typename_concat (parent_prefix, dwarf2_name (parent, cu));
6119 /* FIXME: carlton/2003-11-10: I'm not sure what the
6120 best thing to do here is. */
6121 retval = typename_concat (parent_prefix,
6122 "<<anonymous class>>");
6125 retval = class_name (parent, cu);
6129 retval = parent_prefix;
6133 if (retval != parent_prefix)
6134 xfree (parent_prefix);
6139 /* Return a newly-allocated string formed by concatenating PREFIX,
6140 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6141 string, just return a copy of SUFFIX. */
6144 typename_concat (const char *prefix, const char *suffix)
6146 if (prefix == NULL || prefix[0] == '\0')
6147 return xstrdup (suffix);
6150 char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1);
6152 strcpy (retval, prefix);
6153 strcat (retval, "::");
6154 strcat (retval, suffix);
6160 /* Return a newly-allocated string giving the name of the class given
6164 class_name (struct die_info *die, struct dwarf2_cu *cu)
6166 struct die_info *child;
6169 for (child = die->child; child != NULL; child = sibling_die (child))
6171 if (child->tag == DW_TAG_subprogram)
6172 return class_name_from_physname (dwarf2_linkage_name (child, cu));
6175 name = dwarf2_name (die, cu);
6177 return xstrdup (name);
6179 return xstrdup ("");
6182 static struct type *
6183 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6185 struct objfile *objfile = cu->objfile;
6187 /* FIXME - this should not produce a new (struct type *)
6188 every time. It should cache base types. */
6192 case DW_ATE_address:
6193 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
6195 case DW_ATE_boolean:
6196 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
6198 case DW_ATE_complex_float:
6201 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
6205 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
6211 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
6215 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
6222 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6225 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
6229 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6233 case DW_ATE_signed_char:
6234 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6236 case DW_ATE_unsigned:
6240 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6243 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
6247 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
6251 case DW_ATE_unsigned_char:
6252 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
6255 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6262 copy_die (struct die_info *old_die)
6264 struct die_info *new_die;
6267 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
6268 memset (new_die, 0, sizeof (struct die_info));
6270 new_die->tag = old_die->tag;
6271 new_die->has_children = old_die->has_children;
6272 new_die->abbrev = old_die->abbrev;
6273 new_die->offset = old_die->offset;
6274 new_die->type = NULL;
6276 num_attrs = old_die->num_attrs;
6277 new_die->num_attrs = num_attrs;
6278 new_die->attrs = (struct attribute *)
6279 xmalloc (num_attrs * sizeof (struct attribute));
6281 for (i = 0; i < old_die->num_attrs; ++i)
6283 new_die->attrs[i].name = old_die->attrs[i].name;
6284 new_die->attrs[i].form = old_die->attrs[i].form;
6285 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
6288 new_die->next = NULL;
6293 /* Return sibling of die, NULL if no sibling. */
6295 static struct die_info *
6296 sibling_die (struct die_info *die)
6298 return die->sibling;
6301 /* Get linkage name of a die, return NULL if not found. */
6304 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
6306 struct attribute *attr;
6308 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
6309 if (attr && DW_STRING (attr))
6310 return DW_STRING (attr);
6311 attr = dwarf2_attr (die, DW_AT_name, cu);
6312 if (attr && DW_STRING (attr))
6313 return DW_STRING (attr);
6317 /* Get name of a die, return NULL if not found. */
6320 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
6322 struct attribute *attr;
6324 attr = dwarf2_attr (die, DW_AT_name, cu);
6325 if (attr && DW_STRING (attr))
6326 return DW_STRING (attr);
6330 /* Return the die that this die in an extension of, or NULL if there
6333 static struct die_info *
6334 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
6336 struct attribute *attr;
6337 struct die_info *extension_die;
6340 attr = dwarf2_attr (die, DW_AT_extension, cu);
6344 ref = dwarf2_get_ref_die_offset (attr, cu);
6345 extension_die = follow_die_ref (ref);
6348 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
6351 return extension_die;
6354 /* Convert a DIE tag into its string name. */
6357 dwarf_tag_name (unsigned tag)
6361 case DW_TAG_padding:
6362 return "DW_TAG_padding";
6363 case DW_TAG_array_type:
6364 return "DW_TAG_array_type";
6365 case DW_TAG_class_type:
6366 return "DW_TAG_class_type";
6367 case DW_TAG_entry_point:
6368 return "DW_TAG_entry_point";
6369 case DW_TAG_enumeration_type:
6370 return "DW_TAG_enumeration_type";
6371 case DW_TAG_formal_parameter:
6372 return "DW_TAG_formal_parameter";
6373 case DW_TAG_imported_declaration:
6374 return "DW_TAG_imported_declaration";
6376 return "DW_TAG_label";
6377 case DW_TAG_lexical_block:
6378 return "DW_TAG_lexical_block";
6380 return "DW_TAG_member";
6381 case DW_TAG_pointer_type:
6382 return "DW_TAG_pointer_type";
6383 case DW_TAG_reference_type:
6384 return "DW_TAG_reference_type";
6385 case DW_TAG_compile_unit:
6386 return "DW_TAG_compile_unit";
6387 case DW_TAG_string_type:
6388 return "DW_TAG_string_type";
6389 case DW_TAG_structure_type:
6390 return "DW_TAG_structure_type";
6391 case DW_TAG_subroutine_type:
6392 return "DW_TAG_subroutine_type";
6393 case DW_TAG_typedef:
6394 return "DW_TAG_typedef";
6395 case DW_TAG_union_type:
6396 return "DW_TAG_union_type";
6397 case DW_TAG_unspecified_parameters:
6398 return "DW_TAG_unspecified_parameters";
6399 case DW_TAG_variant:
6400 return "DW_TAG_variant";
6401 case DW_TAG_common_block:
6402 return "DW_TAG_common_block";
6403 case DW_TAG_common_inclusion:
6404 return "DW_TAG_common_inclusion";
6405 case DW_TAG_inheritance:
6406 return "DW_TAG_inheritance";
6407 case DW_TAG_inlined_subroutine:
6408 return "DW_TAG_inlined_subroutine";
6410 return "DW_TAG_module";
6411 case DW_TAG_ptr_to_member_type:
6412 return "DW_TAG_ptr_to_member_type";
6413 case DW_TAG_set_type:
6414 return "DW_TAG_set_type";
6415 case DW_TAG_subrange_type:
6416 return "DW_TAG_subrange_type";
6417 case DW_TAG_with_stmt:
6418 return "DW_TAG_with_stmt";
6419 case DW_TAG_access_declaration:
6420 return "DW_TAG_access_declaration";
6421 case DW_TAG_base_type:
6422 return "DW_TAG_base_type";
6423 case DW_TAG_catch_block:
6424 return "DW_TAG_catch_block";
6425 case DW_TAG_const_type:
6426 return "DW_TAG_const_type";
6427 case DW_TAG_constant:
6428 return "DW_TAG_constant";
6429 case DW_TAG_enumerator:
6430 return "DW_TAG_enumerator";
6431 case DW_TAG_file_type:
6432 return "DW_TAG_file_type";
6434 return "DW_TAG_friend";
6435 case DW_TAG_namelist:
6436 return "DW_TAG_namelist";
6437 case DW_TAG_namelist_item:
6438 return "DW_TAG_namelist_item";
6439 case DW_TAG_packed_type:
6440 return "DW_TAG_packed_type";
6441 case DW_TAG_subprogram:
6442 return "DW_TAG_subprogram";
6443 case DW_TAG_template_type_param:
6444 return "DW_TAG_template_type_param";
6445 case DW_TAG_template_value_param:
6446 return "DW_TAG_template_value_param";
6447 case DW_TAG_thrown_type:
6448 return "DW_TAG_thrown_type";
6449 case DW_TAG_try_block:
6450 return "DW_TAG_try_block";
6451 case DW_TAG_variant_part:
6452 return "DW_TAG_variant_part";
6453 case DW_TAG_variable:
6454 return "DW_TAG_variable";
6455 case DW_TAG_volatile_type:
6456 return "DW_TAG_volatile_type";
6457 case DW_TAG_dwarf_procedure:
6458 return "DW_TAG_dwarf_procedure";
6459 case DW_TAG_restrict_type:
6460 return "DW_TAG_restrict_type";
6461 case DW_TAG_interface_type:
6462 return "DW_TAG_interface_type";
6463 case DW_TAG_namespace:
6464 return "DW_TAG_namespace";
6465 case DW_TAG_imported_module:
6466 return "DW_TAG_imported_module";
6467 case DW_TAG_unspecified_type:
6468 return "DW_TAG_unspecified_type";
6469 case DW_TAG_partial_unit:
6470 return "DW_TAG_partial_unit";
6471 case DW_TAG_imported_unit:
6472 return "DW_TAG_imported_unit";
6473 case DW_TAG_MIPS_loop:
6474 return "DW_TAG_MIPS_loop";
6475 case DW_TAG_format_label:
6476 return "DW_TAG_format_label";
6477 case DW_TAG_function_template:
6478 return "DW_TAG_function_template";
6479 case DW_TAG_class_template:
6480 return "DW_TAG_class_template";
6482 return "DW_TAG_<unknown>";
6486 /* Convert a DWARF attribute code into its string name. */
6489 dwarf_attr_name (unsigned attr)
6494 return "DW_AT_sibling";
6495 case DW_AT_location:
6496 return "DW_AT_location";
6498 return "DW_AT_name";
6499 case DW_AT_ordering:
6500 return "DW_AT_ordering";
6501 case DW_AT_subscr_data:
6502 return "DW_AT_subscr_data";
6503 case DW_AT_byte_size:
6504 return "DW_AT_byte_size";
6505 case DW_AT_bit_offset:
6506 return "DW_AT_bit_offset";
6507 case DW_AT_bit_size:
6508 return "DW_AT_bit_size";
6509 case DW_AT_element_list:
6510 return "DW_AT_element_list";
6511 case DW_AT_stmt_list:
6512 return "DW_AT_stmt_list";
6514 return "DW_AT_low_pc";
6516 return "DW_AT_high_pc";
6517 case DW_AT_language:
6518 return "DW_AT_language";
6520 return "DW_AT_member";
6522 return "DW_AT_discr";
6523 case DW_AT_discr_value:
6524 return "DW_AT_discr_value";
6525 case DW_AT_visibility:
6526 return "DW_AT_visibility";
6528 return "DW_AT_import";
6529 case DW_AT_string_length:
6530 return "DW_AT_string_length";
6531 case DW_AT_common_reference:
6532 return "DW_AT_common_reference";
6533 case DW_AT_comp_dir:
6534 return "DW_AT_comp_dir";
6535 case DW_AT_const_value:
6536 return "DW_AT_const_value";
6537 case DW_AT_containing_type:
6538 return "DW_AT_containing_type";
6539 case DW_AT_default_value:
6540 return "DW_AT_default_value";
6542 return "DW_AT_inline";
6543 case DW_AT_is_optional:
6544 return "DW_AT_is_optional";
6545 case DW_AT_lower_bound:
6546 return "DW_AT_lower_bound";
6547 case DW_AT_producer:
6548 return "DW_AT_producer";
6549 case DW_AT_prototyped:
6550 return "DW_AT_prototyped";
6551 case DW_AT_return_addr:
6552 return "DW_AT_return_addr";
6553 case DW_AT_start_scope:
6554 return "DW_AT_start_scope";
6555 case DW_AT_stride_size:
6556 return "DW_AT_stride_size";
6557 case DW_AT_upper_bound:
6558 return "DW_AT_upper_bound";
6559 case DW_AT_abstract_origin:
6560 return "DW_AT_abstract_origin";
6561 case DW_AT_accessibility:
6562 return "DW_AT_accessibility";
6563 case DW_AT_address_class:
6564 return "DW_AT_address_class";
6565 case DW_AT_artificial:
6566 return "DW_AT_artificial";
6567 case DW_AT_base_types:
6568 return "DW_AT_base_types";
6569 case DW_AT_calling_convention:
6570 return "DW_AT_calling_convention";
6572 return "DW_AT_count";
6573 case DW_AT_data_member_location:
6574 return "DW_AT_data_member_location";
6575 case DW_AT_decl_column:
6576 return "DW_AT_decl_column";
6577 case DW_AT_decl_file:
6578 return "DW_AT_decl_file";
6579 case DW_AT_decl_line:
6580 return "DW_AT_decl_line";
6581 case DW_AT_declaration:
6582 return "DW_AT_declaration";
6583 case DW_AT_discr_list:
6584 return "DW_AT_discr_list";
6585 case DW_AT_encoding:
6586 return "DW_AT_encoding";
6587 case DW_AT_external:
6588 return "DW_AT_external";
6589 case DW_AT_frame_base:
6590 return "DW_AT_frame_base";
6592 return "DW_AT_friend";
6593 case DW_AT_identifier_case:
6594 return "DW_AT_identifier_case";
6595 case DW_AT_macro_info:
6596 return "DW_AT_macro_info";
6597 case DW_AT_namelist_items:
6598 return "DW_AT_namelist_items";
6599 case DW_AT_priority:
6600 return "DW_AT_priority";
6602 return "DW_AT_segment";
6603 case DW_AT_specification:
6604 return "DW_AT_specification";
6605 case DW_AT_static_link:
6606 return "DW_AT_static_link";
6608 return "DW_AT_type";
6609 case DW_AT_use_location:
6610 return "DW_AT_use_location";
6611 case DW_AT_variable_parameter:
6612 return "DW_AT_variable_parameter";
6613 case DW_AT_virtuality:
6614 return "DW_AT_virtuality";
6615 case DW_AT_vtable_elem_location:
6616 return "DW_AT_vtable_elem_location";
6617 case DW_AT_allocated:
6618 return "DW_AT_allocated";
6619 case DW_AT_associated:
6620 return "DW_AT_associated";
6621 case DW_AT_data_location:
6622 return "DW_AT_data_location";
6624 return "DW_AT_stride";
6625 case DW_AT_entry_pc:
6626 return "DW_AT_entry_pc";
6627 case DW_AT_use_UTF8:
6628 return "DW_AT_use_UTF8";
6629 case DW_AT_extension:
6630 return "DW_AT_extension";
6632 return "DW_AT_ranges";
6633 case DW_AT_trampoline:
6634 return "DW_AT_trampoline";
6635 case DW_AT_call_column:
6636 return "DW_AT_call_column";
6637 case DW_AT_call_file:
6638 return "DW_AT_call_file";
6639 case DW_AT_call_line:
6640 return "DW_AT_call_line";
6642 case DW_AT_MIPS_fde:
6643 return "DW_AT_MIPS_fde";
6644 case DW_AT_MIPS_loop_begin:
6645 return "DW_AT_MIPS_loop_begin";
6646 case DW_AT_MIPS_tail_loop_begin:
6647 return "DW_AT_MIPS_tail_loop_begin";
6648 case DW_AT_MIPS_epilog_begin:
6649 return "DW_AT_MIPS_epilog_begin";
6650 case DW_AT_MIPS_loop_unroll_factor:
6651 return "DW_AT_MIPS_loop_unroll_factor";
6652 case DW_AT_MIPS_software_pipeline_depth:
6653 return "DW_AT_MIPS_software_pipeline_depth";
6655 case DW_AT_MIPS_linkage_name:
6656 return "DW_AT_MIPS_linkage_name";
6658 case DW_AT_sf_names:
6659 return "DW_AT_sf_names";
6660 case DW_AT_src_info:
6661 return "DW_AT_src_info";
6662 case DW_AT_mac_info:
6663 return "DW_AT_mac_info";
6664 case DW_AT_src_coords:
6665 return "DW_AT_src_coords";
6666 case DW_AT_body_begin:
6667 return "DW_AT_body_begin";
6668 case DW_AT_body_end:
6669 return "DW_AT_body_end";
6670 case DW_AT_GNU_vector:
6671 return "DW_AT_GNU_vector";
6673 return "DW_AT_<unknown>";
6677 /* Convert a DWARF value form code into its string name. */
6680 dwarf_form_name (unsigned form)
6685 return "DW_FORM_addr";
6686 case DW_FORM_block2:
6687 return "DW_FORM_block2";
6688 case DW_FORM_block4:
6689 return "DW_FORM_block4";
6691 return "DW_FORM_data2";
6693 return "DW_FORM_data4";
6695 return "DW_FORM_data8";
6696 case DW_FORM_string:
6697 return "DW_FORM_string";
6699 return "DW_FORM_block";
6700 case DW_FORM_block1:
6701 return "DW_FORM_block1";
6703 return "DW_FORM_data1";
6705 return "DW_FORM_flag";
6707 return "DW_FORM_sdata";
6709 return "DW_FORM_strp";
6711 return "DW_FORM_udata";
6712 case DW_FORM_ref_addr:
6713 return "DW_FORM_ref_addr";
6715 return "DW_FORM_ref1";
6717 return "DW_FORM_ref2";
6719 return "DW_FORM_ref4";
6721 return "DW_FORM_ref8";
6722 case DW_FORM_ref_udata:
6723 return "DW_FORM_ref_udata";
6724 case DW_FORM_indirect:
6725 return "DW_FORM_indirect";
6727 return "DW_FORM_<unknown>";
6731 /* Convert a DWARF stack opcode into its string name. */
6734 dwarf_stack_op_name (unsigned op)
6739 return "DW_OP_addr";
6741 return "DW_OP_deref";
6743 return "DW_OP_const1u";
6745 return "DW_OP_const1s";
6747 return "DW_OP_const2u";
6749 return "DW_OP_const2s";
6751 return "DW_OP_const4u";
6753 return "DW_OP_const4s";
6755 return "DW_OP_const8u";
6757 return "DW_OP_const8s";
6759 return "DW_OP_constu";
6761 return "DW_OP_consts";
6765 return "DW_OP_drop";
6767 return "DW_OP_over";
6769 return "DW_OP_pick";
6771 return "DW_OP_swap";
6775 return "DW_OP_xderef";
6783 return "DW_OP_minus";
6795 return "DW_OP_plus";
6796 case DW_OP_plus_uconst:
6797 return "DW_OP_plus_uconst";
6803 return "DW_OP_shra";
6821 return "DW_OP_skip";
6823 return "DW_OP_lit0";
6825 return "DW_OP_lit1";
6827 return "DW_OP_lit2";
6829 return "DW_OP_lit3";
6831 return "DW_OP_lit4";
6833 return "DW_OP_lit5";
6835 return "DW_OP_lit6";
6837 return "DW_OP_lit7";
6839 return "DW_OP_lit8";
6841 return "DW_OP_lit9";
6843 return "DW_OP_lit10";
6845 return "DW_OP_lit11";
6847 return "DW_OP_lit12";
6849 return "DW_OP_lit13";
6851 return "DW_OP_lit14";
6853 return "DW_OP_lit15";
6855 return "DW_OP_lit16";
6857 return "DW_OP_lit17";
6859 return "DW_OP_lit18";
6861 return "DW_OP_lit19";
6863 return "DW_OP_lit20";
6865 return "DW_OP_lit21";
6867 return "DW_OP_lit22";
6869 return "DW_OP_lit23";
6871 return "DW_OP_lit24";
6873 return "DW_OP_lit25";
6875 return "DW_OP_lit26";
6877 return "DW_OP_lit27";
6879 return "DW_OP_lit28";
6881 return "DW_OP_lit29";
6883 return "DW_OP_lit30";
6885 return "DW_OP_lit31";
6887 return "DW_OP_reg0";
6889 return "DW_OP_reg1";
6891 return "DW_OP_reg2";
6893 return "DW_OP_reg3";
6895 return "DW_OP_reg4";
6897 return "DW_OP_reg5";
6899 return "DW_OP_reg6";
6901 return "DW_OP_reg7";
6903 return "DW_OP_reg8";
6905 return "DW_OP_reg9";
6907 return "DW_OP_reg10";
6909 return "DW_OP_reg11";
6911 return "DW_OP_reg12";
6913 return "DW_OP_reg13";
6915 return "DW_OP_reg14";
6917 return "DW_OP_reg15";
6919 return "DW_OP_reg16";
6921 return "DW_OP_reg17";
6923 return "DW_OP_reg18";
6925 return "DW_OP_reg19";
6927 return "DW_OP_reg20";
6929 return "DW_OP_reg21";
6931 return "DW_OP_reg22";
6933 return "DW_OP_reg23";
6935 return "DW_OP_reg24";
6937 return "DW_OP_reg25";
6939 return "DW_OP_reg26";
6941 return "DW_OP_reg27";
6943 return "DW_OP_reg28";
6945 return "DW_OP_reg29";
6947 return "DW_OP_reg30";
6949 return "DW_OP_reg31";
6951 return "DW_OP_breg0";
6953 return "DW_OP_breg1";
6955 return "DW_OP_breg2";
6957 return "DW_OP_breg3";
6959 return "DW_OP_breg4";
6961 return "DW_OP_breg5";
6963 return "DW_OP_breg6";
6965 return "DW_OP_breg7";
6967 return "DW_OP_breg8";
6969 return "DW_OP_breg9";
6971 return "DW_OP_breg10";
6973 return "DW_OP_breg11";
6975 return "DW_OP_breg12";
6977 return "DW_OP_breg13";
6979 return "DW_OP_breg14";
6981 return "DW_OP_breg15";
6983 return "DW_OP_breg16";
6985 return "DW_OP_breg17";
6987 return "DW_OP_breg18";
6989 return "DW_OP_breg19";
6991 return "DW_OP_breg20";
6993 return "DW_OP_breg21";
6995 return "DW_OP_breg22";
6997 return "DW_OP_breg23";
6999 return "DW_OP_breg24";
7001 return "DW_OP_breg25";
7003 return "DW_OP_breg26";
7005 return "DW_OP_breg27";
7007 return "DW_OP_breg28";
7009 return "DW_OP_breg29";
7011 return "DW_OP_breg30";
7013 return "DW_OP_breg31";
7015 return "DW_OP_regx";
7017 return "DW_OP_fbreg";
7019 return "DW_OP_bregx";
7021 return "DW_OP_piece";
7022 case DW_OP_deref_size:
7023 return "DW_OP_deref_size";
7024 case DW_OP_xderef_size:
7025 return "DW_OP_xderef_size";
7028 /* DWARF 3 extensions. */
7029 case DW_OP_push_object_address:
7030 return "DW_OP_push_object_address";
7032 return "DW_OP_call2";
7034 return "DW_OP_call4";
7035 case DW_OP_call_ref:
7036 return "DW_OP_call_ref";
7037 /* GNU extensions. */
7038 case DW_OP_GNU_push_tls_address:
7039 return "DW_OP_GNU_push_tls_address";
7041 return "OP_<unknown>";
7046 dwarf_bool_name (unsigned mybool)
7054 /* Convert a DWARF type code into its string name. */
7057 dwarf_type_encoding_name (unsigned enc)
7061 case DW_ATE_address:
7062 return "DW_ATE_address";
7063 case DW_ATE_boolean:
7064 return "DW_ATE_boolean";
7065 case DW_ATE_complex_float:
7066 return "DW_ATE_complex_float";
7068 return "DW_ATE_float";
7070 return "DW_ATE_signed";
7071 case DW_ATE_signed_char:
7072 return "DW_ATE_signed_char";
7073 case DW_ATE_unsigned:
7074 return "DW_ATE_unsigned";
7075 case DW_ATE_unsigned_char:
7076 return "DW_ATE_unsigned_char";
7077 case DW_ATE_imaginary_float:
7078 return "DW_ATE_imaginary_float";
7080 return "DW_ATE_<unknown>";
7084 /* Convert a DWARF call frame info operation to its string name. */
7088 dwarf_cfi_name (unsigned cfi_opc)
7092 case DW_CFA_advance_loc:
7093 return "DW_CFA_advance_loc";
7095 return "DW_CFA_offset";
7096 case DW_CFA_restore:
7097 return "DW_CFA_restore";
7099 return "DW_CFA_nop";
7100 case DW_CFA_set_loc:
7101 return "DW_CFA_set_loc";
7102 case DW_CFA_advance_loc1:
7103 return "DW_CFA_advance_loc1";
7104 case DW_CFA_advance_loc2:
7105 return "DW_CFA_advance_loc2";
7106 case DW_CFA_advance_loc4:
7107 return "DW_CFA_advance_loc4";
7108 case DW_CFA_offset_extended:
7109 return "DW_CFA_offset_extended";
7110 case DW_CFA_restore_extended:
7111 return "DW_CFA_restore_extended";
7112 case DW_CFA_undefined:
7113 return "DW_CFA_undefined";
7114 case DW_CFA_same_value:
7115 return "DW_CFA_same_value";
7116 case DW_CFA_register:
7117 return "DW_CFA_register";
7118 case DW_CFA_remember_state:
7119 return "DW_CFA_remember_state";
7120 case DW_CFA_restore_state:
7121 return "DW_CFA_restore_state";
7122 case DW_CFA_def_cfa:
7123 return "DW_CFA_def_cfa";
7124 case DW_CFA_def_cfa_register:
7125 return "DW_CFA_def_cfa_register";
7126 case DW_CFA_def_cfa_offset:
7127 return "DW_CFA_def_cfa_offset";
7130 case DW_CFA_def_cfa_expression:
7131 return "DW_CFA_def_cfa_expression";
7132 case DW_CFA_expression:
7133 return "DW_CFA_expression";
7134 case DW_CFA_offset_extended_sf:
7135 return "DW_CFA_offset_extended_sf";
7136 case DW_CFA_def_cfa_sf:
7137 return "DW_CFA_def_cfa_sf";
7138 case DW_CFA_def_cfa_offset_sf:
7139 return "DW_CFA_def_cfa_offset_sf";
7141 /* SGI/MIPS specific */
7142 case DW_CFA_MIPS_advance_loc8:
7143 return "DW_CFA_MIPS_advance_loc8";
7145 /* GNU extensions */
7146 case DW_CFA_GNU_window_save:
7147 return "DW_CFA_GNU_window_save";
7148 case DW_CFA_GNU_args_size:
7149 return "DW_CFA_GNU_args_size";
7150 case DW_CFA_GNU_negative_offset_extended:
7151 return "DW_CFA_GNU_negative_offset_extended";
7154 return "DW_CFA_<unknown>";
7160 dump_die (struct die_info *die)
7164 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7165 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7166 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7167 dwarf_bool_name (die->child != NULL));
7169 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7170 for (i = 0; i < die->num_attrs; ++i)
7172 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7173 dwarf_attr_name (die->attrs[i].name),
7174 dwarf_form_name (die->attrs[i].form));
7175 switch (die->attrs[i].form)
7177 case DW_FORM_ref_addr:
7179 fprintf_unfiltered (gdb_stderr, "address: ");
7180 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7182 case DW_FORM_block2:
7183 case DW_FORM_block4:
7185 case DW_FORM_block1:
7186 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7197 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7199 case DW_FORM_string:
7201 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7202 DW_STRING (&die->attrs[i])
7203 ? DW_STRING (&die->attrs[i]) : "");
7206 if (DW_UNSND (&die->attrs[i]))
7207 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7209 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7211 case DW_FORM_indirect:
7212 /* the reader will have reduced the indirect form to
7213 the "base form" so this form should not occur */
7214 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7217 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7218 die->attrs[i].form);
7220 fprintf_unfiltered (gdb_stderr, "\n");
7225 dump_die_list (struct die_info *die)
7230 if (die->child != NULL)
7231 dump_die_list (die->child);
7232 if (die->sibling != NULL)
7233 dump_die_list (die->sibling);
7238 store_in_ref_table (unsigned int offset, struct die_info *die)
7241 struct die_info *old;
7243 h = (offset % REF_HASH_SIZE);
7244 old = die_ref_table[h];
7245 die->next_ref = old;
7246 die_ref_table[h] = die;
7251 dwarf2_empty_hash_tables (void)
7253 memset (die_ref_table, 0, sizeof (die_ref_table));
7257 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
7259 unsigned int result = 0;
7263 case DW_FORM_ref_addr:
7264 result = DW_ADDR (attr);
7270 case DW_FORM_ref_udata:
7271 result = cu->header.offset + DW_UNSND (attr);
7274 complaint (&symfile_complaints,
7275 "unsupported die ref attribute form: '%s'",
7276 dwarf_form_name (attr->form));
7281 /* Return the constant value held by the given attribute. Return -1
7282 if the value held by the attribute is not constant. */
7285 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7287 if (attr->form == DW_FORM_sdata)
7288 return DW_SND (attr);
7289 else if (attr->form == DW_FORM_udata
7290 || attr->form == DW_FORM_data1
7291 || attr->form == DW_FORM_data2
7292 || attr->form == DW_FORM_data4
7293 || attr->form == DW_FORM_data8)
7294 return DW_UNSND (attr);
7297 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
7298 dwarf_form_name (attr->form));
7299 return default_value;
7303 static struct die_info *
7304 follow_die_ref (unsigned int offset)
7306 struct die_info *die;
7309 h = (offset % REF_HASH_SIZE);
7310 die = die_ref_table[h];
7313 if (die->offset == offset)
7317 die = die->next_ref;
7322 static struct type *
7323 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
7324 struct dwarf2_cu *cu)
7326 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
7328 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7329 typeid, objfile->name);
7332 /* Look for this particular type in the fundamental type vector. If
7333 one is not found, create and install one appropriate for the
7334 current language and the current target machine. */
7336 if (cu->ftypes[typeid] == NULL)
7338 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
7341 return (cu->ftypes[typeid]);
7344 /* Decode simple location descriptions.
7345 Given a pointer to a dwarf block that defines a location, compute
7346 the location and return the value.
7348 NOTE drow/2003-11-18: This function is called in two situations
7349 now: for the address of static or global variables (partial symbols
7350 only) and for offsets into structures which are expected to be
7351 (more or less) constant. The partial symbol case should go away,
7352 and only the constant case should remain. That will let this
7353 function complain more accurately. A few special modes are allowed
7354 without complaint for global variables (for instance, global
7355 register values and thread-local values).
7357 A location description containing no operations indicates that the
7358 object is optimized out. The return value is 0 for that case.
7359 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7360 callers will only want a very basic result and this can become a
7363 When the result is a register number, the global isreg flag is set,
7364 otherwise it is cleared.
7366 Note that stack[0] is unused except as a default error return.
7367 Note that stack overflow is not yet handled. */
7370 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
7372 struct objfile *objfile = cu->objfile;
7373 struct comp_unit_head *cu_header = &cu->header;
7375 int size = blk->size;
7376 char *data = blk->data;
7377 CORE_ADDR stack[64];
7379 unsigned int bytes_read, unsnd;
7424 stack[++stacki] = op - DW_OP_lit0;
7460 stack[++stacki] = op - DW_OP_reg0;
7462 dwarf2_complex_location_expr_complaint ();
7467 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7469 stack[++stacki] = unsnd;
7471 dwarf2_complex_location_expr_complaint ();
7475 stack[++stacki] = read_address (objfile->obfd, &data[i],
7481 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
7486 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
7491 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
7496 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
7501 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
7506 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
7511 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
7517 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
7522 stack[stacki + 1] = stack[stacki];
7527 stack[stacki - 1] += stack[stacki];
7531 case DW_OP_plus_uconst:
7532 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7537 stack[stacki - 1] -= stack[stacki];
7542 /* If we're not the last op, then we definitely can't encode
7543 this using GDB's address_class enum. This is valid for partial
7544 global symbols, although the variable's address will be bogus
7547 dwarf2_complex_location_expr_complaint ();
7550 case DW_OP_GNU_push_tls_address:
7551 /* The top of the stack has the offset from the beginning
7552 of the thread control block at which the variable is located. */
7553 /* Nothing should follow this operator, so the top of stack would
7555 /* This is valid for partial global symbols, but the variable's
7556 address will be bogus in the psymtab. */
7558 dwarf2_complex_location_expr_complaint ();
7562 complaint (&symfile_complaints, "unsupported stack op: '%s'",
7563 dwarf_stack_op_name (op));
7564 return (stack[stacki]);
7567 return (stack[stacki]);
7570 /* memory allocation interface */
7573 dwarf2_free_tmp_obstack (void *ignore)
7575 obstack_free (&dwarf2_tmp_obstack, NULL);
7578 static struct dwarf_block *
7579 dwarf_alloc_block (void)
7581 struct dwarf_block *blk;
7583 blk = (struct dwarf_block *)
7584 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
7588 static struct abbrev_info *
7589 dwarf_alloc_abbrev (void)
7591 struct abbrev_info *abbrev;
7593 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
7594 memset (abbrev, 0, sizeof (struct abbrev_info));
7598 static struct die_info *
7599 dwarf_alloc_die (void)
7601 struct die_info *die;
7603 die = (struct die_info *) xmalloc (sizeof (struct die_info));
7604 memset (die, 0, sizeof (struct die_info));
7609 /* Macro support. */
7612 /* Return the full name of file number I in *LH's file name table.
7613 Use COMP_DIR as the name of the current directory of the
7614 compilation. The result is allocated using xmalloc; the caller is
7615 responsible for freeing it. */
7617 file_full_name (int file, struct line_header *lh, const char *comp_dir)
7619 struct file_entry *fe = &lh->file_names[file - 1];
7621 if (IS_ABSOLUTE_PATH (fe->name))
7622 return xstrdup (fe->name);
7630 dir = lh->include_dirs[fe->dir_index - 1];
7636 dir_len = strlen (dir);
7637 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
7638 strcpy (full_name, dir);
7639 full_name[dir_len] = '/';
7640 strcpy (full_name + dir_len + 1, fe->name);
7644 return xstrdup (fe->name);
7649 static struct macro_source_file *
7650 macro_start_file (int file, int line,
7651 struct macro_source_file *current_file,
7652 const char *comp_dir,
7653 struct line_header *lh, struct objfile *objfile)
7655 /* The full name of this source file. */
7656 char *full_name = file_full_name (file, lh, comp_dir);
7658 /* We don't create a macro table for this compilation unit
7659 at all until we actually get a filename. */
7660 if (! pending_macros)
7661 pending_macros = new_macro_table (&objfile->symbol_obstack,
7662 objfile->macro_cache);
7665 /* If we have no current file, then this must be the start_file
7666 directive for the compilation unit's main source file. */
7667 current_file = macro_set_main (pending_macros, full_name);
7669 current_file = macro_include (current_file, line, full_name);
7673 return current_file;
7677 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7678 followed by a null byte. */
7680 copy_string (const char *buf, int len)
7682 char *s = xmalloc (len + 1);
7683 memcpy (s, buf, len);
7691 consume_improper_spaces (const char *p, const char *body)
7695 complaint (&symfile_complaints,
7696 "macro definition contains spaces in formal argument list:\n`%s'",
7708 parse_macro_definition (struct macro_source_file *file, int line,
7713 /* The body string takes one of two forms. For object-like macro
7714 definitions, it should be:
7716 <macro name> " " <definition>
7718 For function-like macro definitions, it should be:
7720 <macro name> "() " <definition>
7722 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7724 Spaces may appear only where explicitly indicated, and in the
7727 The Dwarf 2 spec says that an object-like macro's name is always
7728 followed by a space, but versions of GCC around March 2002 omit
7729 the space when the macro's definition is the empty string.
7731 The Dwarf 2 spec says that there should be no spaces between the
7732 formal arguments in a function-like macro's formal argument list,
7733 but versions of GCC around March 2002 include spaces after the
7737 /* Find the extent of the macro name. The macro name is terminated
7738 by either a space or null character (for an object-like macro) or
7739 an opening paren (for a function-like macro). */
7740 for (p = body; *p; p++)
7741 if (*p == ' ' || *p == '(')
7744 if (*p == ' ' || *p == '\0')
7746 /* It's an object-like macro. */
7747 int name_len = p - body;
7748 char *name = copy_string (body, name_len);
7749 const char *replacement;
7752 replacement = body + name_len + 1;
7755 dwarf2_macro_malformed_definition_complaint (body);
7756 replacement = body + name_len;
7759 macro_define_object (file, line, name, replacement);
7765 /* It's a function-like macro. */
7766 char *name = copy_string (body, p - body);
7769 char **argv = xmalloc (argv_size * sizeof (*argv));
7773 p = consume_improper_spaces (p, body);
7775 /* Parse the formal argument list. */
7776 while (*p && *p != ')')
7778 /* Find the extent of the current argument name. */
7779 const char *arg_start = p;
7781 while (*p && *p != ',' && *p != ')' && *p != ' ')
7784 if (! *p || p == arg_start)
7785 dwarf2_macro_malformed_definition_complaint (body);
7788 /* Make sure argv has room for the new argument. */
7789 if (argc >= argv_size)
7792 argv = xrealloc (argv, argv_size * sizeof (*argv));
7795 argv[argc++] = copy_string (arg_start, p - arg_start);
7798 p = consume_improper_spaces (p, body);
7800 /* Consume the comma, if present. */
7805 p = consume_improper_spaces (p, body);
7814 /* Perfectly formed definition, no complaints. */
7815 macro_define_function (file, line, name,
7816 argc, (const char **) argv,
7818 else if (*p == '\0')
7820 /* Complain, but do define it. */
7821 dwarf2_macro_malformed_definition_complaint (body);
7822 macro_define_function (file, line, name,
7823 argc, (const char **) argv,
7827 /* Just complain. */
7828 dwarf2_macro_malformed_definition_complaint (body);
7831 /* Just complain. */
7832 dwarf2_macro_malformed_definition_complaint (body);
7838 for (i = 0; i < argc; i++)
7844 dwarf2_macro_malformed_definition_complaint (body);
7849 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7850 char *comp_dir, bfd *abfd,
7851 struct dwarf2_cu *cu)
7853 char *mac_ptr, *mac_end;
7854 struct macro_source_file *current_file = 0;
7856 if (dwarf_macinfo_buffer == NULL)
7858 complaint (&symfile_complaints, "missing .debug_macinfo section");
7862 mac_ptr = dwarf_macinfo_buffer + offset;
7863 mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size;
7867 enum dwarf_macinfo_record_type macinfo_type;
7869 /* Do we at least have room for a macinfo type byte? */
7870 if (mac_ptr >= mac_end)
7872 dwarf2_macros_too_long_complaint ();
7876 macinfo_type = read_1_byte (abfd, mac_ptr);
7879 switch (macinfo_type)
7881 /* A zero macinfo type indicates the end of the macro
7886 case DW_MACINFO_define:
7887 case DW_MACINFO_undef:
7893 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7894 mac_ptr += bytes_read;
7895 body = read_string (abfd, mac_ptr, &bytes_read);
7896 mac_ptr += bytes_read;
7899 complaint (&symfile_complaints,
7900 "debug info gives macro %s outside of any file: %s",
7902 DW_MACINFO_define ? "definition" : macinfo_type ==
7903 DW_MACINFO_undef ? "undefinition" :
7904 "something-or-other", body);
7907 if (macinfo_type == DW_MACINFO_define)
7908 parse_macro_definition (current_file, line, body);
7909 else if (macinfo_type == DW_MACINFO_undef)
7910 macro_undef (current_file, line, body);
7915 case DW_MACINFO_start_file:
7920 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7921 mac_ptr += bytes_read;
7922 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7923 mac_ptr += bytes_read;
7925 current_file = macro_start_file (file, line,
7926 current_file, comp_dir,
7931 case DW_MACINFO_end_file:
7933 complaint (&symfile_complaints,
7934 "macro debug info has an unmatched `close_file' directive");
7937 current_file = current_file->included_by;
7940 enum dwarf_macinfo_record_type next_type;
7942 /* GCC circa March 2002 doesn't produce the zero
7943 type byte marking the end of the compilation
7944 unit. Complain if it's not there, but exit no
7947 /* Do we at least have room for a macinfo type byte? */
7948 if (mac_ptr >= mac_end)
7950 dwarf2_macros_too_long_complaint ();
7954 /* We don't increment mac_ptr here, so this is just
7956 next_type = read_1_byte (abfd, mac_ptr);
7958 complaint (&symfile_complaints,
7959 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7966 case DW_MACINFO_vendor_ext:
7972 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7973 mac_ptr += bytes_read;
7974 string = read_string (abfd, mac_ptr, &bytes_read);
7975 mac_ptr += bytes_read;
7977 /* We don't recognize any vendor extensions. */
7984 /* Check if the attribute's form is a DW_FORM_block*
7985 if so return true else false. */
7987 attr_form_is_block (struct attribute *attr)
7989 return (attr == NULL ? 0 :
7990 attr->form == DW_FORM_block1
7991 || attr->form == DW_FORM_block2
7992 || attr->form == DW_FORM_block4
7993 || attr->form == DW_FORM_block);
7997 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7998 struct dwarf2_cu *cu)
8000 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
8002 struct dwarf2_loclist_baton *baton;
8004 baton = obstack_alloc (&cu->objfile->symbol_obstack,
8005 sizeof (struct dwarf2_loclist_baton));
8006 baton->objfile = cu->objfile;
8008 /* We don't know how long the location list is, but make sure we
8009 don't run off the edge of the section. */
8010 baton->size = dwarf_loc_size - DW_UNSND (attr);
8011 baton->data = dwarf_loc_buffer + DW_UNSND (attr);
8012 baton->base_address = cu->header.base_address;
8013 if (cu->header.base_known == 0)
8014 complaint (&symfile_complaints,
8015 "Location list used without specifying the CU base address.");
8017 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
8018 SYMBOL_LOCATION_BATON (sym) = baton;
8022 struct dwarf2_locexpr_baton *baton;
8024 baton = obstack_alloc (&cu->objfile->symbol_obstack,
8025 sizeof (struct dwarf2_locexpr_baton));
8026 baton->objfile = cu->objfile;
8028 if (attr_form_is_block (attr))
8030 /* Note that we're just copying the block's data pointer
8031 here, not the actual data. We're still pointing into the
8032 dwarf_info_buffer for SYM's objfile; right now we never
8033 release that buffer, but when we do clean up properly
8034 this may need to change. */
8035 baton->size = DW_BLOCK (attr)->size;
8036 baton->data = DW_BLOCK (attr)->data;
8040 dwarf2_invalid_attrib_class_complaint ("location description",
8041 SYMBOL_NATURAL_NAME (sym));
8046 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
8047 SYMBOL_LOCATION_BATON (sym) = baton;