1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
46 /* .debug_info header for a compilation unit
47 Because of alignment constraints, this structure has padding and cannot
48 be mapped directly onto the beginning of the .debug_info section. */
49 typedef struct comp_unit_header
51 unsigned int length; /* length of the .debug_info
53 unsigned short version; /* version number -- 2 for DWARF
55 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
56 unsigned char addr_size; /* byte size of an address -- 4 */
59 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
61 /* .debug_pubnames header
62 Because of alignment constraints, this structure has padding and cannot
63 be mapped directly onto the beginning of the .debug_info section. */
64 typedef struct pubnames_header
66 unsigned int length; /* length of the .debug_pubnames
68 unsigned char version; /* version number -- 2 for DWARF
70 unsigned int info_offset; /* offset into .debug_info section */
71 unsigned int info_size; /* byte size of .debug_info section
75 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
77 /* .debug_pubnames header
78 Because of alignment constraints, this structure has padding and cannot
79 be mapped directly onto the beginning of the .debug_info section. */
80 typedef struct aranges_header
82 unsigned int length; /* byte len of the .debug_aranges
84 unsigned short version; /* version number -- 2 for DWARF
86 unsigned int info_offset; /* offset into .debug_info section */
87 unsigned char addr_size; /* byte size of an address */
88 unsigned char seg_size; /* byte size of segment descriptor */
91 #define _ACTUAL_ARANGES_HEADER_SIZE 12
93 /* .debug_line statement program prologue
94 Because of alignment constraints, this structure has padding and cannot
95 be mapped directly onto the beginning of the .debug_info section. */
96 typedef struct statement_prologue
98 unsigned int total_length; /* byte length of the statement
100 unsigned short version; /* version number -- 2 for DWARF
102 unsigned int prologue_length; /* # bytes between prologue &
104 unsigned char minimum_instruction_length; /* byte size of
106 unsigned char default_is_stmt; /* initial value of is_stmt
109 unsigned char line_range;
110 unsigned char opcode_base; /* number assigned to first special
112 unsigned char *standard_opcode_lengths;
116 /* offsets and sizes of debugging sections */
118 static file_ptr dwarf_info_offset;
119 static file_ptr dwarf_abbrev_offset;
120 static file_ptr dwarf_line_offset;
121 static file_ptr dwarf_pubnames_offset;
122 static file_ptr dwarf_aranges_offset;
123 static file_ptr dwarf_loc_offset;
124 static file_ptr dwarf_macinfo_offset;
125 static file_ptr dwarf_str_offset;
127 static unsigned int dwarf_info_size;
128 static unsigned int dwarf_abbrev_size;
129 static unsigned int dwarf_line_size;
130 static unsigned int dwarf_pubnames_size;
131 static unsigned int dwarf_aranges_size;
132 static unsigned int dwarf_loc_size;
133 static unsigned int dwarf_macinfo_size;
134 static unsigned int dwarf_str_size;
136 /* names of the debugging sections */
138 #define INFO_SECTION ".debug_info"
139 #define ABBREV_SECTION ".debug_abbrev"
140 #define LINE_SECTION ".debug_line"
141 #define PUBNAMES_SECTION ".debug_pubnames"
142 #define ARANGES_SECTION ".debug_aranges"
143 #define LOC_SECTION ".debug_loc"
144 #define MACINFO_SECTION ".debug_macinfo"
145 #define STR_SECTION ".debug_str"
147 /* local data types */
149 /* The data in a compilation unit header looks like this. */
150 struct comp_unit_head
154 unsigned int abbrev_offset;
155 unsigned char addr_size;
158 /* The data in the .debug_line statement prologue looks like this. */
161 unsigned int total_length;
162 unsigned short version;
163 unsigned int prologue_length;
164 unsigned char minimum_instruction_length;
165 unsigned char default_is_stmt;
167 unsigned char line_range;
168 unsigned char opcode_base;
169 unsigned char *standard_opcode_lengths;
172 /* When we construct a partial symbol table entry we only
173 need this much information. */
174 struct partial_die_info
177 unsigned char has_children;
178 unsigned char is_external;
179 unsigned char is_declaration;
180 unsigned char has_type;
186 struct dwarf_block *locdesc;
187 unsigned int language;
191 /* This data structure holds the information of an abbrev. */
194 unsigned int number; /* number identifying abbrev */
195 enum dwarf_tag tag; /* dwarf tag */
196 int has_children; /* boolean */
197 unsigned int num_attrs; /* number of attributes */
198 struct attr_abbrev *attrs; /* an array of attribute descriptions */
199 struct abbrev_info *next; /* next in chain */
204 enum dwarf_attribute name;
205 enum dwarf_form form;
208 /* This data structure holds a complete die structure. */
211 enum dwarf_tag tag; /* Tag indicating type of die */
212 unsigned short has_children; /* Does the die have children */
213 unsigned int abbrev; /* Abbrev number */
214 unsigned int offset; /* Offset in .debug_info section */
215 unsigned int num_attrs; /* Number of attributes */
216 struct attribute *attrs; /* An array of attributes */
217 struct die_info *next_ref; /* Next die in ref hash table */
218 struct die_info *next; /* Next die in linked list */
219 struct type *type; /* Cached type information */
222 /* Attributes have a name and a value */
225 enum dwarf_attribute name;
226 enum dwarf_form form;
230 struct dwarf_block *blk;
238 /* Get at parts of an attribute structure */
240 #define DW_STRING(attr) ((attr)->u.str)
241 #define DW_UNSND(attr) ((attr)->u.unsnd)
242 #define DW_BLOCK(attr) ((attr)->u.blk)
243 #define DW_SND(attr) ((attr)->u.snd)
244 #define DW_ADDR(attr) ((attr)->u.addr)
246 /* Blocks are a bunch of untyped bytes. */
253 /* We only hold one compilation unit's abbrevs in
254 memory at any one time. */
255 #ifndef ABBREV_HASH_SIZE
256 #define ABBREV_HASH_SIZE 121
258 #ifndef ATTR_ALLOC_CHUNK
259 #define ATTR_ALLOC_CHUNK 4
262 static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
264 /* A hash table of die offsets for following references. */
265 #ifndef REF_HASH_SIZE
266 #define REF_HASH_SIZE 1021
269 static struct die_info *die_ref_table[REF_HASH_SIZE];
271 /* Obstack for allocating temporary storage used during symbol reading. */
272 static struct obstack dwarf2_tmp_obstack;
274 /* Offset to the first byte of the current compilation unit header,
275 for resolving relative reference dies. */
276 static unsigned int cu_header_offset;
278 /* Allocate fields for structs, unions and enums in this size. */
279 #ifndef DW_FIELD_ALLOC_CHUNK
280 #define DW_FIELD_ALLOC_CHUNK 4
283 /* The language we are debugging. */
284 static enum language cu_language;
285 static const struct language_defn *cu_language_defn;
287 /* Actually data from the sections. */
288 static char *dwarf_info_buffer;
289 static char *dwarf_abbrev_buffer;
290 static char *dwarf_line_buffer;
292 /* A zeroed version of a partial die for initialization purposes. */
293 static struct partial_die_info zeroed_partial_die;
295 /* The generic symbol table building routines have separate lists for
296 file scope symbols and all all other scopes (local scopes). So
297 we need to select the right one to pass to add_symbol_to_list().
298 We do it by keeping a pointer to the correct list in list_in_scope.
300 FIXME: The original dwarf code just treated the file scope as the first
301 local scope, and all other local scopes as nested local scopes, and worked
302 fine. Check to see if we really need to distinguish these
304 static struct pending **list_in_scope = &file_symbols;
306 /* FIXME: decode_locdesc sets these variables to describe the location
307 to the caller. These ought to be a structure or something. If
308 none of the flags are set, the object lives at the address returned
309 by decode_locdesc. */
311 static int optimized_out; /* No ops in location in expression,
312 so object was optimized out. */
313 static int isreg; /* Object lives in register.
314 decode_locdesc's return value is
315 the register number. */
316 static int offreg; /* Object's address is the sum of the
317 register specified by basereg, plus
318 the offset returned. */
319 static int basereg; /* See `offreg'. */
320 static int isderef; /* Value described by flags above is
321 the address of a pointer to the object. */
322 static int islocal; /* Variable is at the returned offset
323 from the frame start, but there's
324 no identified frame pointer for
325 this function, so we can't say
326 which register it's relative to;
329 /* DW_AT_frame_base values for the current function.
330 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
331 contains the register number for the frame register.
332 frame_base_offset is the offset from the frame register to the
333 virtual stack frame. */
334 static int frame_base_reg;
335 static CORE_ADDR frame_base_offset;
337 /* This value is added to each symbol value. FIXME: Generalize to
338 the section_offsets structure used by dbxread (once this is done,
339 pass the appropriate section number to end_symtab). */
340 static CORE_ADDR baseaddr; /* Add to each symbol value */
342 /* We put a pointer to this structure in the read_symtab_private field
344 The complete dwarf information for an objfile is kept in the
345 psymbol_obstack, so that absolute die references can be handled.
346 Most of the information in this structure is related to an entire
347 object file and could be passed via the sym_private field of the objfile.
348 It is however conceivable that dwarf2 might not be the only type
349 of symbols read from an object file. */
353 /* Pointer to start of dwarf info buffer for the objfile. */
355 char *dwarf_info_buffer;
357 /* Offset in dwarf_info_buffer for this compilation unit. */
359 unsigned long dwarf_info_offset;
361 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
363 char *dwarf_abbrev_buffer;
365 /* Size of dwarf abbreviation section for the objfile. */
367 unsigned int dwarf_abbrev_size;
369 /* Pointer to start of dwarf line buffer for the objfile. */
371 char *dwarf_line_buffer;
374 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
375 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
376 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
377 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
378 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
379 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
381 /* Maintain an array of referenced fundamental types for the current
382 compilation unit being read. For DWARF version 1, we have to construct
383 the fundamental types on the fly, since no information about the
384 fundamental types is supplied. Each such fundamental type is created by
385 calling a language dependent routine to create the type, and then a
386 pointer to that type is then placed in the array at the index specified
387 by it's FT_<TYPENAME> value. The array has a fixed size set by the
388 FT_NUM_MEMBERS compile time constant, which is the number of predefined
389 fundamental types gdb knows how to construct. */
390 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
392 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
393 but this would require a corresponding change in unpack_field_as_long
395 static int bits_per_byte = 8;
397 /* The routines that read and process dies for a C struct or C++ class
398 pass lists of data member fields and lists of member function fields
399 in an instance of a field_info structure, as defined below. */
402 /* List of data member and baseclasses fields. */
405 struct nextfield *next;
412 /* Number of fields. */
415 /* Number of baseclasses. */
418 /* Set if the accesibility of one of the fields is not public. */
419 int non_public_fields;
421 /* Member function fields array, entries are allocated in the order they
422 are encountered in the object file. */
425 struct nextfnfield *next;
426 struct fn_field fnfield;
430 /* Member function fieldlist array, contains name of possibly overloaded
431 member function, number of overloaded member functions and a pointer
432 to the head of the member function field chain. */
437 struct nextfnfield *head;
441 /* Number of entries in the fnfieldlists array. */
445 /* FIXME: Kludge to mark a varargs function type for C++ member function
446 argument processing. */
447 #define TYPE_FLAG_VARARGS (1 << 10)
449 /* Dwarf2 has no clean way to discern C++ static and non-static member
450 functions. G++ helps GDB by marking the first parameter for non-static
451 member functions (which is the this pointer) as artificial.
452 We pass this information between dwarf2_add_member_fn and
453 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
454 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
456 /* Various complaints about symbol reading that don't abort the process */
458 static struct complaint dwarf2_const_ignored =
460 "type qualifier 'const' ignored", 0, 0
462 static struct complaint dwarf2_volatile_ignored =
464 "type qualifier 'volatile' ignored", 0, 0
466 static struct complaint dwarf2_non_const_array_bound_ignored =
468 "non-constant array bounds form '%s' ignored", 0, 0
470 static struct complaint dwarf2_missing_line_number_section =
472 "missing .debug_line section", 0, 0
474 static struct complaint dwarf2_mangled_line_number_section =
476 "mangled .debug_line section", 0, 0
478 static struct complaint dwarf2_unsupported_die_ref_attr =
480 "unsupported die ref attribute form: '%s'", 0, 0
482 static struct complaint dwarf2_unsupported_stack_op =
484 "unsupported stack op: '%s'", 0, 0
486 static struct complaint dwarf2_complex_location_expr =
488 "location expression too complex", 0, 0
490 static struct complaint dwarf2_unsupported_tag =
492 "unsupported tag: '%s'", 0, 0
494 static struct complaint dwarf2_unsupported_at_encoding =
496 "unsupported DW_AT_encoding: '%s'", 0, 0
498 static struct complaint dwarf2_unsupported_at_frame_base =
500 "unsupported DW_AT_frame_base for function '%s'", 0, 0
502 static struct complaint dwarf2_unexpected_tag =
504 "unexepected tag in read_type_die: '%s'", 0, 0
506 static struct complaint dwarf2_missing_at_frame_base =
508 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
510 static struct complaint dwarf2_bad_static_member_name =
512 "unrecognized static data member name '%s'", 0, 0
514 static struct complaint dwarf2_unsupported_accessibility =
516 "unsupported accessibility %d", 0, 0
518 static struct complaint dwarf2_bad_member_name_complaint =
520 "cannot extract member name from '%s'", 0, 0
522 static struct complaint dwarf2_missing_member_fn_type_complaint =
524 "member function type missing for '%s'", 0, 0
526 static struct complaint dwarf2_vtbl_not_found_complaint =
528 "virtual function table pointer not found when defining class '%s'", 0, 0
530 static struct complaint dwarf2_absolute_sibling_complaint =
532 "ignoring absolute DW_AT_sibling", 0, 0
534 static struct complaint dwarf2_const_value_length_mismatch =
536 "const value length mismatch for '%s', got %d, expected %d", 0, 0
538 static struct complaint dwarf2_unsupported_const_value_attr =
540 "unsupported const value attribute form: '%s'", 0, 0
543 /* Remember the addr_size read from the dwarf.
544 If a target expects to link compilation units with differing address
545 sizes, gdb needs to be sure that the appropriate size is here for
546 whatever scope is currently getting read. */
547 static int address_size;
549 /* Some elf32 object file formats while linked for a 32 bit address
550 space contain debug information that has assumed 64 bit
551 addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
552 symbol table contains 32bit address values while its .debug_info
553 section contains 64 bit address values.
554 ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
555 the ADDRESS_SIZE bytes read from the file */
556 static int address_significant_size;
558 /* Externals references. */
559 extern int info_verbose; /* From main.c; nonzero => verbose */
561 /* local function prototypes */
563 static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR));
566 static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *, int));
569 static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *, int));
571 static char *scan_partial_symbols PARAMS ((char *, struct objfile *,
572 CORE_ADDR *, CORE_ADDR *));
574 static void add_partial_symbol PARAMS ((struct partial_die_info *,
577 static void dwarf2_psymtab_to_symtab PARAMS ((struct partial_symtab *));
579 static void psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
581 static char *dwarf2_read_section PARAMS ((struct objfile *, file_ptr,
584 static void dwarf2_read_abbrevs PARAMS ((bfd *, unsigned int));
586 static void dwarf2_empty_abbrev_table PARAMS ((PTR));
588 static struct abbrev_info *dwarf2_lookup_abbrev PARAMS ((unsigned int));
590 static char *read_partial_die PARAMS ((struct partial_die_info *,
591 bfd *, char *, int *));
593 static char *read_full_die PARAMS ((struct die_info **, bfd *, char *));
595 static char *read_attribute PARAMS ((struct attribute *, struct attr_abbrev *,
598 static unsigned int read_1_byte PARAMS ((bfd *, char *));
600 static int read_1_signed_byte PARAMS ((bfd *, char *));
602 static unsigned int read_2_bytes PARAMS ((bfd *, char *));
604 static unsigned int read_4_bytes PARAMS ((bfd *, char *));
606 static unsigned int read_8_bytes PARAMS ((bfd *, char *));
608 static CORE_ADDR read_address PARAMS ((bfd *, char *));
610 static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
612 static char *read_string PARAMS ((bfd *, char *, unsigned int *));
614 static unsigned int read_unsigned_leb128 PARAMS ((bfd *, char *,
617 static int read_signed_leb128 PARAMS ((bfd *, char *, unsigned int *));
619 static void set_cu_language PARAMS ((unsigned int));
621 static struct attribute *dwarf_attr PARAMS ((struct die_info *,
624 static int die_is_declaration (struct die_info *);
626 static void dwarf_decode_lines PARAMS ((unsigned int, char *, bfd *));
628 static void dwarf2_start_subfile PARAMS ((char *, char *));
630 static struct symbol *new_symbol PARAMS ((struct die_info *, struct type *,
633 static void dwarf2_const_value PARAMS ((struct attribute *, struct symbol *,
636 static void dwarf2_const_value_data (struct attribute *attr,
640 static struct type *die_type PARAMS ((struct die_info *, struct objfile *));
642 static struct type *die_containing_type PARAMS ((struct die_info *,
646 static struct type *type_at_offset PARAMS ((unsigned int, struct objfile *));
649 static struct type *tag_type_to_type PARAMS ((struct die_info *,
652 static void read_type_die PARAMS ((struct die_info *, struct objfile *));
654 static void read_typedef PARAMS ((struct die_info *, struct objfile *));
656 static void read_base_type PARAMS ((struct die_info *, struct objfile *));
658 static void read_file_scope PARAMS ((struct die_info *, struct objfile *));
660 static void read_func_scope PARAMS ((struct die_info *, struct objfile *));
662 static void read_lexical_block_scope PARAMS ((struct die_info *,
665 static int dwarf2_get_pc_bounds PARAMS ((struct die_info *,
666 CORE_ADDR *, CORE_ADDR *,
669 static void dwarf2_add_field PARAMS ((struct field_info *, struct die_info *,
672 static void dwarf2_attach_fields_to_type PARAMS ((struct field_info *,
676 static void dwarf2_add_member_fn PARAMS ((struct field_info *,
677 struct die_info *, struct type *,
678 struct objfile * objfile));
680 static void dwarf2_attach_fn_fields_to_type PARAMS ((struct field_info *,
684 static void read_structure_scope PARAMS ((struct die_info *, struct objfile *));
686 static void read_common_block PARAMS ((struct die_info *, struct objfile *));
688 static void read_enumeration PARAMS ((struct die_info *, struct objfile *));
690 static struct type *dwarf_base_type PARAMS ((int, int, struct objfile *));
692 static CORE_ADDR decode_locdesc PARAMS ((struct dwarf_block *,
695 static void read_array_type PARAMS ((struct die_info *, struct objfile *));
697 static void read_tag_pointer_type PARAMS ((struct die_info *,
700 static void read_tag_ptr_to_member_type PARAMS ((struct die_info *,
703 static void read_tag_reference_type PARAMS ((struct die_info *,
706 static void read_tag_const_type PARAMS ((struct die_info *, struct objfile *));
708 static void read_tag_volatile_type PARAMS ((struct die_info *,
711 static void read_tag_string_type PARAMS ((struct die_info *,
714 static void read_subroutine_type PARAMS ((struct die_info *,
717 struct die_info *read_comp_unit PARAMS ((char *, bfd *));
719 static void free_die_list PARAMS ((struct die_info *));
721 static void process_die PARAMS ((struct die_info *, struct objfile *));
723 static char *dwarf2_linkage_name PARAMS ((struct die_info *));
725 static char *dwarf_tag_name PARAMS ((unsigned int));
727 static char *dwarf_attr_name PARAMS ((unsigned int));
729 static char *dwarf_form_name PARAMS ((unsigned int));
731 static char *dwarf_stack_op_name PARAMS ((unsigned int));
733 static char *dwarf_bool_name PARAMS ((unsigned int));
735 static char *dwarf_type_encoding_name PARAMS ((unsigned int));
738 static char *dwarf_cfi_name PARAMS ((unsigned int));
740 struct die_info *copy_die PARAMS ((struct die_info *));
743 struct die_info *sibling_die PARAMS ((struct die_info *));
745 void dump_die PARAMS ((struct die_info *));
747 void dump_die_list PARAMS ((struct die_info *));
749 void store_in_ref_table PARAMS ((unsigned int, struct die_info *));
751 static void dwarf2_empty_die_ref_table PARAMS ((void));
753 static unsigned int dwarf2_get_ref_die_offset PARAMS ((struct attribute *));
755 struct die_info *follow_die_ref PARAMS ((unsigned int));
757 static struct type *dwarf2_fundamental_type PARAMS ((struct objfile *, int));
759 /* memory allocation interface */
761 static void dwarf2_free_tmp_obstack PARAMS ((PTR));
763 static struct dwarf_block *dwarf_alloc_block PARAMS ((void));
765 static struct abbrev_info *dwarf_alloc_abbrev PARAMS ((void));
767 static struct die_info *dwarf_alloc_die PARAMS ((void));
769 /* Try to locate the sections we need for DWARF 2 debugging
770 information and return true if we have enough to do something. */
773 dwarf2_has_info (abfd)
776 dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
777 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
778 if (dwarf_info_offset && dwarf_abbrev_offset)
788 /* This function is mapped across the sections and remembers the
789 offset and size of each of the debugging sections we are interested
793 dwarf2_locate_sections (ignore_abfd, sectp, ignore_ptr)
798 if (STREQ (sectp->name, INFO_SECTION))
800 dwarf_info_offset = sectp->filepos;
801 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
803 else if (STREQ (sectp->name, ABBREV_SECTION))
805 dwarf_abbrev_offset = sectp->filepos;
806 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
808 else if (STREQ (sectp->name, LINE_SECTION))
810 dwarf_line_offset = sectp->filepos;
811 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
813 else if (STREQ (sectp->name, PUBNAMES_SECTION))
815 dwarf_pubnames_offset = sectp->filepos;
816 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
818 else if (STREQ (sectp->name, ARANGES_SECTION))
820 dwarf_aranges_offset = sectp->filepos;
821 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
823 else if (STREQ (sectp->name, LOC_SECTION))
825 dwarf_loc_offset = sectp->filepos;
826 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
828 else if (STREQ (sectp->name, MACINFO_SECTION))
830 dwarf_macinfo_offset = sectp->filepos;
831 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
833 else if (STREQ (sectp->name, STR_SECTION))
835 dwarf_str_offset = sectp->filepos;
836 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
840 /* Build a partial symbol table. */
843 dwarf2_build_psymtabs (objfile, mainline)
844 struct objfile *objfile;
848 /* We definitely need the .debug_info and .debug_abbrev sections */
850 dwarf_info_buffer = dwarf2_read_section (objfile,
853 dwarf_abbrev_buffer = dwarf2_read_section (objfile,
856 dwarf_line_buffer = dwarf2_read_section (objfile,
860 if (mainline || objfile->global_psymbols.size == 0 ||
861 objfile->static_psymbols.size == 0)
863 init_psymbol_list (objfile, 1024);
867 if (dwarf_aranges_offset && dwarf_pubnames_offset)
869 /* Things are significantly easier if we have .debug_aranges and
870 .debug_pubnames sections */
872 dwarf2_build_psymtabs_easy (objfile, mainline);
876 /* only test this case for now */
878 /* In this case we have to work a bit harder */
879 dwarf2_build_psymtabs_hard (objfile, mainline);
884 /* Build the partial symbol table from the information in the
885 .debug_pubnames and .debug_aranges sections. */
888 dwarf2_build_psymtabs_easy (objfile, mainline)
889 struct objfile *objfile;
892 bfd *abfd = objfile->obfd;
893 char *aranges_buffer, *pubnames_buffer;
894 char *aranges_ptr, *pubnames_ptr;
895 unsigned int entry_length, version, info_offset, info_size;
897 pubnames_buffer = dwarf2_read_section (objfile,
898 dwarf_pubnames_offset,
899 dwarf_pubnames_size);
900 pubnames_ptr = pubnames_buffer;
901 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
903 entry_length = read_4_bytes (abfd, pubnames_ptr);
905 version = read_1_byte (abfd, pubnames_ptr);
907 info_offset = read_4_bytes (abfd, pubnames_ptr);
909 info_size = read_4_bytes (abfd, pubnames_ptr);
913 aranges_buffer = dwarf2_read_section (objfile,
914 dwarf_aranges_offset,
920 /* Build the partial symbol table by doing a quick pass through the
921 .debug_info and .debug_abbrev sections. */
924 dwarf2_build_psymtabs_hard (objfile, mainline)
925 struct objfile *objfile;
928 /* Instead of reading this into a big buffer, we should probably use
929 mmap() on architectures that support it. (FIXME) */
930 bfd *abfd = objfile->obfd;
931 char *info_ptr, *abbrev_ptr;
932 char *beg_of_comp_unit;
933 struct comp_unit_head cu_header;
934 struct partial_die_info comp_unit_die;
935 struct partial_symtab *pst;
936 struct cleanup *back_to;
937 int comp_unit_has_pc_info;
938 CORE_ADDR lowpc, highpc;
940 /* Number of bytes of any addresses that are signficant */
941 address_significant_size = get_elf_backend_data (abfd)->s->arch_size / 8;
943 info_ptr = dwarf_info_buffer;
944 abbrev_ptr = dwarf_abbrev_buffer;
946 obstack_init (&dwarf2_tmp_obstack);
947 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
949 while ((unsigned int) (info_ptr - dwarf_info_buffer)
950 + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
952 beg_of_comp_unit = info_ptr;
953 cu_header.length = read_4_bytes (abfd, info_ptr);
955 cu_header.version = read_2_bytes (abfd, info_ptr);
957 cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
959 cu_header.addr_size = read_1_byte (abfd, info_ptr);
961 address_size = cu_header.addr_size;
963 if (cu_header.version != 2)
965 error ("Dwarf Error: wrong version in compilation unit header.");
968 if (cu_header.abbrev_offset >= dwarf_abbrev_size)
970 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
971 (long) cu_header.abbrev_offset,
972 (long) (beg_of_comp_unit - dwarf_info_buffer));
975 if (beg_of_comp_unit + cu_header.length + 4
976 > dwarf_info_buffer + dwarf_info_size)
978 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
979 (long) cu_header.length,
980 (long) (beg_of_comp_unit - dwarf_info_buffer));
983 if (address_size < address_significant_size)
985 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
986 (long) cu_header.addr_size,
987 (long) (beg_of_comp_unit - dwarf_info_buffer));
990 /* Read the abbrevs for this compilation unit into a table */
991 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
992 make_cleanup (dwarf2_empty_abbrev_table, NULL);
994 /* Read the compilation unit die */
995 info_ptr = read_partial_die (&comp_unit_die, abfd,
996 info_ptr, &comp_unit_has_pc_info);
998 /* Set the language we're debugging */
999 set_cu_language (comp_unit_die.language);
1001 /* Allocate a new partial symbol table structure */
1002 pst = start_psymtab_common (objfile, objfile->section_offsets,
1003 comp_unit_die.name ? comp_unit_die.name : "",
1004 comp_unit_die.lowpc,
1005 objfile->global_psymbols.next,
1006 objfile->static_psymbols.next);
1008 pst->read_symtab_private = (char *)
1009 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
1010 cu_header_offset = beg_of_comp_unit - dwarf_info_buffer;
1011 DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
1012 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
1013 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
1014 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
1015 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
1016 baseaddr = ANOFFSET (objfile->section_offsets, 0);
1018 /* Store the function that reads in the rest of the symbol table */
1019 pst->read_symtab = dwarf2_psymtab_to_symtab;
1021 /* Check if comp unit has_children.
1022 If so, read the rest of the partial symbols from this comp unit.
1023 If not, there's no more debug_info for this comp unit. */
1024 if (comp_unit_die.has_children)
1026 info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc);
1028 /* If the compilation unit didn't have an explicit address range,
1029 then use the information extracted from its child dies. */
1030 if (!comp_unit_has_pc_info)
1032 comp_unit_die.lowpc = lowpc;
1033 comp_unit_die.highpc = highpc;
1036 pst->textlow = comp_unit_die.lowpc + baseaddr;
1037 pst->texthigh = comp_unit_die.highpc + baseaddr;
1039 pst->n_global_syms = objfile->global_psymbols.next -
1040 (objfile->global_psymbols.list + pst->globals_offset);
1041 pst->n_static_syms = objfile->static_psymbols.next -
1042 (objfile->static_psymbols.list + pst->statics_offset);
1043 sort_pst_symbols (pst);
1045 /* If there is already a psymtab or symtab for a file of this
1046 name, remove it. (If there is a symtab, more drastic things
1047 also happen.) This happens in VxWorks. */
1048 free_named_symtabs (pst->filename);
1050 info_ptr = beg_of_comp_unit + cu_header.length + 4;
1052 do_cleanups (back_to);
1055 /* Read in all interesting dies to the end of the compilation unit. */
1058 scan_partial_symbols (info_ptr, objfile, lowpc, highpc)
1060 struct objfile *objfile;
1064 bfd *abfd = objfile->obfd;
1065 struct partial_die_info pdi;
1067 /* This function is called after we've read in the comp_unit_die in
1068 order to read its children. We start the nesting level at 1 since
1069 we have pushed 1 level down in order to read the comp unit's children.
1070 The comp unit itself is at level 0, so we stop reading when we pop
1071 back to that level. */
1073 int nesting_level = 1;
1076 *lowpc = ((CORE_ADDR) -1);
1077 *highpc = ((CORE_ADDR) 0);
1079 while (nesting_level)
1081 info_ptr = read_partial_die (&pdi, abfd, info_ptr, &has_pc_info);
1087 case DW_TAG_subprogram:
1090 if (pdi.lowpc < *lowpc)
1094 if (pdi.highpc > *highpc)
1096 *highpc = pdi.highpc;
1098 if ((pdi.is_external || nesting_level == 1)
1099 && !pdi.is_declaration)
1101 add_partial_symbol (&pdi, objfile);
1105 case DW_TAG_variable:
1106 case DW_TAG_typedef:
1107 case DW_TAG_class_type:
1108 case DW_TAG_structure_type:
1109 case DW_TAG_union_type:
1110 case DW_TAG_enumeration_type:
1111 if ((pdi.is_external || nesting_level == 1)
1112 && !pdi.is_declaration)
1114 add_partial_symbol (&pdi, objfile);
1117 case DW_TAG_enumerator:
1118 /* File scope enumerators are added to the partial symbol
1120 if (nesting_level == 2)
1121 add_partial_symbol (&pdi, objfile);
1123 case DW_TAG_base_type:
1124 /* File scope base type definitions are added to the partial
1126 if (nesting_level == 1)
1127 add_partial_symbol (&pdi, objfile);
1134 /* If the die has a sibling, skip to the sibling.
1135 Do not skip enumeration types, we want to record their
1137 if (pdi.sibling && pdi.tag != DW_TAG_enumeration_type)
1139 info_ptr = pdi.sibling;
1141 else if (pdi.has_children)
1143 /* Die has children, but the optional DW_AT_sibling attribute
1154 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1155 from `maint check'. */
1156 if (*lowpc == ((CORE_ADDR) -1))
1162 add_partial_symbol (pdi, objfile)
1163 struct partial_die_info *pdi;
1164 struct objfile *objfile;
1170 case DW_TAG_subprogram:
1171 if (pdi->is_external)
1173 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1174 mst_text, objfile); */
1175 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1176 VAR_NAMESPACE, LOC_BLOCK,
1177 &objfile->global_psymbols,
1178 0, pdi->lowpc + baseaddr, cu_language, objfile);
1182 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1183 mst_file_text, objfile); */
1184 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1185 VAR_NAMESPACE, LOC_BLOCK,
1186 &objfile->static_psymbols,
1187 0, pdi->lowpc + baseaddr, cu_language, objfile);
1190 case DW_TAG_variable:
1191 if (pdi->is_external)
1194 Don't enter into the minimal symbol tables as there is
1195 a minimal symbol table entry from the ELF symbols already.
1196 Enter into partial symbol table if it has a location
1197 descriptor or a type.
1198 If the location descriptor is missing, new_symbol will create
1199 a LOC_UNRESOLVED symbol, the address of the variable will then
1200 be determined from the minimal symbol table whenever the variable
1202 The address for the partial symbol table entry is not
1203 used by GDB, but it comes in handy for debugging partial symbol
1207 addr = decode_locdesc (pdi->locdesc, objfile);
1208 if (pdi->locdesc || pdi->has_type)
1209 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1210 VAR_NAMESPACE, LOC_STATIC,
1211 &objfile->global_psymbols,
1212 0, addr + baseaddr, cu_language, objfile);
1216 /* Static Variable. Skip symbols without location descriptors. */
1217 if (pdi->locdesc == NULL)
1219 addr = decode_locdesc (pdi->locdesc, objfile);
1220 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1221 mst_file_data, objfile); */
1222 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1223 VAR_NAMESPACE, LOC_STATIC,
1224 &objfile->static_psymbols,
1225 0, addr + baseaddr, cu_language, objfile);
1228 case DW_TAG_typedef:
1229 case DW_TAG_base_type:
1230 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1231 VAR_NAMESPACE, LOC_TYPEDEF,
1232 &objfile->static_psymbols,
1233 0, (CORE_ADDR) 0, cu_language, objfile);
1235 case DW_TAG_class_type:
1236 case DW_TAG_structure_type:
1237 case DW_TAG_union_type:
1238 case DW_TAG_enumeration_type:
1239 /* Skip aggregate types without children, these are external
1241 if (pdi->has_children == 0)
1243 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1244 STRUCT_NAMESPACE, LOC_TYPEDEF,
1245 &objfile->static_psymbols,
1246 0, (CORE_ADDR) 0, cu_language, objfile);
1248 if (cu_language == language_cplus)
1250 /* For C++, these implicitly act as typedefs as well. */
1251 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1252 VAR_NAMESPACE, LOC_TYPEDEF,
1253 &objfile->static_psymbols,
1254 0, (CORE_ADDR) 0, cu_language, objfile);
1257 case DW_TAG_enumerator:
1258 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1259 VAR_NAMESPACE, LOC_CONST,
1260 &objfile->static_psymbols,
1261 0, (CORE_ADDR) 0, cu_language, objfile);
1268 /* Expand this partial symbol table into a full symbol table. */
1271 dwarf2_psymtab_to_symtab (pst)
1272 struct partial_symtab *pst;
1274 /* FIXME: This is barely more than a stub. */
1279 warning ("bug: psymtab for %s is already read in.", pst->filename);
1285 printf_filtered ("Reading in symbols for %s...", pst->filename);
1286 gdb_flush (gdb_stdout);
1289 psymtab_to_symtab_1 (pst);
1291 /* Finish up the debug error message. */
1293 printf_filtered ("done.\n");
1299 psymtab_to_symtab_1 (pst)
1300 struct partial_symtab *pst;
1302 struct objfile *objfile = pst->objfile;
1303 bfd *abfd = objfile->obfd;
1304 struct comp_unit_head cu_header;
1305 struct die_info *dies;
1306 unsigned long offset;
1307 CORE_ADDR lowpc, highpc;
1308 struct die_info *child_die;
1310 struct symtab *symtab;
1311 struct cleanup *back_to;
1313 /* Set local variables from the partial symbol table info. */
1314 offset = DWARF_INFO_OFFSET (pst);
1315 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1316 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1317 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1318 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1319 baseaddr = ANOFFSET (pst->section_offsets, 0);
1320 cu_header_offset = offset;
1321 info_ptr = dwarf_info_buffer + offset;
1323 obstack_init (&dwarf2_tmp_obstack);
1324 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1327 make_cleanup (really_free_pendings, NULL);
1329 /* read in the comp_unit header */
1330 cu_header.length = read_4_bytes (abfd, info_ptr);
1332 cu_header.version = read_2_bytes (abfd, info_ptr);
1334 cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
1336 cu_header.addr_size = read_1_byte (abfd, info_ptr);
1339 /* Read the abbrevs for this compilation unit */
1340 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
1341 make_cleanup (dwarf2_empty_abbrev_table, NULL);
1343 dies = read_comp_unit (info_ptr, abfd);
1345 make_cleanup ((make_cleanup_func) free_die_list, dies);
1347 /* Do line number decoding in read_file_scope () */
1348 process_die (dies, objfile);
1350 if (!dwarf2_get_pc_bounds (dies, &lowpc, &highpc, objfile))
1352 /* Some compilers don't define a DW_AT_high_pc attribute for
1353 the compilation unit. If the DW_AT_high_pc is missing,
1354 synthesize it, by scanning the DIE's below the compilation unit. */
1356 if (dies->has_children)
1358 child_die = dies->next;
1359 while (child_die && child_die->tag)
1361 if (child_die->tag == DW_TAG_subprogram)
1363 CORE_ADDR low, high;
1365 if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile))
1367 highpc = max (highpc, high);
1370 child_die = sibling_die (child_die);
1374 symtab = end_symtab (highpc + baseaddr, objfile, 0);
1376 /* Set symtab language to language from DW_AT_language.
1377 If the compilation is from a C file generated by language preprocessors,
1378 do not set the language if it was already deduced by start_subfile. */
1380 && !(cu_language == language_c && symtab->language != language_c))
1382 symtab->language = cu_language;
1384 pst->symtab = symtab;
1386 sort_symtab_syms (pst->symtab);
1388 do_cleanups (back_to);
1391 /* Process a die and its children. */
1394 process_die (die, objfile)
1395 struct die_info *die;
1396 struct objfile *objfile;
1400 case DW_TAG_padding:
1402 case DW_TAG_compile_unit:
1403 read_file_scope (die, objfile);
1405 case DW_TAG_subprogram:
1406 read_subroutine_type (die, objfile);
1407 read_func_scope (die, objfile);
1409 case DW_TAG_inlined_subroutine:
1410 /* FIXME: These are ignored for now.
1411 They could be used to set breakpoints on all inlined instances
1412 of a function and make GDB `next' properly over inlined functions. */
1414 case DW_TAG_lexical_block:
1415 read_lexical_block_scope (die, objfile);
1417 case DW_TAG_class_type:
1418 case DW_TAG_structure_type:
1419 case DW_TAG_union_type:
1420 read_structure_scope (die, objfile);
1422 case DW_TAG_enumeration_type:
1423 read_enumeration (die, objfile);
1425 case DW_TAG_subroutine_type:
1426 read_subroutine_type (die, objfile);
1428 case DW_TAG_array_type:
1429 read_array_type (die, objfile);
1431 case DW_TAG_pointer_type:
1432 read_tag_pointer_type (die, objfile);
1434 case DW_TAG_ptr_to_member_type:
1435 read_tag_ptr_to_member_type (die, objfile);
1437 case DW_TAG_reference_type:
1438 read_tag_reference_type (die, objfile);
1440 case DW_TAG_string_type:
1441 read_tag_string_type (die, objfile);
1443 case DW_TAG_base_type:
1444 read_base_type (die, objfile);
1445 if (dwarf_attr (die, DW_AT_name))
1447 /* Add a typedef symbol for the base type definition. */
1448 new_symbol (die, die->type, objfile);
1451 case DW_TAG_common_block:
1452 read_common_block (die, objfile);
1454 case DW_TAG_common_inclusion:
1457 new_symbol (die, NULL, objfile);
1463 read_file_scope (die, objfile)
1464 struct die_info *die;
1465 struct objfile *objfile;
1467 unsigned int line_offset = 0;
1468 CORE_ADDR lowpc = ((CORE_ADDR) -1);
1469 CORE_ADDR highpc = ((CORE_ADDR) 0);
1470 struct attribute *attr;
1471 char *name = "<unknown>";
1472 char *comp_dir = NULL;
1473 struct die_info *child_die;
1474 bfd *abfd = objfile->obfd;
1476 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1478 if (die->has_children)
1480 child_die = die->next;
1481 while (child_die && child_die->tag)
1483 if (child_die->tag == DW_TAG_subprogram)
1485 CORE_ADDR low, high;
1487 if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile))
1489 lowpc = min (lowpc, low);
1490 highpc = max (highpc, high);
1493 child_die = sibling_die (child_die);
1498 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1499 from finish_block. */
1500 if (lowpc == ((CORE_ADDR) -1))
1505 attr = dwarf_attr (die, DW_AT_name);
1508 name = DW_STRING (attr);
1510 attr = dwarf_attr (die, DW_AT_comp_dir);
1513 comp_dir = DW_STRING (attr);
1516 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1517 directory, get rid of it. */
1518 char *cp = strchr (comp_dir, ':');
1520 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1525 if (objfile->ei.entry_point >= lowpc &&
1526 objfile->ei.entry_point < highpc)
1528 objfile->ei.entry_file_lowpc = lowpc;
1529 objfile->ei.entry_file_highpc = highpc;
1532 attr = dwarf_attr (die, DW_AT_language);
1535 set_cu_language (DW_UNSND (attr));
1538 /* We assume that we're processing GCC output. */
1539 processing_gcc_compilation = 2;
1541 /* FIXME:Do something here. */
1542 if (dip->at_producer != NULL)
1544 handle_producer (dip->at_producer);
1548 /* The compilation unit may be in a different language or objfile,
1549 zero out all remembered fundamental types. */
1550 memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
1552 start_symtab (name, comp_dir, lowpc);
1553 record_debugformat ("DWARF 2");
1555 /* Decode line number information if present. */
1556 attr = dwarf_attr (die, DW_AT_stmt_list);
1559 line_offset = DW_UNSND (attr);
1560 dwarf_decode_lines (line_offset, comp_dir, abfd);
1563 /* Process all dies in compilation unit. */
1564 if (die->has_children)
1566 child_die = die->next;
1567 while (child_die && child_die->tag)
1569 process_die (child_die, objfile);
1570 child_die = sibling_die (child_die);
1576 read_func_scope (die, objfile)
1577 struct die_info *die;
1578 struct objfile *objfile;
1580 register struct context_stack *new;
1583 struct die_info *child_die;
1584 struct attribute *attr;
1587 name = dwarf2_linkage_name (die);
1589 /* Ignore functions with missing or empty names and functions with
1590 missing or invalid low and high pc attributes. */
1591 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1597 if (objfile->ei.entry_point >= lowpc &&
1598 objfile->ei.entry_point < highpc)
1600 objfile->ei.entry_func_lowpc = lowpc;
1601 objfile->ei.entry_func_highpc = highpc;
1604 /* Decode DW_AT_frame_base location descriptor if present, keep result
1605 for DW_OP_fbreg operands in decode_locdesc. */
1606 frame_base_reg = -1;
1607 frame_base_offset = 0;
1608 attr = dwarf_attr (die, DW_AT_frame_base);
1611 CORE_ADDR addr = decode_locdesc (DW_BLOCK (attr), objfile);
1613 complain (&dwarf2_unsupported_at_frame_base, name);
1615 frame_base_reg = addr;
1618 frame_base_reg = basereg;
1619 frame_base_offset = addr;
1622 complain (&dwarf2_unsupported_at_frame_base, name);
1625 new = push_context (0, lowpc);
1626 new->name = new_symbol (die, die->type, objfile);
1627 list_in_scope = &local_symbols;
1629 if (die->has_children)
1631 child_die = die->next;
1632 while (child_die && child_die->tag)
1634 process_die (child_die, objfile);
1635 child_die = sibling_die (child_die);
1639 new = pop_context ();
1640 /* Make a block for the local symbols within. */
1641 finish_block (new->name, &local_symbols, new->old_blocks,
1642 lowpc, highpc, objfile);
1643 list_in_scope = &file_symbols;
1646 /* Process all the DIES contained within a lexical block scope. Start
1647 a new scope, process the dies, and then close the scope. */
1650 read_lexical_block_scope (die, objfile)
1651 struct die_info *die;
1652 struct objfile *objfile;
1654 register struct context_stack *new;
1655 CORE_ADDR lowpc, highpc;
1656 struct die_info *child_die;
1658 /* Ignore blocks with missing or invalid low and high pc attributes. */
1659 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1664 push_context (0, lowpc);
1665 if (die->has_children)
1667 child_die = die->next;
1668 while (child_die && child_die->tag)
1670 process_die (child_die, objfile);
1671 child_die = sibling_die (child_die);
1674 new = pop_context ();
1676 if (local_symbols != NULL)
1678 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
1681 local_symbols = new->locals;
1684 /* Get low and high pc attributes from a die.
1685 Return 1 if the attributes are present and valid, otherwise, return 0. */
1688 dwarf2_get_pc_bounds (die, lowpc, highpc, objfile)
1689 struct die_info *die;
1692 struct objfile *objfile;
1694 struct attribute *attr;
1698 attr = dwarf_attr (die, DW_AT_low_pc);
1700 low = DW_ADDR (attr);
1703 attr = dwarf_attr (die, DW_AT_high_pc);
1705 high = DW_ADDR (attr);
1712 /* When using the GNU linker, .gnu.linkonce. sections are used to
1713 eliminate duplicate copies of functions and vtables and such.
1714 The linker will arbitrarily choose one and discard the others.
1715 The AT_*_pc values for such functions refer to local labels in
1716 these sections. If the section from that file was discarded, the
1717 labels are not in the output, so the relocs get a value of 0.
1718 If this is a discarded function, mark the pc bounds as invalid,
1719 so that GDB will ignore it. */
1720 if (low == 0 && (bfd_get_file_flags (objfile->obfd) & HAS_RELOC) == 0)
1728 /* Add an aggregate field to the field list. */
1731 dwarf2_add_field (fip, die, objfile)
1732 struct field_info *fip;
1733 struct die_info *die;
1734 struct objfile *objfile;
1736 struct nextfield *new_field;
1737 struct attribute *attr;
1739 char *fieldname = "";
1741 /* Allocate a new field list entry and link it in. */
1742 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
1743 make_cleanup (free, new_field);
1744 memset (new_field, 0, sizeof (struct nextfield));
1745 new_field->next = fip->fields;
1746 fip->fields = new_field;
1749 /* Handle accessibility and virtuality of field.
1750 The default accessibility for members is public, the default
1751 accessibility for inheritance is private. */
1752 if (die->tag != DW_TAG_inheritance)
1753 new_field->accessibility = DW_ACCESS_public;
1755 new_field->accessibility = DW_ACCESS_private;
1756 new_field->virtuality = DW_VIRTUALITY_none;
1758 attr = dwarf_attr (die, DW_AT_accessibility);
1760 new_field->accessibility = DW_UNSND (attr);
1761 if (new_field->accessibility != DW_ACCESS_public)
1762 fip->non_public_fields = 1;
1763 attr = dwarf_attr (die, DW_AT_virtuality);
1765 new_field->virtuality = DW_UNSND (attr);
1767 fp = &new_field->field;
1768 if (die->tag == DW_TAG_member)
1770 /* Get type of field. */
1771 fp->type = die_type (die, objfile);
1773 /* Get bit size of field (zero if none). */
1774 attr = dwarf_attr (die, DW_AT_bit_size);
1777 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
1781 FIELD_BITSIZE (*fp) = 0;
1784 /* Get bit offset of field. */
1785 attr = dwarf_attr (die, DW_AT_data_member_location);
1788 FIELD_BITPOS (*fp) =
1789 decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1792 FIELD_BITPOS (*fp) = 0;
1793 attr = dwarf_attr (die, DW_AT_bit_offset);
1796 if (BITS_BIG_ENDIAN)
1798 /* For big endian bits, the DW_AT_bit_offset gives the
1799 additional bit offset from the MSB of the containing
1800 anonymous object to the MSB of the field. We don't
1801 have to do anything special since we don't need to
1802 know the size of the anonymous object. */
1803 FIELD_BITPOS (*fp) += DW_UNSND (attr);
1807 /* For little endian bits, compute the bit offset to the
1808 MSB of the anonymous object, subtract off the number of
1809 bits from the MSB of the field to the MSB of the
1810 object, and then subtract off the number of bits of
1811 the field itself. The result is the bit offset of
1812 the LSB of the field. */
1814 int bit_offset = DW_UNSND (attr);
1816 attr = dwarf_attr (die, DW_AT_byte_size);
1819 /* The size of the anonymous object containing
1820 the bit field is explicit, so use the
1821 indicated size (in bytes). */
1822 anonymous_size = DW_UNSND (attr);
1826 /* The size of the anonymous object containing
1827 the bit field must be inferred from the type
1828 attribute of the data member containing the
1830 anonymous_size = TYPE_LENGTH (fp->type);
1832 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
1833 - bit_offset - FIELD_BITSIZE (*fp);
1837 /* Get name of field. */
1838 attr = dwarf_attr (die, DW_AT_name);
1839 if (attr && DW_STRING (attr))
1840 fieldname = DW_STRING (attr);
1841 fp->name = obsavestring (fieldname, strlen (fieldname),
1842 &objfile->type_obstack);
1844 /* Change accessibility for artificial fields (e.g. virtual table
1845 pointer or virtual base class pointer) to private. */
1846 if (dwarf_attr (die, DW_AT_artificial))
1848 new_field->accessibility = DW_ACCESS_private;
1849 fip->non_public_fields = 1;
1852 else if (die->tag == DW_TAG_variable)
1856 /* C++ static member.
1857 Get name of field. */
1858 attr = dwarf_attr (die, DW_AT_name);
1859 if (attr && DW_STRING (attr))
1860 fieldname = DW_STRING (attr);
1864 /* Get physical name. */
1865 physname = dwarf2_linkage_name (die);
1867 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
1868 &objfile->type_obstack));
1869 FIELD_TYPE (*fp) = die_type (die, objfile);
1870 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
1871 &objfile->type_obstack);
1873 else if (die->tag == DW_TAG_inheritance)
1875 /* C++ base class field. */
1876 attr = dwarf_attr (die, DW_AT_data_member_location);
1878 FIELD_BITPOS (*fp) = decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1879 FIELD_BITSIZE (*fp) = 0;
1880 FIELD_TYPE (*fp) = die_type (die, objfile);
1881 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
1882 fip->nbaseclasses++;
1886 /* Create the vector of fields, and attach it to the type. */
1889 dwarf2_attach_fields_to_type (fip, type, objfile)
1890 struct field_info *fip;
1892 struct objfile *objfile;
1894 int nfields = fip->nfields;
1896 /* Record the field count, allocate space for the array of fields,
1897 and create blank accessibility bitfields if necessary. */
1898 TYPE_NFIELDS (type) = nfields;
1899 TYPE_FIELDS (type) = (struct field *)
1900 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1901 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
1903 if (fip->non_public_fields)
1905 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1907 TYPE_FIELD_PRIVATE_BITS (type) =
1908 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1909 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
1911 TYPE_FIELD_PROTECTED_BITS (type) =
1912 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1913 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
1915 TYPE_FIELD_IGNORE_BITS (type) =
1916 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1917 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
1920 /* If the type has baseclasses, allocate and clear a bit vector for
1921 TYPE_FIELD_VIRTUAL_BITS. */
1922 if (fip->nbaseclasses)
1924 int num_bytes = B_BYTES (fip->nbaseclasses);
1927 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1928 pointer = (char *) TYPE_ALLOC (type, num_bytes);
1929 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
1930 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
1931 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
1934 /* Copy the saved-up fields into the field vector. Start from the head
1935 of the list, adding to the tail of the field array, so that they end
1936 up in the same order in the array in which they were added to the list. */
1937 while (nfields-- > 0)
1939 TYPE_FIELD (type, nfields) = fip->fields->field;
1940 switch (fip->fields->accessibility)
1942 case DW_ACCESS_private:
1943 SET_TYPE_FIELD_PRIVATE (type, nfields);
1946 case DW_ACCESS_protected:
1947 SET_TYPE_FIELD_PROTECTED (type, nfields);
1950 case DW_ACCESS_public:
1954 /* Unknown accessibility. Complain and treat it as public. */
1956 complain (&dwarf2_unsupported_accessibility,
1957 fip->fields->accessibility);
1961 if (nfields < fip->nbaseclasses)
1963 switch (fip->fields->virtuality)
1965 case DW_VIRTUALITY_virtual:
1966 case DW_VIRTUALITY_pure_virtual:
1967 SET_TYPE_FIELD_VIRTUAL (type, nfields);
1971 fip->fields = fip->fields->next;
1975 /* Add a member function to the proper fieldlist. */
1978 dwarf2_add_member_fn (fip, die, type, objfile)
1979 struct field_info *fip;
1980 struct die_info *die;
1982 struct objfile *objfile;
1984 struct attribute *attr;
1985 struct fnfieldlist *flp;
1987 struct fn_field *fnp;
1990 struct nextfnfield *new_fnfield;
1992 /* Get name of member function. */
1993 attr = dwarf_attr (die, DW_AT_name);
1994 if (attr && DW_STRING (attr))
1995 fieldname = DW_STRING (attr);
1999 /* Get the mangled name. */
2000 physname = dwarf2_linkage_name (die);
2002 /* Look up member function name in fieldlist. */
2003 for (i = 0; i < fip->nfnfields; i++)
2005 if (STREQ (fip->fnfieldlists[i].name, fieldname))
2009 /* Create new list element if necessary. */
2010 if (i < fip->nfnfields)
2011 flp = &fip->fnfieldlists[i];
2014 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2016 fip->fnfieldlists = (struct fnfieldlist *)
2017 xrealloc (fip->fnfieldlists,
2018 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2019 * sizeof (struct fnfieldlist));
2020 if (fip->nfnfields == 0)
2021 make_cleanup ((make_cleanup_func) free_current_contents,
2022 &fip->fnfieldlists);
2024 flp = &fip->fnfieldlists[fip->nfnfields];
2025 flp->name = fieldname;
2031 /* Create a new member function field and chain it to the field list
2033 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2034 make_cleanup (free, new_fnfield);
2035 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2036 new_fnfield->next = flp->head;
2037 flp->head = new_fnfield;
2040 /* Fill in the member function field info. */
2041 fnp = &new_fnfield->fnfield;
2042 fnp->physname = obsavestring (physname, strlen (physname),
2043 &objfile->type_obstack);
2044 fnp->type = alloc_type (objfile);
2045 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2047 struct type *return_type = TYPE_TARGET_TYPE (die->type);
2048 struct type **arg_types;
2049 int nparams = TYPE_NFIELDS (die->type);
2052 /* Copy argument types from the subroutine type. */
2053 arg_types = (struct type **)
2054 TYPE_ALLOC (fnp->type, (nparams + 1) * sizeof (struct type *));
2055 for (iparams = 0; iparams < nparams; iparams++)
2056 arg_types[iparams] = TYPE_FIELD_TYPE (die->type, iparams);
2058 /* Set last entry in argument type vector. */
2059 if (TYPE_FLAGS (die->type) & TYPE_FLAG_VARARGS)
2060 arg_types[nparams] = NULL;
2062 arg_types[nparams] = dwarf2_fundamental_type (objfile, FT_VOID);
2064 smash_to_method_type (fnp->type, type, return_type, arg_types);
2066 /* Handle static member functions.
2067 Dwarf2 has no clean way to discern C++ static and non-static
2068 member functions. G++ helps GDB by marking the first
2069 parameter for non-static member functions (which is the
2070 this pointer) as artificial. We obtain this information
2071 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2072 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2073 fnp->voffset = VOFFSET_STATIC;
2076 complain (&dwarf2_missing_member_fn_type_complaint, physname);
2078 /* Get fcontext from DW_AT_containing_type if present. */
2079 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2080 fnp->fcontext = die_containing_type (die, objfile);
2082 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2083 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2085 /* Get accessibility. */
2086 attr = dwarf_attr (die, DW_AT_accessibility);
2089 switch (DW_UNSND (attr))
2091 case DW_ACCESS_private:
2092 fnp->is_private = 1;
2094 case DW_ACCESS_protected:
2095 fnp->is_protected = 1;
2100 /* Get index in virtual function table if it is a virtual member function. */
2101 attr = dwarf_attr (die, DW_AT_vtable_elem_location);
2103 fnp->voffset = decode_locdesc (DW_BLOCK (attr), objfile) + 2;
2106 /* Create the vector of member function fields, and attach it to the type. */
2109 dwarf2_attach_fn_fields_to_type (fip, type, objfile)
2110 struct field_info *fip;
2112 struct objfile *objfile;
2114 struct fnfieldlist *flp;
2115 int total_length = 0;
2118 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2119 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2120 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2122 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2124 struct nextfnfield *nfp = flp->head;
2125 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2128 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2129 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2130 fn_flp->fn_fields = (struct fn_field *)
2131 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2132 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2133 fn_flp->fn_fields[k] = nfp->fnfield;
2135 total_length += flp->length;
2138 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2139 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2142 /* Called when we find the DIE that starts a structure or union scope
2143 (definition) to process all dies that define the members of the
2146 NOTE: we need to call struct_type regardless of whether or not the
2147 DIE has an at_name attribute, since it might be an anonymous
2148 structure or union. This gets the type entered into our set of
2151 However, if the structure is incomplete (an opaque struct/union)
2152 then suppress creating a symbol table entry for it since gdb only
2153 wants to find the one with the complete definition. Note that if
2154 it is complete, we just call new_symbol, which does it's own
2155 checking about whether the struct/union is anonymous or not (and
2156 suppresses creating a symbol table entry itself). */
2159 read_structure_scope (die, objfile)
2160 struct die_info *die;
2161 struct objfile *objfile;
2164 struct attribute *attr;
2166 type = alloc_type (objfile);
2168 INIT_CPLUS_SPECIFIC (type);
2169 attr = dwarf_attr (die, DW_AT_name);
2170 if (attr && DW_STRING (attr))
2172 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2173 strlen (DW_STRING (attr)),
2174 &objfile->type_obstack);
2177 if (die->tag == DW_TAG_structure_type)
2179 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2181 else if (die->tag == DW_TAG_union_type)
2183 TYPE_CODE (type) = TYPE_CODE_UNION;
2187 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2189 TYPE_CODE (type) = TYPE_CODE_CLASS;
2192 attr = dwarf_attr (die, DW_AT_byte_size);
2195 TYPE_LENGTH (type) = DW_UNSND (attr);
2199 TYPE_LENGTH (type) = 0;
2202 /* We need to add the type field to the die immediately so we don't
2203 infinitely recurse when dealing with pointers to the structure
2204 type within the structure itself. */
2207 if (die->has_children && ! die_is_declaration (die))
2209 struct field_info fi;
2210 struct die_info *child_die;
2211 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
2213 memset (&fi, 0, sizeof (struct field_info));
2215 child_die = die->next;
2217 while (child_die && child_die->tag)
2219 if (child_die->tag == DW_TAG_member)
2221 dwarf2_add_field (&fi, child_die, objfile);
2223 else if (child_die->tag == DW_TAG_variable)
2225 /* C++ static member. */
2226 dwarf2_add_field (&fi, child_die, objfile);
2228 else if (child_die->tag == DW_TAG_subprogram)
2230 /* C++ member function. */
2231 process_die (child_die, objfile);
2232 dwarf2_add_member_fn (&fi, child_die, type, objfile);
2234 else if (child_die->tag == DW_TAG_inheritance)
2236 /* C++ base class field. */
2237 dwarf2_add_field (&fi, child_die, objfile);
2241 process_die (child_die, objfile);
2243 child_die = sibling_die (child_die);
2246 /* Attach fields and member functions to the type. */
2248 dwarf2_attach_fields_to_type (&fi, type, objfile);
2251 dwarf2_attach_fn_fields_to_type (&fi, type, objfile);
2253 /* Get the type which refers to the base class (possibly this
2254 class itself) which contains the vtable pointer for the current
2255 class from the DW_AT_containing_type attribute. */
2257 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2259 struct type *t = die_containing_type (die, objfile);
2261 TYPE_VPTR_BASETYPE (type) = t;
2264 static const char vptr_name[] =
2265 {'_', 'v', 'p', 't', 'r', '\0'};
2268 /* Our own class provides vtbl ptr. */
2269 for (i = TYPE_NFIELDS (t) - 1;
2270 i >= TYPE_N_BASECLASSES (t);
2273 char *fieldname = TYPE_FIELD_NAME (t, i);
2275 if (STREQN (fieldname, vptr_name, strlen (vptr_name) - 1)
2276 && is_cplus_marker (fieldname[strlen (vptr_name)]))
2278 TYPE_VPTR_FIELDNO (type) = i;
2283 /* Complain if virtual function table field not found. */
2284 if (i < TYPE_N_BASECLASSES (t))
2285 complain (&dwarf2_vtbl_not_found_complaint,
2286 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "");
2290 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2295 new_symbol (die, type, objfile);
2297 do_cleanups (back_to);
2301 /* No children, must be stub. */
2302 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2308 /* Given a pointer to a die which begins an enumeration, process all
2309 the dies that define the members of the enumeration.
2311 This will be much nicer in draft 6 of the DWARF spec when our
2312 members will be dies instead squished into the DW_AT_element_list
2315 NOTE: We reverse the order of the element list. */
2318 read_enumeration (die, objfile)
2319 struct die_info *die;
2320 struct objfile *objfile;
2322 struct die_info *child_die;
2324 struct field *fields;
2325 struct attribute *attr;
2328 int unsigned_enum = 1;
2330 type = alloc_type (objfile);
2332 TYPE_CODE (type) = TYPE_CODE_ENUM;
2333 attr = dwarf_attr (die, DW_AT_name);
2334 if (attr && DW_STRING (attr))
2336 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2337 strlen (DW_STRING (attr)),
2338 &objfile->type_obstack);
2341 attr = dwarf_attr (die, DW_AT_byte_size);
2344 TYPE_LENGTH (type) = DW_UNSND (attr);
2348 TYPE_LENGTH (type) = 0;
2353 if (die->has_children)
2355 child_die = die->next;
2356 while (child_die && child_die->tag)
2358 if (child_die->tag != DW_TAG_enumerator)
2360 process_die (child_die, objfile);
2364 attr = dwarf_attr (child_die, DW_AT_name);
2367 sym = new_symbol (child_die, type, objfile);
2368 if (SYMBOL_VALUE (sym) < 0)
2371 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
2373 fields = (struct field *)
2375 (num_fields + DW_FIELD_ALLOC_CHUNK)
2376 * sizeof (struct field));
2379 FIELD_NAME (fields[num_fields]) = SYMBOL_NAME (sym);
2380 FIELD_TYPE (fields[num_fields]) = NULL;
2381 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
2382 FIELD_BITSIZE (fields[num_fields]) = 0;
2388 child_die = sibling_die (child_die);
2393 TYPE_NFIELDS (type) = num_fields;
2394 TYPE_FIELDS (type) = (struct field *)
2395 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
2396 memcpy (TYPE_FIELDS (type), fields,
2397 sizeof (struct field) * num_fields);
2401 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
2404 new_symbol (die, type, objfile);
2407 /* Extract all information from a DW_TAG_array_type DIE and put it in
2408 the DIE's type field. For now, this only handles one dimensional
2412 read_array_type (die, objfile)
2413 struct die_info *die;
2414 struct objfile *objfile;
2416 struct die_info *child_die;
2417 struct type *type = NULL;
2418 struct type *element_type, *range_type, *index_type;
2419 struct type **range_types = NULL;
2420 struct attribute *attr;
2422 struct cleanup *back_to;
2424 /* Return if we've already decoded this type. */
2430 element_type = die_type (die, objfile);
2432 /* Irix 6.2 native cc creates array types without children for
2433 arrays with unspecified length. */
2434 if (die->has_children == 0)
2436 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2437 range_type = create_range_type (NULL, index_type, 0, -1);
2438 die->type = create_array_type (NULL, element_type, range_type);
2442 back_to = make_cleanup (null_cleanup, NULL);
2443 child_die = die->next;
2444 while (child_die && child_die->tag)
2446 if (child_die->tag == DW_TAG_subrange_type)
2448 unsigned int low, high;
2450 /* Default bounds to an array with unspecified length. */
2453 if (cu_language == language_fortran)
2455 /* FORTRAN implies a lower bound of 1, if not given. */
2459 index_type = die_type (child_die, objfile);
2460 attr = dwarf_attr (child_die, DW_AT_lower_bound);
2463 if (attr->form == DW_FORM_sdata)
2465 low = DW_SND (attr);
2467 else if (attr->form == DW_FORM_udata
2468 || attr->form == DW_FORM_data1
2469 || attr->form == DW_FORM_data2
2470 || attr->form == DW_FORM_data4)
2472 low = DW_UNSND (attr);
2476 complain (&dwarf2_non_const_array_bound_ignored,
2477 dwarf_form_name (attr->form));
2479 die->type = lookup_pointer_type (element_type);
2486 attr = dwarf_attr (child_die, DW_AT_upper_bound);
2489 if (attr->form == DW_FORM_sdata)
2491 high = DW_SND (attr);
2493 else if (attr->form == DW_FORM_udata
2494 || attr->form == DW_FORM_data1
2495 || attr->form == DW_FORM_data2
2496 || attr->form == DW_FORM_data4)
2498 high = DW_UNSND (attr);
2500 else if (attr->form == DW_FORM_block1)
2502 /* GCC encodes arrays with unspecified or dynamic length
2503 with a DW_FORM_block1 attribute.
2504 FIXME: GDB does not yet know how to handle dynamic
2505 arrays properly, treat them as arrays with unspecified
2511 complain (&dwarf2_non_const_array_bound_ignored,
2512 dwarf_form_name (attr->form));
2514 die->type = lookup_pointer_type (element_type);
2522 /* Create a range type and save it for array type creation. */
2523 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
2525 range_types = (struct type **)
2526 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
2527 * sizeof (struct type *));
2529 make_cleanup ((make_cleanup_func) free_current_contents,
2532 range_types[ndim++] = create_range_type (NULL, index_type, low, high);
2534 child_die = sibling_die (child_die);
2537 /* Dwarf2 dimensions are output from left to right, create the
2538 necessary array types in backwards order. */
2539 type = element_type;
2541 type = create_array_type (NULL, type, range_types[ndim]);
2543 do_cleanups (back_to);
2545 /* Install the type in the die. */
2549 /* First cut: install each common block member as a global variable. */
2552 read_common_block (die, objfile)
2553 struct die_info *die;
2554 struct objfile *objfile;
2556 struct die_info *child_die;
2557 struct attribute *attr;
2559 CORE_ADDR base = (CORE_ADDR) 0;
2561 attr = dwarf_attr (die, DW_AT_location);
2564 base = decode_locdesc (DW_BLOCK (attr), objfile);
2566 if (die->has_children)
2568 child_die = die->next;
2569 while (child_die && child_die->tag)
2571 sym = new_symbol (child_die, NULL, objfile);
2572 attr = dwarf_attr (child_die, DW_AT_data_member_location);
2575 SYMBOL_VALUE_ADDRESS (sym) =
2576 base + decode_locdesc (DW_BLOCK (attr), objfile);
2577 add_symbol_to_list (sym, &global_symbols);
2579 child_die = sibling_die (child_die);
2584 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2585 the user defined type vector. */
2588 read_tag_pointer_type (die, objfile)
2589 struct die_info *die;
2590 struct objfile *objfile;
2593 struct attribute *attr;
2600 type = lookup_pointer_type (die_type (die, objfile));
2601 attr = dwarf_attr (die, DW_AT_byte_size);
2604 TYPE_LENGTH (type) = DW_UNSND (attr);
2608 TYPE_LENGTH (type) = address_size;
2613 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2614 the user defined type vector. */
2617 read_tag_ptr_to_member_type (die, objfile)
2618 struct die_info *die;
2619 struct objfile *objfile;
2622 struct type *to_type;
2623 struct type *domain;
2630 type = alloc_type (objfile);
2631 to_type = die_type (die, objfile);
2632 domain = die_containing_type (die, objfile);
2633 smash_to_member_type (type, domain, to_type);
2638 /* Extract all information from a DW_TAG_reference_type DIE and add to
2639 the user defined type vector. */
2642 read_tag_reference_type (die, objfile)
2643 struct die_info *die;
2644 struct objfile *objfile;
2647 struct attribute *attr;
2654 type = lookup_reference_type (die_type (die, objfile));
2655 attr = dwarf_attr (die, DW_AT_byte_size);
2658 TYPE_LENGTH (type) = DW_UNSND (attr);
2662 TYPE_LENGTH (type) = address_size;
2668 read_tag_const_type (die, objfile)
2669 struct die_info *die;
2670 struct objfile *objfile;
2677 complain (&dwarf2_const_ignored);
2678 die->type = die_type (die, objfile);
2682 read_tag_volatile_type (die, objfile)
2683 struct die_info *die;
2684 struct objfile *objfile;
2691 complain (&dwarf2_volatile_ignored);
2692 die->type = die_type (die, objfile);
2695 /* Extract all information from a DW_TAG_string_type DIE and add to
2696 the user defined type vector. It isn't really a user defined type,
2697 but it behaves like one, with other DIE's using an AT_user_def_type
2698 attribute to reference it. */
2701 read_tag_string_type (die, objfile)
2702 struct die_info *die;
2703 struct objfile *objfile;
2705 struct type *type, *range_type, *index_type, *char_type;
2706 struct attribute *attr;
2707 unsigned int length;
2714 attr = dwarf_attr (die, DW_AT_string_length);
2717 length = DW_UNSND (attr);
2723 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2724 range_type = create_range_type (NULL, index_type, 1, length);
2725 char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
2726 type = create_string_type (char_type, range_type);
2730 /* Handle DIES due to C code like:
2734 int (*funcp)(int a, long l);
2738 ('funcp' generates a DW_TAG_subroutine_type DIE)
2742 read_subroutine_type (die, objfile)
2743 struct die_info *die;
2744 struct objfile *objfile;
2746 struct type *type; /* Type that this function returns */
2747 struct type *ftype; /* Function that returns above type */
2748 struct attribute *attr;
2750 /* Decode the type that this subroutine returns */
2755 type = die_type (die, objfile);
2756 ftype = lookup_function_type (type);
2758 /* All functions in C++ have prototypes. */
2759 attr = dwarf_attr (die, DW_AT_prototyped);
2760 if ((attr && (DW_UNSND (attr) != 0))
2761 || cu_language == language_cplus)
2762 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
2764 if (die->has_children)
2766 struct die_info *child_die;
2770 /* Count the number of parameters.
2771 FIXME: GDB currently ignores vararg functions, but knows about
2772 vararg member functions. */
2773 child_die = die->next;
2774 while (child_die && child_die->tag)
2776 if (child_die->tag == DW_TAG_formal_parameter)
2778 else if (child_die->tag == DW_TAG_unspecified_parameters)
2779 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
2780 child_die = sibling_die (child_die);
2783 /* Allocate storage for parameters and fill them in. */
2784 TYPE_NFIELDS (ftype) = nparams;
2785 TYPE_FIELDS (ftype) = (struct field *)
2786 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
2788 child_die = die->next;
2789 while (child_die && child_die->tag)
2791 if (child_die->tag == DW_TAG_formal_parameter)
2793 /* Dwarf2 has no clean way to discern C++ static and non-static
2794 member functions. G++ helps GDB by marking the first
2795 parameter for non-static member functions (which is the
2796 this pointer) as artificial. We pass this information
2797 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2798 attr = dwarf_attr (child_die, DW_AT_artificial);
2800 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
2802 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
2803 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, objfile);
2806 child_die = sibling_die (child_die);
2814 read_typedef (die, objfile)
2815 struct die_info *die;
2816 struct objfile *objfile;
2822 struct attribute *attr;
2825 xtype = die_type (die, objfile);
2827 type = alloc_type (objfile);
2828 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2829 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2830 TYPE_TARGET_TYPE (type) = xtype;
2831 attr = dwarf_attr (die, DW_AT_name);
2832 if (attr && DW_STRING (attr))
2833 TYPE_NAME (type) = obsavestring (DW_STRING (attr),
2834 strlen (DW_STRING (attr)),
2835 &objfile->type_obstack);
2841 /* Find a representation of a given base type and install
2842 it in the TYPE field of the die. */
2845 read_base_type (die, objfile)
2846 struct die_info *die;
2847 struct objfile *objfile;
2850 struct attribute *attr;
2851 int encoding = 0, size = 0;
2853 /* If we've already decoded this die, this is a no-op. */
2859 attr = dwarf_attr (die, DW_AT_encoding);
2862 encoding = DW_UNSND (attr);
2864 attr = dwarf_attr (die, DW_AT_byte_size);
2867 size = DW_UNSND (attr);
2869 attr = dwarf_attr (die, DW_AT_name);
2870 if (attr && DW_STRING (attr))
2872 enum type_code code = TYPE_CODE_INT;
2873 int is_unsigned = 0;
2877 case DW_ATE_address:
2878 /* Turn DW_ATE_address into a void * pointer. */
2879 code = TYPE_CODE_PTR;
2882 case DW_ATE_boolean:
2883 code = TYPE_CODE_BOOL;
2886 case DW_ATE_complex_float:
2887 code = TYPE_CODE_COMPLEX;
2890 code = TYPE_CODE_FLT;
2893 case DW_ATE_signed_char:
2895 case DW_ATE_unsigned:
2896 case DW_ATE_unsigned_char:
2900 complain (&dwarf2_unsupported_at_encoding,
2901 dwarf_type_encoding_name (encoding));
2904 type = init_type (code, size, is_unsigned, DW_STRING (attr), objfile);
2905 if (encoding == DW_ATE_address)
2906 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID);
2910 type = dwarf_base_type (encoding, size, objfile);
2915 /* Read a whole compilation unit into a linked list of dies. */
2918 read_comp_unit (info_ptr, abfd)
2922 struct die_info *first_die, *last_die, *die;
2926 /* Reset die reference table, we are building a new one now. */
2927 dwarf2_empty_die_ref_table ();
2931 first_die = last_die = NULL;
2934 cur_ptr = read_full_die (&die, abfd, cur_ptr);
2935 if (die->has_children)
2946 /* Enter die in reference hash table */
2947 store_in_ref_table (die->offset, die);
2951 first_die = last_die = die;
2955 last_die->next = die;
2959 while (nesting_level > 0);
2963 /* Free a linked list of dies. */
2966 free_die_list (dies)
2967 struct die_info *dies;
2969 struct die_info *die, *next;
2981 /* Read the contents of the section at OFFSET and of size SIZE from the
2982 object file specified by OBJFILE into the psymbol_obstack and return it. */
2985 dwarf2_read_section (objfile, offset, size)
2986 struct objfile *objfile;
2990 bfd *abfd = objfile->obfd;
2996 buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
2997 if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
2998 (bfd_read (buf, size, 1, abfd) != size))
3001 error ("Dwarf Error: Can't read DWARF data from '%s'",
3002 bfd_get_filename (abfd));
3007 /* In DWARF version 2, the description of the debugging information is
3008 stored in a separate .debug_abbrev section. Before we read any
3009 dies from a section we read in all abbreviations and install them
3013 dwarf2_read_abbrevs (abfd, offset)
3015 unsigned int offset;
3018 struct abbrev_info *cur_abbrev;
3019 unsigned int abbrev_number, bytes_read, abbrev_name;
3020 unsigned int abbrev_form, hash_number;
3022 /* empty the table */
3023 dwarf2_empty_abbrev_table (NULL);
3025 abbrev_ptr = dwarf_abbrev_buffer + offset;
3026 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3027 abbrev_ptr += bytes_read;
3029 /* loop until we reach an abbrev number of 0 */
3030 while (abbrev_number)
3032 cur_abbrev = dwarf_alloc_abbrev ();
3034 /* read in abbrev header */
3035 cur_abbrev->number = abbrev_number;
3036 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3037 abbrev_ptr += bytes_read;
3038 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
3041 /* now read in declarations */
3042 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3043 abbrev_ptr += bytes_read;
3044 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3045 abbrev_ptr += bytes_read;
3048 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
3050 cur_abbrev->attrs = (struct attr_abbrev *)
3051 xrealloc (cur_abbrev->attrs,
3052 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
3053 * sizeof (struct attr_abbrev));
3055 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
3056 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
3057 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3058 abbrev_ptr += bytes_read;
3059 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3060 abbrev_ptr += bytes_read;
3063 hash_number = abbrev_number % ABBREV_HASH_SIZE;
3064 cur_abbrev->next = dwarf2_abbrevs[hash_number];
3065 dwarf2_abbrevs[hash_number] = cur_abbrev;
3067 /* Get next abbreviation.
3068 Under Irix6 the abbreviations for a compilation unit are not
3069 always properly terminated with an abbrev number of 0.
3070 Exit loop if we encounter an abbreviation which we have
3071 already read (which means we are about to read the abbreviations
3072 for the next compile unit) or if the end of the abbreviation
3073 table is reached. */
3074 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
3075 >= dwarf_abbrev_size)
3077 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3078 abbrev_ptr += bytes_read;
3079 if (dwarf2_lookup_abbrev (abbrev_number) != NULL)
3084 /* Empty the abbrev table for a new compilation unit. */
3088 dwarf2_empty_abbrev_table (ignore)
3092 struct abbrev_info *abbrev, *next;
3094 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
3097 abbrev = dwarf2_abbrevs[i];
3100 next = abbrev->next;
3101 free (abbrev->attrs);
3105 dwarf2_abbrevs[i] = NULL;
3109 /* Lookup an abbrev_info structure in the abbrev hash table. */
3111 static struct abbrev_info *
3112 dwarf2_lookup_abbrev (number)
3113 unsigned int number;
3115 unsigned int hash_number;
3116 struct abbrev_info *abbrev;
3118 hash_number = number % ABBREV_HASH_SIZE;
3119 abbrev = dwarf2_abbrevs[hash_number];
3123 if (abbrev->number == number)
3126 abbrev = abbrev->next;
3131 /* Read a minimal amount of information into the minimal die structure. */
3134 read_partial_die (part_die, abfd, info_ptr, has_pc_info)
3135 struct partial_die_info *part_die;
3140 unsigned int abbrev_number, bytes_read, i;
3141 struct abbrev_info *abbrev;
3142 struct attribute attr;
3143 struct attribute spec_attr;
3144 int found_spec_attr = 0;
3145 int has_low_pc_attr = 0;
3146 int has_high_pc_attr = 0;
3148 *part_die = zeroed_partial_die;
3150 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3151 info_ptr += bytes_read;
3155 abbrev = dwarf2_lookup_abbrev (abbrev_number);
3158 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number);
3160 part_die->offset = info_ptr - dwarf_info_buffer;
3161 part_die->tag = abbrev->tag;
3162 part_die->has_children = abbrev->has_children;
3163 part_die->abbrev = abbrev_number;
3165 for (i = 0; i < abbrev->num_attrs; ++i)
3167 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr);
3169 /* Store the data if it is of an attribute we want to keep in a
3170 partial symbol table. */
3175 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3176 if (part_die->name == NULL)
3177 part_die->name = DW_STRING (&attr);
3179 case DW_AT_MIPS_linkage_name:
3180 part_die->name = DW_STRING (&attr);
3183 has_low_pc_attr = 1;
3184 part_die->lowpc = DW_ADDR (&attr);
3187 has_high_pc_attr = 1;
3188 part_die->highpc = DW_ADDR (&attr);
3190 case DW_AT_location:
3191 part_die->locdesc = DW_BLOCK (&attr);
3193 case DW_AT_language:
3194 part_die->language = DW_UNSND (&attr);
3196 case DW_AT_external:
3197 part_die->is_external = DW_UNSND (&attr);
3199 case DW_AT_declaration:
3200 part_die->is_declaration = DW_UNSND (&attr);
3203 part_die->has_type = 1;
3205 case DW_AT_abstract_origin:
3206 case DW_AT_specification:
3207 found_spec_attr = 1;
3211 /* Ignore absolute siblings, they might point outside of
3212 the current compile unit. */
3213 if (attr.form == DW_FORM_ref_addr)
3214 complain (&dwarf2_absolute_sibling_complaint);
3217 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr);
3224 /* If we found a reference attribute and the die has no name, try
3225 to find a name in the referred to die. */
3227 if (found_spec_attr && part_die->name == NULL)
3229 struct partial_die_info spec_die;
3233 spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr);
3234 read_partial_die (&spec_die, abfd, spec_ptr, &dummy);
3237 part_die->name = spec_die.name;
3239 /* Copy DW_AT_external attribute if it is set. */
3240 if (spec_die.is_external)
3241 part_die->is_external = spec_die.is_external;
3245 /* When using the GNU linker, .gnu.linkonce. sections are used to
3246 eliminate duplicate copies of functions and vtables and such.
3247 The linker will arbitrarily choose one and discard the others.
3248 The AT_*_pc values for such functions refer to local labels in
3249 these sections. If the section from that file was discarded, the
3250 labels are not in the output, so the relocs get a value of 0.
3251 If this is a discarded function, mark the pc bounds as invalid,
3252 so that GDB will ignore it. */
3253 if (has_low_pc_attr && has_high_pc_attr
3254 && part_die->lowpc < part_die->highpc
3255 && (part_die->lowpc != 0
3256 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
3261 /* Read the die from the .debug_info section buffer. And set diep to
3262 point to a newly allocated die with its information. */
3265 read_full_die (diep, abfd, info_ptr)
3266 struct die_info **diep;
3270 unsigned int abbrev_number, bytes_read, i, offset;
3271 struct abbrev_info *abbrev;
3272 struct die_info *die;
3274 offset = info_ptr - dwarf_info_buffer;
3275 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3276 info_ptr += bytes_read;
3279 die = dwarf_alloc_die ();
3281 die->abbrev = abbrev_number;
3287 abbrev = dwarf2_lookup_abbrev (abbrev_number);
3290 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number);
3292 die = dwarf_alloc_die ();
3293 die->offset = offset;
3294 die->tag = abbrev->tag;
3295 die->has_children = abbrev->has_children;
3296 die->abbrev = abbrev_number;
3299 die->num_attrs = abbrev->num_attrs;
3300 die->attrs = (struct attribute *)
3301 xmalloc (die->num_attrs * sizeof (struct attribute));
3303 for (i = 0; i < abbrev->num_attrs; ++i)
3305 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
3313 /* Read an attribute described by an abbreviated attribute. */
3316 read_attribute (attr, abbrev, abfd, info_ptr)
3317 struct attribute *attr;
3318 struct attr_abbrev *abbrev;
3322 unsigned int bytes_read;
3323 struct dwarf_block *blk;
3325 attr->name = abbrev->name;
3326 attr->form = abbrev->form;
3327 switch (abbrev->form)
3330 case DW_FORM_ref_addr:
3331 DW_ADDR (attr) = read_address (abfd, info_ptr);
3332 info_ptr += address_size;
3334 case DW_FORM_block2:
3335 blk = dwarf_alloc_block ();
3336 blk->size = read_2_bytes (abfd, info_ptr);
3338 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3339 info_ptr += blk->size;
3340 DW_BLOCK (attr) = blk;
3342 case DW_FORM_block4:
3343 blk = dwarf_alloc_block ();
3344 blk->size = read_4_bytes (abfd, info_ptr);
3346 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3347 info_ptr += blk->size;
3348 DW_BLOCK (attr) = blk;
3351 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
3355 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
3359 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
3362 case DW_FORM_string:
3363 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
3364 info_ptr += bytes_read;
3367 blk = dwarf_alloc_block ();
3368 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3369 info_ptr += bytes_read;
3370 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3371 info_ptr += blk->size;
3372 DW_BLOCK (attr) = blk;
3374 case DW_FORM_block1:
3375 blk = dwarf_alloc_block ();
3376 blk->size = read_1_byte (abfd, info_ptr);
3378 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3379 info_ptr += blk->size;
3380 DW_BLOCK (attr) = blk;
3383 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3387 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3391 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
3392 info_ptr += bytes_read;
3395 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3396 info_ptr += bytes_read;
3399 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3403 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
3407 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
3410 case DW_FORM_ref_udata:
3411 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3412 info_ptr += bytes_read;
3415 case DW_FORM_indirect:
3417 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3418 dwarf_form_name (abbrev->form));
3423 /* read dwarf information from a buffer */
3426 read_1_byte (abfd, buf)
3430 return bfd_get_8 (abfd, (bfd_byte *) buf);
3434 read_1_signed_byte (abfd, buf)
3438 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
3442 read_2_bytes (abfd, buf)
3446 return bfd_get_16 (abfd, (bfd_byte *) buf);
3450 read_2_signed_bytes (abfd, buf)
3454 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
3458 read_4_bytes (abfd, buf)
3462 return bfd_get_32 (abfd, (bfd_byte *) buf);
3466 read_4_signed_bytes (abfd, buf)
3470 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
3474 read_8_bytes (abfd, buf)
3478 return bfd_get_64 (abfd, (bfd_byte *) buf);
3482 read_address (abfd, buf)
3486 CORE_ADDR retval = 0;
3488 switch (address_size)
3491 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
3494 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
3497 /* *THE* alternative is 8, right? */
3500 /* If the address being read is larger than the address that is
3501 applicable for the object file format then mask it down to the
3502 correct size. Take care to avoid unnecessary shift or shift
3504 if (address_size > address_significant_size
3505 && address_significant_size < sizeof (CORE_ADDR))
3507 CORE_ADDR mask = ((CORE_ADDR) 0) - 1;
3508 retval &= ~(mask << (address_significant_size * 8));
3514 read_n_bytes (abfd, buf, size)
3519 /* If the size of a host char is 8 bits, we can return a pointer
3520 to the buffer, otherwise we have to copy the data to a buffer
3521 allocated on the temporary obstack. */
3522 #if HOST_CHAR_BIT == 8
3528 ret = obstack_alloc (&dwarf2_tmp_obstack, size);
3529 for (i = 0; i < size; ++i)
3531 ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
3539 read_string (abfd, buf, bytes_read_ptr)
3542 unsigned int *bytes_read_ptr;
3544 /* If the size of a host char is 8 bits, we can return a pointer
3545 to the string, otherwise we have to copy the string to a buffer
3546 allocated on the temporary obstack. */
3547 #if HOST_CHAR_BIT == 8
3550 *bytes_read_ptr = 1;
3553 *bytes_read_ptr = strlen (buf) + 1;
3559 while ((byte = bfd_get_8 (abfd, (bfd_byte *) buf)) != 0)
3561 obstack_1grow (&dwarf2_tmp_obstack, byte);
3567 *bytes_read_ptr = 1;
3570 obstack_1grow (&dwarf2_tmp_obstack, '\0');
3571 *bytes_read_ptr = i + 1;
3572 return obstack_finish (&dwarf2_tmp_obstack);
3577 read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
3580 unsigned int *bytes_read_ptr;
3582 unsigned int result, num_read;
3592 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
3595 result |= ((byte & 127) << shift);
3596 if ((byte & 128) == 0)
3602 *bytes_read_ptr = num_read;
3607 read_signed_leb128 (abfd, buf, bytes_read_ptr)
3610 unsigned int *bytes_read_ptr;
3613 int i, shift, size, num_read;
3623 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
3626 result |= ((byte & 127) << shift);
3628 if ((byte & 128) == 0)
3633 if ((shift < size) && (byte & 0x40))
3635 result |= -(1 << shift);
3637 *bytes_read_ptr = num_read;
3642 set_cu_language (lang)
3649 cu_language = language_c;
3651 case DW_LANG_C_plus_plus:
3652 cu_language = language_cplus;
3654 case DW_LANG_Fortran77:
3655 case DW_LANG_Fortran90:
3656 cu_language = language_fortran;
3658 case DW_LANG_Mips_Assembler:
3659 cu_language = language_asm;
3662 case DW_LANG_Cobol74:
3663 case DW_LANG_Cobol85:
3664 case DW_LANG_Pascal83:
3665 case DW_LANG_Modula2:
3667 cu_language = language_unknown;
3670 cu_language_defn = language_def (cu_language);
3673 /* Return the named attribute or NULL if not there. */
3675 static struct attribute *
3676 dwarf_attr (die, name)
3677 struct die_info *die;
3681 struct attribute *spec = NULL;
3683 for (i = 0; i < die->num_attrs; ++i)
3685 if (die->attrs[i].name == name)
3687 return &die->attrs[i];
3689 if (die->attrs[i].name == DW_AT_specification
3690 || die->attrs[i].name == DW_AT_abstract_origin)
3691 spec = &die->attrs[i];
3695 struct die_info *ref_die =
3696 follow_die_ref (dwarf2_get_ref_die_offset (spec));
3699 return dwarf_attr (ref_die, name);
3706 die_is_declaration (struct die_info *die)
3708 return (dwarf_attr (die, DW_AT_declaration)
3709 && ! dwarf_attr (die, DW_AT_specification));
3712 /* Decode the line number information for the compilation unit whose
3713 line number info is at OFFSET in the .debug_line section.
3714 The compilation directory of the file is passed in COMP_DIR. */
3718 unsigned int num_files;
3731 unsigned int num_dirs;
3736 dwarf_decode_lines (offset, comp_dir, abfd)
3737 unsigned int offset;
3743 struct line_head lh;
3744 struct cleanup *back_to;
3745 unsigned int i, bytes_read;
3746 char *cur_file, *cur_dir;
3747 unsigned char op_code, extended_op, adj_opcode;
3749 #define FILE_ALLOC_CHUNK 5
3750 #define DIR_ALLOC_CHUNK 5
3752 struct filenames files;
3753 struct directories dirs;
3755 if (dwarf_line_buffer == NULL)
3757 complain (&dwarf2_missing_line_number_section);
3761 files.num_files = 0;
3767 line_ptr = dwarf_line_buffer + offset;
3769 /* read in the prologue */
3770 lh.total_length = read_4_bytes (abfd, line_ptr);
3772 line_end = line_ptr + lh.total_length;
3773 lh.version = read_2_bytes (abfd, line_ptr);
3775 lh.prologue_length = read_4_bytes (abfd, line_ptr);
3777 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
3779 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
3781 lh.line_base = read_1_signed_byte (abfd, line_ptr);
3783 lh.line_range = read_1_byte (abfd, line_ptr);
3785 lh.opcode_base = read_1_byte (abfd, line_ptr);
3787 lh.standard_opcode_lengths = (unsigned char *)
3788 xmalloc (lh.opcode_base * sizeof (unsigned char));
3789 back_to = make_cleanup ((make_cleanup_func) free_current_contents,
3790 &lh.standard_opcode_lengths);
3792 lh.standard_opcode_lengths[0] = 1;
3793 for (i = 1; i < lh.opcode_base; ++i)
3795 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
3799 /* Read directory table */
3800 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3802 line_ptr += bytes_read;
3803 if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0)
3805 dirs.dirs = (char **)
3806 xrealloc (dirs.dirs,
3807 (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
3808 if (dirs.num_dirs == 0)
3809 make_cleanup ((make_cleanup_func) free_current_contents, &dirs.dirs);
3811 dirs.dirs[dirs.num_dirs++] = cur_dir;
3813 line_ptr += bytes_read;
3815 /* Read file name table */
3816 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3818 line_ptr += bytes_read;
3819 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3821 files.files = (struct fileinfo *)
3822 xrealloc (files.files,
3823 (files.num_files + FILE_ALLOC_CHUNK)
3824 * sizeof (struct fileinfo));
3825 if (files.num_files == 0)
3826 make_cleanup ((make_cleanup_func) free_current_contents,
3829 files.files[files.num_files].name = cur_file;
3830 files.files[files.num_files].dir =
3831 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3832 line_ptr += bytes_read;
3833 files.files[files.num_files].time =
3834 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3835 line_ptr += bytes_read;
3836 files.files[files.num_files].size =
3837 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3838 line_ptr += bytes_read;
3841 line_ptr += bytes_read;
3843 /* Read the statement sequences until there's nothing left. */
3844 while (line_ptr < line_end)
3846 /* state machine registers */
3847 CORE_ADDR address = 0;
3848 unsigned int file = 1;
3849 unsigned int line = 1;
3850 unsigned int column = 0;
3851 int is_stmt = lh.default_is_stmt;
3852 int basic_block = 0;
3853 int end_sequence = 0;
3855 /* Start a subfile for the current file of the state machine. */
3856 if (files.num_files >= file)
3858 /* The file and directory tables are 0 based, the references
3860 dwarf2_start_subfile (files.files[file - 1].name,
3861 (files.files[file - 1].dir
3862 ? dirs.dirs[files.files[file - 1].dir - 1]
3866 /* Decode the table. */
3867 while (!end_sequence)
3869 op_code = read_1_byte (abfd, line_ptr);
3873 case DW_LNS_extended_op:
3874 line_ptr += 1; /* ignore length */
3875 extended_op = read_1_byte (abfd, line_ptr);
3877 switch (extended_op)
3879 case DW_LNE_end_sequence:
3881 /* Don't call record_line here. The end_sequence
3882 instruction provides the address of the first byte
3883 *after* the last line in the sequence; it's not the
3884 address of any real source line. However, the GDB
3885 linetable structure only records the starts of lines,
3886 not the ends. This is a weakness of GDB. */
3888 case DW_LNE_set_address:
3889 address = read_address (abfd, line_ptr) + baseaddr;
3890 line_ptr += address_size;
3892 case DW_LNE_define_file:
3893 cur_file = read_string (abfd, line_ptr, &bytes_read);
3894 line_ptr += bytes_read;
3895 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3897 files.files = (struct fileinfo *)
3898 xrealloc (files.files,
3899 (files.num_files + FILE_ALLOC_CHUNK)
3900 * sizeof (struct fileinfo));
3901 if (files.num_files == 0)
3902 make_cleanup ((make_cleanup_func) free_current_contents,
3905 files.files[files.num_files].name = cur_file;
3906 files.files[files.num_files].dir =
3907 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3908 line_ptr += bytes_read;
3909 files.files[files.num_files].time =
3910 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3911 line_ptr += bytes_read;
3912 files.files[files.num_files].size =
3913 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3914 line_ptr += bytes_read;
3918 complain (&dwarf2_mangled_line_number_section);
3923 record_line (current_subfile, line, address);
3926 case DW_LNS_advance_pc:
3927 address += lh.minimum_instruction_length
3928 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3929 line_ptr += bytes_read;
3931 case DW_LNS_advance_line:
3932 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
3933 line_ptr += bytes_read;
3935 case DW_LNS_set_file:
3936 /* The file and directory tables are 0 based, the references
3938 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3939 line_ptr += bytes_read;
3940 dwarf2_start_subfile
3941 (files.files[file - 1].name,
3942 (files.files[file - 1].dir
3943 ? dirs.dirs[files.files[file - 1].dir - 1]
3946 case DW_LNS_set_column:
3947 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3948 line_ptr += bytes_read;
3950 case DW_LNS_negate_stmt:
3951 is_stmt = (!is_stmt);
3953 case DW_LNS_set_basic_block:
3956 /* Add to the address register of the state machine the
3957 address increment value corresponding to special opcode
3958 255. Ie, this value is scaled by the minimum instruction
3959 length since special opcode 255 would have scaled the
3961 case DW_LNS_const_add_pc:
3962 address += (lh.minimum_instruction_length
3963 * ((255 - lh.opcode_base) / lh.line_range));
3965 case DW_LNS_fixed_advance_pc:
3966 address += read_2_bytes (abfd, line_ptr);
3969 default: /* special operand */
3970 adj_opcode = op_code - lh.opcode_base;
3971 address += (adj_opcode / lh.line_range)
3972 * lh.minimum_instruction_length;
3973 line += lh.line_base + (adj_opcode % lh.line_range);
3974 /* append row to matrix using current values */
3975 record_line (current_subfile, line, address);
3981 do_cleanups (back_to);
3984 /* Start a subfile for DWARF. FILENAME is the name of the file and
3985 DIRNAME the name of the source directory which contains FILENAME
3986 or NULL if not known.
3987 This routine tries to keep line numbers from identical absolute and
3988 relative file names in a common subfile.
3990 Using the `list' example from the GDB testsuite, which resides in
3991 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3992 of /srcdir/list0.c yields the following debugging information for list0.c:
3994 DW_AT_name: /srcdir/list0.c
3995 DW_AT_comp_dir: /compdir
3996 files.files[0].name: list0.h
3997 files.files[0].dir: /srcdir
3998 files.files[1].name: list0.c
3999 files.files[1].dir: /srcdir
4001 The line number information for list0.c has to end up in a single
4002 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4005 dwarf2_start_subfile (filename, dirname)
4009 /* If the filename isn't absolute, try to match an existing subfile
4010 with the full pathname. */
4012 if (*filename != '/' && dirname != NULL)
4014 struct subfile *subfile;
4015 char *fullname = concat (dirname, "/", filename, NULL);
4017 for (subfile = subfiles; subfile; subfile = subfile->next)
4019 if (STREQ (subfile->name, fullname))
4021 current_subfile = subfile;
4028 start_subfile (filename, dirname);
4031 /* Given a pointer to a DWARF information entry, figure out if we need
4032 to make a symbol table entry for it, and if so, create a new entry
4033 and return a pointer to it.
4034 If TYPE is NULL, determine symbol type from the die, otherwise
4035 used the passed type. */
4037 static struct symbol *
4038 new_symbol (die, type, objfile)
4039 struct die_info *die;
4041 struct objfile *objfile;
4043 struct symbol *sym = NULL;
4045 struct attribute *attr = NULL;
4046 struct attribute *attr2 = NULL;
4049 name = dwarf2_linkage_name (die);
4052 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
4053 sizeof (struct symbol));
4054 OBJSTAT (objfile, n_syms++);
4055 memset (sym, 0, sizeof (struct symbol));
4056 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
4057 &objfile->symbol_obstack);
4059 /* Default assumptions.
4060 Use the passed type or decode it from the die. */
4061 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4062 SYMBOL_CLASS (sym) = LOC_STATIC;
4064 SYMBOL_TYPE (sym) = type;
4066 SYMBOL_TYPE (sym) = die_type (die, objfile);
4067 attr = dwarf_attr (die, DW_AT_decl_line);
4070 SYMBOL_LINE (sym) = DW_UNSND (attr);
4073 /* If this symbol is from a C++ compilation, then attempt to
4074 cache the demangled form for future reference. This is a
4075 typical time versus space tradeoff, that was decided in favor
4076 of time because it sped up C++ symbol lookups by a factor of
4079 SYMBOL_LANGUAGE (sym) = cu_language;
4080 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
4084 attr = dwarf_attr (die, DW_AT_low_pc);
4087 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
4089 SYMBOL_CLASS (sym) = LOC_LABEL;
4091 case DW_TAG_subprogram:
4092 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4094 SYMBOL_CLASS (sym) = LOC_BLOCK;
4095 attr2 = dwarf_attr (die, DW_AT_external);
4096 if (attr2 && (DW_UNSND (attr2) != 0))
4098 add_symbol_to_list (sym, &global_symbols);
4102 add_symbol_to_list (sym, list_in_scope);
4105 case DW_TAG_variable:
4106 /* Compilation with minimal debug info may result in variables
4107 with missing type entries. Change the misleading `void' type
4108 to something sensible. */
4109 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
4110 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
4111 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
4112 "<variable, no debug info>",
4114 attr = dwarf_attr (die, DW_AT_const_value);
4117 dwarf2_const_value (attr, sym, objfile);
4118 attr2 = dwarf_attr (die, DW_AT_external);
4119 if (attr2 && (DW_UNSND (attr2) != 0))
4120 add_symbol_to_list (sym, &global_symbols);
4122 add_symbol_to_list (sym, list_in_scope);
4125 attr = dwarf_attr (die, DW_AT_location);
4128 attr2 = dwarf_attr (die, DW_AT_external);
4129 if (attr2 && (DW_UNSND (attr2) != 0))
4131 SYMBOL_VALUE_ADDRESS (sym) =
4132 decode_locdesc (DW_BLOCK (attr), objfile);
4133 add_symbol_to_list (sym, &global_symbols);
4135 /* In shared libraries the address of the variable
4136 in the location descriptor might still be relocatable,
4137 so its value could be zero.
4138 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4139 value is zero, the address of the variable will then
4140 be determined from the minimal symbol table whenever
4141 the variable is referenced. */
4142 if (SYMBOL_VALUE_ADDRESS (sym))
4144 SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
4145 SYMBOL_CLASS (sym) = LOC_STATIC;
4148 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
4152 SYMBOL_VALUE (sym) = addr =
4153 decode_locdesc (DW_BLOCK (attr), objfile);
4154 add_symbol_to_list (sym, list_in_scope);
4157 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
4161 SYMBOL_CLASS (sym) = LOC_REGISTER;
4165 SYMBOL_CLASS (sym) = LOC_BASEREG;
4166 SYMBOL_BASEREG (sym) = basereg;
4170 SYMBOL_CLASS (sym) = LOC_LOCAL;
4174 SYMBOL_CLASS (sym) = LOC_STATIC;
4175 SYMBOL_VALUE_ADDRESS (sym) = addr + baseaddr;
4181 /* We do not know the address of this symbol.
4182 If it is an external symbol and we have type information
4183 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4184 The address of the variable will then be determined from
4185 the minimal symbol table whenever the variable is
4187 attr2 = dwarf_attr (die, DW_AT_external);
4188 if (attr2 && (DW_UNSND (attr2) != 0)
4189 && dwarf_attr (die, DW_AT_type) != NULL)
4191 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
4192 add_symbol_to_list (sym, &global_symbols);
4196 case DW_TAG_formal_parameter:
4197 attr = dwarf_attr (die, DW_AT_location);
4200 SYMBOL_VALUE (sym) = decode_locdesc (DW_BLOCK (attr), objfile);
4203 SYMBOL_CLASS (sym) = LOC_REGPARM;
4209 if (basereg != frame_base_reg)
4210 complain (&dwarf2_complex_location_expr);
4211 SYMBOL_CLASS (sym) = LOC_REF_ARG;
4215 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
4216 SYMBOL_BASEREG (sym) = basereg;
4221 SYMBOL_CLASS (sym) = LOC_ARG;
4224 attr = dwarf_attr (die, DW_AT_const_value);
4227 dwarf2_const_value (attr, sym, objfile);
4229 add_symbol_to_list (sym, list_in_scope);
4231 case DW_TAG_unspecified_parameters:
4232 /* From varargs functions; gdb doesn't seem to have any
4233 interest in this information, so just ignore it for now.
4236 case DW_TAG_class_type:
4237 case DW_TAG_structure_type:
4238 case DW_TAG_union_type:
4239 case DW_TAG_enumeration_type:
4240 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4241 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
4242 add_symbol_to_list (sym, list_in_scope);
4244 /* The semantics of C++ state that "struct foo { ... }" also
4245 defines a typedef for "foo". Synthesize a typedef symbol so
4246 that "ptype foo" works as expected. */
4247 if (cu_language == language_cplus)
4249 struct symbol *typedef_sym = (struct symbol *)
4250 obstack_alloc (&objfile->symbol_obstack,
4251 sizeof (struct symbol));
4252 *typedef_sym = *sym;
4253 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
4254 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
4255 TYPE_NAME (SYMBOL_TYPE (sym)) =
4256 obsavestring (SYMBOL_NAME (sym),
4257 strlen (SYMBOL_NAME (sym)),
4258 &objfile->type_obstack);
4259 add_symbol_to_list (typedef_sym, list_in_scope);
4262 case DW_TAG_typedef:
4263 case DW_TAG_base_type:
4264 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4265 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4266 add_symbol_to_list (sym, list_in_scope);
4268 case DW_TAG_enumerator:
4269 attr = dwarf_attr (die, DW_AT_const_value);
4272 dwarf2_const_value (attr, sym, objfile);
4274 add_symbol_to_list (sym, list_in_scope);
4277 /* Not a tag we recognize. Hopefully we aren't processing
4278 trash data, but since we must specifically ignore things
4279 we don't recognize, there is nothing else we should do at
4281 complain (&dwarf2_unsupported_tag, dwarf_tag_name (die->tag));
4288 /* Copy constant value from an attribute to a symbol. */
4291 dwarf2_const_value (attr, sym, objfile)
4292 struct attribute *attr;
4294 struct objfile *objfile;
4296 struct dwarf_block *blk;
4301 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != (unsigned int) address_size)
4302 complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym),
4303 address_size, TYPE_LENGTH (SYMBOL_TYPE (sym)));
4304 SYMBOL_VALUE_BYTES (sym) = (char *)
4305 obstack_alloc (&objfile->symbol_obstack, address_size);
4306 store_address (SYMBOL_VALUE_BYTES (sym), address_size, DW_ADDR (attr));
4307 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
4309 case DW_FORM_block1:
4310 case DW_FORM_block2:
4311 case DW_FORM_block4:
4313 blk = DW_BLOCK (attr);
4314 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
4315 complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym),
4316 blk->size, TYPE_LENGTH (SYMBOL_TYPE (sym)));
4317 SYMBOL_VALUE_BYTES (sym) = (char *)
4318 obstack_alloc (&objfile->symbol_obstack, blk->size);
4319 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
4320 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
4323 /* The DW_AT_const_value attributes are supposed to carry the
4324 symbol's value "represented as it would be on the target
4325 architecture." By the time we get here, it's already been
4326 converted to host endianness, so we just need to sign- or
4327 zero-extend it as appropriate. */
4329 dwarf2_const_value_data (attr, sym, 8);
4332 dwarf2_const_value_data (attr, sym, 16);
4335 dwarf2_const_value_data (attr, sym, 32);
4338 dwarf2_const_value_data (attr, sym, 64);
4342 SYMBOL_VALUE (sym) = DW_SND (attr);
4343 SYMBOL_CLASS (sym) = LOC_CONST;
4347 SYMBOL_VALUE (sym) = DW_UNSND (attr);
4348 SYMBOL_CLASS (sym) = LOC_CONST;
4352 complain (&dwarf2_unsupported_const_value_attr,
4353 dwarf_form_name (attr->form));
4354 SYMBOL_VALUE (sym) = 0;
4355 SYMBOL_CLASS (sym) = LOC_CONST;
4361 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4362 or zero-extend it as appropriate for the symbol's type. */
4364 dwarf2_const_value_data (struct attribute *attr,
4368 LONGEST l = DW_UNSND (attr);
4370 if (bits < sizeof (l) * 8)
4372 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
4373 l &= ((LONGEST) 1 << bits) - 1;
4375 l = (l << (sizeof (l) - bits)) >> (sizeof (l) - bits);
4378 SYMBOL_VALUE (sym) = l;
4379 SYMBOL_CLASS (sym) = LOC_CONST;
4383 /* Return the type of the die in question using its DW_AT_type attribute. */
4385 static struct type *
4386 die_type (die, objfile)
4387 struct die_info *die;
4388 struct objfile *objfile;
4391 struct attribute *type_attr;
4392 struct die_info *type_die;
4395 type_attr = dwarf_attr (die, DW_AT_type);
4398 /* A missing DW_AT_type represents a void type. */
4399 return dwarf2_fundamental_type (objfile, FT_VOID);
4403 ref = dwarf2_get_ref_die_offset (type_attr);
4404 type_die = follow_die_ref (ref);
4407 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
4411 type = tag_type_to_type (type_die, objfile);
4414 dump_die (type_die);
4415 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4420 /* Return the containing type of the die in question using its
4421 DW_AT_containing_type attribute. */
4423 static struct type *
4424 die_containing_type (die, objfile)
4425 struct die_info *die;
4426 struct objfile *objfile;
4428 struct type *type = NULL;
4429 struct attribute *type_attr;
4430 struct die_info *type_die = NULL;
4433 type_attr = dwarf_attr (die, DW_AT_containing_type);
4436 ref = dwarf2_get_ref_die_offset (type_attr);
4437 type_die = follow_die_ref (ref);
4440 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
4443 type = tag_type_to_type (type_die, objfile);
4448 dump_die (type_die);
4449 error ("Dwarf Error: Problem turning containing type into gdb type.");
4455 static struct type *
4456 type_at_offset (offset, objfile)
4457 unsigned int offset;
4458 struct objfile *objfile;
4460 struct die_info *die;
4463 die = follow_die_ref (offset);
4466 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
4469 type = tag_type_to_type (die, objfile);
4474 static struct type *
4475 tag_type_to_type (die, objfile)
4476 struct die_info *die;
4477 struct objfile *objfile;
4485 read_type_die (die, objfile);
4489 error ("Dwarf Error: Cannot find type of die.");
4496 read_type_die (die, objfile)
4497 struct die_info *die;
4498 struct objfile *objfile;
4502 case DW_TAG_class_type:
4503 case DW_TAG_structure_type:
4504 case DW_TAG_union_type:
4505 read_structure_scope (die, objfile);
4507 case DW_TAG_enumeration_type:
4508 read_enumeration (die, objfile);
4510 case DW_TAG_subprogram:
4511 case DW_TAG_subroutine_type:
4512 read_subroutine_type (die, objfile);
4514 case DW_TAG_array_type:
4515 read_array_type (die, objfile);
4517 case DW_TAG_pointer_type:
4518 read_tag_pointer_type (die, objfile);
4520 case DW_TAG_ptr_to_member_type:
4521 read_tag_ptr_to_member_type (die, objfile);
4523 case DW_TAG_reference_type:
4524 read_tag_reference_type (die, objfile);
4526 case DW_TAG_const_type:
4527 read_tag_const_type (die, objfile);
4529 case DW_TAG_volatile_type:
4530 read_tag_volatile_type (die, objfile);
4532 case DW_TAG_string_type:
4533 read_tag_string_type (die, objfile);
4535 case DW_TAG_typedef:
4536 read_typedef (die, objfile);
4538 case DW_TAG_base_type:
4539 read_base_type (die, objfile);
4542 complain (&dwarf2_unexpected_tag, dwarf_tag_name (die->tag));
4547 static struct type *
4548 dwarf_base_type (encoding, size, objfile)
4551 struct objfile *objfile;
4553 /* FIXME - this should not produce a new (struct type *)
4554 every time. It should cache base types. */
4558 case DW_ATE_address:
4559 type = dwarf2_fundamental_type (objfile, FT_VOID);
4561 case DW_ATE_boolean:
4562 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN);
4564 case DW_ATE_complex_float:
4567 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX);
4571 type = dwarf2_fundamental_type (objfile, FT_COMPLEX);
4577 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
4581 type = dwarf2_fundamental_type (objfile, FT_FLOAT);
4588 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
4591 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT);
4595 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
4599 case DW_ATE_signed_char:
4600 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
4602 case DW_ATE_unsigned:
4606 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
4609 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT);
4613 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
4617 case DW_ATE_unsigned_char:
4618 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
4621 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
4629 struct die_info *old_die;
4631 struct die_info *new_die;
4634 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
4635 memset (new_die, 0, sizeof (struct die_info));
4637 new_die->tag = old_die->tag;
4638 new_die->has_children = old_die->has_children;
4639 new_die->abbrev = old_die->abbrev;
4640 new_die->offset = old_die->offset;
4641 new_die->type = NULL;
4643 num_attrs = old_die->num_attrs;
4644 new_die->num_attrs = num_attrs;
4645 new_die->attrs = (struct attribute *)
4646 xmalloc (num_attrs * sizeof (struct attribute));
4648 for (i = 0; i < old_die->num_attrs; ++i)
4650 new_die->attrs[i].name = old_die->attrs[i].name;
4651 new_die->attrs[i].form = old_die->attrs[i].form;
4652 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
4655 new_die->next = NULL;
4660 /* Return sibling of die, NULL if no sibling. */
4664 struct die_info *die;
4666 int nesting_level = 0;
4668 if (!die->has_children)
4670 if (die->next && (die->next->tag == 0))
4683 if (die->has_children)
4693 while (nesting_level);
4694 if (die && (die->tag == 0))
4705 /* Get linkage name of a die, return NULL if not found. */
4708 dwarf2_linkage_name (die)
4709 struct die_info *die;
4711 struct attribute *attr;
4713 attr = dwarf_attr (die, DW_AT_MIPS_linkage_name);
4714 if (attr && DW_STRING (attr))
4715 return DW_STRING (attr);
4716 attr = dwarf_attr (die, DW_AT_name);
4717 if (attr && DW_STRING (attr))
4718 return DW_STRING (attr);
4722 /* Convert a DIE tag into its string name. */
4725 dwarf_tag_name (tag)
4726 register unsigned tag;
4730 case DW_TAG_padding:
4731 return "DW_TAG_padding";
4732 case DW_TAG_array_type:
4733 return "DW_TAG_array_type";
4734 case DW_TAG_class_type:
4735 return "DW_TAG_class_type";
4736 case DW_TAG_entry_point:
4737 return "DW_TAG_entry_point";
4738 case DW_TAG_enumeration_type:
4739 return "DW_TAG_enumeration_type";
4740 case DW_TAG_formal_parameter:
4741 return "DW_TAG_formal_parameter";
4742 case DW_TAG_imported_declaration:
4743 return "DW_TAG_imported_declaration";
4745 return "DW_TAG_label";
4746 case DW_TAG_lexical_block:
4747 return "DW_TAG_lexical_block";
4749 return "DW_TAG_member";
4750 case DW_TAG_pointer_type:
4751 return "DW_TAG_pointer_type";
4752 case DW_TAG_reference_type:
4753 return "DW_TAG_reference_type";
4754 case DW_TAG_compile_unit:
4755 return "DW_TAG_compile_unit";
4756 case DW_TAG_string_type:
4757 return "DW_TAG_string_type";
4758 case DW_TAG_structure_type:
4759 return "DW_TAG_structure_type";
4760 case DW_TAG_subroutine_type:
4761 return "DW_TAG_subroutine_type";
4762 case DW_TAG_typedef:
4763 return "DW_TAG_typedef";
4764 case DW_TAG_union_type:
4765 return "DW_TAG_union_type";
4766 case DW_TAG_unspecified_parameters:
4767 return "DW_TAG_unspecified_parameters";
4768 case DW_TAG_variant:
4769 return "DW_TAG_variant";
4770 case DW_TAG_common_block:
4771 return "DW_TAG_common_block";
4772 case DW_TAG_common_inclusion:
4773 return "DW_TAG_common_inclusion";
4774 case DW_TAG_inheritance:
4775 return "DW_TAG_inheritance";
4776 case DW_TAG_inlined_subroutine:
4777 return "DW_TAG_inlined_subroutine";
4779 return "DW_TAG_module";
4780 case DW_TAG_ptr_to_member_type:
4781 return "DW_TAG_ptr_to_member_type";
4782 case DW_TAG_set_type:
4783 return "DW_TAG_set_type";
4784 case DW_TAG_subrange_type:
4785 return "DW_TAG_subrange_type";
4786 case DW_TAG_with_stmt:
4787 return "DW_TAG_with_stmt";
4788 case DW_TAG_access_declaration:
4789 return "DW_TAG_access_declaration";
4790 case DW_TAG_base_type:
4791 return "DW_TAG_base_type";
4792 case DW_TAG_catch_block:
4793 return "DW_TAG_catch_block";
4794 case DW_TAG_const_type:
4795 return "DW_TAG_const_type";
4796 case DW_TAG_constant:
4797 return "DW_TAG_constant";
4798 case DW_TAG_enumerator:
4799 return "DW_TAG_enumerator";
4800 case DW_TAG_file_type:
4801 return "DW_TAG_file_type";
4803 return "DW_TAG_friend";
4804 case DW_TAG_namelist:
4805 return "DW_TAG_namelist";
4806 case DW_TAG_namelist_item:
4807 return "DW_TAG_namelist_item";
4808 case DW_TAG_packed_type:
4809 return "DW_TAG_packed_type";
4810 case DW_TAG_subprogram:
4811 return "DW_TAG_subprogram";
4812 case DW_TAG_template_type_param:
4813 return "DW_TAG_template_type_param";
4814 case DW_TAG_template_value_param:
4815 return "DW_TAG_template_value_param";
4816 case DW_TAG_thrown_type:
4817 return "DW_TAG_thrown_type";
4818 case DW_TAG_try_block:
4819 return "DW_TAG_try_block";
4820 case DW_TAG_variant_part:
4821 return "DW_TAG_variant_part";
4822 case DW_TAG_variable:
4823 return "DW_TAG_variable";
4824 case DW_TAG_volatile_type:
4825 return "DW_TAG_volatile_type";
4826 case DW_TAG_MIPS_loop:
4827 return "DW_TAG_MIPS_loop";
4828 case DW_TAG_format_label:
4829 return "DW_TAG_format_label";
4830 case DW_TAG_function_template:
4831 return "DW_TAG_function_template";
4832 case DW_TAG_class_template:
4833 return "DW_TAG_class_template";
4835 return "DW_TAG_<unknown>";
4839 /* Convert a DWARF attribute code into its string name. */
4842 dwarf_attr_name (attr)
4843 register unsigned attr;
4848 return "DW_AT_sibling";
4849 case DW_AT_location:
4850 return "DW_AT_location";
4852 return "DW_AT_name";
4853 case DW_AT_ordering:
4854 return "DW_AT_ordering";
4855 case DW_AT_subscr_data:
4856 return "DW_AT_subscr_data";
4857 case DW_AT_byte_size:
4858 return "DW_AT_byte_size";
4859 case DW_AT_bit_offset:
4860 return "DW_AT_bit_offset";
4861 case DW_AT_bit_size:
4862 return "DW_AT_bit_size";
4863 case DW_AT_element_list:
4864 return "DW_AT_element_list";
4865 case DW_AT_stmt_list:
4866 return "DW_AT_stmt_list";
4868 return "DW_AT_low_pc";
4870 return "DW_AT_high_pc";
4871 case DW_AT_language:
4872 return "DW_AT_language";
4874 return "DW_AT_member";
4876 return "DW_AT_discr";
4877 case DW_AT_discr_value:
4878 return "DW_AT_discr_value";
4879 case DW_AT_visibility:
4880 return "DW_AT_visibility";
4882 return "DW_AT_import";
4883 case DW_AT_string_length:
4884 return "DW_AT_string_length";
4885 case DW_AT_common_reference:
4886 return "DW_AT_common_reference";
4887 case DW_AT_comp_dir:
4888 return "DW_AT_comp_dir";
4889 case DW_AT_const_value:
4890 return "DW_AT_const_value";
4891 case DW_AT_containing_type:
4892 return "DW_AT_containing_type";
4893 case DW_AT_default_value:
4894 return "DW_AT_default_value";
4896 return "DW_AT_inline";
4897 case DW_AT_is_optional:
4898 return "DW_AT_is_optional";
4899 case DW_AT_lower_bound:
4900 return "DW_AT_lower_bound";
4901 case DW_AT_producer:
4902 return "DW_AT_producer";
4903 case DW_AT_prototyped:
4904 return "DW_AT_prototyped";
4905 case DW_AT_return_addr:
4906 return "DW_AT_return_addr";
4907 case DW_AT_start_scope:
4908 return "DW_AT_start_scope";
4909 case DW_AT_stride_size:
4910 return "DW_AT_stride_size";
4911 case DW_AT_upper_bound:
4912 return "DW_AT_upper_bound";
4913 case DW_AT_abstract_origin:
4914 return "DW_AT_abstract_origin";
4915 case DW_AT_accessibility:
4916 return "DW_AT_accessibility";
4917 case DW_AT_address_class:
4918 return "DW_AT_address_class";
4919 case DW_AT_artificial:
4920 return "DW_AT_artificial";
4921 case DW_AT_base_types:
4922 return "DW_AT_base_types";
4923 case DW_AT_calling_convention:
4924 return "DW_AT_calling_convention";
4926 return "DW_AT_count";
4927 case DW_AT_data_member_location:
4928 return "DW_AT_data_member_location";
4929 case DW_AT_decl_column:
4930 return "DW_AT_decl_column";
4931 case DW_AT_decl_file:
4932 return "DW_AT_decl_file";
4933 case DW_AT_decl_line:
4934 return "DW_AT_decl_line";
4935 case DW_AT_declaration:
4936 return "DW_AT_declaration";
4937 case DW_AT_discr_list:
4938 return "DW_AT_discr_list";
4939 case DW_AT_encoding:
4940 return "DW_AT_encoding";
4941 case DW_AT_external:
4942 return "DW_AT_external";
4943 case DW_AT_frame_base:
4944 return "DW_AT_frame_base";
4946 return "DW_AT_friend";
4947 case DW_AT_identifier_case:
4948 return "DW_AT_identifier_case";
4949 case DW_AT_macro_info:
4950 return "DW_AT_macro_info";
4951 case DW_AT_namelist_items:
4952 return "DW_AT_namelist_items";
4953 case DW_AT_priority:
4954 return "DW_AT_priority";
4956 return "DW_AT_segment";
4957 case DW_AT_specification:
4958 return "DW_AT_specification";
4959 case DW_AT_static_link:
4960 return "DW_AT_static_link";
4962 return "DW_AT_type";
4963 case DW_AT_use_location:
4964 return "DW_AT_use_location";
4965 case DW_AT_variable_parameter:
4966 return "DW_AT_variable_parameter";
4967 case DW_AT_virtuality:
4968 return "DW_AT_virtuality";
4969 case DW_AT_vtable_elem_location:
4970 return "DW_AT_vtable_elem_location";
4973 case DW_AT_MIPS_fde:
4974 return "DW_AT_MIPS_fde";
4975 case DW_AT_MIPS_loop_begin:
4976 return "DW_AT_MIPS_loop_begin";
4977 case DW_AT_MIPS_tail_loop_begin:
4978 return "DW_AT_MIPS_tail_loop_begin";
4979 case DW_AT_MIPS_epilog_begin:
4980 return "DW_AT_MIPS_epilog_begin";
4981 case DW_AT_MIPS_loop_unroll_factor:
4982 return "DW_AT_MIPS_loop_unroll_factor";
4983 case DW_AT_MIPS_software_pipeline_depth:
4984 return "DW_AT_MIPS_software_pipeline_depth";
4985 case DW_AT_MIPS_linkage_name:
4986 return "DW_AT_MIPS_linkage_name";
4989 case DW_AT_sf_names:
4990 return "DW_AT_sf_names";
4991 case DW_AT_src_info:
4992 return "DW_AT_src_info";
4993 case DW_AT_mac_info:
4994 return "DW_AT_mac_info";
4995 case DW_AT_src_coords:
4996 return "DW_AT_src_coords";
4997 case DW_AT_body_begin:
4998 return "DW_AT_body_begin";
4999 case DW_AT_body_end:
5000 return "DW_AT_body_end";
5002 return "DW_AT_<unknown>";
5006 /* Convert a DWARF value form code into its string name. */
5009 dwarf_form_name (form)
5010 register unsigned form;
5015 return "DW_FORM_addr";
5016 case DW_FORM_block2:
5017 return "DW_FORM_block2";
5018 case DW_FORM_block4:
5019 return "DW_FORM_block4";
5021 return "DW_FORM_data2";
5023 return "DW_FORM_data4";
5025 return "DW_FORM_data8";
5026 case DW_FORM_string:
5027 return "DW_FORM_string";
5029 return "DW_FORM_block";
5030 case DW_FORM_block1:
5031 return "DW_FORM_block1";
5033 return "DW_FORM_data1";
5035 return "DW_FORM_flag";
5037 return "DW_FORM_sdata";
5039 return "DW_FORM_strp";
5041 return "DW_FORM_udata";
5042 case DW_FORM_ref_addr:
5043 return "DW_FORM_ref_addr";
5045 return "DW_FORM_ref1";
5047 return "DW_FORM_ref2";
5049 return "DW_FORM_ref4";
5051 return "DW_FORM_ref8";
5052 case DW_FORM_ref_udata:
5053 return "DW_FORM_ref_udata";
5054 case DW_FORM_indirect:
5055 return "DW_FORM_indirect";
5057 return "DW_FORM_<unknown>";
5061 /* Convert a DWARF stack opcode into its string name. */
5064 dwarf_stack_op_name (op)
5065 register unsigned op;
5070 return "DW_OP_addr";
5072 return "DW_OP_deref";
5074 return "DW_OP_const1u";
5076 return "DW_OP_const1s";
5078 return "DW_OP_const2u";
5080 return "DW_OP_const2s";
5082 return "DW_OP_const4u";
5084 return "DW_OP_const4s";
5086 return "DW_OP_const8u";
5088 return "DW_OP_const8s";
5090 return "DW_OP_constu";
5092 return "DW_OP_consts";
5096 return "DW_OP_drop";
5098 return "DW_OP_over";
5100 return "DW_OP_pick";
5102 return "DW_OP_swap";
5106 return "DW_OP_xderef";
5114 return "DW_OP_minus";
5126 return "DW_OP_plus";
5127 case DW_OP_plus_uconst:
5128 return "DW_OP_plus_uconst";
5134 return "DW_OP_shra";
5152 return "DW_OP_skip";
5154 return "DW_OP_lit0";
5156 return "DW_OP_lit1";
5158 return "DW_OP_lit2";
5160 return "DW_OP_lit3";
5162 return "DW_OP_lit4";
5164 return "DW_OP_lit5";
5166 return "DW_OP_lit6";
5168 return "DW_OP_lit7";
5170 return "DW_OP_lit8";
5172 return "DW_OP_lit9";
5174 return "DW_OP_lit10";
5176 return "DW_OP_lit11";
5178 return "DW_OP_lit12";
5180 return "DW_OP_lit13";
5182 return "DW_OP_lit14";
5184 return "DW_OP_lit15";
5186 return "DW_OP_lit16";
5188 return "DW_OP_lit17";
5190 return "DW_OP_lit18";
5192 return "DW_OP_lit19";
5194 return "DW_OP_lit20";
5196 return "DW_OP_lit21";
5198 return "DW_OP_lit22";
5200 return "DW_OP_lit23";
5202 return "DW_OP_lit24";
5204 return "DW_OP_lit25";
5206 return "DW_OP_lit26";
5208 return "DW_OP_lit27";
5210 return "DW_OP_lit28";
5212 return "DW_OP_lit29";
5214 return "DW_OP_lit30";
5216 return "DW_OP_lit31";
5218 return "DW_OP_reg0";
5220 return "DW_OP_reg1";
5222 return "DW_OP_reg2";
5224 return "DW_OP_reg3";
5226 return "DW_OP_reg4";
5228 return "DW_OP_reg5";
5230 return "DW_OP_reg6";
5232 return "DW_OP_reg7";
5234 return "DW_OP_reg8";
5236 return "DW_OP_reg9";
5238 return "DW_OP_reg10";
5240 return "DW_OP_reg11";
5242 return "DW_OP_reg12";
5244 return "DW_OP_reg13";
5246 return "DW_OP_reg14";
5248 return "DW_OP_reg15";
5250 return "DW_OP_reg16";
5252 return "DW_OP_reg17";
5254 return "DW_OP_reg18";
5256 return "DW_OP_reg19";
5258 return "DW_OP_reg20";
5260 return "DW_OP_reg21";
5262 return "DW_OP_reg22";
5264 return "DW_OP_reg23";
5266 return "DW_OP_reg24";
5268 return "DW_OP_reg25";
5270 return "DW_OP_reg26";
5272 return "DW_OP_reg27";
5274 return "DW_OP_reg28";
5276 return "DW_OP_reg29";
5278 return "DW_OP_reg30";
5280 return "DW_OP_reg31";
5282 return "DW_OP_breg0";
5284 return "DW_OP_breg1";
5286 return "DW_OP_breg2";
5288 return "DW_OP_breg3";
5290 return "DW_OP_breg4";
5292 return "DW_OP_breg5";
5294 return "DW_OP_breg6";
5296 return "DW_OP_breg7";
5298 return "DW_OP_breg8";
5300 return "DW_OP_breg9";
5302 return "DW_OP_breg10";
5304 return "DW_OP_breg11";
5306 return "DW_OP_breg12";
5308 return "DW_OP_breg13";
5310 return "DW_OP_breg14";
5312 return "DW_OP_breg15";
5314 return "DW_OP_breg16";
5316 return "DW_OP_breg17";
5318 return "DW_OP_breg18";
5320 return "DW_OP_breg19";
5322 return "DW_OP_breg20";
5324 return "DW_OP_breg21";
5326 return "DW_OP_breg22";
5328 return "DW_OP_breg23";
5330 return "DW_OP_breg24";
5332 return "DW_OP_breg25";
5334 return "DW_OP_breg26";
5336 return "DW_OP_breg27";
5338 return "DW_OP_breg28";
5340 return "DW_OP_breg29";
5342 return "DW_OP_breg30";
5344 return "DW_OP_breg31";
5346 return "DW_OP_regx";
5348 return "DW_OP_fbreg";
5350 return "DW_OP_bregx";
5352 return "DW_OP_piece";
5353 case DW_OP_deref_size:
5354 return "DW_OP_deref_size";
5355 case DW_OP_xderef_size:
5356 return "DW_OP_xderef_size";
5360 return "OP_<unknown>";
5365 dwarf_bool_name (mybool)
5374 /* Convert a DWARF type code into its string name. */
5377 dwarf_type_encoding_name (enc)
5378 register unsigned enc;
5382 case DW_ATE_address:
5383 return "DW_ATE_address";
5384 case DW_ATE_boolean:
5385 return "DW_ATE_boolean";
5386 case DW_ATE_complex_float:
5387 return "DW_ATE_complex_float";
5389 return "DW_ATE_float";
5391 return "DW_ATE_signed";
5392 case DW_ATE_signed_char:
5393 return "DW_ATE_signed_char";
5394 case DW_ATE_unsigned:
5395 return "DW_ATE_unsigned";
5396 case DW_ATE_unsigned_char:
5397 return "DW_ATE_unsigned_char";
5399 return "DW_ATE_<unknown>";
5403 /* Convert a DWARF call frame info operation to its string name. */
5407 dwarf_cfi_name (cfi_opc)
5408 register unsigned cfi_opc;
5412 case DW_CFA_advance_loc:
5413 return "DW_CFA_advance_loc";
5415 return "DW_CFA_offset";
5416 case DW_CFA_restore:
5417 return "DW_CFA_restore";
5419 return "DW_CFA_nop";
5420 case DW_CFA_set_loc:
5421 return "DW_CFA_set_loc";
5422 case DW_CFA_advance_loc1:
5423 return "DW_CFA_advance_loc1";
5424 case DW_CFA_advance_loc2:
5425 return "DW_CFA_advance_loc2";
5426 case DW_CFA_advance_loc4:
5427 return "DW_CFA_advance_loc4";
5428 case DW_CFA_offset_extended:
5429 return "DW_CFA_offset_extended";
5430 case DW_CFA_restore_extended:
5431 return "DW_CFA_restore_extended";
5432 case DW_CFA_undefined:
5433 return "DW_CFA_undefined";
5434 case DW_CFA_same_value:
5435 return "DW_CFA_same_value";
5436 case DW_CFA_register:
5437 return "DW_CFA_register";
5438 case DW_CFA_remember_state:
5439 return "DW_CFA_remember_state";
5440 case DW_CFA_restore_state:
5441 return "DW_CFA_restore_state";
5442 case DW_CFA_def_cfa:
5443 return "DW_CFA_def_cfa";
5444 case DW_CFA_def_cfa_register:
5445 return "DW_CFA_def_cfa_register";
5446 case DW_CFA_def_cfa_offset:
5447 return "DW_CFA_def_cfa_offset";
5448 /* SGI/MIPS specific */
5449 case DW_CFA_MIPS_advance_loc8:
5450 return "DW_CFA_MIPS_advance_loc8";
5452 return "DW_CFA_<unknown>";
5459 struct die_info *die;
5463 fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n",
5464 dwarf_tag_name (die->tag), die->abbrev, die->offset);
5465 fprintf (stderr, "\thas children: %s\n",
5466 dwarf_bool_name (die->has_children));
5468 fprintf (stderr, "\tattributes:\n");
5469 for (i = 0; i < die->num_attrs; ++i)
5471 fprintf (stderr, "\t\t%s (%s) ",
5472 dwarf_attr_name (die->attrs[i].name),
5473 dwarf_form_name (die->attrs[i].form));
5474 switch (die->attrs[i].form)
5476 case DW_FORM_ref_addr:
5478 fprintf (stderr, "address: ");
5479 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
5481 case DW_FORM_block2:
5482 case DW_FORM_block4:
5484 case DW_FORM_block1:
5485 fprintf (stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
5495 fprintf (stderr, "constant: %d", DW_UNSND (&die->attrs[i]));
5497 case DW_FORM_string:
5498 fprintf (stderr, "string: \"%s\"",
5499 DW_STRING (&die->attrs[i])
5500 ? DW_STRING (&die->attrs[i]) : "");
5503 if (DW_UNSND (&die->attrs[i]))
5504 fprintf (stderr, "flag: TRUE");
5506 fprintf (stderr, "flag: FALSE");
5508 case DW_FORM_strp: /* we do not support separate string
5510 case DW_FORM_indirect: /* we do not handle indirect yet */
5511 case DW_FORM_data8: /* we do not have 64 bit quantities */
5513 fprintf (stderr, "unsupported attribute form: %d.",
5514 die->attrs[i].form);
5516 fprintf (stderr, "\n");
5522 struct die_info *die;
5532 store_in_ref_table (offset, die)
5533 unsigned int offset;
5534 struct die_info *die;
5537 struct die_info *old;
5539 h = (offset % REF_HASH_SIZE);
5540 old = die_ref_table[h];
5541 die->next_ref = old;
5542 die_ref_table[h] = die;
5547 dwarf2_empty_die_ref_table ()
5549 memset (die_ref_table, 0, sizeof (die_ref_table));
5553 dwarf2_get_ref_die_offset (attr)
5554 struct attribute *attr;
5556 unsigned int result = 0;
5560 case DW_FORM_ref_addr:
5561 result = DW_ADDR (attr);
5566 case DW_FORM_ref_udata:
5567 result = cu_header_offset + DW_UNSND (attr);
5570 complain (&dwarf2_unsupported_die_ref_attr, dwarf_form_name (attr->form));
5576 follow_die_ref (offset)
5577 unsigned int offset;
5579 struct die_info *die;
5582 h = (offset % REF_HASH_SIZE);
5583 die = die_ref_table[h];
5586 if (die->offset == offset)
5590 die = die->next_ref;
5595 static struct type *
5596 dwarf2_fundamental_type (objfile, typeid)
5597 struct objfile *objfile;
5600 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
5602 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5606 /* Look for this particular type in the fundamental type vector. If
5607 one is not found, create and install one appropriate for the
5608 current language and the current target machine. */
5610 if (ftypes[typeid] == NULL)
5612 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
5615 return (ftypes[typeid]);
5618 /* Decode simple location descriptions.
5619 Given a pointer to a dwarf block that defines a location, compute
5620 the location and return the value.
5622 FIXME: This is a kludge until we figure out a better
5623 way to handle the location descriptions.
5624 Gdb's design does not mesh well with the DWARF2 notion of a location
5625 computing interpreter, which is a shame because the flexibility goes unused.
5626 FIXME: Implement more operations as necessary.
5628 A location description containing no operations indicates that the
5629 object is optimized out. The global optimized_out flag is set for
5630 those, the return value is meaningless.
5632 When the result is a register number, the global isreg flag is set,
5633 otherwise it is cleared.
5635 When the result is a base register offset, the global offreg flag is set
5636 and the register number is returned in basereg, otherwise it is cleared.
5638 When the DW_OP_fbreg operation is encountered without a corresponding
5639 DW_AT_frame_base attribute, the global islocal flag is set.
5640 Hopefully the machine dependent code knows how to set up a virtual
5641 frame pointer for the local references.
5643 Note that stack[0] is unused except as a default error return.
5644 Note that stack overflow is not yet handled. */
5647 decode_locdesc (blk, objfile)
5648 struct dwarf_block *blk;
5649 struct objfile *objfile;
5652 int size = blk->size;
5653 char *data = blk->data;
5654 CORE_ADDR stack[64];
5656 unsigned int bytes_read, unsnd;
5707 stack[++stacki] = op - DW_OP_reg0;
5712 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5714 #if defined(HARRIS_TARGET) && defined(_M88K)
5715 /* The Harris 88110 gdb ports have long kept their special reg
5716 numbers between their gp-regs and their x-regs. This is
5717 not how our dwarf is generated. Punt. */
5720 stack[++stacki] = unsnd;
5756 basereg = op - DW_OP_breg0;
5757 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5763 basereg = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5765 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5770 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5772 if (frame_base_reg >= 0)
5775 basereg = frame_base_reg;
5776 stack[stacki] += frame_base_offset;
5780 complain (&dwarf2_missing_at_frame_base);
5786 stack[++stacki] = read_address (objfile->obfd, &data[i]);
5791 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
5796 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
5801 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
5806 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
5811 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
5816 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
5821 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
5827 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5832 stack[stacki - 1] += stack[stacki];
5836 case DW_OP_plus_uconst:
5837 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5842 stack[stacki - 1] = stack[stacki] - stack[stacki - 1];
5848 /* If we're not the last op, then we definitely can't encode
5849 this using GDB's address_class enum. */
5851 complain (&dwarf2_complex_location_expr);
5855 complain (&dwarf2_unsupported_stack_op, dwarf_stack_op_name (op));
5856 return (stack[stacki]);
5859 return (stack[stacki]);
5862 /* memory allocation interface */
5866 dwarf2_free_tmp_obstack (ignore)
5869 obstack_free (&dwarf2_tmp_obstack, NULL);
5872 static struct dwarf_block *
5873 dwarf_alloc_block ()
5875 struct dwarf_block *blk;
5877 blk = (struct dwarf_block *)
5878 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
5882 static struct abbrev_info *
5883 dwarf_alloc_abbrev ()
5885 struct abbrev_info *abbrev;
5887 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
5888 memset (abbrev, 0, sizeof (struct abbrev_info));
5892 static struct die_info *
5895 struct die_info *die;
5897 die = (struct die_info *) xmalloc (sizeof (struct die_info));
5898 memset (die, 0, sizeof (struct die_info));