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;
236 /* The line number information for a compilation unit (found in the
237 .debug_line section) begins with a "statement program header",
238 which contains the following information. */
241 unsigned int total_length;
242 unsigned short version;
243 unsigned int header_length;
244 unsigned char minimum_instruction_length;
245 unsigned char default_is_stmt;
247 unsigned char line_range;
248 unsigned char opcode_base;
250 /* standard_opcode_lengths[i] is the number of operands for the
251 standard opcode whose value is i. This means that
252 standard_opcode_lengths[0] is unused, and the last meaningful
253 element is standard_opcode_lengths[opcode_base - 1]. */
254 unsigned char *standard_opcode_lengths;
256 /* The include_directories table. NOTE! These strings are not
257 allocated with xmalloc; instead, they are pointers into
258 debug_line_buffer. If you try to free them, `free' will get
260 unsigned int num_include_dirs, include_dirs_size;
263 /* The file_names table. NOTE! These strings are not allocated
264 with xmalloc; instead, they are pointers into debug_line_buffer.
265 Don't try to free them directly. */
266 unsigned int num_file_names, file_names_size;
270 unsigned int dir_index;
271 unsigned int mod_time;
275 /* The start and end of the statement program following this
276 header. These point into dwarf_line_buffer. */
277 char *statement_program_start, *statement_program_end;
280 /* When we construct a partial symbol table entry we only
281 need this much information. */
282 struct partial_die_info
285 unsigned char has_children;
286 unsigned char is_external;
287 unsigned char is_declaration;
288 unsigned char has_type;
295 struct dwarf_block *locdesc;
296 unsigned int language;
300 /* This data structure holds the information of an abbrev. */
303 unsigned int number; /* number identifying abbrev */
304 enum dwarf_tag tag; /* dwarf tag */
305 int has_children; /* boolean */
306 unsigned int num_attrs; /* number of attributes */
307 struct attr_abbrev *attrs; /* an array of attribute descriptions */
308 struct abbrev_info *next; /* next in chain */
313 enum dwarf_attribute name;
314 enum dwarf_form form;
317 /* This data structure holds a complete die structure. */
320 enum dwarf_tag tag; /* Tag indicating type of die */
321 unsigned int abbrev; /* Abbrev number */
322 unsigned int offset; /* Offset in .debug_info section */
323 unsigned int num_attrs; /* Number of attributes */
324 struct attribute *attrs; /* An array of attributes */
325 struct die_info *next_ref; /* Next die in ref hash table */
327 /* The dies in a compilation unit form an n-ary tree. PARENT
328 points to this die's parent; CHILD points to the first child of
329 this node; and all the children of a given node are chained
330 together via their SIBLING fields, terminated by a die whose
332 struct die_info *child; /* Its first child, if any. */
333 struct die_info *sibling; /* Its next sibling, if any. */
334 struct die_info *parent; /* Its parent, if any. */
336 struct type *type; /* Cached type information */
339 /* Attributes have a name and a value */
342 enum dwarf_attribute name;
343 enum dwarf_form form;
347 struct dwarf_block *blk;
355 struct function_range
358 CORE_ADDR lowpc, highpc;
360 struct function_range *next;
363 static struct function_range *cu_first_fn, *cu_last_fn, *cu_cached_fn;
365 /* Get at parts of an attribute structure */
367 #define DW_STRING(attr) ((attr)->u.str)
368 #define DW_UNSND(attr) ((attr)->u.unsnd)
369 #define DW_BLOCK(attr) ((attr)->u.blk)
370 #define DW_SND(attr) ((attr)->u.snd)
371 #define DW_ADDR(attr) ((attr)->u.addr)
373 /* Blocks are a bunch of untyped bytes. */
380 #ifndef ATTR_ALLOC_CHUNK
381 #define ATTR_ALLOC_CHUNK 4
384 /* A hash table of die offsets for following references. */
385 #ifndef REF_HASH_SIZE
386 #define REF_HASH_SIZE 1021
389 static struct die_info *die_ref_table[REF_HASH_SIZE];
391 /* Obstack for allocating temporary storage used during symbol reading. */
392 static struct obstack dwarf2_tmp_obstack;
394 /* Offset to the first byte of the current compilation unit header,
395 for resolving relative reference dies. */
396 static unsigned int cu_header_offset;
398 /* Allocate fields for structs, unions and enums in this size. */
399 #ifndef DW_FIELD_ALLOC_CHUNK
400 #define DW_FIELD_ALLOC_CHUNK 4
403 /* The language we are debugging. */
404 static enum language cu_language;
405 static const struct language_defn *cu_language_defn;
407 /* Actually data from the sections. */
408 static char *dwarf_info_buffer;
409 static char *dwarf_abbrev_buffer;
410 static char *dwarf_line_buffer;
411 static char *dwarf_str_buffer;
412 static char *dwarf_macinfo_buffer;
413 static char *dwarf_ranges_buffer;
414 static char *dwarf_loc_buffer;
416 /* A zeroed version of a partial die for initialization purposes. */
417 static struct partial_die_info zeroed_partial_die;
419 /* The generic symbol table building routines have separate lists for
420 file scope symbols and all all other scopes (local scopes). So
421 we need to select the right one to pass to add_symbol_to_list().
422 We do it by keeping a pointer to the correct list in list_in_scope.
424 FIXME: The original dwarf code just treated the file scope as the first
425 local scope, and all other local scopes as nested local scopes, and worked
426 fine. Check to see if we really need to distinguish these
428 static struct pending **list_in_scope = &file_symbols;
430 /* FIXME: decode_locdesc sets these variables to describe the location
431 to the caller. These ought to be a structure or something. If
432 none of the flags are set, the object lives at the address returned
433 by decode_locdesc. */
435 static int isreg; /* Object lives in register.
436 decode_locdesc's return value is
437 the register number. */
439 /* This value is added to each symbol value. FIXME: Generalize to
440 the section_offsets structure used by dbxread (once this is done,
441 pass the appropriate section number to end_symtab). */
442 static CORE_ADDR baseaddr; /* Add to each symbol value */
444 /* We put a pointer to this structure in the read_symtab_private field
446 The complete dwarf information for an objfile is kept in the
447 psymbol_obstack, so that absolute die references can be handled.
448 Most of the information in this structure is related to an entire
449 object file and could be passed via the sym_private field of the objfile.
450 It is however conceivable that dwarf2 might not be the only type
451 of symbols read from an object file. */
455 /* Pointer to start of dwarf info buffer for the objfile. */
457 char *dwarf_info_buffer;
459 /* Offset in dwarf_info_buffer for this compilation unit. */
461 unsigned long dwarf_info_offset;
463 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
465 char *dwarf_abbrev_buffer;
467 /* Size of dwarf abbreviation section for the objfile. */
469 unsigned int dwarf_abbrev_size;
471 /* Pointer to start of dwarf line buffer for the objfile. */
473 char *dwarf_line_buffer;
475 /* Size of dwarf_line_buffer, in bytes. */
477 unsigned int dwarf_line_size;
479 /* Pointer to start of dwarf string buffer for the objfile. */
481 char *dwarf_str_buffer;
483 /* Size of dwarf string section for the objfile. */
485 unsigned int dwarf_str_size;
487 /* Pointer to start of dwarf macro buffer for the objfile. */
489 char *dwarf_macinfo_buffer;
491 /* Size of dwarf macinfo section for the objfile. */
493 unsigned int dwarf_macinfo_size;
495 /* Pointer to start of dwarf ranges buffer for the objfile. */
497 char *dwarf_ranges_buffer;
499 /* Size of dwarf ranges buffer for the objfile. */
501 unsigned int dwarf_ranges_size;
503 /* Pointer to start of dwarf locations buffer for the objfile. */
505 char *dwarf_loc_buffer;
507 /* Size of dwarf locations buffer for the objfile. */
509 unsigned int dwarf_loc_size;
512 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
513 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
514 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
515 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
516 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
517 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
518 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
519 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
520 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
521 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
522 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
523 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
524 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
525 #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer)
526 #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size)
528 /* Maintain an array of referenced fundamental types for the current
529 compilation unit being read. For DWARF version 1, we have to construct
530 the fundamental types on the fly, since no information about the
531 fundamental types is supplied. Each such fundamental type is created by
532 calling a language dependent routine to create the type, and then a
533 pointer to that type is then placed in the array at the index specified
534 by it's FT_<TYPENAME> value. The array has a fixed size set by the
535 FT_NUM_MEMBERS compile time constant, which is the number of predefined
536 fundamental types gdb knows how to construct. */
537 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
539 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
540 but this would require a corresponding change in unpack_field_as_long
542 static int bits_per_byte = 8;
544 /* The routines that read and process dies for a C struct or C++ class
545 pass lists of data member fields and lists of member function fields
546 in an instance of a field_info structure, as defined below. */
549 /* List of data member and baseclasses fields. */
552 struct nextfield *next;
559 /* Number of fields. */
562 /* Number of baseclasses. */
565 /* Set if the accesibility of one of the fields is not public. */
566 int non_public_fields;
568 /* Member function fields array, entries are allocated in the order they
569 are encountered in the object file. */
572 struct nextfnfield *next;
573 struct fn_field fnfield;
577 /* Member function fieldlist array, contains name of possibly overloaded
578 member function, number of overloaded member functions and a pointer
579 to the head of the member function field chain. */
584 struct nextfnfield *head;
588 /* Number of entries in the fnfieldlists array. */
592 /* Various complaints about symbol reading that don't abort the process */
595 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
597 complaint (&symfile_complaints,
598 "statement list doesn't fit in .debug_line section");
602 dwarf2_complex_location_expr_complaint (void)
604 complaint (&symfile_complaints, "location expression too complex");
608 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
611 complaint (&symfile_complaints,
612 "const value length mismatch for '%s', got %d, expected %d", arg1,
617 dwarf2_macros_too_long_complaint (void)
619 complaint (&symfile_complaints,
620 "macro info runs off end of `.debug_macinfo' section");
624 dwarf2_macro_malformed_definition_complaint (const char *arg1)
626 complaint (&symfile_complaints,
627 "macro debug info contains a malformed macro definition:\n`%s'",
632 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
634 complaint (&symfile_complaints,
635 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
638 /* local function prototypes */
640 static void dwarf2_locate_sections (bfd *, asection *, void *);
643 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
646 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
648 static char *scan_partial_symbols (char *, CORE_ADDR *, CORE_ADDR *,
650 const char *namespace);
652 static void add_partial_symbol (struct partial_die_info *, struct dwarf2_cu *,
653 const char *namespace);
655 static int pdi_needs_namespace (enum dwarf_tag tag, const char *namespace);
657 static char *add_partial_namespace (struct partial_die_info *pdi,
659 CORE_ADDR *lowpc, CORE_ADDR *highpc,
660 struct dwarf2_cu *cu,
661 const char *namespace);
663 static char *add_partial_structure (struct partial_die_info *struct_pdi,
665 struct dwarf2_cu *cu,
666 const char *namespace);
668 static char *add_partial_enumeration (struct partial_die_info *enum_pdi,
670 struct dwarf2_cu *cu,
671 const char *namespace);
673 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
676 struct dwarf2_cu *cu);
678 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
680 static void psymtab_to_symtab_1 (struct partial_symtab *);
682 char *dwarf2_read_section (struct objfile *, asection *);
684 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
686 static void dwarf2_empty_abbrev_table (void *);
688 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
691 static char *read_partial_die (struct partial_die_info *,
692 bfd *, char *, struct dwarf2_cu *);
694 static char *read_full_die (struct die_info **, bfd *, char *,
695 struct dwarf2_cu *, int *);
697 static char *read_attribute (struct attribute *, struct attr_abbrev *,
698 bfd *, char *, struct dwarf2_cu *);
700 static char *read_attribute_value (struct attribute *, unsigned,
701 bfd *, char *, struct dwarf2_cu *);
703 static unsigned int read_1_byte (bfd *, char *);
705 static int read_1_signed_byte (bfd *, char *);
707 static unsigned int read_2_bytes (bfd *, char *);
709 static unsigned int read_4_bytes (bfd *, char *);
711 static unsigned long read_8_bytes (bfd *, char *);
713 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
716 static LONGEST read_initial_length (bfd *, char *,
717 struct comp_unit_head *, int *bytes_read);
719 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
722 static char *read_n_bytes (bfd *, char *, unsigned int);
724 static char *read_string (bfd *, char *, unsigned int *);
726 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
729 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
731 static long read_signed_leb128 (bfd *, char *, unsigned int *);
733 static void set_cu_language (unsigned int);
735 static struct attribute *dwarf_attr (struct die_info *, unsigned int);
737 static int die_is_declaration (struct die_info *);
739 static struct die_info *die_specification (struct die_info *die);
741 static void free_line_header (struct line_header *lh);
743 static struct line_header *(dwarf_decode_line_header
744 (unsigned int offset,
745 bfd *abfd, struct dwarf2_cu *cu));
747 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
750 static void dwarf2_start_subfile (char *, char *);
752 static struct symbol *new_symbol (struct die_info *, struct type *,
755 static void dwarf2_const_value (struct attribute *, struct symbol *,
758 static void dwarf2_const_value_data (struct attribute *attr,
762 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
764 static struct type *die_containing_type (struct die_info *,
768 static struct type *type_at_offset (unsigned int, struct objfile *);
771 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
773 static void read_type_die (struct die_info *, struct dwarf2_cu *);
775 static char *determine_prefix (struct die_info *die);
777 static char *typename_concat (const char *prefix, const char *suffix);
779 static char *class_name (struct die_info *die);
781 static void read_typedef (struct die_info *, struct dwarf2_cu *);
783 static void read_base_type (struct die_info *, struct dwarf2_cu *);
785 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
787 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
789 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
791 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
793 static int dwarf2_get_pc_bounds (struct die_info *,
794 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
796 static void get_scope_pc_bounds (struct die_info *,
797 CORE_ADDR *, CORE_ADDR *,
800 static void dwarf2_add_field (struct field_info *, struct die_info *,
803 static void dwarf2_attach_fields_to_type (struct field_info *,
804 struct type *, struct dwarf2_cu *);
806 static void dwarf2_add_member_fn (struct field_info *,
807 struct die_info *, struct type *,
810 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
811 struct type *, struct dwarf2_cu *);
813 static void read_structure_scope (struct die_info *, struct dwarf2_cu *);
815 static void read_common_block (struct die_info *, struct dwarf2_cu *);
817 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
819 static const char *namespace_name (struct die_info *die,
822 static void read_enumeration (struct die_info *, struct dwarf2_cu *);
824 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
826 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
828 static void read_array_type (struct die_info *, struct dwarf2_cu *);
830 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
832 static void read_tag_ptr_to_member_type (struct die_info *,
835 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
837 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
839 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
841 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
843 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
845 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
847 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
850 struct die_info *parent);
852 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
855 struct die_info *parent);
857 static void free_die_list (struct die_info *);
859 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
861 static void process_die (struct die_info *, struct dwarf2_cu *);
863 static char *dwarf2_linkage_name (struct die_info *);
865 static char *dwarf2_name (struct die_info *die);
867 static struct die_info *dwarf2_extension (struct die_info *die);
869 static char *dwarf_tag_name (unsigned int);
871 static char *dwarf_attr_name (unsigned int);
873 static char *dwarf_form_name (unsigned int);
875 static char *dwarf_stack_op_name (unsigned int);
877 static char *dwarf_bool_name (unsigned int);
879 static char *dwarf_type_encoding_name (unsigned int);
882 static char *dwarf_cfi_name (unsigned int);
884 struct die_info *copy_die (struct die_info *);
887 static struct die_info *sibling_die (struct die_info *);
889 static void dump_die (struct die_info *);
891 static void dump_die_list (struct die_info *);
893 static void store_in_ref_table (unsigned int, struct die_info *);
895 static void dwarf2_empty_hash_tables (void);
897 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
899 static int dwarf2_get_attr_constant_value (struct attribute *, int);
901 static struct die_info *follow_die_ref (unsigned int);
903 static struct type *dwarf2_fundamental_type (struct objfile *, int);
905 /* memory allocation interface */
907 static void dwarf2_free_tmp_obstack (void *);
909 static struct dwarf_block *dwarf_alloc_block (void);
911 static struct abbrev_info *dwarf_alloc_abbrev (void);
913 static struct die_info *dwarf_alloc_die (void);
915 static void initialize_cu_func_list (void);
917 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR);
919 static void dwarf_decode_macros (struct line_header *, unsigned int,
920 char *, bfd *, struct dwarf2_cu *);
922 static int attr_form_is_block (struct attribute *);
925 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
926 struct dwarf2_cu *cu);
928 /* Try to locate the sections we need for DWARF 2 debugging
929 information and return true if we have enough to do something. */
932 dwarf2_has_info (bfd *abfd)
934 dwarf_info_section = 0;
935 dwarf_abbrev_section = 0;
936 dwarf_line_section = 0;
937 dwarf_str_section = 0;
938 dwarf_macinfo_section = 0;
939 dwarf_frame_section = 0;
940 dwarf_eh_frame_section = 0;
941 dwarf_ranges_section = 0;
942 dwarf_loc_section = 0;
944 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
945 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
948 /* This function is mapped across the sections and remembers the
949 offset and size of each of the debugging sections we are interested
953 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
955 if (strcmp (sectp->name, INFO_SECTION) == 0)
957 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
958 dwarf_info_section = sectp;
960 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
962 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
963 dwarf_abbrev_section = sectp;
965 else if (strcmp (sectp->name, LINE_SECTION) == 0)
967 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
968 dwarf_line_section = sectp;
970 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
972 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
973 dwarf_pubnames_section = sectp;
975 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
977 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
978 dwarf_aranges_section = sectp;
980 else if (strcmp (sectp->name, LOC_SECTION) == 0)
982 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
983 dwarf_loc_section = sectp;
985 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
987 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
988 dwarf_macinfo_section = sectp;
990 else if (strcmp (sectp->name, STR_SECTION) == 0)
992 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
993 dwarf_str_section = sectp;
995 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
997 dwarf_frame_size = bfd_get_section_size_before_reloc (sectp);
998 dwarf_frame_section = sectp;
1000 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1002 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1003 if (aflag & SEC_HAS_CONTENTS)
1005 dwarf_eh_frame_size = bfd_get_section_size_before_reloc (sectp);
1006 dwarf_eh_frame_section = sectp;
1009 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1011 dwarf_ranges_size = bfd_get_section_size_before_reloc (sectp);
1012 dwarf_ranges_section = sectp;
1016 /* Build a partial symbol table. */
1019 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1022 /* We definitely need the .debug_info and .debug_abbrev sections */
1024 dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1025 dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1027 if (dwarf_line_section)
1028 dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1030 dwarf_line_buffer = NULL;
1032 if (dwarf_str_section)
1033 dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1035 dwarf_str_buffer = NULL;
1037 if (dwarf_macinfo_section)
1038 dwarf_macinfo_buffer = dwarf2_read_section (objfile,
1039 dwarf_macinfo_section);
1041 dwarf_macinfo_buffer = NULL;
1043 if (dwarf_ranges_section)
1044 dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1046 dwarf_ranges_buffer = NULL;
1048 if (dwarf_loc_section)
1049 dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1051 dwarf_loc_buffer = NULL;
1054 || (objfile->global_psymbols.size == 0
1055 && objfile->static_psymbols.size == 0))
1057 init_psymbol_list (objfile, 1024);
1061 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1063 /* Things are significantly easier if we have .debug_aranges and
1064 .debug_pubnames sections */
1066 dwarf2_build_psymtabs_easy (objfile, mainline);
1070 /* only test this case for now */
1072 /* In this case we have to work a bit harder */
1073 dwarf2_build_psymtabs_hard (objfile, mainline);
1078 /* Build the partial symbol table from the information in the
1079 .debug_pubnames and .debug_aranges sections. */
1082 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1084 bfd *abfd = objfile->obfd;
1085 char *aranges_buffer, *pubnames_buffer;
1086 char *aranges_ptr, *pubnames_ptr;
1087 unsigned int entry_length, version, info_offset, info_size;
1089 pubnames_buffer = dwarf2_read_section (objfile,
1090 dwarf_pubnames_section);
1091 pubnames_ptr = pubnames_buffer;
1092 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
1094 struct comp_unit_head cu_header;
1097 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1099 pubnames_ptr += bytes_read;
1100 version = read_1_byte (abfd, pubnames_ptr);
1102 info_offset = read_4_bytes (abfd, pubnames_ptr);
1104 info_size = read_4_bytes (abfd, pubnames_ptr);
1108 aranges_buffer = dwarf2_read_section (objfile,
1109 dwarf_aranges_section);
1114 /* Read in the comp unit header information from the debug_info at
1118 read_comp_unit_head (struct comp_unit_head *cu_header,
1119 char *info_ptr, bfd *abfd)
1123 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1125 info_ptr += bytes_read;
1126 cu_header->version = read_2_bytes (abfd, info_ptr);
1128 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1130 info_ptr += bytes_read;
1131 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1133 signed_addr = bfd_get_sign_extend_vma (abfd);
1134 if (signed_addr < 0)
1135 internal_error (__FILE__, __LINE__,
1136 "read_comp_unit_head: dwarf from non elf file");
1137 cu_header->signed_addr_p = signed_addr;
1141 /* Build the partial symbol table by doing a quick pass through the
1142 .debug_info and .debug_abbrev sections. */
1145 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1147 /* Instead of reading this into a big buffer, we should probably use
1148 mmap() on architectures that support it. (FIXME) */
1149 bfd *abfd = objfile->obfd;
1150 char *info_ptr, *abbrev_ptr;
1151 char *beg_of_comp_unit;
1152 struct partial_die_info comp_unit_die;
1153 struct partial_symtab *pst;
1154 struct cleanup *back_to;
1155 CORE_ADDR lowpc, highpc;
1157 info_ptr = dwarf_info_buffer;
1158 abbrev_ptr = dwarf_abbrev_buffer;
1160 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1161 the partial symbol scan, like attribute values.
1163 We could reduce our peak memory consumption during partial symbol
1164 table construction by freeing stuff from this obstack more often
1165 --- say, after processing each compilation unit, or each die ---
1166 but it turns out that this saves almost nothing. For an
1167 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1168 on dwarf2_tmp_obstack. Some investigation showed:
1170 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1171 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1172 all fixed-length values not requiring dynamic allocation.
1174 2) 30% of the attributes used the form DW_FORM_string. For
1175 DW_FORM_string, read_attribute simply hands back a pointer to
1176 the null-terminated string in dwarf_info_buffer, so no dynamic
1177 allocation is needed there either.
1179 3) The remaining 1% of the attributes all used DW_FORM_block1.
1180 75% of those were DW_AT_frame_base location lists for
1181 functions; the rest were DW_AT_location attributes, probably
1182 for the global variables.
1184 Anyway, what this all means is that the memory the dwarf2
1185 reader uses as temporary space reading partial symbols is about
1186 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1188 obstack_init (&dwarf2_tmp_obstack);
1189 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1191 /* Since the objects we're extracting from dwarf_info_buffer vary in
1192 length, only the individual functions to extract them (like
1193 read_comp_unit_head and read_partial_die) can really know whether
1194 the buffer is large enough to hold another complete object.
1196 At the moment, they don't actually check that. If
1197 dwarf_info_buffer holds just one extra byte after the last
1198 compilation unit's dies, then read_comp_unit_head will happily
1199 read off the end of the buffer. read_partial_die is similarly
1200 casual. Those functions should be fixed.
1202 For this loop condition, simply checking whether there's any data
1203 left at all should be sufficient. */
1204 while (info_ptr < dwarf_info_buffer + dwarf_info_size)
1206 struct dwarf2_cu cu;
1207 beg_of_comp_unit = info_ptr;
1209 cu.objfile = objfile;
1210 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1212 if (cu.header.version != 2)
1214 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));
1217 if (cu.header.abbrev_offset >= dwarf_abbrev_size)
1219 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]",
1220 (long) cu.header.abbrev_offset,
1221 (long) (beg_of_comp_unit - dwarf_info_buffer),
1222 bfd_get_filename (abfd));
1225 if (beg_of_comp_unit + cu.header.length + cu.header.initial_length_size
1226 > dwarf_info_buffer + dwarf_info_size)
1228 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]",
1229 (long) cu.header.length,
1230 (long) (beg_of_comp_unit - dwarf_info_buffer),
1231 bfd_get_filename (abfd));
1234 /* Complete the cu_header */
1235 cu.header.offset = beg_of_comp_unit - dwarf_info_buffer;
1236 cu.header.first_die_ptr = info_ptr;
1237 cu.header.cu_head_ptr = beg_of_comp_unit;
1239 /* Read the abbrevs for this compilation unit into a table */
1240 dwarf2_read_abbrevs (abfd, &cu);
1241 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1243 /* Read the compilation unit die */
1244 info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr,
1247 /* Set the language we're debugging */
1248 set_cu_language (comp_unit_die.language);
1250 /* Allocate a new partial symbol table structure */
1251 pst = start_psymtab_common (objfile, objfile->section_offsets,
1252 comp_unit_die.name ? comp_unit_die.name : "",
1253 comp_unit_die.lowpc,
1254 objfile->global_psymbols.next,
1255 objfile->static_psymbols.next);
1257 pst->read_symtab_private = (char *)
1258 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
1259 cu_header_offset = beg_of_comp_unit - dwarf_info_buffer;
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;
1450 /* If we're not in the global namespace and if the namespace name
1451 isn't encoded in a mangled actual_name, add it. */
1453 if (pdi_needs_namespace (pdi->tag, namespace))
1455 actual_name = alloca (strlen (pdi->name) + 2 + strlen (namespace) + 1);
1456 strcpy (actual_name, namespace);
1457 strcat (actual_name, "::");
1458 strcat (actual_name, pdi->name);
1463 case DW_TAG_subprogram:
1464 if (pdi->is_external)
1466 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1467 mst_text, objfile); */
1468 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1469 VAR_DOMAIN, LOC_BLOCK,
1470 &objfile->global_psymbols,
1471 0, pdi->lowpc + baseaddr,
1472 cu_language, objfile);
1476 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1477 mst_file_text, objfile); */
1478 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1479 VAR_DOMAIN, LOC_BLOCK,
1480 &objfile->static_psymbols,
1481 0, pdi->lowpc + baseaddr,
1482 cu_language, objfile);
1485 case DW_TAG_variable:
1486 if (pdi->is_external)
1489 Don't enter into the minimal symbol tables as there is
1490 a minimal symbol table entry from the ELF symbols already.
1491 Enter into partial symbol table if it has a location
1492 descriptor or a type.
1493 If the location descriptor is missing, new_symbol will create
1494 a LOC_UNRESOLVED symbol, the address of the variable will then
1495 be determined from the minimal symbol table whenever the variable
1497 The address for the partial symbol table entry is not
1498 used by GDB, but it comes in handy for debugging partial symbol
1502 addr = decode_locdesc (pdi->locdesc, cu);
1503 if (pdi->locdesc || pdi->has_type)
1504 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1505 VAR_DOMAIN, LOC_STATIC,
1506 &objfile->global_psymbols,
1508 cu_language, objfile);
1512 /* Static Variable. Skip symbols without location descriptors. */
1513 if (pdi->locdesc == NULL)
1515 addr = decode_locdesc (pdi->locdesc, cu);
1516 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1517 mst_file_data, objfile); */
1518 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1519 VAR_DOMAIN, LOC_STATIC,
1520 &objfile->static_psymbols,
1522 cu_language, objfile);
1525 case DW_TAG_typedef:
1526 case DW_TAG_base_type:
1527 case DW_TAG_subrange_type:
1528 add_psymbol_to_list (actual_name, strlen (actual_name),
1529 VAR_DOMAIN, LOC_TYPEDEF,
1530 &objfile->static_psymbols,
1531 0, (CORE_ADDR) 0, cu_language, objfile);
1533 case DW_TAG_class_type:
1534 case DW_TAG_structure_type:
1535 case DW_TAG_union_type:
1536 case DW_TAG_enumeration_type:
1537 /* Skip aggregate types without children, these are external
1539 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1540 static vs. global. */
1541 if (pdi->has_children == 0)
1543 add_psymbol_to_list (actual_name, strlen (actual_name),
1544 STRUCT_DOMAIN, LOC_TYPEDEF,
1545 cu_language == language_cplus
1546 ? &objfile->global_psymbols
1547 : &objfile->static_psymbols,
1548 0, (CORE_ADDR) 0, cu_language, objfile);
1550 if (cu_language == language_cplus)
1552 /* For C++, these implicitly act as typedefs as well. */
1553 add_psymbol_to_list (actual_name, strlen (actual_name),
1554 VAR_DOMAIN, LOC_TYPEDEF,
1555 &objfile->global_psymbols,
1556 0, (CORE_ADDR) 0, cu_language, objfile);
1559 case DW_TAG_enumerator:
1560 add_psymbol_to_list (actual_name, strlen (actual_name),
1561 VAR_DOMAIN, LOC_CONST,
1562 cu_language == language_cplus
1563 ? &objfile->static_psymbols
1564 : &objfile->global_psymbols,
1565 0, (CORE_ADDR) 0, cu_language, objfile);
1571 /* Check to see if we should scan the name for possible namespace
1572 info. Only do this if this is C++, if we don't have namespace
1573 debugging info in the file, if the psym is of an appropriate type
1574 (otherwise we'll have psym == NULL), and if we actually had a
1575 mangled name to begin with. */
1577 if (cu_language == language_cplus
1578 && namespace == NULL
1580 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1581 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1585 /* Determine whether a die of type TAG living in the C++ namespace
1586 NAMESPACE needs to have the name of the namespace prepended to the
1587 name listed in the die. */
1590 pdi_needs_namespace (enum dwarf_tag tag, const char *namespace)
1592 if (namespace == NULL || namespace[0] == '\0')
1597 case DW_TAG_typedef:
1598 case DW_TAG_class_type:
1599 case DW_TAG_structure_type:
1600 case DW_TAG_union_type:
1601 case DW_TAG_enumeration_type:
1602 case DW_TAG_enumerator:
1609 /* Read a partial die corresponding to a namespace; also, add a symbol
1610 corresponding to that namespace to the symbol table. NAMESPACE is
1611 the name of the enclosing namespace. */
1614 add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
1615 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1616 struct dwarf2_cu *cu, const char *namespace)
1618 struct objfile *objfile = cu->objfile;
1619 const char *new_name = pdi->name;
1622 /* Calculate the full name of the namespace that we just entered. */
1624 if (new_name == NULL)
1625 new_name = "(anonymous namespace)";
1626 full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1);
1627 strcpy (full_name, namespace);
1628 if (*namespace != '\0')
1629 strcat (full_name, "::");
1630 strcat (full_name, new_name);
1632 /* FIXME: carlton/2003-10-07: We can't just replace this by a call
1633 to add_partial_symbol, because we don't have a way to pass in the
1634 full name to that function; that might be a flaw in
1635 add_partial_symbol's interface. */
1637 add_psymbol_to_list (full_name, strlen (full_name),
1638 VAR_DOMAIN, LOC_TYPEDEF,
1639 &objfile->global_psymbols,
1640 0, 0, cu_language, objfile);
1642 /* Now scan partial symbols in that namespace. */
1644 if (pdi->has_children)
1645 info_ptr = scan_partial_symbols (info_ptr, lowpc, highpc, cu, full_name);
1650 /* Read a partial die corresponding to a class or structure. */
1653 add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
1654 struct dwarf2_cu *cu,
1655 const char *namespace)
1657 bfd *abfd = cu->objfile->obfd;
1658 char *actual_class_name = NULL;
1660 if (cu_language == language_cplus
1661 && namespace == NULL
1662 && struct_pdi->name != NULL
1663 && struct_pdi->has_children)
1665 /* We don't have namespace debugging information, so see if we
1666 can figure out if this structure lives in a namespace. Look
1667 for a member function; its demangled name will contain
1668 namespace info, if there is any. */
1670 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1671 what template types look like, because the demangler
1672 frequently doesn't give the same name as the debug info. We
1673 could fix this by only using the demangled name to get the
1674 prefix (but see comment in read_structure_scope). */
1676 char *next_child = info_ptr;
1680 struct partial_die_info child_pdi;
1682 next_child = read_partial_die (&child_pdi, abfd, next_child,
1686 if (child_pdi.tag == DW_TAG_subprogram)
1688 actual_class_name = class_name_from_physname (child_pdi.name);
1689 if (actual_class_name != NULL)
1690 struct_pdi->name = actual_class_name;
1695 next_child = locate_pdi_sibling (&child_pdi, next_child,
1701 add_partial_symbol (struct_pdi, cu, namespace);
1702 xfree(actual_class_name);
1704 return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu);
1707 /* Read a partial die corresponding to an enumeration type. */
1710 add_partial_enumeration (struct partial_die_info *enum_pdi, char *info_ptr,
1711 struct dwarf2_cu *cu, const char *namespace)
1713 struct objfile *objfile = cu->objfile;
1714 bfd *abfd = objfile->obfd;
1715 struct partial_die_info pdi;
1717 if (enum_pdi->name != NULL)
1718 add_partial_symbol (enum_pdi, cu, namespace);
1722 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1725 if (pdi.tag != DW_TAG_enumerator || pdi.name == NULL)
1726 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1728 add_partial_symbol (&pdi, cu, namespace);
1734 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the next DIE
1738 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
1739 bfd *abfd, struct dwarf2_cu *cu)
1741 /* Do we know the sibling already? */
1743 if (orig_pdi->sibling)
1744 return orig_pdi->sibling;
1746 /* Are there any children to deal with? */
1748 if (!orig_pdi->has_children)
1751 /* Okay, we don't know the sibling, but we have children that we
1752 want to skip. So read children until we run into one without a
1753 tag; return whatever follows it. */
1757 struct partial_die_info pdi;
1759 info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu);
1764 info_ptr = locate_pdi_sibling (&pdi, info_ptr, abfd, cu);
1768 /* Expand this partial symbol table into a full symbol table. */
1771 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
1773 /* FIXME: This is barely more than a stub. */
1778 warning ("bug: psymtab for %s is already read in.", pst->filename);
1784 printf_filtered ("Reading in symbols for %s...", pst->filename);
1785 gdb_flush (gdb_stdout);
1788 psymtab_to_symtab_1 (pst);
1790 /* Finish up the debug error message. */
1792 printf_filtered ("done.\n");
1798 psymtab_to_symtab_1 (struct partial_symtab *pst)
1800 struct objfile *objfile = pst->objfile;
1801 bfd *abfd = objfile->obfd;
1802 struct dwarf2_cu cu;
1803 struct die_info *dies;
1804 unsigned long offset;
1805 CORE_ADDR lowpc, highpc;
1806 struct die_info *child_die;
1808 struct symtab *symtab;
1809 struct cleanup *back_to;
1810 struct attribute *attr;
1812 /* Set local variables from the partial symbol table info. */
1813 offset = DWARF_INFO_OFFSET (pst);
1814 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1815 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1816 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1817 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1818 dwarf_line_size = DWARF_LINE_SIZE (pst);
1819 dwarf_str_buffer = DWARF_STR_BUFFER (pst);
1820 dwarf_str_size = DWARF_STR_SIZE (pst);
1821 dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst);
1822 dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst);
1823 dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst);
1824 dwarf_ranges_size = DWARF_RANGES_SIZE (pst);
1825 dwarf_loc_buffer = DWARF_LOC_BUFFER (pst);
1826 dwarf_loc_size = DWARF_LOC_SIZE (pst);
1827 baseaddr = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
1828 cu_header_offset = offset;
1829 info_ptr = dwarf_info_buffer + offset;
1831 /* We're in the global namespace. */
1832 processing_current_prefix = "";
1834 obstack_init (&dwarf2_tmp_obstack);
1835 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1838 make_cleanup (really_free_pendings, NULL);
1840 cu.objfile = objfile;
1842 /* read in the comp_unit header */
1843 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
1845 /* Read the abbrevs for this compilation unit */
1846 dwarf2_read_abbrevs (abfd, &cu);
1847 make_cleanup (dwarf2_empty_abbrev_table, cu.header.dwarf2_abbrevs);
1849 dies = read_comp_unit (info_ptr, abfd, &cu);
1851 make_cleanup_free_die_list (dies);
1853 /* Find the base address of the compilation unit for range lists and
1854 location lists. It will normally be specified by DW_AT_low_pc.
1855 In DWARF-3 draft 4, the base address could be overridden by
1856 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1857 compilation units with discontinuous ranges. */
1859 cu.header.base_known = 0;
1860 cu.header.base_address = 0;
1862 attr = dwarf_attr (dies, DW_AT_entry_pc);
1865 cu.header.base_address = DW_ADDR (attr);
1866 cu.header.base_known = 1;
1870 attr = dwarf_attr (dies, DW_AT_low_pc);
1873 cu.header.base_address = DW_ADDR (attr);
1874 cu.header.base_known = 1;
1878 /* Do line number decoding in read_file_scope () */
1879 process_die (dies, &cu);
1881 /* Some compilers don't define a DW_AT_high_pc attribute for the
1882 compilation unit. If the DW_AT_high_pc is missing, synthesize
1883 it, by scanning the DIE's below the compilation unit. */
1884 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
1886 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
1888 /* Set symtab language to language from DW_AT_language.
1889 If the compilation is from a C file generated by language preprocessors,
1890 do not set the language if it was already deduced by start_subfile. */
1892 && !(cu_language == language_c && symtab->language != language_c))
1894 symtab->language = cu_language;
1896 pst->symtab = symtab;
1899 do_cleanups (back_to);
1902 /* Process a die and its children. */
1905 process_die (struct die_info *die, struct dwarf2_cu *cu)
1909 case DW_TAG_padding:
1911 case DW_TAG_compile_unit:
1912 read_file_scope (die, cu);
1914 case DW_TAG_subprogram:
1915 read_subroutine_type (die, cu);
1916 read_func_scope (die, cu);
1918 case DW_TAG_inlined_subroutine:
1919 /* FIXME: These are ignored for now.
1920 They could be used to set breakpoints on all inlined instances
1921 of a function and make GDB `next' properly over inlined functions. */
1923 case DW_TAG_lexical_block:
1924 case DW_TAG_try_block:
1925 case DW_TAG_catch_block:
1926 read_lexical_block_scope (die, cu);
1928 case DW_TAG_class_type:
1929 case DW_TAG_structure_type:
1930 case DW_TAG_union_type:
1931 read_structure_scope (die, cu);
1933 case DW_TAG_enumeration_type:
1934 read_enumeration (die, cu);
1936 case DW_TAG_subroutine_type:
1937 read_subroutine_type (die, cu);
1939 case DW_TAG_array_type:
1940 read_array_type (die, cu);
1942 case DW_TAG_pointer_type:
1943 read_tag_pointer_type (die, cu);
1945 case DW_TAG_ptr_to_member_type:
1946 read_tag_ptr_to_member_type (die, cu);
1948 case DW_TAG_reference_type:
1949 read_tag_reference_type (die, cu);
1951 case DW_TAG_string_type:
1952 read_tag_string_type (die, cu);
1954 case DW_TAG_base_type:
1955 read_base_type (die, cu);
1956 if (dwarf_attr (die, DW_AT_name))
1958 /* Add a typedef symbol for the base type definition. */
1959 new_symbol (die, die->type, cu);
1962 case DW_TAG_subrange_type:
1963 read_subrange_type (die, cu);
1964 if (dwarf_attr (die, DW_AT_name))
1966 /* Add a typedef symbol for the base type definition. */
1967 new_symbol (die, die->type, cu);
1970 case DW_TAG_common_block:
1971 read_common_block (die, cu);
1973 case DW_TAG_common_inclusion:
1975 case DW_TAG_namespace:
1976 processing_has_namespace_info = 1;
1977 read_namespace (die, cu);
1979 case DW_TAG_imported_declaration:
1980 case DW_TAG_imported_module:
1981 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1982 information contained in these. DW_TAG_imported_declaration
1983 dies shouldn't have children; DW_TAG_imported_module dies
1984 shouldn't in the C++ case, but conceivably could in the
1985 Fortran case, so we'll have to replace this gdb_assert if
1986 Fortran compilers start generating that info. */
1987 processing_has_namespace_info = 1;
1988 gdb_assert (die->child == NULL);
1991 new_symbol (die, NULL, cu);
1997 initialize_cu_func_list (void)
1999 cu_first_fn = cu_last_fn = cu_cached_fn = NULL;
2003 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2005 struct objfile *objfile = cu->objfile;
2006 struct comp_unit_head *cu_header = &cu->header;
2007 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2008 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2009 CORE_ADDR highpc = ((CORE_ADDR) 0);
2010 struct attribute *attr;
2011 char *name = "<unknown>";
2012 char *comp_dir = NULL;
2013 struct die_info *child_die;
2014 bfd *abfd = objfile->obfd;
2015 struct line_header *line_header = 0;
2017 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2019 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2020 from finish_block. */
2021 if (lowpc == ((CORE_ADDR) -1))
2026 attr = dwarf_attr (die, DW_AT_name);
2029 name = DW_STRING (attr);
2031 attr = dwarf_attr (die, DW_AT_comp_dir);
2034 comp_dir = DW_STRING (attr);
2037 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2038 directory, get rid of it. */
2039 char *cp = strchr (comp_dir, ':');
2041 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2046 if (objfile->ei.entry_point >= lowpc &&
2047 objfile->ei.entry_point < highpc)
2049 objfile->ei.deprecated_entry_file_lowpc = lowpc;
2050 objfile->ei.deprecated_entry_file_highpc = highpc;
2053 attr = dwarf_attr (die, DW_AT_language);
2056 set_cu_language (DW_UNSND (attr));
2059 /* We assume that we're processing GCC output. */
2060 processing_gcc_compilation = 2;
2062 /* FIXME:Do something here. */
2063 if (dip->at_producer != NULL)
2065 handle_producer (dip->at_producer);
2069 /* The compilation unit may be in a different language or objfile,
2070 zero out all remembered fundamental types. */
2071 memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2073 start_symtab (name, comp_dir, lowpc);
2074 record_debugformat ("DWARF 2");
2076 initialize_cu_func_list ();
2078 /* Process all dies in compilation unit. */
2079 if (die->child != NULL)
2081 child_die = die->child;
2082 while (child_die && child_die->tag)
2084 process_die (child_die, cu);
2085 child_die = sibling_die (child_die);
2089 /* Decode line number information if present. */
2090 attr = dwarf_attr (die, DW_AT_stmt_list);
2093 unsigned int line_offset = DW_UNSND (attr);
2094 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2097 make_cleanup ((make_cleanup_ftype *) free_line_header,
2098 (void *) line_header);
2099 dwarf_decode_lines (line_header, comp_dir, abfd, cu);
2103 /* Decode macro information, if present. Dwarf 2 macro information
2104 refers to information in the line number info statement program
2105 header, so we can only read it if we've read the header
2107 attr = dwarf_attr (die, DW_AT_macro_info);
2108 if (attr && line_header)
2110 unsigned int macro_offset = DW_UNSND (attr);
2111 dwarf_decode_macros (line_header, macro_offset,
2112 comp_dir, abfd, cu);
2114 do_cleanups (back_to);
2118 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc)
2120 struct function_range *thisfn;
2122 thisfn = (struct function_range *)
2123 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range));
2124 thisfn->name = name;
2125 thisfn->lowpc = lowpc;
2126 thisfn->highpc = highpc;
2127 thisfn->seen_line = 0;
2128 thisfn->next = NULL;
2130 if (cu_last_fn == NULL)
2131 cu_first_fn = thisfn;
2133 cu_last_fn->next = thisfn;
2135 cu_last_fn = thisfn;
2139 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2141 struct objfile *objfile = cu->objfile;
2142 struct context_stack *new;
2145 struct die_info *child_die;
2146 struct attribute *attr;
2149 name = dwarf2_linkage_name (die);
2151 /* Ignore functions with missing or empty names and functions with
2152 missing or invalid low and high pc attributes. */
2153 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2159 /* Record the function range for dwarf_decode_lines. */
2160 add_to_cu_func_list (name, lowpc, highpc);
2162 if (objfile->ei.entry_point >= lowpc &&
2163 objfile->ei.entry_point < highpc)
2165 objfile->ei.entry_func_lowpc = lowpc;
2166 objfile->ei.entry_func_highpc = highpc;
2169 new = push_context (0, lowpc);
2170 new->name = new_symbol (die, die->type, cu);
2172 /* If there is a location expression for DW_AT_frame_base, record
2174 attr = dwarf_attr (die, DW_AT_frame_base);
2176 dwarf2_symbol_mark_computed (attr, new->name, cu);
2178 list_in_scope = &local_symbols;
2180 if (die->child != NULL)
2182 child_die = die->child;
2183 while (child_die && child_die->tag)
2185 process_die (child_die, cu);
2186 child_die = sibling_die (child_die);
2190 new = pop_context ();
2191 /* Make a block for the local symbols within. */
2192 finish_block (new->name, &local_symbols, new->old_blocks,
2193 lowpc, highpc, objfile);
2195 /* In C++, we can have functions nested inside functions (e.g., when
2196 a function declares a class that has methods). This means that
2197 when we finish processing a function scope, we may need to go
2198 back to building a containing block's symbol lists. */
2199 local_symbols = new->locals;
2200 param_symbols = new->params;
2202 /* If we've finished processing a top-level function, subsequent
2203 symbols go in the file symbol list. */
2204 if (outermost_context_p ())
2205 list_in_scope = &file_symbols;
2208 /* Process all the DIES contained within a lexical block scope. Start
2209 a new scope, process the dies, and then close the scope. */
2212 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2214 struct objfile *objfile = cu->objfile;
2215 struct context_stack *new;
2216 CORE_ADDR lowpc, highpc;
2217 struct die_info *child_die;
2219 /* Ignore blocks with missing or invalid low and high pc attributes. */
2220 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2221 as multiple lexical blocks? Handling children in a sane way would
2222 be nasty. Might be easier to properly extend generic blocks to
2224 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2229 push_context (0, lowpc);
2230 if (die->child != NULL)
2232 child_die = die->child;
2233 while (child_die && child_die->tag)
2235 process_die (child_die, cu);
2236 child_die = sibling_die (child_die);
2239 new = pop_context ();
2241 if (local_symbols != NULL)
2243 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2246 local_symbols = new->locals;
2249 /* Get low and high pc attributes from a die. Return 1 if the attributes
2250 are present and valid, otherwise, return 0. Return -1 if the range is
2251 discontinuous, i.e. derived from DW_AT_ranges information. */
2253 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2254 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2256 struct objfile *objfile = cu->objfile;
2257 struct comp_unit_head *cu_header = &cu->header;
2258 struct attribute *attr;
2259 bfd *obfd = objfile->obfd;
2264 attr = dwarf_attr (die, DW_AT_high_pc);
2267 high = DW_ADDR (attr);
2268 attr = dwarf_attr (die, DW_AT_low_pc);
2270 low = DW_ADDR (attr);
2272 /* Found high w/o low attribute. */
2275 /* Found consecutive range of addresses. */
2280 attr = dwarf_attr (die, DW_AT_ranges);
2283 unsigned int addr_size = cu_header->addr_size;
2284 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2285 /* Value of the DW_AT_ranges attribute is the offset in the
2286 .debug_ranges section. */
2287 unsigned int offset = DW_UNSND (attr);
2288 /* Base address selection entry. */
2296 found_base = cu_header->base_known;
2297 base = cu_header->base_address;
2299 if (offset >= dwarf_ranges_size)
2301 complaint (&symfile_complaints,
2302 "Offset %d out of bounds for DW_AT_ranges attribute",
2306 buffer = dwarf_ranges_buffer + offset;
2308 /* Read in the largest possible address. */
2309 marker = read_address (obfd, buffer, cu, &dummy);
2310 if ((marker & mask) == mask)
2312 /* If we found the largest possible address, then
2313 read the base address. */
2314 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2315 buffer += 2 * addr_size;
2316 offset += 2 * addr_size;
2324 CORE_ADDR range_beginning, range_end;
2326 range_beginning = read_address (obfd, buffer, cu, &dummy);
2327 buffer += addr_size;
2328 range_end = read_address (obfd, buffer, cu, &dummy);
2329 buffer += addr_size;
2330 offset += 2 * addr_size;
2332 /* An end of list marker is a pair of zero addresses. */
2333 if (range_beginning == 0 && range_end == 0)
2334 /* Found the end of list entry. */
2337 /* Each base address selection entry is a pair of 2 values.
2338 The first is the largest possible address, the second is
2339 the base address. Check for a base address here. */
2340 if ((range_beginning & mask) == mask)
2342 /* If we found the largest possible address, then
2343 read the base address. */
2344 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2351 /* We have no valid base address for the ranges
2353 complaint (&symfile_complaints,
2354 "Invalid .debug_ranges data (no base address)");
2358 range_beginning += base;
2361 /* FIXME: This is recording everything as a low-high
2362 segment of consecutive addresses. We should have a
2363 data structure for discontiguous block ranges
2367 low = range_beginning;
2373 if (range_beginning < low)
2374 low = range_beginning;
2375 if (range_end > high)
2381 /* If the first entry is an end-of-list marker, the range
2382 describes an empty scope, i.e. no instructions. */
2392 /* When using the GNU linker, .gnu.linkonce. sections are used to
2393 eliminate duplicate copies of functions and vtables and such.
2394 The linker will arbitrarily choose one and discard the others.
2395 The AT_*_pc values for such functions refer to local labels in
2396 these sections. If the section from that file was discarded, the
2397 labels are not in the output, so the relocs get a value of 0.
2398 If this is a discarded function, mark the pc bounds as invalid,
2399 so that GDB will ignore it. */
2400 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2408 /* Get the low and high pc's represented by the scope DIE, and store
2409 them in *LOWPC and *HIGHPC. If the correct values can't be
2410 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2413 get_scope_pc_bounds (struct die_info *die,
2414 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2415 struct dwarf2_cu *cu)
2417 CORE_ADDR best_low = (CORE_ADDR) -1;
2418 CORE_ADDR best_high = (CORE_ADDR) 0;
2419 CORE_ADDR current_low, current_high;
2421 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu))
2423 best_low = current_low;
2424 best_high = current_high;
2428 struct die_info *child = die->child;
2430 while (child && child->tag)
2432 switch (child->tag) {
2433 case DW_TAG_subprogram:
2434 if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu))
2436 best_low = min (best_low, current_low);
2437 best_high = max (best_high, current_high);
2440 case DW_TAG_namespace:
2441 /* FIXME: carlton/2004-01-16: Should we do this for
2442 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2443 that current GCC's always emit the DIEs corresponding
2444 to definitions of methods of classes as children of a
2445 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2446 the DIEs giving the declarations, which could be
2447 anywhere). But I don't see any reason why the
2448 standards says that they have to be there. */
2449 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
2451 if (current_low != ((CORE_ADDR) -1))
2453 best_low = min (best_low, current_low);
2454 best_high = max (best_high, current_high);
2462 child = sibling_die (child);
2467 *highpc = best_high;
2470 /* Add an aggregate field to the field list. */
2473 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2474 struct dwarf2_cu *cu)
2476 struct objfile *objfile = cu->objfile;
2477 struct nextfield *new_field;
2478 struct attribute *attr;
2480 char *fieldname = "";
2482 /* Allocate a new field list entry and link it in. */
2483 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2484 make_cleanup (xfree, new_field);
2485 memset (new_field, 0, sizeof (struct nextfield));
2486 new_field->next = fip->fields;
2487 fip->fields = new_field;
2490 /* Handle accessibility and virtuality of field.
2491 The default accessibility for members is public, the default
2492 accessibility for inheritance is private. */
2493 if (die->tag != DW_TAG_inheritance)
2494 new_field->accessibility = DW_ACCESS_public;
2496 new_field->accessibility = DW_ACCESS_private;
2497 new_field->virtuality = DW_VIRTUALITY_none;
2499 attr = dwarf_attr (die, DW_AT_accessibility);
2501 new_field->accessibility = DW_UNSND (attr);
2502 if (new_field->accessibility != DW_ACCESS_public)
2503 fip->non_public_fields = 1;
2504 attr = dwarf_attr (die, DW_AT_virtuality);
2506 new_field->virtuality = DW_UNSND (attr);
2508 fp = &new_field->field;
2510 if (die->tag == DW_TAG_member && ! die_is_declaration (die))
2512 /* Data member other than a C++ static data member. */
2514 /* Get type of field. */
2515 fp->type = die_type (die, cu);
2517 FIELD_STATIC_KIND (*fp) = 0;
2519 /* Get bit size of field (zero if none). */
2520 attr = dwarf_attr (die, DW_AT_bit_size);
2523 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2527 FIELD_BITSIZE (*fp) = 0;
2530 /* Get bit offset of field. */
2531 attr = dwarf_attr (die, DW_AT_data_member_location);
2534 FIELD_BITPOS (*fp) =
2535 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2538 FIELD_BITPOS (*fp) = 0;
2539 attr = dwarf_attr (die, DW_AT_bit_offset);
2542 if (BITS_BIG_ENDIAN)
2544 /* For big endian bits, the DW_AT_bit_offset gives the
2545 additional bit offset from the MSB of the containing
2546 anonymous object to the MSB of the field. We don't
2547 have to do anything special since we don't need to
2548 know the size of the anonymous object. */
2549 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2553 /* For little endian bits, compute the bit offset to the
2554 MSB of the anonymous object, subtract off the number of
2555 bits from the MSB of the field to the MSB of the
2556 object, and then subtract off the number of bits of
2557 the field itself. The result is the bit offset of
2558 the LSB of the field. */
2560 int bit_offset = DW_UNSND (attr);
2562 attr = dwarf_attr (die, DW_AT_byte_size);
2565 /* The size of the anonymous object containing
2566 the bit field is explicit, so use the
2567 indicated size (in bytes). */
2568 anonymous_size = DW_UNSND (attr);
2572 /* The size of the anonymous object containing
2573 the bit field must be inferred from the type
2574 attribute of the data member containing the
2576 anonymous_size = TYPE_LENGTH (fp->type);
2578 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2579 - bit_offset - FIELD_BITSIZE (*fp);
2583 /* Get name of field. */
2584 attr = dwarf_attr (die, DW_AT_name);
2585 if (attr && DW_STRING (attr))
2586 fieldname = DW_STRING (attr);
2587 fp->name = obsavestring (fieldname, strlen (fieldname),
2588 &objfile->type_obstack);
2590 /* Change accessibility for artificial fields (e.g. virtual table
2591 pointer or virtual base class pointer) to private. */
2592 if (dwarf_attr (die, DW_AT_artificial))
2594 new_field->accessibility = DW_ACCESS_private;
2595 fip->non_public_fields = 1;
2598 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2600 /* C++ static member. */
2602 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2603 is a declaration, but all versions of G++ as of this writing
2604 (so through at least 3.2.1) incorrectly generate
2605 DW_TAG_variable tags. */
2609 /* Get name of field. */
2610 attr = dwarf_attr (die, DW_AT_name);
2611 if (attr && DW_STRING (attr))
2612 fieldname = DW_STRING (attr);
2616 /* Get physical name. */
2617 physname = dwarf2_linkage_name (die);
2619 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
2620 &objfile->type_obstack));
2621 FIELD_TYPE (*fp) = die_type (die, cu);
2622 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
2623 &objfile->type_obstack);
2625 else if (die->tag == DW_TAG_inheritance)
2627 /* C++ base class field. */
2628 attr = dwarf_attr (die, DW_AT_data_member_location);
2630 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
2632 FIELD_BITSIZE (*fp) = 0;
2633 FIELD_STATIC_KIND (*fp) = 0;
2634 FIELD_TYPE (*fp) = die_type (die, cu);
2635 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
2636 fip->nbaseclasses++;
2640 /* Create the vector of fields, and attach it to the type. */
2643 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
2644 struct dwarf2_cu *cu)
2646 int nfields = fip->nfields;
2648 /* Record the field count, allocate space for the array of fields,
2649 and create blank accessibility bitfields if necessary. */
2650 TYPE_NFIELDS (type) = nfields;
2651 TYPE_FIELDS (type) = (struct field *)
2652 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2653 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2655 if (fip->non_public_fields)
2657 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2659 TYPE_FIELD_PRIVATE_BITS (type) =
2660 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2661 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2663 TYPE_FIELD_PROTECTED_BITS (type) =
2664 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2665 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2667 TYPE_FIELD_IGNORE_BITS (type) =
2668 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2669 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2672 /* If the type has baseclasses, allocate and clear a bit vector for
2673 TYPE_FIELD_VIRTUAL_BITS. */
2674 if (fip->nbaseclasses)
2676 int num_bytes = B_BYTES (fip->nbaseclasses);
2679 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2680 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2681 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2682 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
2683 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
2686 /* Copy the saved-up fields into the field vector. Start from the head
2687 of the list, adding to the tail of the field array, so that they end
2688 up in the same order in the array in which they were added to the list. */
2689 while (nfields-- > 0)
2691 TYPE_FIELD (type, nfields) = fip->fields->field;
2692 switch (fip->fields->accessibility)
2694 case DW_ACCESS_private:
2695 SET_TYPE_FIELD_PRIVATE (type, nfields);
2698 case DW_ACCESS_protected:
2699 SET_TYPE_FIELD_PROTECTED (type, nfields);
2702 case DW_ACCESS_public:
2706 /* Unknown accessibility. Complain and treat it as public. */
2708 complaint (&symfile_complaints, "unsupported accessibility %d",
2709 fip->fields->accessibility);
2713 if (nfields < fip->nbaseclasses)
2715 switch (fip->fields->virtuality)
2717 case DW_VIRTUALITY_virtual:
2718 case DW_VIRTUALITY_pure_virtual:
2719 SET_TYPE_FIELD_VIRTUAL (type, nfields);
2723 fip->fields = fip->fields->next;
2727 /* Add a member function to the proper fieldlist. */
2730 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
2731 struct type *type, struct dwarf2_cu *cu)
2733 struct objfile *objfile = cu->objfile;
2734 struct attribute *attr;
2735 struct fnfieldlist *flp;
2737 struct fn_field *fnp;
2740 struct nextfnfield *new_fnfield;
2742 /* Get name of member function. */
2743 attr = dwarf_attr (die, DW_AT_name);
2744 if (attr && DW_STRING (attr))
2745 fieldname = DW_STRING (attr);
2749 /* Get the mangled name. */
2750 physname = dwarf2_linkage_name (die);
2752 /* Look up member function name in fieldlist. */
2753 for (i = 0; i < fip->nfnfields; i++)
2755 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
2759 /* Create new list element if necessary. */
2760 if (i < fip->nfnfields)
2761 flp = &fip->fnfieldlists[i];
2764 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2766 fip->fnfieldlists = (struct fnfieldlist *)
2767 xrealloc (fip->fnfieldlists,
2768 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2769 * sizeof (struct fnfieldlist));
2770 if (fip->nfnfields == 0)
2771 make_cleanup (free_current_contents, &fip->fnfieldlists);
2773 flp = &fip->fnfieldlists[fip->nfnfields];
2774 flp->name = fieldname;
2780 /* Create a new member function field and chain it to the field list
2782 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2783 make_cleanup (xfree, new_fnfield);
2784 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2785 new_fnfield->next = flp->head;
2786 flp->head = new_fnfield;
2789 /* Fill in the member function field info. */
2790 fnp = &new_fnfield->fnfield;
2791 fnp->physname = obsavestring (physname, strlen (physname),
2792 &objfile->type_obstack);
2793 fnp->type = alloc_type (objfile);
2794 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2796 int nparams = TYPE_NFIELDS (die->type);
2798 /* TYPE is the domain of this method, and DIE->TYPE is the type
2799 of the method itself (TYPE_CODE_METHOD). */
2800 smash_to_method_type (fnp->type, type,
2801 TYPE_TARGET_TYPE (die->type),
2802 TYPE_FIELDS (die->type),
2803 TYPE_NFIELDS (die->type),
2804 TYPE_VARARGS (die->type));
2806 /* Handle static member functions.
2807 Dwarf2 has no clean way to discern C++ static and non-static
2808 member functions. G++ helps GDB by marking the first
2809 parameter for non-static member functions (which is the
2810 this pointer) as artificial. We obtain this information
2811 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2812 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2813 fnp->voffset = VOFFSET_STATIC;
2816 complaint (&symfile_complaints, "member function type missing for '%s'",
2819 /* Get fcontext from DW_AT_containing_type if present. */
2820 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2821 fnp->fcontext = die_containing_type (die, cu);
2823 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2824 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2826 /* Get accessibility. */
2827 attr = dwarf_attr (die, DW_AT_accessibility);
2830 switch (DW_UNSND (attr))
2832 case DW_ACCESS_private:
2833 fnp->is_private = 1;
2835 case DW_ACCESS_protected:
2836 fnp->is_protected = 1;
2841 /* Check for artificial methods. */
2842 attr = dwarf_attr (die, DW_AT_artificial);
2843 if (attr && DW_UNSND (attr) != 0)
2844 fnp->is_artificial = 1;
2846 /* Get index in virtual function table if it is a virtual member function. */
2847 attr = dwarf_attr (die, DW_AT_vtable_elem_location);
2850 /* Support the .debug_loc offsets */
2851 if (attr_form_is_block (attr))
2853 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
2855 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
2857 dwarf2_complex_location_expr_complaint ();
2861 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2867 /* Create the vector of member function fields, and attach it to the type. */
2870 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
2871 struct dwarf2_cu *cu)
2873 struct fnfieldlist *flp;
2874 int total_length = 0;
2877 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2878 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2879 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2881 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2883 struct nextfnfield *nfp = flp->head;
2884 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2887 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2888 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2889 fn_flp->fn_fields = (struct fn_field *)
2890 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2891 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2892 fn_flp->fn_fields[k] = nfp->fnfield;
2894 total_length += flp->length;
2897 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2898 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2901 /* Called when we find the DIE that starts a structure or union scope
2902 (definition) to process all dies that define the members of the
2905 NOTE: we need to call struct_type regardless of whether or not the
2906 DIE has an at_name attribute, since it might be an anonymous
2907 structure or union. This gets the type entered into our set of
2910 However, if the structure is incomplete (an opaque struct/union)
2911 then suppress creating a symbol table entry for it since gdb only
2912 wants to find the one with the complete definition. Note that if
2913 it is complete, we just call new_symbol, which does it's own
2914 checking about whether the struct/union is anonymous or not (and
2915 suppresses creating a symbol table entry itself). */
2918 read_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
2920 struct objfile *objfile = cu->objfile;
2922 struct attribute *attr;
2923 const char *name = NULL;
2924 const char *previous_prefix = processing_current_prefix;
2925 struct cleanup *back_to = NULL;
2926 /* This says whether or not we want to try to update the structure's
2927 name to include enclosing namespace/class information, if
2929 int need_to_update_name = 0;
2931 type = alloc_type (objfile);
2933 INIT_CPLUS_SPECIFIC (type);
2934 attr = dwarf_attr (die, DW_AT_name);
2935 if (attr && DW_STRING (attr))
2937 name = DW_STRING (attr);
2939 if (cu_language == language_cplus)
2941 struct die_info *spec_die = die_specification (die);
2943 if (spec_die != NULL)
2945 char *specification_prefix = determine_prefix (spec_die);
2946 processing_current_prefix = specification_prefix;
2947 back_to = make_cleanup (xfree, specification_prefix);
2951 if (processing_has_namespace_info)
2953 /* FIXME: carlton/2003-11-10: This variable exists only for
2954 const-correctness reasons. When I tried to change
2955 TYPE_TAG_NAME to be a const char *, I ran into a cascade
2956 of changes which would have forced decode_line_1 to take
2958 char *new_prefix = obconcat (&objfile->type_obstack,
2959 processing_current_prefix,
2960 processing_current_prefix[0] == '\0'
2963 TYPE_TAG_NAME (type) = new_prefix;
2964 processing_current_prefix = new_prefix;
2968 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
2969 &objfile->type_obstack);
2970 need_to_update_name = (cu_language == language_cplus);
2974 if (die->tag == DW_TAG_structure_type)
2976 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2978 else if (die->tag == DW_TAG_union_type)
2980 TYPE_CODE (type) = TYPE_CODE_UNION;
2984 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2986 TYPE_CODE (type) = TYPE_CODE_CLASS;
2989 attr = dwarf_attr (die, DW_AT_byte_size);
2992 TYPE_LENGTH (type) = DW_UNSND (attr);
2996 TYPE_LENGTH (type) = 0;
2999 /* We need to add the type field to the die immediately so we don't
3000 infinitely recurse when dealing with pointers to the structure
3001 type within the structure itself. */
3004 if (die->child != NULL && ! die_is_declaration (die))
3006 struct field_info fi;
3007 struct die_info *child_die;
3008 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3010 memset (&fi, 0, sizeof (struct field_info));
3012 child_die = die->child;
3014 while (child_die && child_die->tag)
3016 if (child_die->tag == DW_TAG_member
3017 || child_die->tag == DW_TAG_variable)
3019 /* NOTE: carlton/2002-11-05: A C++ static data member
3020 should be a DW_TAG_member that is a declaration, but
3021 all versions of G++ as of this writing (so through at
3022 least 3.2.1) incorrectly generate DW_TAG_variable
3023 tags for them instead. */
3024 dwarf2_add_field (&fi, child_die, cu);
3026 else if (child_die->tag == DW_TAG_subprogram)
3028 /* C++ member function. */
3029 process_die (child_die, cu);
3030 dwarf2_add_member_fn (&fi, child_die, type, cu);
3031 if (need_to_update_name)
3033 /* The demangled names of member functions contain
3034 information about enclosing namespaces/classes,
3037 /* FIXME: carlton/2003-11-10: The excessive
3038 demangling here is a bit wasteful, as is the
3039 memory usage for names. */
3041 /* NOTE: carlton/2003-11-10: As commented in
3042 add_partial_structure, the demangler sometimes
3043 prints the type info in a different form from the
3044 debug info. We could solve this by using the
3045 demangled name to get the prefix; if doing so,
3046 however, we'd need to be careful when reading a
3047 class that's nested inside a template class.
3048 That would also cause problems when trying to
3049 determine RTTI information, since we use the
3050 demangler to determine the appropriate class
3052 char *actual_class_name
3053 = class_name_from_physname (dwarf2_linkage_name
3055 if (actual_class_name != NULL
3056 && strcmp (actual_class_name, name) != 0)
3058 TYPE_TAG_NAME (type)
3059 = obsavestring (actual_class_name,
3060 strlen (actual_class_name),
3061 &objfile->type_obstack);
3063 xfree (actual_class_name);
3064 need_to_update_name = 0;
3067 else if (child_die->tag == DW_TAG_inheritance)
3069 /* C++ base class field. */
3070 dwarf2_add_field (&fi, child_die, cu);
3074 process_die (child_die, cu);
3076 child_die = sibling_die (child_die);
3079 /* Attach fields and member functions to the type. */
3081 dwarf2_attach_fields_to_type (&fi, type, cu);
3084 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3086 /* Get the type which refers to the base class (possibly this
3087 class itself) which contains the vtable pointer for the current
3088 class from the DW_AT_containing_type attribute. */
3090 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
3092 struct type *t = die_containing_type (die, cu);
3094 TYPE_VPTR_BASETYPE (type) = t;
3097 static const char vptr_name[] =
3098 {'_', 'v', 'p', 't', 'r', '\0'};
3101 /* Our own class provides vtbl ptr. */
3102 for (i = TYPE_NFIELDS (t) - 1;
3103 i >= TYPE_N_BASECLASSES (t);
3106 char *fieldname = TYPE_FIELD_NAME (t, i);
3108 if ((strncmp (fieldname, vptr_name,
3109 strlen (vptr_name) - 1)
3111 && is_cplus_marker (fieldname[strlen (vptr_name)]))
3113 TYPE_VPTR_FIELDNO (type) = i;
3118 /* Complain if virtual function table field not found. */
3119 if (i < TYPE_N_BASECLASSES (t))
3120 complaint (&symfile_complaints,
3121 "virtual function table pointer not found when defining class '%s'",
3122 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3127 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3132 new_symbol (die, type, cu);
3134 do_cleanups (back_to);
3138 /* No children, must be stub. */
3139 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3142 processing_current_prefix = previous_prefix;
3143 if (back_to != NULL)
3144 do_cleanups (back_to);
3147 /* Given a pointer to a die which begins an enumeration, process all
3148 the dies that define the members of the enumeration.
3150 This will be much nicer in draft 6 of the DWARF spec when our
3151 members will be dies instead squished into the DW_AT_element_list
3154 NOTE: We reverse the order of the element list. */
3157 read_enumeration (struct die_info *die, struct dwarf2_cu *cu)
3159 struct objfile *objfile = cu->objfile;
3160 struct die_info *child_die;
3162 struct field *fields;
3163 struct attribute *attr;
3166 int unsigned_enum = 1;
3168 type = alloc_type (objfile);
3170 TYPE_CODE (type) = TYPE_CODE_ENUM;
3171 attr = dwarf_attr (die, DW_AT_name);
3172 if (attr && DW_STRING (attr))
3174 const char *name = DW_STRING (attr);
3176 if (processing_has_namespace_info)
3178 TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
3179 processing_current_prefix,
3180 processing_current_prefix[0] == '\0'
3186 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
3187 &objfile->type_obstack);
3191 attr = dwarf_attr (die, DW_AT_byte_size);
3194 TYPE_LENGTH (type) = DW_UNSND (attr);
3198 TYPE_LENGTH (type) = 0;
3203 if (die->child != NULL)
3205 child_die = die->child;
3206 while (child_die && child_die->tag)
3208 if (child_die->tag != DW_TAG_enumerator)
3210 process_die (child_die, cu);
3214 attr = dwarf_attr (child_die, DW_AT_name);
3217 sym = new_symbol (child_die, type, cu);
3218 if (SYMBOL_VALUE (sym) < 0)
3221 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3223 fields = (struct field *)
3225 (num_fields + DW_FIELD_ALLOC_CHUNK)
3226 * sizeof (struct field));
3229 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3230 FIELD_TYPE (fields[num_fields]) = NULL;
3231 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3232 FIELD_BITSIZE (fields[num_fields]) = 0;
3233 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3239 child_die = sibling_die (child_die);
3244 TYPE_NFIELDS (type) = num_fields;
3245 TYPE_FIELDS (type) = (struct field *)
3246 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
3247 memcpy (TYPE_FIELDS (type), fields,
3248 sizeof (struct field) * num_fields);
3252 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
3255 new_symbol (die, type, cu);
3258 /* Extract all information from a DW_TAG_array_type DIE and put it in
3259 the DIE's type field. For now, this only handles one dimensional
3263 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3265 struct objfile *objfile = cu->objfile;
3266 struct die_info *child_die;
3267 struct type *type = NULL;
3268 struct type *element_type, *range_type, *index_type;
3269 struct type **range_types = NULL;
3270 struct attribute *attr;
3272 struct cleanup *back_to;
3274 /* Return if we've already decoded this type. */
3280 element_type = die_type (die, cu);
3282 /* Irix 6.2 native cc creates array types without children for
3283 arrays with unspecified length. */
3284 if (die->child == NULL)
3286 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
3287 range_type = create_range_type (NULL, index_type, 0, -1);
3288 die->type = create_array_type (NULL, element_type, range_type);
3292 back_to = make_cleanup (null_cleanup, NULL);
3293 child_die = die->child;
3294 while (child_die && child_die->tag)
3296 if (child_die->tag == DW_TAG_subrange_type)
3298 read_subrange_type (child_die, cu);
3300 if (child_die->type != NULL)
3302 /* The range type was succesfully read. Save it for
3303 the array type creation. */
3304 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3306 range_types = (struct type **)
3307 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3308 * sizeof (struct type *));
3310 make_cleanup (free_current_contents, &range_types);
3312 range_types[ndim++] = child_die->type;
3315 child_die = sibling_die (child_die);
3318 /* Dwarf2 dimensions are output from left to right, create the
3319 necessary array types in backwards order. */
3320 type = element_type;
3322 type = create_array_type (NULL, type, range_types[ndim]);
3324 /* Understand Dwarf2 support for vector types (like they occur on
3325 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3326 array type. This is not part of the Dwarf2/3 standard yet, but a
3327 custom vendor extension. The main difference between a regular
3328 array and the vector variant is that vectors are passed by value
3330 attr = dwarf_attr (die, DW_AT_GNU_vector);
3332 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3334 do_cleanups (back_to);
3336 /* Install the type in the die. */
3340 /* First cut: install each common block member as a global variable. */
3343 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3345 struct die_info *child_die;
3346 struct attribute *attr;
3348 CORE_ADDR base = (CORE_ADDR) 0;
3350 attr = dwarf_attr (die, DW_AT_location);
3353 /* Support the .debug_loc offsets */
3354 if (attr_form_is_block (attr))
3356 base = decode_locdesc (DW_BLOCK (attr), cu);
3358 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3360 dwarf2_complex_location_expr_complaint ();
3364 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3365 "common block member");
3368 if (die->child != NULL)
3370 child_die = die->child;
3371 while (child_die && child_die->tag)
3373 sym = new_symbol (child_die, NULL, cu);
3374 attr = dwarf_attr (child_die, DW_AT_data_member_location);
3377 SYMBOL_VALUE_ADDRESS (sym) =
3378 base + decode_locdesc (DW_BLOCK (attr), cu);
3379 add_symbol_to_list (sym, &global_symbols);
3381 child_die = sibling_die (child_die);
3386 /* Read a C++ namespace. */
3389 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3391 struct objfile *objfile = cu->objfile;
3392 const char *previous_prefix = processing_current_prefix;
3395 struct die_info *current_die;
3397 name = namespace_name (die, &is_anonymous);
3399 /* Now build the name of the current namespace. */
3401 if (previous_prefix[0] == '\0')
3403 processing_current_prefix = name;
3407 /* We need temp_name around because processing_current_prefix
3408 is a const char *. */
3409 char *temp_name = alloca (strlen (previous_prefix)
3410 + 2 + strlen(name) + 1);
3411 strcpy (temp_name, previous_prefix);
3412 strcat (temp_name, "::");
3413 strcat (temp_name, name);
3415 processing_current_prefix = temp_name;
3418 /* Add a symbol associated to this if we haven't seen the namespace
3419 before. Also, add a using directive if it's an anonymous
3422 if (dwarf2_extension (die) == NULL)
3426 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3427 this cast will hopefully become unnecessary. */
3428 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3429 (char *) processing_current_prefix,
3431 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3433 new_symbol (die, type, cu);
3436 cp_add_using_directive (processing_current_prefix,
3437 strlen (previous_prefix),
3438 strlen (processing_current_prefix));
3441 if (die->child != NULL)
3443 struct die_info *child_die = die->child;
3445 while (child_die && child_die->tag)
3447 process_die (child_die, cu);
3448 child_die = sibling_die (child_die);
3452 processing_current_prefix = previous_prefix;
3455 /* Return the name of the namespace represented by DIE. Set
3456 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3460 namespace_name (struct die_info *die, int *is_anonymous)
3462 struct die_info *current_die;
3463 const char *name = NULL;
3465 /* Loop through the extensions until we find a name. */
3467 for (current_die = die;
3468 current_die != NULL;
3469 current_die = dwarf2_extension (die))
3471 name = dwarf2_name (current_die);
3476 /* Is it an anonymous namespace? */
3478 *is_anonymous = (name == NULL);
3480 name = "(anonymous namespace)";
3485 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3486 the user defined type vector. */
3489 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3491 struct comp_unit_head *cu_header = &cu->header;
3493 struct attribute *attr_byte_size;
3494 struct attribute *attr_address_class;
3495 int byte_size, addr_class;
3502 type = lookup_pointer_type (die_type (die, cu));
3504 attr_byte_size = dwarf_attr (die, DW_AT_byte_size);
3506 byte_size = DW_UNSND (attr_byte_size);
3508 byte_size = cu_header->addr_size;
3510 attr_address_class = dwarf_attr (die, DW_AT_address_class);
3511 if (attr_address_class)
3512 addr_class = DW_UNSND (attr_address_class);
3514 addr_class = DW_ADDR_none;
3516 /* If the pointer size or address class is different than the
3517 default, create a type variant marked as such and set the
3518 length accordingly. */
3519 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3521 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3525 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
3526 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
3527 type = make_type_with_address_space (type, type_flags);
3529 else if (TYPE_LENGTH (type) != byte_size)
3531 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
3534 /* Should we also complain about unhandled address classes? */
3538 TYPE_LENGTH (type) = byte_size;
3542 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3543 the user defined type vector. */
3546 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
3548 struct objfile *objfile = cu->objfile;
3550 struct type *to_type;
3551 struct type *domain;
3558 type = alloc_type (objfile);
3559 to_type = die_type (die, cu);
3560 domain = die_containing_type (die, cu);
3561 smash_to_member_type (type, domain, to_type);
3566 /* Extract all information from a DW_TAG_reference_type DIE and add to
3567 the user defined type vector. */
3570 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
3572 struct comp_unit_head *cu_header = &cu->header;
3574 struct attribute *attr;
3581 type = lookup_reference_type (die_type (die, cu));
3582 attr = dwarf_attr (die, DW_AT_byte_size);
3585 TYPE_LENGTH (type) = DW_UNSND (attr);
3589 TYPE_LENGTH (type) = cu_header->addr_size;
3595 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
3597 struct type *base_type;
3604 base_type = die_type (die, cu);
3605 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
3609 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
3611 struct type *base_type;
3618 base_type = die_type (die, cu);
3619 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
3622 /* Extract all information from a DW_TAG_string_type DIE and add to
3623 the user defined type vector. It isn't really a user defined type,
3624 but it behaves like one, with other DIE's using an AT_user_def_type
3625 attribute to reference it. */
3628 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
3630 struct objfile *objfile = cu->objfile;
3631 struct type *type, *range_type, *index_type, *char_type;
3632 struct attribute *attr;
3633 unsigned int length;
3640 attr = dwarf_attr (die, DW_AT_string_length);
3643 length = DW_UNSND (attr);
3647 /* check for the DW_AT_byte_size attribute */
3648 attr = dwarf_attr (die, DW_AT_byte_size);
3651 length = DW_UNSND (attr);
3658 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
3659 range_type = create_range_type (NULL, index_type, 1, length);
3660 if (cu_language == language_fortran)
3662 /* Need to create a unique string type for bounds
3664 type = create_string_type (0, range_type);
3668 char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
3669 type = create_string_type (char_type, range_type);
3674 /* Handle DIES due to C code like:
3678 int (*funcp)(int a, long l);
3682 ('funcp' generates a DW_TAG_subroutine_type DIE)
3686 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
3688 struct type *type; /* Type that this function returns */
3689 struct type *ftype; /* Function that returns above type */
3690 struct attribute *attr;
3692 /* Decode the type that this subroutine returns */
3697 type = die_type (die, cu);
3698 ftype = lookup_function_type (type);
3700 /* All functions in C++ have prototypes. */
3701 attr = dwarf_attr (die, DW_AT_prototyped);
3702 if ((attr && (DW_UNSND (attr) != 0))
3703 || cu_language == language_cplus)
3704 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
3706 if (die->child != NULL)
3708 struct die_info *child_die;
3712 /* Count the number of parameters.
3713 FIXME: GDB currently ignores vararg functions, but knows about
3714 vararg member functions. */
3715 child_die = die->child;
3716 while (child_die && child_die->tag)
3718 if (child_die->tag == DW_TAG_formal_parameter)
3720 else if (child_die->tag == DW_TAG_unspecified_parameters)
3721 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
3722 child_die = sibling_die (child_die);
3725 /* Allocate storage for parameters and fill them in. */
3726 TYPE_NFIELDS (ftype) = nparams;
3727 TYPE_FIELDS (ftype) = (struct field *)
3728 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
3730 child_die = die->child;
3731 while (child_die && child_die->tag)
3733 if (child_die->tag == DW_TAG_formal_parameter)
3735 /* Dwarf2 has no clean way to discern C++ static and non-static
3736 member functions. G++ helps GDB by marking the first
3737 parameter for non-static member functions (which is the
3738 this pointer) as artificial. We pass this information
3739 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3740 attr = dwarf_attr (child_die, DW_AT_artificial);
3742 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
3744 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
3745 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
3748 child_die = sibling_die (child_die);
3756 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
3758 struct objfile *objfile = cu->objfile;
3759 struct attribute *attr;
3764 attr = dwarf_attr (die, DW_AT_name);
3765 if (attr && DW_STRING (attr))
3767 name = DW_STRING (attr);
3769 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
3770 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
3774 /* Find a representation of a given base type and install
3775 it in the TYPE field of the die. */
3778 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
3780 struct objfile *objfile = cu->objfile;
3782 struct attribute *attr;
3783 int encoding = 0, size = 0;
3785 /* If we've already decoded this die, this is a no-op. */
3791 attr = dwarf_attr (die, DW_AT_encoding);
3794 encoding = DW_UNSND (attr);
3796 attr = dwarf_attr (die, DW_AT_byte_size);
3799 size = DW_UNSND (attr);
3801 attr = dwarf_attr (die, DW_AT_name);
3802 if (attr && DW_STRING (attr))
3804 enum type_code code = TYPE_CODE_INT;
3809 case DW_ATE_address:
3810 /* Turn DW_ATE_address into a void * pointer. */
3811 code = TYPE_CODE_PTR;
3812 type_flags |= TYPE_FLAG_UNSIGNED;
3814 case DW_ATE_boolean:
3815 code = TYPE_CODE_BOOL;
3816 type_flags |= TYPE_FLAG_UNSIGNED;
3818 case DW_ATE_complex_float:
3819 code = TYPE_CODE_COMPLEX;
3822 code = TYPE_CODE_FLT;
3825 case DW_ATE_signed_char:
3827 case DW_ATE_unsigned:
3828 case DW_ATE_unsigned_char:
3829 type_flags |= TYPE_FLAG_UNSIGNED;
3832 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
3833 dwarf_type_encoding_name (encoding));
3836 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
3837 if (encoding == DW_ATE_address)
3838 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID);
3839 else if (encoding == DW_ATE_complex_float)
3842 TYPE_TARGET_TYPE (type)
3843 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
3844 else if (size == 16)
3845 TYPE_TARGET_TYPE (type)
3846 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
3848 TYPE_TARGET_TYPE (type)
3849 = dwarf2_fundamental_type (objfile, FT_FLOAT);
3854 type = dwarf_base_type (encoding, size, cu);
3859 /* Read the given DW_AT_subrange DIE. */
3862 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
3864 struct type *base_type;
3865 struct type *range_type;
3866 struct attribute *attr;
3870 /* If we have already decoded this die, then nothing more to do. */
3874 base_type = die_type (die, cu);
3875 if (base_type == NULL)
3877 complaint (&symfile_complaints,
3878 "DW_AT_type missing from DW_TAG_subrange_type");
3882 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
3883 base_type = alloc_type (NULL);
3885 if (cu_language == language_fortran)
3887 /* FORTRAN implies a lower bound of 1, if not given. */
3891 attr = dwarf_attr (die, DW_AT_lower_bound);
3893 low = dwarf2_get_attr_constant_value (attr, 0);
3895 attr = dwarf_attr (die, DW_AT_upper_bound);
3898 if (attr->form == DW_FORM_block1)
3900 /* GCC encodes arrays with unspecified or dynamic length
3901 with a DW_FORM_block1 attribute.
3902 FIXME: GDB does not yet know how to handle dynamic
3903 arrays properly, treat them as arrays with unspecified
3906 FIXME: jimb/2003-09-22: GDB does not really know
3907 how to handle arrays of unspecified length
3908 either; we just represent them as zero-length
3909 arrays. Choose an appropriate upper bound given
3910 the lower bound we've computed above. */
3914 high = dwarf2_get_attr_constant_value (attr, 1);
3917 range_type = create_range_type (NULL, base_type, low, high);
3919 attr = dwarf_attr (die, DW_AT_name);
3920 if (attr && DW_STRING (attr))
3921 TYPE_NAME (range_type) = DW_STRING (attr);
3923 attr = dwarf_attr (die, DW_AT_byte_size);
3925 TYPE_LENGTH (range_type) = DW_UNSND (attr);
3927 die->type = range_type;
3931 /* Read a whole compilation unit into a linked list of dies. */
3933 static struct die_info *
3934 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
3936 /* Reset die reference table; we are
3937 building new ones now. */
3938 dwarf2_empty_hash_tables ();
3940 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
3943 /* Read a single die and all its descendents. Set the die's sibling
3944 field to NULL; set other fields in the die correctly, and set all
3945 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
3946 location of the info_ptr after reading all of those dies. PARENT
3947 is the parent of the die in question. */
3949 static struct die_info *
3950 read_die_and_children (char *info_ptr, bfd *abfd,
3951 struct dwarf2_cu *cu,
3952 char **new_info_ptr,
3953 struct die_info *parent)
3955 struct die_info *die;
3959 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
3960 store_in_ref_table (die->offset, die);
3964 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
3970 *new_info_ptr = cur_ptr;
3973 die->sibling = NULL;
3974 die->parent = parent;
3978 /* Read a die, all of its descendents, and all of its siblings; set
3979 all of the fields of all of the dies correctly. Arguments are as
3980 in read_die_and_children. */
3982 static struct die_info *
3983 read_die_and_siblings (char *info_ptr, bfd *abfd,
3984 struct dwarf2_cu *cu,
3985 char **new_info_ptr,
3986 struct die_info *parent)
3988 struct die_info *first_die, *last_sibling;
3992 first_die = last_sibling = NULL;
3996 struct die_info *die
3997 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4005 last_sibling->sibling = die;
4010 *new_info_ptr = cur_ptr;
4020 /* Free a linked list of dies. */
4023 free_die_list (struct die_info *dies)
4025 struct die_info *die, *next;
4030 if (die->child != NULL)
4031 free_die_list (die->child);
4032 next = die->sibling;
4040 do_free_die_list_cleanup (void *dies)
4042 free_die_list (dies);
4045 static struct cleanup *
4046 make_cleanup_free_die_list (struct die_info *dies)
4048 return make_cleanup (do_free_die_list_cleanup, dies);
4052 /* Read the contents of the section at OFFSET and of size SIZE from the
4053 object file specified by OBJFILE into the psymbol_obstack and return it. */
4056 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4058 bfd *abfd = objfile->obfd;
4060 bfd_size_type size = bfd_get_section_size_before_reloc (sectp);
4065 buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
4067 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4071 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4072 || bfd_bread (buf, size, abfd) != size)
4073 error ("Dwarf Error: Can't read DWARF data from '%s'",
4074 bfd_get_filename (abfd));
4079 /* In DWARF version 2, the description of the debugging information is
4080 stored in a separate .debug_abbrev section. Before we read any
4081 dies from a section we read in all abbreviations and install them
4085 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4087 struct comp_unit_head *cu_header = &cu->header;
4089 struct abbrev_info *cur_abbrev;
4090 unsigned int abbrev_number, bytes_read, abbrev_name;
4091 unsigned int abbrev_form, hash_number;
4093 /* Initialize dwarf2 abbrevs */
4094 memset (cu_header->dwarf2_abbrevs, 0,
4095 ABBREV_HASH_SIZE*sizeof (struct abbrev_info *));
4097 abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset;
4098 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4099 abbrev_ptr += bytes_read;
4101 /* loop until we reach an abbrev number of 0 */
4102 while (abbrev_number)
4104 cur_abbrev = dwarf_alloc_abbrev ();
4106 /* read in abbrev header */
4107 cur_abbrev->number = abbrev_number;
4108 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4109 abbrev_ptr += bytes_read;
4110 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4113 /* now read in declarations */
4114 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4115 abbrev_ptr += bytes_read;
4116 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4117 abbrev_ptr += bytes_read;
4120 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
4122 cur_abbrev->attrs = (struct attr_abbrev *)
4123 xrealloc (cur_abbrev->attrs,
4124 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
4125 * sizeof (struct attr_abbrev));
4127 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
4128 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4129 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4130 abbrev_ptr += bytes_read;
4131 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4132 abbrev_ptr += bytes_read;
4135 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4136 cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number];
4137 cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev;
4139 /* Get next abbreviation.
4140 Under Irix6 the abbreviations for a compilation unit are not
4141 always properly terminated with an abbrev number of 0.
4142 Exit loop if we encounter an abbreviation which we have
4143 already read (which means we are about to read the abbreviations
4144 for the next compile unit) or if the end of the abbreviation
4145 table is reached. */
4146 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
4147 >= dwarf_abbrev_size)
4149 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4150 abbrev_ptr += bytes_read;
4151 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4156 /* Empty the abbrev table for a new compilation unit. */
4159 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table)
4162 struct abbrev_info *abbrev, *next;
4163 struct abbrev_info **abbrevs;
4165 abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table;
4167 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
4170 abbrev = abbrevs[i];
4173 next = abbrev->next;
4174 xfree (abbrev->attrs);
4182 /* Lookup an abbrev_info structure in the abbrev hash table. */
4184 static struct abbrev_info *
4185 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4187 struct comp_unit_head *cu_header = &cu->header;
4188 unsigned int hash_number;
4189 struct abbrev_info *abbrev;
4191 hash_number = number % ABBREV_HASH_SIZE;
4192 abbrev = cu_header->dwarf2_abbrevs[hash_number];
4196 if (abbrev->number == number)
4199 abbrev = abbrev->next;
4204 /* Read a minimal amount of information into the minimal die structure. */
4207 read_partial_die (struct partial_die_info *part_die, bfd *abfd,
4208 char *info_ptr, struct dwarf2_cu *cu)
4210 unsigned int abbrev_number, bytes_read, i;
4211 struct abbrev_info *abbrev;
4212 struct attribute attr;
4213 struct attribute spec_attr;
4214 int found_spec_attr = 0;
4215 int has_low_pc_attr = 0;
4216 int has_high_pc_attr = 0;
4218 *part_die = zeroed_partial_die;
4219 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4220 info_ptr += bytes_read;
4224 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4227 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
4228 bfd_get_filename (abfd));
4230 part_die->offset = info_ptr - dwarf_info_buffer;
4231 part_die->tag = abbrev->tag;
4232 part_die->has_children = abbrev->has_children;
4233 part_die->abbrev = abbrev_number;
4235 for (i = 0; i < abbrev->num_attrs; ++i)
4237 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4239 /* Store the data if it is of an attribute we want to keep in a
4240 partial symbol table. */
4245 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4246 if (part_die->name == NULL)
4247 part_die->name = DW_STRING (&attr);
4249 case DW_AT_MIPS_linkage_name:
4250 part_die->name = DW_STRING (&attr);
4253 has_low_pc_attr = 1;
4254 part_die->lowpc = DW_ADDR (&attr);
4257 has_high_pc_attr = 1;
4258 part_die->highpc = DW_ADDR (&attr);
4260 case DW_AT_location:
4261 /* Support the .debug_loc offsets */
4262 if (attr_form_is_block (&attr))
4264 part_die->locdesc = DW_BLOCK (&attr);
4266 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4268 dwarf2_complex_location_expr_complaint ();
4272 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4273 "partial symbol information");
4276 case DW_AT_language:
4277 part_die->language = DW_UNSND (&attr);
4279 case DW_AT_external:
4280 part_die->is_external = DW_UNSND (&attr);
4282 case DW_AT_declaration:
4283 part_die->is_declaration = DW_UNSND (&attr);
4286 part_die->has_type = 1;
4288 case DW_AT_abstract_origin:
4289 case DW_AT_specification:
4290 found_spec_attr = 1;
4294 /* Ignore absolute siblings, they might point outside of
4295 the current compile unit. */
4296 if (attr.form == DW_FORM_ref_addr)
4297 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
4300 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr);
4307 /* If we found a reference attribute and the die has no name, try
4308 to find a name in the referred to die. */
4310 if (found_spec_attr && part_die->name == NULL)
4312 struct partial_die_info spec_die;
4315 spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr);
4316 read_partial_die (&spec_die, abfd, spec_ptr, cu);
4319 part_die->name = spec_die.name;
4321 /* Copy DW_AT_external attribute if it is set. */
4322 if (spec_die.is_external)
4323 part_die->is_external = spec_die.is_external;
4327 /* When using the GNU linker, .gnu.linkonce. sections are used to
4328 eliminate duplicate copies of functions and vtables and such.
4329 The linker will arbitrarily choose one and discard the others.
4330 The AT_*_pc values for such functions refer to local labels in
4331 these sections. If the section from that file was discarded, the
4332 labels are not in the output, so the relocs get a value of 0.
4333 If this is a discarded function, mark the pc bounds as invalid,
4334 so that GDB will ignore it. */
4335 if (has_low_pc_attr && has_high_pc_attr
4336 && part_die->lowpc < part_die->highpc
4337 && (part_die->lowpc != 0
4338 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
4339 part_die->has_pc_info = 1;
4343 /* Read the die from the .debug_info section buffer. Set DIEP to
4344 point to a newly allocated die with its information, except for its
4345 child, sibling, and parent fields. Set HAS_CHILDREN to tell
4346 whether the die has children or not. */
4349 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
4350 struct dwarf2_cu *cu, int *has_children)
4352 unsigned int abbrev_number, bytes_read, i, offset;
4353 struct abbrev_info *abbrev;
4354 struct die_info *die;
4356 offset = info_ptr - dwarf_info_buffer;
4357 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4358 info_ptr += bytes_read;
4361 die = dwarf_alloc_die ();
4363 die->abbrev = abbrev_number;
4370 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4373 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
4375 bfd_get_filename (abfd));
4377 die = dwarf_alloc_die ();
4378 die->offset = offset;
4379 die->tag = abbrev->tag;
4380 die->abbrev = abbrev_number;
4383 die->num_attrs = abbrev->num_attrs;
4384 die->attrs = (struct attribute *)
4385 xmalloc (die->num_attrs * sizeof (struct attribute));
4387 for (i = 0; i < abbrev->num_attrs; ++i)
4389 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
4390 abfd, info_ptr, cu);
4394 *has_children = abbrev->has_children;
4398 /* Read an attribute value described by an attribute form. */
4401 read_attribute_value (struct attribute *attr, unsigned form,
4402 bfd *abfd, char *info_ptr,
4403 struct dwarf2_cu *cu)
4405 struct comp_unit_head *cu_header = &cu->header;
4406 unsigned int bytes_read;
4407 struct dwarf_block *blk;
4413 case DW_FORM_ref_addr:
4414 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
4415 info_ptr += bytes_read;
4417 case DW_FORM_block2:
4418 blk = dwarf_alloc_block ();
4419 blk->size = read_2_bytes (abfd, info_ptr);
4421 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4422 info_ptr += blk->size;
4423 DW_BLOCK (attr) = blk;
4425 case DW_FORM_block4:
4426 blk = dwarf_alloc_block ();
4427 blk->size = read_4_bytes (abfd, info_ptr);
4429 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4430 info_ptr += blk->size;
4431 DW_BLOCK (attr) = blk;
4434 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4438 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4442 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4445 case DW_FORM_string:
4446 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
4447 info_ptr += bytes_read;
4450 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
4452 info_ptr += bytes_read;
4455 blk = dwarf_alloc_block ();
4456 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4457 info_ptr += bytes_read;
4458 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4459 info_ptr += blk->size;
4460 DW_BLOCK (attr) = blk;
4462 case DW_FORM_block1:
4463 blk = dwarf_alloc_block ();
4464 blk->size = read_1_byte (abfd, info_ptr);
4466 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
4467 info_ptr += blk->size;
4468 DW_BLOCK (attr) = blk;
4471 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4475 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4479 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
4480 info_ptr += bytes_read;
4483 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4484 info_ptr += bytes_read;
4487 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
4491 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
4495 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
4499 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
4502 case DW_FORM_ref_udata:
4503 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4504 info_ptr += bytes_read;
4506 case DW_FORM_indirect:
4507 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4508 info_ptr += bytes_read;
4509 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
4512 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
4513 dwarf_form_name (form),
4514 bfd_get_filename (abfd));
4519 /* Read an attribute described by an abbreviated attribute. */
4522 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
4523 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
4525 attr->name = abbrev->name;
4526 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
4529 /* read dwarf information from a buffer */
4532 read_1_byte (bfd *abfd, char *buf)
4534 return bfd_get_8 (abfd, (bfd_byte *) buf);
4538 read_1_signed_byte (bfd *abfd, char *buf)
4540 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
4544 read_2_bytes (bfd *abfd, char *buf)
4546 return bfd_get_16 (abfd, (bfd_byte *) buf);
4550 read_2_signed_bytes (bfd *abfd, char *buf)
4552 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4556 read_4_bytes (bfd *abfd, char *buf)
4558 return bfd_get_32 (abfd, (bfd_byte *) buf);
4562 read_4_signed_bytes (bfd *abfd, char *buf)
4564 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4567 static unsigned long
4568 read_8_bytes (bfd *abfd, char *buf)
4570 return bfd_get_64 (abfd, (bfd_byte *) buf);
4574 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
4576 struct comp_unit_head *cu_header = &cu->header;
4577 CORE_ADDR retval = 0;
4579 if (cu_header->signed_addr_p)
4581 switch (cu_header->addr_size)
4584 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
4587 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
4590 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
4593 internal_error (__FILE__, __LINE__,
4594 "read_address: bad switch, signed [in module %s]",
4595 bfd_get_filename (abfd));
4600 switch (cu_header->addr_size)
4603 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
4606 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4609 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4612 internal_error (__FILE__, __LINE__,
4613 "read_address: bad switch, unsigned [in module %s]",
4614 bfd_get_filename (abfd));
4618 *bytes_read = cu_header->addr_size;
4622 /* Read the initial length from a section. The (draft) DWARF 3
4623 specification allows the initial length to take up either 4 bytes
4624 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4625 bytes describe the length and all offsets will be 8 bytes in length
4628 An older, non-standard 64-bit format is also handled by this
4629 function. The older format in question stores the initial length
4630 as an 8-byte quantity without an escape value. Lengths greater
4631 than 2^32 aren't very common which means that the initial 4 bytes
4632 is almost always zero. Since a length value of zero doesn't make
4633 sense for the 32-bit format, this initial zero can be considered to
4634 be an escape value which indicates the presence of the older 64-bit
4635 format. As written, the code can't detect (old format) lengths
4636 greater than 4GB. If it becomes necessary to handle lengths somewhat
4637 larger than 4GB, we could allow other small values (such as the
4638 non-sensical values of 1, 2, and 3) to also be used as escape values
4639 indicating the presence of the old format.
4641 The value returned via bytes_read should be used to increment
4642 the relevant pointer after calling read_initial_length().
4644 As a side effect, this function sets the fields initial_length_size
4645 and offset_size in cu_header to the values appropriate for the
4646 length field. (The format of the initial length field determines
4647 the width of file offsets to be fetched later with fetch_offset().)
4649 [ Note: read_initial_length() and read_offset() are based on the
4650 document entitled "DWARF Debugging Information Format", revision
4651 3, draft 8, dated November 19, 2001. This document was obtained
4654 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4656 This document is only a draft and is subject to change. (So beware.)
4658 Details regarding the older, non-standard 64-bit format were
4659 determined empirically by examining 64-bit ELF files produced
4660 by the SGI toolchain on an IRIX 6.5 machine.
4662 - Kevin, July 16, 2002
4666 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
4671 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4673 if (retval == 0xffffffff)
4675 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
4677 if (cu_header != NULL)
4679 cu_header->initial_length_size = 12;
4680 cu_header->offset_size = 8;
4683 else if (retval == 0)
4685 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4687 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4689 if (cu_header != NULL)
4691 cu_header->initial_length_size = 8;
4692 cu_header->offset_size = 8;
4698 if (cu_header != NULL)
4700 cu_header->initial_length_size = 4;
4701 cu_header->offset_size = 4;
4708 /* Read an offset from the data stream. The size of the offset is
4709 given by cu_header->offset_size. */
4712 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
4717 switch (cu_header->offset_size)
4720 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
4724 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
4728 internal_error (__FILE__, __LINE__,
4729 "read_offset: bad switch [in module %s]",
4730 bfd_get_filename (abfd));
4737 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
4739 /* If the size of a host char is 8 bits, we can return a pointer
4740 to the buffer, otherwise we have to copy the data to a buffer
4741 allocated on the temporary obstack. */
4742 gdb_assert (HOST_CHAR_BIT == 8);
4747 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4749 /* If the size of a host char is 8 bits, we can return a pointer
4750 to the string, otherwise we have to copy the string to a buffer
4751 allocated on the temporary obstack. */
4752 gdb_assert (HOST_CHAR_BIT == 8);
4755 *bytes_read_ptr = 1;
4758 *bytes_read_ptr = strlen (buf) + 1;
4763 read_indirect_string (bfd *abfd, char *buf,
4764 const struct comp_unit_head *cu_header,
4765 unsigned int *bytes_read_ptr)
4767 LONGEST str_offset = read_offset (abfd, buf, cu_header,
4768 (int *) bytes_read_ptr);
4770 if (dwarf_str_buffer == NULL)
4772 error ("DW_FORM_strp used without .debug_str section [in module %s]",
4773 bfd_get_filename (abfd));
4776 if (str_offset >= dwarf_str_size)
4778 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
4779 bfd_get_filename (abfd));
4782 gdb_assert (HOST_CHAR_BIT == 8);
4783 if (dwarf_str_buffer[str_offset] == '\0')
4785 return dwarf_str_buffer + str_offset;
4788 static unsigned long
4789 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4791 unsigned long result;
4792 unsigned int num_read;
4802 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4805 result |= ((unsigned long)(byte & 127) << shift);
4806 if ((byte & 128) == 0)
4812 *bytes_read_ptr = num_read;
4817 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
4820 int i, shift, size, num_read;
4830 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
4833 result |= ((long)(byte & 127) << shift);
4835 if ((byte & 128) == 0)
4840 if ((shift < size) && (byte & 0x40))
4842 result |= -(1 << shift);
4844 *bytes_read_ptr = num_read;
4849 set_cu_language (unsigned int lang)
4855 cu_language = language_c;
4857 case DW_LANG_C_plus_plus:
4858 cu_language = language_cplus;
4860 case DW_LANG_Fortran77:
4861 case DW_LANG_Fortran90:
4862 case DW_LANG_Fortran95:
4863 cu_language = language_fortran;
4865 case DW_LANG_Mips_Assembler:
4866 cu_language = language_asm;
4869 cu_language = language_java;
4873 case DW_LANG_Cobol74:
4874 case DW_LANG_Cobol85:
4875 case DW_LANG_Pascal83:
4876 case DW_LANG_Modula2:
4878 cu_language = language_minimal;
4881 cu_language_defn = language_def (cu_language);
4884 /* Return the named attribute or NULL if not there. */
4886 static struct attribute *
4887 dwarf_attr (struct die_info *die, unsigned int name)
4890 struct attribute *spec = NULL;
4892 for (i = 0; i < die->num_attrs; ++i)
4894 if (die->attrs[i].name == name)
4896 return &die->attrs[i];
4898 if (die->attrs[i].name == DW_AT_specification
4899 || die->attrs[i].name == DW_AT_abstract_origin)
4900 spec = &die->attrs[i];
4904 struct die_info *ref_die =
4905 follow_die_ref (dwarf2_get_ref_die_offset (spec));
4908 return dwarf_attr (ref_die, name);
4915 die_is_declaration (struct die_info *die)
4917 return (dwarf_attr (die, DW_AT_declaration)
4918 && ! dwarf_attr (die, DW_AT_specification));
4921 /* Return the die giving the specification for DIE, if there is
4924 static struct die_info *
4925 die_specification (struct die_info *die)
4927 struct attribute *spec_attr = dwarf_attr (die, DW_AT_specification);
4929 if (spec_attr == NULL)
4932 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr));
4935 /* Free the line_header structure *LH, and any arrays and strings it
4938 free_line_header (struct line_header *lh)
4940 if (lh->standard_opcode_lengths)
4941 xfree (lh->standard_opcode_lengths);
4943 /* Remember that all the lh->file_names[i].name pointers are
4944 pointers into debug_line_buffer, and don't need to be freed. */
4946 xfree (lh->file_names);
4948 /* Similarly for the include directory names. */
4949 if (lh->include_dirs)
4950 xfree (lh->include_dirs);
4956 /* Add an entry to LH's include directory table. */
4958 add_include_dir (struct line_header *lh, char *include_dir)
4960 /* Grow the array if necessary. */
4961 if (lh->include_dirs_size == 0)
4963 lh->include_dirs_size = 1; /* for testing */
4964 lh->include_dirs = xmalloc (lh->include_dirs_size
4965 * sizeof (*lh->include_dirs));
4967 else if (lh->num_include_dirs >= lh->include_dirs_size)
4969 lh->include_dirs_size *= 2;
4970 lh->include_dirs = xrealloc (lh->include_dirs,
4971 (lh->include_dirs_size
4972 * sizeof (*lh->include_dirs)));
4975 lh->include_dirs[lh->num_include_dirs++] = include_dir;
4979 /* Add an entry to LH's file name table. */
4981 add_file_name (struct line_header *lh,
4983 unsigned int dir_index,
4984 unsigned int mod_time,
4985 unsigned int length)
4987 struct file_entry *fe;
4989 /* Grow the array if necessary. */
4990 if (lh->file_names_size == 0)
4992 lh->file_names_size = 1; /* for testing */
4993 lh->file_names = xmalloc (lh->file_names_size
4994 * sizeof (*lh->file_names));
4996 else if (lh->num_file_names >= lh->file_names_size)
4998 lh->file_names_size *= 2;
4999 lh->file_names = xrealloc (lh->file_names,
5000 (lh->file_names_size
5001 * sizeof (*lh->file_names)));
5004 fe = &lh->file_names[lh->num_file_names++];
5006 fe->dir_index = dir_index;
5007 fe->mod_time = mod_time;
5008 fe->length = length;
5012 /* Read the statement program header starting at OFFSET in
5013 dwarf_line_buffer, according to the endianness of ABFD. Return a
5014 pointer to a struct line_header, allocated using xmalloc.
5016 NOTE: the strings in the include directory and file name tables of
5017 the returned object point into debug_line_buffer, and must not be
5019 static struct line_header *
5020 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5021 struct dwarf2_cu *cu)
5023 struct cleanup *back_to;
5024 struct line_header *lh;
5028 char *cur_dir, *cur_file;
5030 if (dwarf_line_buffer == NULL)
5032 complaint (&symfile_complaints, "missing .debug_line section");
5036 /* Make sure that at least there's room for the total_length field. That
5037 could be 12 bytes long, but we're just going to fudge that. */
5038 if (offset + 4 >= dwarf_line_size)
5040 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5044 lh = xmalloc (sizeof (*lh));
5045 memset (lh, 0, sizeof (*lh));
5046 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5049 line_ptr = dwarf_line_buffer + offset;
5051 /* read in the header */
5052 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
5053 line_ptr += bytes_read;
5054 if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size)
5056 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5059 lh->statement_program_end = line_ptr + lh->total_length;
5060 lh->version = read_2_bytes (abfd, line_ptr);
5062 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5063 line_ptr += bytes_read;
5064 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5066 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5068 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5070 lh->line_range = read_1_byte (abfd, line_ptr);
5072 lh->opcode_base = read_1_byte (abfd, line_ptr);
5074 lh->standard_opcode_lengths
5075 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5077 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5078 for (i = 1; i < lh->opcode_base; ++i)
5080 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5084 /* Read directory table */
5085 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5087 line_ptr += bytes_read;
5088 add_include_dir (lh, cur_dir);
5090 line_ptr += bytes_read;
5092 /* Read file name table */
5093 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5095 unsigned int dir_index, mod_time, length;
5097 line_ptr += bytes_read;
5098 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5099 line_ptr += bytes_read;
5100 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5101 line_ptr += bytes_read;
5102 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5103 line_ptr += bytes_read;
5105 add_file_name (lh, cur_file, dir_index, mod_time, length);
5107 line_ptr += bytes_read;
5108 lh->statement_program_start = line_ptr;
5110 if (line_ptr > dwarf_line_buffer + dwarf_line_size)
5111 complaint (&symfile_complaints,
5112 "line number info header doesn't fit in `.debug_line' section");
5114 discard_cleanups (back_to);
5118 /* This function exists to work around a bug in certain compilers
5119 (particularly GCC 2.95), in which the first line number marker of a
5120 function does not show up until after the prologue, right before
5121 the second line number marker. This function shifts ADDRESS down
5122 to the beginning of the function if necessary, and is called on
5123 addresses passed to record_line. */
5126 check_cu_functions (CORE_ADDR address)
5128 struct function_range *fn;
5130 /* Find the function_range containing address. */
5135 cu_cached_fn = cu_first_fn;
5139 if (fn->lowpc <= address && fn->highpc > address)
5145 while (fn && fn != cu_cached_fn)
5146 if (fn->lowpc <= address && fn->highpc > address)
5156 if (address != fn->lowpc)
5157 complaint (&symfile_complaints,
5158 "misplaced first line number at 0x%lx for '%s'",
5159 (unsigned long) address, fn->name);
5164 /* Decode the line number information for the compilation unit whose
5165 line number info is at OFFSET in the .debug_line section.
5166 The compilation directory of the file is passed in COMP_DIR. */
5169 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5170 struct dwarf2_cu *cu)
5174 unsigned int bytes_read;
5175 unsigned char op_code, extended_op, adj_opcode;
5177 line_ptr = lh->statement_program_start;
5178 line_end = lh->statement_program_end;
5180 /* Read the statement sequences until there's nothing left. */
5181 while (line_ptr < line_end)
5183 /* state machine registers */
5184 CORE_ADDR address = 0;
5185 unsigned int file = 1;
5186 unsigned int line = 1;
5187 unsigned int column = 0;
5188 int is_stmt = lh->default_is_stmt;
5189 int basic_block = 0;
5190 int end_sequence = 0;
5192 /* Start a subfile for the current file of the state machine. */
5193 if (lh->num_file_names >= file)
5195 /* lh->include_dirs and lh->file_names are 0-based, but the
5196 directory and file name numbers in the statement program
5198 struct file_entry *fe = &lh->file_names[file - 1];
5201 dir = lh->include_dirs[fe->dir_index - 1];
5204 dwarf2_start_subfile (fe->name, dir);
5207 /* Decode the table. */
5208 while (!end_sequence)
5210 op_code = read_1_byte (abfd, line_ptr);
5213 if (op_code >= lh->opcode_base)
5214 { /* Special operand. */
5215 adj_opcode = op_code - lh->opcode_base;
5216 address += (adj_opcode / lh->line_range)
5217 * lh->minimum_instruction_length;
5218 line += lh->line_base + (adj_opcode % lh->line_range);
5219 /* append row to matrix using current values */
5220 record_line (current_subfile, line,
5221 check_cu_functions (address));
5224 else switch (op_code)
5226 case DW_LNS_extended_op:
5227 line_ptr += 1; /* ignore length */
5228 extended_op = read_1_byte (abfd, line_ptr);
5230 switch (extended_op)
5232 case DW_LNE_end_sequence:
5234 record_line (current_subfile, 0, address);
5236 case DW_LNE_set_address:
5237 address = read_address (abfd, line_ptr, cu, &bytes_read);
5238 line_ptr += bytes_read;
5239 address += baseaddr;
5241 case DW_LNE_define_file:
5244 unsigned int dir_index, mod_time, length;
5246 cur_file = read_string (abfd, line_ptr, &bytes_read);
5247 line_ptr += bytes_read;
5249 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5250 line_ptr += bytes_read;
5252 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5253 line_ptr += bytes_read;
5255 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5256 line_ptr += bytes_read;
5257 add_file_name (lh, cur_file, dir_index, mod_time, length);
5261 complaint (&symfile_complaints,
5262 "mangled .debug_line section");
5267 record_line (current_subfile, line,
5268 check_cu_functions (address));
5271 case DW_LNS_advance_pc:
5272 address += lh->minimum_instruction_length
5273 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5274 line_ptr += bytes_read;
5276 case DW_LNS_advance_line:
5277 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
5278 line_ptr += bytes_read;
5280 case DW_LNS_set_file:
5282 /* lh->include_dirs and lh->file_names are 0-based,
5283 but the directory and file name numbers in the
5284 statement program are 1-based. */
5285 struct file_entry *fe;
5287 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5288 line_ptr += bytes_read;
5289 fe = &lh->file_names[file - 1];
5291 dir = lh->include_dirs[fe->dir_index - 1];
5294 dwarf2_start_subfile (fe->name, dir);
5297 case DW_LNS_set_column:
5298 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5299 line_ptr += bytes_read;
5301 case DW_LNS_negate_stmt:
5302 is_stmt = (!is_stmt);
5304 case DW_LNS_set_basic_block:
5307 /* Add to the address register of the state machine the
5308 address increment value corresponding to special opcode
5309 255. Ie, this value is scaled by the minimum instruction
5310 length since special opcode 255 would have scaled the
5312 case DW_LNS_const_add_pc:
5313 address += (lh->minimum_instruction_length
5314 * ((255 - lh->opcode_base) / lh->line_range));
5316 case DW_LNS_fixed_advance_pc:
5317 address += read_2_bytes (abfd, line_ptr);
5321 { /* Unknown standard opcode, ignore it. */
5323 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
5325 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5326 line_ptr += bytes_read;
5334 /* Start a subfile for DWARF. FILENAME is the name of the file and
5335 DIRNAME the name of the source directory which contains FILENAME
5336 or NULL if not known.
5337 This routine tries to keep line numbers from identical absolute and
5338 relative file names in a common subfile.
5340 Using the `list' example from the GDB testsuite, which resides in
5341 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
5342 of /srcdir/list0.c yields the following debugging information for list0.c:
5344 DW_AT_name: /srcdir/list0.c
5345 DW_AT_comp_dir: /compdir
5346 files.files[0].name: list0.h
5347 files.files[0].dir: /srcdir
5348 files.files[1].name: list0.c
5349 files.files[1].dir: /srcdir
5351 The line number information for list0.c has to end up in a single
5352 subfile, so that `break /srcdir/list0.c:1' works as expected. */
5355 dwarf2_start_subfile (char *filename, char *dirname)
5357 /* If the filename isn't absolute, try to match an existing subfile
5358 with the full pathname. */
5360 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
5362 struct subfile *subfile;
5363 char *fullname = concat (dirname, "/", filename, NULL);
5365 for (subfile = subfiles; subfile; subfile = subfile->next)
5367 if (FILENAME_CMP (subfile->name, fullname) == 0)
5369 current_subfile = subfile;
5376 start_subfile (filename, dirname);
5380 var_decode_location (struct attribute *attr, struct symbol *sym,
5381 struct dwarf2_cu *cu)
5383 struct objfile *objfile = cu->objfile;
5384 struct comp_unit_head *cu_header = &cu->header;
5386 /* NOTE drow/2003-01-30: There used to be a comment and some special
5387 code here to turn a symbol with DW_AT_external and a
5388 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
5389 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
5390 with some versions of binutils) where shared libraries could have
5391 relocations against symbols in their debug information - the
5392 minimal symbol would have the right address, but the debug info
5393 would not. It's no longer necessary, because we will explicitly
5394 apply relocations when we read in the debug information now. */
5396 /* A DW_AT_location attribute with no contents indicates that a
5397 variable has been optimized away. */
5398 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
5400 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
5404 /* Handle one degenerate form of location expression specially, to
5405 preserve GDB's previous behavior when section offsets are
5406 specified. If this is just a DW_OP_addr then mark this symbol
5409 if (attr_form_is_block (attr)
5410 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
5411 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
5415 SYMBOL_VALUE_ADDRESS (sym) =
5416 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
5417 fixup_symbol_section (sym, objfile);
5418 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
5419 SYMBOL_SECTION (sym));
5420 SYMBOL_CLASS (sym) = LOC_STATIC;
5424 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
5425 expression evaluator, and use LOC_COMPUTED only when necessary
5426 (i.e. when the value of a register or memory location is
5427 referenced, or a thread-local block, etc.). Then again, it might
5428 not be worthwhile. I'm assuming that it isn't unless performance
5429 or memory numbers show me otherwise. */
5431 dwarf2_symbol_mark_computed (attr, sym, cu);
5432 SYMBOL_CLASS (sym) = LOC_COMPUTED;
5435 /* Given a pointer to a DWARF information entry, figure out if we need
5436 to make a symbol table entry for it, and if so, create a new entry
5437 and return a pointer to it.
5438 If TYPE is NULL, determine symbol type from the die, otherwise
5439 used the passed type. */
5441 static struct symbol *
5442 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
5444 struct objfile *objfile = cu->objfile;
5445 struct symbol *sym = NULL;
5447 struct attribute *attr = NULL;
5448 struct attribute *attr2 = NULL;
5450 if (die->tag != DW_TAG_namespace)
5451 name = dwarf2_linkage_name (die);
5453 name = TYPE_NAME (type);
5457 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
5458 sizeof (struct symbol));
5459 OBJSTAT (objfile, n_syms++);
5460 memset (sym, 0, sizeof (struct symbol));
5462 /* Cache this symbol's name and the name's demangled form (if any). */
5463 SYMBOL_LANGUAGE (sym) = cu_language;
5464 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
5466 /* Default assumptions.
5467 Use the passed type or decode it from the die. */
5468 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5469 SYMBOL_CLASS (sym) = LOC_STATIC;
5471 SYMBOL_TYPE (sym) = type;
5473 SYMBOL_TYPE (sym) = die_type (die, cu);
5474 attr = dwarf_attr (die, DW_AT_decl_line);
5477 SYMBOL_LINE (sym) = DW_UNSND (attr);
5482 attr = dwarf_attr (die, DW_AT_low_pc);
5485 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
5487 SYMBOL_CLASS (sym) = LOC_LABEL;
5489 case DW_TAG_subprogram:
5490 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
5492 SYMBOL_CLASS (sym) = LOC_BLOCK;
5493 attr2 = dwarf_attr (die, DW_AT_external);
5494 if (attr2 && (DW_UNSND (attr2) != 0))
5496 add_symbol_to_list (sym, &global_symbols);
5500 add_symbol_to_list (sym, list_in_scope);
5503 case DW_TAG_variable:
5504 /* Compilation with minimal debug info may result in variables
5505 with missing type entries. Change the misleading `void' type
5506 to something sensible. */
5507 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
5508 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
5509 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
5510 "<variable, no debug info>",
5512 attr = dwarf_attr (die, DW_AT_const_value);
5515 dwarf2_const_value (attr, sym, cu);
5516 attr2 = dwarf_attr (die, DW_AT_external);
5517 if (attr2 && (DW_UNSND (attr2) != 0))
5518 add_symbol_to_list (sym, &global_symbols);
5520 add_symbol_to_list (sym, list_in_scope);
5523 attr = dwarf_attr (die, DW_AT_location);
5526 var_decode_location (attr, sym, cu);
5527 attr2 = dwarf_attr (die, DW_AT_external);
5528 if (attr2 && (DW_UNSND (attr2) != 0))
5529 add_symbol_to_list (sym, &global_symbols);
5531 add_symbol_to_list (sym, list_in_scope);
5535 /* We do not know the address of this symbol.
5536 If it is an external symbol and we have type information
5537 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5538 The address of the variable will then be determined from
5539 the minimal symbol table whenever the variable is
5541 attr2 = dwarf_attr (die, DW_AT_external);
5542 if (attr2 && (DW_UNSND (attr2) != 0)
5543 && dwarf_attr (die, DW_AT_type) != NULL)
5545 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
5546 add_symbol_to_list (sym, &global_symbols);
5550 case DW_TAG_formal_parameter:
5551 attr = dwarf_attr (die, DW_AT_location);
5554 var_decode_location (attr, sym, cu);
5555 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
5556 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
5557 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
5559 attr = dwarf_attr (die, DW_AT_const_value);
5562 dwarf2_const_value (attr, sym, cu);
5564 add_symbol_to_list (sym, list_in_scope);
5566 case DW_TAG_unspecified_parameters:
5567 /* From varargs functions; gdb doesn't seem to have any
5568 interest in this information, so just ignore it for now.
5571 case DW_TAG_class_type:
5572 case DW_TAG_structure_type:
5573 case DW_TAG_union_type:
5574 case DW_TAG_enumeration_type:
5575 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5576 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
5578 /* Make sure that the symbol includes appropriate enclosing
5579 classes/namespaces in its name. These are calculated in
5580 read_structure_scope, and the correct name is saved in
5583 if (cu_language == language_cplus)
5585 struct type *type = SYMBOL_TYPE (sym);
5587 if (TYPE_TAG_NAME (type) != NULL)
5589 /* FIXME: carlton/2003-11-10: Should this use
5590 SYMBOL_SET_NAMES instead? (The same problem also
5591 arises a further down in the function.) */
5592 SYMBOL_LINKAGE_NAME (sym)
5593 = obsavestring (TYPE_TAG_NAME (type),
5594 strlen (TYPE_TAG_NAME (type)),
5595 &objfile->symbol_obstack);
5600 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
5601 really ever be static objects: otherwise, if you try
5602 to, say, break of a class's method and you're in a file
5603 which doesn't mention that class, it won't work unless
5604 the check for all static symbols in lookup_symbol_aux
5605 saves you. See the OtherFileClass tests in
5606 gdb.c++/namespace.exp. */
5608 struct pending **list_to_add;
5610 list_to_add = (list_in_scope == &file_symbols
5611 && cu_language == language_cplus
5612 ? &global_symbols : list_in_scope);
5614 add_symbol_to_list (sym, list_to_add);
5616 /* The semantics of C++ state that "struct foo { ... }" also
5617 defines a typedef for "foo". Synthesize a typedef symbol so
5618 that "ptype foo" works as expected. */
5619 if (cu_language == language_cplus)
5621 struct symbol *typedef_sym = (struct symbol *)
5622 obstack_alloc (&objfile->symbol_obstack,
5623 sizeof (struct symbol));
5624 *typedef_sym = *sym;
5625 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
5626 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
5627 TYPE_NAME (SYMBOL_TYPE (sym)) =
5628 obsavestring (SYMBOL_NATURAL_NAME (sym),
5629 strlen (SYMBOL_NATURAL_NAME (sym)),
5630 &objfile->type_obstack);
5631 add_symbol_to_list (typedef_sym, list_to_add);
5635 case DW_TAG_typedef:
5636 if (processing_has_namespace_info
5637 && processing_current_prefix[0] != '\0')
5639 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->symbol_obstack,
5640 processing_current_prefix,
5644 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5645 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5646 add_symbol_to_list (sym, list_in_scope);
5648 case DW_TAG_base_type:
5649 case DW_TAG_subrange_type:
5650 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5651 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
5652 add_symbol_to_list (sym, list_in_scope);
5654 case DW_TAG_enumerator:
5655 if (processing_has_namespace_info
5656 && processing_current_prefix[0] != '\0')
5658 SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->symbol_obstack,
5659 processing_current_prefix,
5663 attr = dwarf_attr (die, DW_AT_const_value);
5666 dwarf2_const_value (attr, sym, cu);
5669 /* NOTE: carlton/2003-11-10: See comment above in the
5670 DW_TAG_class_type, etc. block. */
5672 struct pending **list_to_add;
5674 list_to_add = (list_in_scope == &file_symbols
5675 && cu_language == language_cplus
5676 ? &global_symbols : list_in_scope);
5678 add_symbol_to_list (sym, list_to_add);
5681 case DW_TAG_namespace:
5682 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
5683 add_symbol_to_list (sym, &global_symbols);
5686 /* Not a tag we recognize. Hopefully we aren't processing
5687 trash data, but since we must specifically ignore things
5688 we don't recognize, there is nothing else we should do at
5690 complaint (&symfile_complaints, "unsupported tag: '%s'",
5691 dwarf_tag_name (die->tag));
5698 /* Copy constant value from an attribute to a symbol. */
5701 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
5702 struct dwarf2_cu *cu)
5704 struct objfile *objfile = cu->objfile;
5705 struct comp_unit_head *cu_header = &cu->header;
5706 struct dwarf_block *blk;
5711 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
5712 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5713 cu_header->addr_size,
5714 TYPE_LENGTH (SYMBOL_TYPE
5716 SYMBOL_VALUE_BYTES (sym) = (char *)
5717 obstack_alloc (&objfile->symbol_obstack, cu_header->addr_size);
5718 /* NOTE: cagney/2003-05-09: In-lined store_address call with
5719 it's body - store_unsigned_integer. */
5720 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
5722 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5724 case DW_FORM_block1:
5725 case DW_FORM_block2:
5726 case DW_FORM_block4:
5728 blk = DW_BLOCK (attr);
5729 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
5730 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
5732 TYPE_LENGTH (SYMBOL_TYPE
5734 SYMBOL_VALUE_BYTES (sym) = (char *)
5735 obstack_alloc (&objfile->symbol_obstack, blk->size);
5736 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
5737 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
5740 /* The DW_AT_const_value attributes are supposed to carry the
5741 symbol's value "represented as it would be on the target
5742 architecture." By the time we get here, it's already been
5743 converted to host endianness, so we just need to sign- or
5744 zero-extend it as appropriate. */
5746 dwarf2_const_value_data (attr, sym, 8);
5749 dwarf2_const_value_data (attr, sym, 16);
5752 dwarf2_const_value_data (attr, sym, 32);
5755 dwarf2_const_value_data (attr, sym, 64);
5759 SYMBOL_VALUE (sym) = DW_SND (attr);
5760 SYMBOL_CLASS (sym) = LOC_CONST;
5764 SYMBOL_VALUE (sym) = DW_UNSND (attr);
5765 SYMBOL_CLASS (sym) = LOC_CONST;
5769 complaint (&symfile_complaints,
5770 "unsupported const value attribute form: '%s'",
5771 dwarf_form_name (attr->form));
5772 SYMBOL_VALUE (sym) = 0;
5773 SYMBOL_CLASS (sym) = LOC_CONST;
5779 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5780 or zero-extend it as appropriate for the symbol's type. */
5782 dwarf2_const_value_data (struct attribute *attr,
5786 LONGEST l = DW_UNSND (attr);
5788 if (bits < sizeof (l) * 8)
5790 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
5791 l &= ((LONGEST) 1 << bits) - 1;
5793 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
5796 SYMBOL_VALUE (sym) = l;
5797 SYMBOL_CLASS (sym) = LOC_CONST;
5801 /* Return the type of the die in question using its DW_AT_type attribute. */
5803 static struct type *
5804 die_type (struct die_info *die, struct dwarf2_cu *cu)
5807 struct attribute *type_attr;
5808 struct die_info *type_die;
5811 type_attr = dwarf_attr (die, DW_AT_type);
5814 /* A missing DW_AT_type represents a void type. */
5815 return dwarf2_fundamental_type (cu->objfile, FT_VOID);
5819 ref = dwarf2_get_ref_die_offset (type_attr);
5820 type_die = follow_die_ref (ref);
5823 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
5824 ref, cu->objfile->name);
5828 type = tag_type_to_type (type_die, cu);
5831 dump_die (type_die);
5832 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
5838 /* Return the containing type of the die in question using its
5839 DW_AT_containing_type attribute. */
5841 static struct type *
5842 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
5844 struct type *type = NULL;
5845 struct attribute *type_attr;
5846 struct die_info *type_die = NULL;
5849 type_attr = dwarf_attr (die, DW_AT_containing_type);
5852 ref = dwarf2_get_ref_die_offset (type_attr);
5853 type_die = follow_die_ref (ref);
5856 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
5860 type = tag_type_to_type (type_die, cu);
5865 dump_die (type_die);
5866 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
5873 static struct type *
5874 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
5876 struct die_info *die;
5879 die = follow_die_ref (offset);
5882 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
5885 type = tag_type_to_type (die, cu);
5890 static struct type *
5891 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
5899 read_type_die (die, cu);
5903 error ("Dwarf Error: Cannot find type of die [in module %s]",
5911 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
5913 char *prefix = determine_prefix (die);
5914 const char *old_prefix = processing_current_prefix;
5915 struct cleanup *back_to = make_cleanup (xfree, prefix);
5916 processing_current_prefix = prefix;
5920 case DW_TAG_class_type:
5921 case DW_TAG_structure_type:
5922 case DW_TAG_union_type:
5923 read_structure_scope (die, cu);
5925 case DW_TAG_enumeration_type:
5926 read_enumeration (die, cu);
5928 case DW_TAG_subprogram:
5929 case DW_TAG_subroutine_type:
5930 read_subroutine_type (die, cu);
5932 case DW_TAG_array_type:
5933 read_array_type (die, cu);
5935 case DW_TAG_pointer_type:
5936 read_tag_pointer_type (die, cu);
5938 case DW_TAG_ptr_to_member_type:
5939 read_tag_ptr_to_member_type (die, cu);
5941 case DW_TAG_reference_type:
5942 read_tag_reference_type (die, cu);
5944 case DW_TAG_const_type:
5945 read_tag_const_type (die, cu);
5947 case DW_TAG_volatile_type:
5948 read_tag_volatile_type (die, cu);
5950 case DW_TAG_string_type:
5951 read_tag_string_type (die, cu);
5953 case DW_TAG_typedef:
5954 read_typedef (die, cu);
5956 case DW_TAG_subrange_type:
5957 read_subrange_type (die, cu);
5959 case DW_TAG_base_type:
5960 read_base_type (die, cu);
5963 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
5964 dwarf_tag_name (die->tag));
5968 processing_current_prefix = old_prefix;
5969 do_cleanups (back_to);
5972 /* Return the name of the namespace/class that DIE is defined
5973 within, or NULL if we can't tell. The caller should xfree the
5977 determine_prefix (struct die_info *die)
5979 struct die_info *parent;
5981 if (cu_language != language_cplus)
5984 parent = die->parent;
5988 return (processing_has_namespace_info ? xstrdup ("") : NULL);
5992 char *parent_prefix = determine_prefix (parent);
5995 switch (parent->tag) {
5996 case DW_TAG_namespace:
6000 retval = typename_concat (parent_prefix,
6001 namespace_name (parent, &dummy));
6004 case DW_TAG_class_type:
6005 case DW_TAG_structure_type:
6007 if (parent_prefix != NULL)
6009 const char *parent_name = dwarf2_name (parent);
6011 if (parent_name != NULL)
6012 retval = typename_concat (parent_prefix, dwarf2_name (parent));
6014 /* FIXME: carlton/2003-11-10: I'm not sure what the
6015 best thing to do here is. */
6016 retval = typename_concat (parent_prefix,
6017 "<<anonymous class>>");
6020 retval = class_name (parent);
6024 retval = parent_prefix;
6028 if (retval != parent_prefix)
6029 xfree (parent_prefix);
6034 /* Return a newly-allocated string formed by concatenating PREFIX,
6035 "::", and SUFFIX, except that if PREFIX is NULL or the empty
6036 string, just return a copy of SUFFIX. */
6039 typename_concat (const char *prefix, const char *suffix)
6041 if (prefix == NULL || prefix[0] == '\0')
6042 return xstrdup (suffix);
6045 char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1);
6047 strcpy (retval, prefix);
6048 strcat (retval, "::");
6049 strcat (retval, suffix);
6055 /* Return a newly-allocated string giving the name of the class given
6059 class_name (struct die_info *die)
6061 struct die_info *child;
6064 for (child = die->child; child != NULL; child = sibling_die (child))
6066 if (child->tag == DW_TAG_subprogram)
6067 return class_name_from_physname (dwarf2_linkage_name (child));
6070 name = dwarf2_name (die);
6072 return xstrdup (name);
6074 return xstrdup ("");
6077 static struct type *
6078 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6080 struct objfile *objfile = cu->objfile;
6082 /* FIXME - this should not produce a new (struct type *)
6083 every time. It should cache base types. */
6087 case DW_ATE_address:
6088 type = dwarf2_fundamental_type (objfile, FT_VOID);
6090 case DW_ATE_boolean:
6091 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN);
6093 case DW_ATE_complex_float:
6096 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX);
6100 type = dwarf2_fundamental_type (objfile, FT_COMPLEX);
6106 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
6110 type = dwarf2_fundamental_type (objfile, FT_FLOAT);
6117 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
6120 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT);
6124 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
6128 case DW_ATE_signed_char:
6129 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
6131 case DW_ATE_unsigned:
6135 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
6138 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT);
6142 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
6146 case DW_ATE_unsigned_char:
6147 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
6150 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
6157 copy_die (struct die_info *old_die)
6159 struct die_info *new_die;
6162 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
6163 memset (new_die, 0, sizeof (struct die_info));
6165 new_die->tag = old_die->tag;
6166 new_die->has_children = old_die->has_children;
6167 new_die->abbrev = old_die->abbrev;
6168 new_die->offset = old_die->offset;
6169 new_die->type = NULL;
6171 num_attrs = old_die->num_attrs;
6172 new_die->num_attrs = num_attrs;
6173 new_die->attrs = (struct attribute *)
6174 xmalloc (num_attrs * sizeof (struct attribute));
6176 for (i = 0; i < old_die->num_attrs; ++i)
6178 new_die->attrs[i].name = old_die->attrs[i].name;
6179 new_die->attrs[i].form = old_die->attrs[i].form;
6180 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
6183 new_die->next = NULL;
6188 /* Return sibling of die, NULL if no sibling. */
6190 static struct die_info *
6191 sibling_die (struct die_info *die)
6193 return die->sibling;
6196 /* Get linkage name of a die, return NULL if not found. */
6199 dwarf2_linkage_name (struct die_info *die)
6201 struct attribute *attr;
6203 attr = dwarf_attr (die, DW_AT_MIPS_linkage_name);
6204 if (attr && DW_STRING (attr))
6205 return DW_STRING (attr);
6206 attr = dwarf_attr (die, DW_AT_name);
6207 if (attr && DW_STRING (attr))
6208 return DW_STRING (attr);
6212 /* Get name of a die, return NULL if not found. */
6215 dwarf2_name (struct die_info *die)
6217 struct attribute *attr;
6219 attr = dwarf_attr (die, DW_AT_name);
6220 if (attr && DW_STRING (attr))
6221 return DW_STRING (attr);
6225 /* Return the die that this die in an extension of, or NULL if there
6228 static struct die_info *
6229 dwarf2_extension (struct die_info *die)
6231 struct attribute *attr;
6232 struct die_info *extension_die;
6235 attr = dwarf_attr (die, DW_AT_extension);
6239 ref = dwarf2_get_ref_die_offset (attr);
6240 extension_die = follow_die_ref (ref);
6243 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
6246 return extension_die;
6249 /* Convert a DIE tag into its string name. */
6252 dwarf_tag_name (unsigned tag)
6256 case DW_TAG_padding:
6257 return "DW_TAG_padding";
6258 case DW_TAG_array_type:
6259 return "DW_TAG_array_type";
6260 case DW_TAG_class_type:
6261 return "DW_TAG_class_type";
6262 case DW_TAG_entry_point:
6263 return "DW_TAG_entry_point";
6264 case DW_TAG_enumeration_type:
6265 return "DW_TAG_enumeration_type";
6266 case DW_TAG_formal_parameter:
6267 return "DW_TAG_formal_parameter";
6268 case DW_TAG_imported_declaration:
6269 return "DW_TAG_imported_declaration";
6271 return "DW_TAG_label";
6272 case DW_TAG_lexical_block:
6273 return "DW_TAG_lexical_block";
6275 return "DW_TAG_member";
6276 case DW_TAG_pointer_type:
6277 return "DW_TAG_pointer_type";
6278 case DW_TAG_reference_type:
6279 return "DW_TAG_reference_type";
6280 case DW_TAG_compile_unit:
6281 return "DW_TAG_compile_unit";
6282 case DW_TAG_string_type:
6283 return "DW_TAG_string_type";
6284 case DW_TAG_structure_type:
6285 return "DW_TAG_structure_type";
6286 case DW_TAG_subroutine_type:
6287 return "DW_TAG_subroutine_type";
6288 case DW_TAG_typedef:
6289 return "DW_TAG_typedef";
6290 case DW_TAG_union_type:
6291 return "DW_TAG_union_type";
6292 case DW_TAG_unspecified_parameters:
6293 return "DW_TAG_unspecified_parameters";
6294 case DW_TAG_variant:
6295 return "DW_TAG_variant";
6296 case DW_TAG_common_block:
6297 return "DW_TAG_common_block";
6298 case DW_TAG_common_inclusion:
6299 return "DW_TAG_common_inclusion";
6300 case DW_TAG_inheritance:
6301 return "DW_TAG_inheritance";
6302 case DW_TAG_inlined_subroutine:
6303 return "DW_TAG_inlined_subroutine";
6305 return "DW_TAG_module";
6306 case DW_TAG_ptr_to_member_type:
6307 return "DW_TAG_ptr_to_member_type";
6308 case DW_TAG_set_type:
6309 return "DW_TAG_set_type";
6310 case DW_TAG_subrange_type:
6311 return "DW_TAG_subrange_type";
6312 case DW_TAG_with_stmt:
6313 return "DW_TAG_with_stmt";
6314 case DW_TAG_access_declaration:
6315 return "DW_TAG_access_declaration";
6316 case DW_TAG_base_type:
6317 return "DW_TAG_base_type";
6318 case DW_TAG_catch_block:
6319 return "DW_TAG_catch_block";
6320 case DW_TAG_const_type:
6321 return "DW_TAG_const_type";
6322 case DW_TAG_constant:
6323 return "DW_TAG_constant";
6324 case DW_TAG_enumerator:
6325 return "DW_TAG_enumerator";
6326 case DW_TAG_file_type:
6327 return "DW_TAG_file_type";
6329 return "DW_TAG_friend";
6330 case DW_TAG_namelist:
6331 return "DW_TAG_namelist";
6332 case DW_TAG_namelist_item:
6333 return "DW_TAG_namelist_item";
6334 case DW_TAG_packed_type:
6335 return "DW_TAG_packed_type";
6336 case DW_TAG_subprogram:
6337 return "DW_TAG_subprogram";
6338 case DW_TAG_template_type_param:
6339 return "DW_TAG_template_type_param";
6340 case DW_TAG_template_value_param:
6341 return "DW_TAG_template_value_param";
6342 case DW_TAG_thrown_type:
6343 return "DW_TAG_thrown_type";
6344 case DW_TAG_try_block:
6345 return "DW_TAG_try_block";
6346 case DW_TAG_variant_part:
6347 return "DW_TAG_variant_part";
6348 case DW_TAG_variable:
6349 return "DW_TAG_variable";
6350 case DW_TAG_volatile_type:
6351 return "DW_TAG_volatile_type";
6352 case DW_TAG_dwarf_procedure:
6353 return "DW_TAG_dwarf_procedure";
6354 case DW_TAG_restrict_type:
6355 return "DW_TAG_restrict_type";
6356 case DW_TAG_interface_type:
6357 return "DW_TAG_interface_type";
6358 case DW_TAG_namespace:
6359 return "DW_TAG_namespace";
6360 case DW_TAG_imported_module:
6361 return "DW_TAG_imported_module";
6362 case DW_TAG_unspecified_type:
6363 return "DW_TAG_unspecified_type";
6364 case DW_TAG_partial_unit:
6365 return "DW_TAG_partial_unit";
6366 case DW_TAG_imported_unit:
6367 return "DW_TAG_imported_unit";
6368 case DW_TAG_MIPS_loop:
6369 return "DW_TAG_MIPS_loop";
6370 case DW_TAG_format_label:
6371 return "DW_TAG_format_label";
6372 case DW_TAG_function_template:
6373 return "DW_TAG_function_template";
6374 case DW_TAG_class_template:
6375 return "DW_TAG_class_template";
6377 return "DW_TAG_<unknown>";
6381 /* Convert a DWARF attribute code into its string name. */
6384 dwarf_attr_name (unsigned attr)
6389 return "DW_AT_sibling";
6390 case DW_AT_location:
6391 return "DW_AT_location";
6393 return "DW_AT_name";
6394 case DW_AT_ordering:
6395 return "DW_AT_ordering";
6396 case DW_AT_subscr_data:
6397 return "DW_AT_subscr_data";
6398 case DW_AT_byte_size:
6399 return "DW_AT_byte_size";
6400 case DW_AT_bit_offset:
6401 return "DW_AT_bit_offset";
6402 case DW_AT_bit_size:
6403 return "DW_AT_bit_size";
6404 case DW_AT_element_list:
6405 return "DW_AT_element_list";
6406 case DW_AT_stmt_list:
6407 return "DW_AT_stmt_list";
6409 return "DW_AT_low_pc";
6411 return "DW_AT_high_pc";
6412 case DW_AT_language:
6413 return "DW_AT_language";
6415 return "DW_AT_member";
6417 return "DW_AT_discr";
6418 case DW_AT_discr_value:
6419 return "DW_AT_discr_value";
6420 case DW_AT_visibility:
6421 return "DW_AT_visibility";
6423 return "DW_AT_import";
6424 case DW_AT_string_length:
6425 return "DW_AT_string_length";
6426 case DW_AT_common_reference:
6427 return "DW_AT_common_reference";
6428 case DW_AT_comp_dir:
6429 return "DW_AT_comp_dir";
6430 case DW_AT_const_value:
6431 return "DW_AT_const_value";
6432 case DW_AT_containing_type:
6433 return "DW_AT_containing_type";
6434 case DW_AT_default_value:
6435 return "DW_AT_default_value";
6437 return "DW_AT_inline";
6438 case DW_AT_is_optional:
6439 return "DW_AT_is_optional";
6440 case DW_AT_lower_bound:
6441 return "DW_AT_lower_bound";
6442 case DW_AT_producer:
6443 return "DW_AT_producer";
6444 case DW_AT_prototyped:
6445 return "DW_AT_prototyped";
6446 case DW_AT_return_addr:
6447 return "DW_AT_return_addr";
6448 case DW_AT_start_scope:
6449 return "DW_AT_start_scope";
6450 case DW_AT_stride_size:
6451 return "DW_AT_stride_size";
6452 case DW_AT_upper_bound:
6453 return "DW_AT_upper_bound";
6454 case DW_AT_abstract_origin:
6455 return "DW_AT_abstract_origin";
6456 case DW_AT_accessibility:
6457 return "DW_AT_accessibility";
6458 case DW_AT_address_class:
6459 return "DW_AT_address_class";
6460 case DW_AT_artificial:
6461 return "DW_AT_artificial";
6462 case DW_AT_base_types:
6463 return "DW_AT_base_types";
6464 case DW_AT_calling_convention:
6465 return "DW_AT_calling_convention";
6467 return "DW_AT_count";
6468 case DW_AT_data_member_location:
6469 return "DW_AT_data_member_location";
6470 case DW_AT_decl_column:
6471 return "DW_AT_decl_column";
6472 case DW_AT_decl_file:
6473 return "DW_AT_decl_file";
6474 case DW_AT_decl_line:
6475 return "DW_AT_decl_line";
6476 case DW_AT_declaration:
6477 return "DW_AT_declaration";
6478 case DW_AT_discr_list:
6479 return "DW_AT_discr_list";
6480 case DW_AT_encoding:
6481 return "DW_AT_encoding";
6482 case DW_AT_external:
6483 return "DW_AT_external";
6484 case DW_AT_frame_base:
6485 return "DW_AT_frame_base";
6487 return "DW_AT_friend";
6488 case DW_AT_identifier_case:
6489 return "DW_AT_identifier_case";
6490 case DW_AT_macro_info:
6491 return "DW_AT_macro_info";
6492 case DW_AT_namelist_items:
6493 return "DW_AT_namelist_items";
6494 case DW_AT_priority:
6495 return "DW_AT_priority";
6497 return "DW_AT_segment";
6498 case DW_AT_specification:
6499 return "DW_AT_specification";
6500 case DW_AT_static_link:
6501 return "DW_AT_static_link";
6503 return "DW_AT_type";
6504 case DW_AT_use_location:
6505 return "DW_AT_use_location";
6506 case DW_AT_variable_parameter:
6507 return "DW_AT_variable_parameter";
6508 case DW_AT_virtuality:
6509 return "DW_AT_virtuality";
6510 case DW_AT_vtable_elem_location:
6511 return "DW_AT_vtable_elem_location";
6512 case DW_AT_allocated:
6513 return "DW_AT_allocated";
6514 case DW_AT_associated:
6515 return "DW_AT_associated";
6516 case DW_AT_data_location:
6517 return "DW_AT_data_location";
6519 return "DW_AT_stride";
6520 case DW_AT_entry_pc:
6521 return "DW_AT_entry_pc";
6522 case DW_AT_use_UTF8:
6523 return "DW_AT_use_UTF8";
6524 case DW_AT_extension:
6525 return "DW_AT_extension";
6527 return "DW_AT_ranges";
6528 case DW_AT_trampoline:
6529 return "DW_AT_trampoline";
6530 case DW_AT_call_column:
6531 return "DW_AT_call_column";
6532 case DW_AT_call_file:
6533 return "DW_AT_call_file";
6534 case DW_AT_call_line:
6535 return "DW_AT_call_line";
6537 case DW_AT_MIPS_fde:
6538 return "DW_AT_MIPS_fde";
6539 case DW_AT_MIPS_loop_begin:
6540 return "DW_AT_MIPS_loop_begin";
6541 case DW_AT_MIPS_tail_loop_begin:
6542 return "DW_AT_MIPS_tail_loop_begin";
6543 case DW_AT_MIPS_epilog_begin:
6544 return "DW_AT_MIPS_epilog_begin";
6545 case DW_AT_MIPS_loop_unroll_factor:
6546 return "DW_AT_MIPS_loop_unroll_factor";
6547 case DW_AT_MIPS_software_pipeline_depth:
6548 return "DW_AT_MIPS_software_pipeline_depth";
6550 case DW_AT_MIPS_linkage_name:
6551 return "DW_AT_MIPS_linkage_name";
6553 case DW_AT_sf_names:
6554 return "DW_AT_sf_names";
6555 case DW_AT_src_info:
6556 return "DW_AT_src_info";
6557 case DW_AT_mac_info:
6558 return "DW_AT_mac_info";
6559 case DW_AT_src_coords:
6560 return "DW_AT_src_coords";
6561 case DW_AT_body_begin:
6562 return "DW_AT_body_begin";
6563 case DW_AT_body_end:
6564 return "DW_AT_body_end";
6565 case DW_AT_GNU_vector:
6566 return "DW_AT_GNU_vector";
6568 return "DW_AT_<unknown>";
6572 /* Convert a DWARF value form code into its string name. */
6575 dwarf_form_name (unsigned form)
6580 return "DW_FORM_addr";
6581 case DW_FORM_block2:
6582 return "DW_FORM_block2";
6583 case DW_FORM_block4:
6584 return "DW_FORM_block4";
6586 return "DW_FORM_data2";
6588 return "DW_FORM_data4";
6590 return "DW_FORM_data8";
6591 case DW_FORM_string:
6592 return "DW_FORM_string";
6594 return "DW_FORM_block";
6595 case DW_FORM_block1:
6596 return "DW_FORM_block1";
6598 return "DW_FORM_data1";
6600 return "DW_FORM_flag";
6602 return "DW_FORM_sdata";
6604 return "DW_FORM_strp";
6606 return "DW_FORM_udata";
6607 case DW_FORM_ref_addr:
6608 return "DW_FORM_ref_addr";
6610 return "DW_FORM_ref1";
6612 return "DW_FORM_ref2";
6614 return "DW_FORM_ref4";
6616 return "DW_FORM_ref8";
6617 case DW_FORM_ref_udata:
6618 return "DW_FORM_ref_udata";
6619 case DW_FORM_indirect:
6620 return "DW_FORM_indirect";
6622 return "DW_FORM_<unknown>";
6626 /* Convert a DWARF stack opcode into its string name. */
6629 dwarf_stack_op_name (unsigned op)
6634 return "DW_OP_addr";
6636 return "DW_OP_deref";
6638 return "DW_OP_const1u";
6640 return "DW_OP_const1s";
6642 return "DW_OP_const2u";
6644 return "DW_OP_const2s";
6646 return "DW_OP_const4u";
6648 return "DW_OP_const4s";
6650 return "DW_OP_const8u";
6652 return "DW_OP_const8s";
6654 return "DW_OP_constu";
6656 return "DW_OP_consts";
6660 return "DW_OP_drop";
6662 return "DW_OP_over";
6664 return "DW_OP_pick";
6666 return "DW_OP_swap";
6670 return "DW_OP_xderef";
6678 return "DW_OP_minus";
6690 return "DW_OP_plus";
6691 case DW_OP_plus_uconst:
6692 return "DW_OP_plus_uconst";
6698 return "DW_OP_shra";
6716 return "DW_OP_skip";
6718 return "DW_OP_lit0";
6720 return "DW_OP_lit1";
6722 return "DW_OP_lit2";
6724 return "DW_OP_lit3";
6726 return "DW_OP_lit4";
6728 return "DW_OP_lit5";
6730 return "DW_OP_lit6";
6732 return "DW_OP_lit7";
6734 return "DW_OP_lit8";
6736 return "DW_OP_lit9";
6738 return "DW_OP_lit10";
6740 return "DW_OP_lit11";
6742 return "DW_OP_lit12";
6744 return "DW_OP_lit13";
6746 return "DW_OP_lit14";
6748 return "DW_OP_lit15";
6750 return "DW_OP_lit16";
6752 return "DW_OP_lit17";
6754 return "DW_OP_lit18";
6756 return "DW_OP_lit19";
6758 return "DW_OP_lit20";
6760 return "DW_OP_lit21";
6762 return "DW_OP_lit22";
6764 return "DW_OP_lit23";
6766 return "DW_OP_lit24";
6768 return "DW_OP_lit25";
6770 return "DW_OP_lit26";
6772 return "DW_OP_lit27";
6774 return "DW_OP_lit28";
6776 return "DW_OP_lit29";
6778 return "DW_OP_lit30";
6780 return "DW_OP_lit31";
6782 return "DW_OP_reg0";
6784 return "DW_OP_reg1";
6786 return "DW_OP_reg2";
6788 return "DW_OP_reg3";
6790 return "DW_OP_reg4";
6792 return "DW_OP_reg5";
6794 return "DW_OP_reg6";
6796 return "DW_OP_reg7";
6798 return "DW_OP_reg8";
6800 return "DW_OP_reg9";
6802 return "DW_OP_reg10";
6804 return "DW_OP_reg11";
6806 return "DW_OP_reg12";
6808 return "DW_OP_reg13";
6810 return "DW_OP_reg14";
6812 return "DW_OP_reg15";
6814 return "DW_OP_reg16";
6816 return "DW_OP_reg17";
6818 return "DW_OP_reg18";
6820 return "DW_OP_reg19";
6822 return "DW_OP_reg20";
6824 return "DW_OP_reg21";
6826 return "DW_OP_reg22";
6828 return "DW_OP_reg23";
6830 return "DW_OP_reg24";
6832 return "DW_OP_reg25";
6834 return "DW_OP_reg26";
6836 return "DW_OP_reg27";
6838 return "DW_OP_reg28";
6840 return "DW_OP_reg29";
6842 return "DW_OP_reg30";
6844 return "DW_OP_reg31";
6846 return "DW_OP_breg0";
6848 return "DW_OP_breg1";
6850 return "DW_OP_breg2";
6852 return "DW_OP_breg3";
6854 return "DW_OP_breg4";
6856 return "DW_OP_breg5";
6858 return "DW_OP_breg6";
6860 return "DW_OP_breg7";
6862 return "DW_OP_breg8";
6864 return "DW_OP_breg9";
6866 return "DW_OP_breg10";
6868 return "DW_OP_breg11";
6870 return "DW_OP_breg12";
6872 return "DW_OP_breg13";
6874 return "DW_OP_breg14";
6876 return "DW_OP_breg15";
6878 return "DW_OP_breg16";
6880 return "DW_OP_breg17";
6882 return "DW_OP_breg18";
6884 return "DW_OP_breg19";
6886 return "DW_OP_breg20";
6888 return "DW_OP_breg21";
6890 return "DW_OP_breg22";
6892 return "DW_OP_breg23";
6894 return "DW_OP_breg24";
6896 return "DW_OP_breg25";
6898 return "DW_OP_breg26";
6900 return "DW_OP_breg27";
6902 return "DW_OP_breg28";
6904 return "DW_OP_breg29";
6906 return "DW_OP_breg30";
6908 return "DW_OP_breg31";
6910 return "DW_OP_regx";
6912 return "DW_OP_fbreg";
6914 return "DW_OP_bregx";
6916 return "DW_OP_piece";
6917 case DW_OP_deref_size:
6918 return "DW_OP_deref_size";
6919 case DW_OP_xderef_size:
6920 return "DW_OP_xderef_size";
6923 /* DWARF 3 extensions. */
6924 case DW_OP_push_object_address:
6925 return "DW_OP_push_object_address";
6927 return "DW_OP_call2";
6929 return "DW_OP_call4";
6930 case DW_OP_call_ref:
6931 return "DW_OP_call_ref";
6932 /* GNU extensions. */
6933 case DW_OP_GNU_push_tls_address:
6934 return "DW_OP_GNU_push_tls_address";
6936 return "OP_<unknown>";
6941 dwarf_bool_name (unsigned mybool)
6949 /* Convert a DWARF type code into its string name. */
6952 dwarf_type_encoding_name (unsigned enc)
6956 case DW_ATE_address:
6957 return "DW_ATE_address";
6958 case DW_ATE_boolean:
6959 return "DW_ATE_boolean";
6960 case DW_ATE_complex_float:
6961 return "DW_ATE_complex_float";
6963 return "DW_ATE_float";
6965 return "DW_ATE_signed";
6966 case DW_ATE_signed_char:
6967 return "DW_ATE_signed_char";
6968 case DW_ATE_unsigned:
6969 return "DW_ATE_unsigned";
6970 case DW_ATE_unsigned_char:
6971 return "DW_ATE_unsigned_char";
6972 case DW_ATE_imaginary_float:
6973 return "DW_ATE_imaginary_float";
6975 return "DW_ATE_<unknown>";
6979 /* Convert a DWARF call frame info operation to its string name. */
6983 dwarf_cfi_name (unsigned cfi_opc)
6987 case DW_CFA_advance_loc:
6988 return "DW_CFA_advance_loc";
6990 return "DW_CFA_offset";
6991 case DW_CFA_restore:
6992 return "DW_CFA_restore";
6994 return "DW_CFA_nop";
6995 case DW_CFA_set_loc:
6996 return "DW_CFA_set_loc";
6997 case DW_CFA_advance_loc1:
6998 return "DW_CFA_advance_loc1";
6999 case DW_CFA_advance_loc2:
7000 return "DW_CFA_advance_loc2";
7001 case DW_CFA_advance_loc4:
7002 return "DW_CFA_advance_loc4";
7003 case DW_CFA_offset_extended:
7004 return "DW_CFA_offset_extended";
7005 case DW_CFA_restore_extended:
7006 return "DW_CFA_restore_extended";
7007 case DW_CFA_undefined:
7008 return "DW_CFA_undefined";
7009 case DW_CFA_same_value:
7010 return "DW_CFA_same_value";
7011 case DW_CFA_register:
7012 return "DW_CFA_register";
7013 case DW_CFA_remember_state:
7014 return "DW_CFA_remember_state";
7015 case DW_CFA_restore_state:
7016 return "DW_CFA_restore_state";
7017 case DW_CFA_def_cfa:
7018 return "DW_CFA_def_cfa";
7019 case DW_CFA_def_cfa_register:
7020 return "DW_CFA_def_cfa_register";
7021 case DW_CFA_def_cfa_offset:
7022 return "DW_CFA_def_cfa_offset";
7025 case DW_CFA_def_cfa_expression:
7026 return "DW_CFA_def_cfa_expression";
7027 case DW_CFA_expression:
7028 return "DW_CFA_expression";
7029 case DW_CFA_offset_extended_sf:
7030 return "DW_CFA_offset_extended_sf";
7031 case DW_CFA_def_cfa_sf:
7032 return "DW_CFA_def_cfa_sf";
7033 case DW_CFA_def_cfa_offset_sf:
7034 return "DW_CFA_def_cfa_offset_sf";
7036 /* SGI/MIPS specific */
7037 case DW_CFA_MIPS_advance_loc8:
7038 return "DW_CFA_MIPS_advance_loc8";
7040 /* GNU extensions */
7041 case DW_CFA_GNU_window_save:
7042 return "DW_CFA_GNU_window_save";
7043 case DW_CFA_GNU_args_size:
7044 return "DW_CFA_GNU_args_size";
7045 case DW_CFA_GNU_negative_offset_extended:
7046 return "DW_CFA_GNU_negative_offset_extended";
7049 return "DW_CFA_<unknown>";
7055 dump_die (struct die_info *die)
7059 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7060 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7061 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7062 dwarf_bool_name (die->child != NULL));
7064 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7065 for (i = 0; i < die->num_attrs; ++i)
7067 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7068 dwarf_attr_name (die->attrs[i].name),
7069 dwarf_form_name (die->attrs[i].form));
7070 switch (die->attrs[i].form)
7072 case DW_FORM_ref_addr:
7074 fprintf_unfiltered (gdb_stderr, "address: ");
7075 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7077 case DW_FORM_block2:
7078 case DW_FORM_block4:
7080 case DW_FORM_block1:
7081 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7092 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7094 case DW_FORM_string:
7096 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7097 DW_STRING (&die->attrs[i])
7098 ? DW_STRING (&die->attrs[i]) : "");
7101 if (DW_UNSND (&die->attrs[i]))
7102 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7104 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7106 case DW_FORM_indirect:
7107 /* the reader will have reduced the indirect form to
7108 the "base form" so this form should not occur */
7109 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7112 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7113 die->attrs[i].form);
7115 fprintf_unfiltered (gdb_stderr, "\n");
7120 dump_die_list (struct die_info *die)
7125 if (die->child != NULL)
7126 dump_die_list (die->child);
7127 if (die->sibling != NULL)
7128 dump_die_list (die->sibling);
7133 store_in_ref_table (unsigned int offset, struct die_info *die)
7136 struct die_info *old;
7138 h = (offset % REF_HASH_SIZE);
7139 old = die_ref_table[h];
7140 die->next_ref = old;
7141 die_ref_table[h] = die;
7146 dwarf2_empty_hash_tables (void)
7148 memset (die_ref_table, 0, sizeof (die_ref_table));
7152 dwarf2_get_ref_die_offset (struct attribute *attr)
7154 unsigned int result = 0;
7158 case DW_FORM_ref_addr:
7159 result = DW_ADDR (attr);
7165 case DW_FORM_ref_udata:
7166 result = cu_header_offset + DW_UNSND (attr);
7169 complaint (&symfile_complaints,
7170 "unsupported die ref attribute form: '%s'",
7171 dwarf_form_name (attr->form));
7176 /* Return the constant value held by the given attribute. Return -1
7177 if the value held by the attribute is not constant. */
7180 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
7182 if (attr->form == DW_FORM_sdata)
7183 return DW_SND (attr);
7184 else if (attr->form == DW_FORM_udata
7185 || attr->form == DW_FORM_data1
7186 || attr->form == DW_FORM_data2
7187 || attr->form == DW_FORM_data4
7188 || attr->form == DW_FORM_data8)
7189 return DW_UNSND (attr);
7192 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
7193 dwarf_form_name (attr->form));
7194 return default_value;
7198 static struct die_info *
7199 follow_die_ref (unsigned int offset)
7201 struct die_info *die;
7204 h = (offset % REF_HASH_SIZE);
7205 die = die_ref_table[h];
7208 if (die->offset == offset)
7212 die = die->next_ref;
7217 static struct type *
7218 dwarf2_fundamental_type (struct objfile *objfile, int typeid)
7220 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
7222 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
7223 typeid, objfile->name);
7226 /* Look for this particular type in the fundamental type vector. If
7227 one is not found, create and install one appropriate for the
7228 current language and the current target machine. */
7230 if (ftypes[typeid] == NULL)
7232 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
7235 return (ftypes[typeid]);
7238 /* Decode simple location descriptions.
7239 Given a pointer to a dwarf block that defines a location, compute
7240 the location and return the value.
7242 NOTE drow/2003-11-18: This function is called in two situations
7243 now: for the address of static or global variables (partial symbols
7244 only) and for offsets into structures which are expected to be
7245 (more or less) constant. The partial symbol case should go away,
7246 and only the constant case should remain. That will let this
7247 function complain more accurately. A few special modes are allowed
7248 without complaint for global variables (for instance, global
7249 register values and thread-local values).
7251 A location description containing no operations indicates that the
7252 object is optimized out. The return value is 0 for that case.
7253 FIXME drow/2003-11-16: No callers check for this case any more; soon all
7254 callers will only want a very basic result and this can become a
7257 When the result is a register number, the global isreg flag is set,
7258 otherwise it is cleared.
7260 Note that stack[0] is unused except as a default error return.
7261 Note that stack overflow is not yet handled. */
7264 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
7266 struct objfile *objfile = cu->objfile;
7267 struct comp_unit_head *cu_header = &cu->header;
7269 int size = blk->size;
7270 char *data = blk->data;
7271 CORE_ADDR stack[64];
7273 unsigned int bytes_read, unsnd;
7318 stack[++stacki] = op - DW_OP_lit0;
7354 stack[++stacki] = op - DW_OP_reg0;
7356 dwarf2_complex_location_expr_complaint ();
7361 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7363 stack[++stacki] = unsnd;
7365 dwarf2_complex_location_expr_complaint ();
7369 stack[++stacki] = read_address (objfile->obfd, &data[i],
7375 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
7380 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
7385 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
7390 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
7395 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
7400 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
7405 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
7411 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
7416 stack[stacki + 1] = stack[stacki];
7421 stack[stacki - 1] += stack[stacki];
7425 case DW_OP_plus_uconst:
7426 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
7431 stack[stacki - 1] -= stack[stacki];
7436 /* If we're not the last op, then we definitely can't encode
7437 this using GDB's address_class enum. This is valid for partial
7438 global symbols, although the variable's address will be bogus
7441 dwarf2_complex_location_expr_complaint ();
7444 case DW_OP_GNU_push_tls_address:
7445 /* The top of the stack has the offset from the beginning
7446 of the thread control block at which the variable is located. */
7447 /* Nothing should follow this operator, so the top of stack would
7449 /* This is valid for partial global symbols, but the variable's
7450 address will be bogus in the psymtab. */
7452 dwarf2_complex_location_expr_complaint ();
7456 complaint (&symfile_complaints, "unsupported stack op: '%s'",
7457 dwarf_stack_op_name (op));
7458 return (stack[stacki]);
7461 return (stack[stacki]);
7464 /* memory allocation interface */
7467 dwarf2_free_tmp_obstack (void *ignore)
7469 obstack_free (&dwarf2_tmp_obstack, NULL);
7472 static struct dwarf_block *
7473 dwarf_alloc_block (void)
7475 struct dwarf_block *blk;
7477 blk = (struct dwarf_block *)
7478 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
7482 static struct abbrev_info *
7483 dwarf_alloc_abbrev (void)
7485 struct abbrev_info *abbrev;
7487 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
7488 memset (abbrev, 0, sizeof (struct abbrev_info));
7492 static struct die_info *
7493 dwarf_alloc_die (void)
7495 struct die_info *die;
7497 die = (struct die_info *) xmalloc (sizeof (struct die_info));
7498 memset (die, 0, sizeof (struct die_info));
7503 /* Macro support. */
7506 /* Return the full name of file number I in *LH's file name table.
7507 Use COMP_DIR as the name of the current directory of the
7508 compilation. The result is allocated using xmalloc; the caller is
7509 responsible for freeing it. */
7511 file_full_name (int file, struct line_header *lh, const char *comp_dir)
7513 struct file_entry *fe = &lh->file_names[file - 1];
7515 if (IS_ABSOLUTE_PATH (fe->name))
7516 return xstrdup (fe->name);
7524 dir = lh->include_dirs[fe->dir_index - 1];
7530 dir_len = strlen (dir);
7531 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
7532 strcpy (full_name, dir);
7533 full_name[dir_len] = '/';
7534 strcpy (full_name + dir_len + 1, fe->name);
7538 return xstrdup (fe->name);
7543 static struct macro_source_file *
7544 macro_start_file (int file, int line,
7545 struct macro_source_file *current_file,
7546 const char *comp_dir,
7547 struct line_header *lh, struct objfile *objfile)
7549 /* The full name of this source file. */
7550 char *full_name = file_full_name (file, lh, comp_dir);
7552 /* We don't create a macro table for this compilation unit
7553 at all until we actually get a filename. */
7554 if (! pending_macros)
7555 pending_macros = new_macro_table (&objfile->symbol_obstack,
7556 objfile->macro_cache);
7559 /* If we have no current file, then this must be the start_file
7560 directive for the compilation unit's main source file. */
7561 current_file = macro_set_main (pending_macros, full_name);
7563 current_file = macro_include (current_file, line, full_name);
7567 return current_file;
7571 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
7572 followed by a null byte. */
7574 copy_string (const char *buf, int len)
7576 char *s = xmalloc (len + 1);
7577 memcpy (s, buf, len);
7585 consume_improper_spaces (const char *p, const char *body)
7589 complaint (&symfile_complaints,
7590 "macro definition contains spaces in formal argument list:\n`%s'",
7602 parse_macro_definition (struct macro_source_file *file, int line,
7607 /* The body string takes one of two forms. For object-like macro
7608 definitions, it should be:
7610 <macro name> " " <definition>
7612 For function-like macro definitions, it should be:
7614 <macro name> "() " <definition>
7616 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7618 Spaces may appear only where explicitly indicated, and in the
7621 The Dwarf 2 spec says that an object-like macro's name is always
7622 followed by a space, but versions of GCC around March 2002 omit
7623 the space when the macro's definition is the empty string.
7625 The Dwarf 2 spec says that there should be no spaces between the
7626 formal arguments in a function-like macro's formal argument list,
7627 but versions of GCC around March 2002 include spaces after the
7631 /* Find the extent of the macro name. The macro name is terminated
7632 by either a space or null character (for an object-like macro) or
7633 an opening paren (for a function-like macro). */
7634 for (p = body; *p; p++)
7635 if (*p == ' ' || *p == '(')
7638 if (*p == ' ' || *p == '\0')
7640 /* It's an object-like macro. */
7641 int name_len = p - body;
7642 char *name = copy_string (body, name_len);
7643 const char *replacement;
7646 replacement = body + name_len + 1;
7649 dwarf2_macro_malformed_definition_complaint (body);
7650 replacement = body + name_len;
7653 macro_define_object (file, line, name, replacement);
7659 /* It's a function-like macro. */
7660 char *name = copy_string (body, p - body);
7663 char **argv = xmalloc (argv_size * sizeof (*argv));
7667 p = consume_improper_spaces (p, body);
7669 /* Parse the formal argument list. */
7670 while (*p && *p != ')')
7672 /* Find the extent of the current argument name. */
7673 const char *arg_start = p;
7675 while (*p && *p != ',' && *p != ')' && *p != ' ')
7678 if (! *p || p == arg_start)
7679 dwarf2_macro_malformed_definition_complaint (body);
7682 /* Make sure argv has room for the new argument. */
7683 if (argc >= argv_size)
7686 argv = xrealloc (argv, argv_size * sizeof (*argv));
7689 argv[argc++] = copy_string (arg_start, p - arg_start);
7692 p = consume_improper_spaces (p, body);
7694 /* Consume the comma, if present. */
7699 p = consume_improper_spaces (p, body);
7708 /* Perfectly formed definition, no complaints. */
7709 macro_define_function (file, line, name,
7710 argc, (const char **) argv,
7712 else if (*p == '\0')
7714 /* Complain, but do define it. */
7715 dwarf2_macro_malformed_definition_complaint (body);
7716 macro_define_function (file, line, name,
7717 argc, (const char **) argv,
7721 /* Just complain. */
7722 dwarf2_macro_malformed_definition_complaint (body);
7725 /* Just complain. */
7726 dwarf2_macro_malformed_definition_complaint (body);
7732 for (i = 0; i < argc; i++)
7738 dwarf2_macro_malformed_definition_complaint (body);
7743 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
7744 char *comp_dir, bfd *abfd,
7745 struct dwarf2_cu *cu)
7747 char *mac_ptr, *mac_end;
7748 struct macro_source_file *current_file = 0;
7750 if (dwarf_macinfo_buffer == NULL)
7752 complaint (&symfile_complaints, "missing .debug_macinfo section");
7756 mac_ptr = dwarf_macinfo_buffer + offset;
7757 mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size;
7761 enum dwarf_macinfo_record_type macinfo_type;
7763 /* Do we at least have room for a macinfo type byte? */
7764 if (mac_ptr >= mac_end)
7766 dwarf2_macros_too_long_complaint ();
7770 macinfo_type = read_1_byte (abfd, mac_ptr);
7773 switch (macinfo_type)
7775 /* A zero macinfo type indicates the end of the macro
7780 case DW_MACINFO_define:
7781 case DW_MACINFO_undef:
7787 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7788 mac_ptr += bytes_read;
7789 body = read_string (abfd, mac_ptr, &bytes_read);
7790 mac_ptr += bytes_read;
7793 complaint (&symfile_complaints,
7794 "debug info gives macro %s outside of any file: %s",
7796 DW_MACINFO_define ? "definition" : macinfo_type ==
7797 DW_MACINFO_undef ? "undefinition" :
7798 "something-or-other", body);
7801 if (macinfo_type == DW_MACINFO_define)
7802 parse_macro_definition (current_file, line, body);
7803 else if (macinfo_type == DW_MACINFO_undef)
7804 macro_undef (current_file, line, body);
7809 case DW_MACINFO_start_file:
7814 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7815 mac_ptr += bytes_read;
7816 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7817 mac_ptr += bytes_read;
7819 current_file = macro_start_file (file, line,
7820 current_file, comp_dir,
7825 case DW_MACINFO_end_file:
7827 complaint (&symfile_complaints,
7828 "macro debug info has an unmatched `close_file' directive");
7831 current_file = current_file->included_by;
7834 enum dwarf_macinfo_record_type next_type;
7836 /* GCC circa March 2002 doesn't produce the zero
7837 type byte marking the end of the compilation
7838 unit. Complain if it's not there, but exit no
7841 /* Do we at least have room for a macinfo type byte? */
7842 if (mac_ptr >= mac_end)
7844 dwarf2_macros_too_long_complaint ();
7848 /* We don't increment mac_ptr here, so this is just
7850 next_type = read_1_byte (abfd, mac_ptr);
7852 complaint (&symfile_complaints,
7853 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7860 case DW_MACINFO_vendor_ext:
7866 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
7867 mac_ptr += bytes_read;
7868 string = read_string (abfd, mac_ptr, &bytes_read);
7869 mac_ptr += bytes_read;
7871 /* We don't recognize any vendor extensions. */
7878 /* Check if the attribute's form is a DW_FORM_block*
7879 if so return true else false. */
7881 attr_form_is_block (struct attribute *attr)
7883 return (attr == NULL ? 0 :
7884 attr->form == DW_FORM_block1
7885 || attr->form == DW_FORM_block2
7886 || attr->form == DW_FORM_block4
7887 || attr->form == DW_FORM_block);
7891 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
7892 struct dwarf2_cu *cu)
7894 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
7896 struct dwarf2_loclist_baton *baton;
7898 baton = obstack_alloc (&cu->objfile->symbol_obstack,
7899 sizeof (struct dwarf2_loclist_baton));
7900 baton->objfile = cu->objfile;
7902 /* We don't know how long the location list is, but make sure we
7903 don't run off the edge of the section. */
7904 baton->size = dwarf_loc_size - DW_UNSND (attr);
7905 baton->data = dwarf_loc_buffer + DW_UNSND (attr);
7906 baton->base_address = cu->header.base_address;
7907 if (cu->header.base_known == 0)
7908 complaint (&symfile_complaints,
7909 "Location list used without specifying the CU base address.");
7911 SYMBOL_LOCATION_FUNCS (sym) = &dwarf2_loclist_funcs;
7912 SYMBOL_LOCATION_BATON (sym) = baton;
7916 struct dwarf2_locexpr_baton *baton;
7918 baton = obstack_alloc (&cu->objfile->symbol_obstack,
7919 sizeof (struct dwarf2_locexpr_baton));
7920 baton->objfile = cu->objfile;
7922 if (attr_form_is_block (attr))
7924 /* Note that we're just copying the block's data pointer
7925 here, not the actual data. We're still pointing into the
7926 dwarf_info_buffer for SYM's objfile; right now we never
7927 release that buffer, but when we do clean up properly
7928 this may need to change. */
7929 baton->size = DW_BLOCK (attr)->size;
7930 baton->data = DW_BLOCK (attr)->data;
7934 dwarf2_invalid_attrib_class_complaint ("location description",
7935 SYMBOL_NATURAL_NAME (sym));
7940 SYMBOL_LOCATION_FUNCS (sym) = &dwarf2_locexpr_funcs;
7941 SYMBOL_LOCATION_BATON (sym) = baton;