1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
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. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
46 #ifndef DWARF2_REG_TO_REGNUM
47 #define DWARF2_REG_TO_REGNUM(REG) (REG)
51 /* .debug_info header for a compilation unit
52 Because of alignment constraints, this structure has padding and cannot
53 be mapped directly onto the beginning of the .debug_info section. */
54 typedef struct comp_unit_header
56 unsigned int length; /* length of the .debug_info
58 unsigned short version; /* version number -- 2 for DWARF
60 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
61 unsigned char addr_size; /* byte size of an address -- 4 */
64 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
67 /* .debug_pubnames header
68 Because of alignment constraints, this structure has padding and cannot
69 be mapped directly onto the beginning of the .debug_info section. */
70 typedef struct pubnames_header
72 unsigned int length; /* length of the .debug_pubnames
74 unsigned char version; /* version number -- 2 for DWARF
76 unsigned int info_offset; /* offset into .debug_info section */
77 unsigned int info_size; /* byte size of .debug_info section
81 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
83 /* .debug_pubnames header
84 Because of alignment constraints, this structure has padding and cannot
85 be mapped directly onto the beginning of the .debug_info section. */
86 typedef struct aranges_header
88 unsigned int length; /* byte len of the .debug_aranges
90 unsigned short version; /* version number -- 2 for DWARF
92 unsigned int info_offset; /* offset into .debug_info section */
93 unsigned char addr_size; /* byte size of an address */
94 unsigned char seg_size; /* byte size of segment descriptor */
97 #define _ACTUAL_ARANGES_HEADER_SIZE 12
99 /* .debug_line statement program prologue
100 Because of alignment constraints, this structure has padding and cannot
101 be mapped directly onto the beginning of the .debug_info section. */
102 typedef struct statement_prologue
104 unsigned int total_length; /* byte length of the statement
106 unsigned short version; /* version number -- 2 for DWARF
108 unsigned int prologue_length; /* # bytes between prologue &
110 unsigned char minimum_instruction_length; /* byte size of
112 unsigned char default_is_stmt; /* initial value of is_stmt
115 unsigned char line_range;
116 unsigned char opcode_base; /* number assigned to first special
118 unsigned char *standard_opcode_lengths;
122 /* offsets and sizes of debugging sections */
124 static file_ptr dwarf_info_offset;
125 static file_ptr dwarf_abbrev_offset;
126 static file_ptr dwarf_line_offset;
127 static file_ptr dwarf_pubnames_offset;
128 static file_ptr dwarf_aranges_offset;
129 static file_ptr dwarf_loc_offset;
130 static file_ptr dwarf_macinfo_offset;
131 static file_ptr dwarf_str_offset;
133 static unsigned int dwarf_info_size;
134 static unsigned int dwarf_abbrev_size;
135 static unsigned int dwarf_line_size;
136 static unsigned int dwarf_pubnames_size;
137 static unsigned int dwarf_aranges_size;
138 static unsigned int dwarf_loc_size;
139 static unsigned int dwarf_macinfo_size;
140 static unsigned int dwarf_str_size;
142 /* names of the debugging sections */
144 #define INFO_SECTION ".debug_info"
145 #define ABBREV_SECTION ".debug_abbrev"
146 #define LINE_SECTION ".debug_line"
147 #define PUBNAMES_SECTION ".debug_pubnames"
148 #define ARANGES_SECTION ".debug_aranges"
149 #define LOC_SECTION ".debug_loc"
150 #define MACINFO_SECTION ".debug_macinfo"
151 #define STR_SECTION ".debug_str"
153 /* local data types */
155 /* The data in a compilation unit header, after target2host
156 translation, looks like this. */
157 struct comp_unit_head
159 unsigned long length;
161 unsigned int abbrev_offset;
162 unsigned char addr_size;
163 unsigned char signed_addr_p;
164 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
165 unsigned int initial_length_size; /* size of the length field; either
169 /* The data in the .debug_line statement prologue looks like this. */
172 unsigned int total_length;
173 unsigned short version;
174 unsigned int prologue_length;
175 unsigned char minimum_instruction_length;
176 unsigned char default_is_stmt;
178 unsigned char line_range;
179 unsigned char opcode_base;
180 unsigned char *standard_opcode_lengths;
183 /* When we construct a partial symbol table entry we only
184 need this much information. */
185 struct partial_die_info
188 unsigned char has_children;
189 unsigned char is_external;
190 unsigned char is_declaration;
191 unsigned char has_type;
197 struct dwarf_block *locdesc;
198 unsigned int language;
202 /* This data structure holds the information of an abbrev. */
205 unsigned int number; /* number identifying abbrev */
206 enum dwarf_tag tag; /* dwarf tag */
207 int has_children; /* boolean */
208 unsigned int num_attrs; /* number of attributes */
209 struct attr_abbrev *attrs; /* an array of attribute descriptions */
210 struct abbrev_info *next; /* next in chain */
215 enum dwarf_attribute name;
216 enum dwarf_form form;
219 /* This data structure holds a complete die structure. */
222 enum dwarf_tag tag; /* Tag indicating type of die */
223 unsigned short has_children; /* Does the die have children */
224 unsigned int abbrev; /* Abbrev number */
225 unsigned int offset; /* Offset in .debug_info section */
226 unsigned int num_attrs; /* Number of attributes */
227 struct attribute *attrs; /* An array of attributes */
228 struct die_info *next_ref; /* Next die in ref hash table */
229 struct die_info *next; /* Next die in linked list */
230 struct type *type; /* Cached type information */
233 /* Attributes have a name and a value */
236 enum dwarf_attribute name;
237 enum dwarf_form form;
241 struct dwarf_block *blk;
249 /* Get at parts of an attribute structure */
251 #define DW_STRING(attr) ((attr)->u.str)
252 #define DW_UNSND(attr) ((attr)->u.unsnd)
253 #define DW_BLOCK(attr) ((attr)->u.blk)
254 #define DW_SND(attr) ((attr)->u.snd)
255 #define DW_ADDR(attr) ((attr)->u.addr)
257 /* Blocks are a bunch of untyped bytes. */
264 /* We only hold one compilation unit's abbrevs in
265 memory at any one time. */
266 #ifndef ABBREV_HASH_SIZE
267 #define ABBREV_HASH_SIZE 121
269 #ifndef ATTR_ALLOC_CHUNK
270 #define ATTR_ALLOC_CHUNK 4
273 static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
275 /* A hash table of die offsets for following references. */
276 #ifndef REF_HASH_SIZE
277 #define REF_HASH_SIZE 1021
280 static struct die_info *die_ref_table[REF_HASH_SIZE];
282 /* Obstack for allocating temporary storage used during symbol reading. */
283 static struct obstack dwarf2_tmp_obstack;
285 /* Offset to the first byte of the current compilation unit header,
286 for resolving relative reference dies. */
287 static unsigned int cu_header_offset;
289 /* Allocate fields for structs, unions and enums in this size. */
290 #ifndef DW_FIELD_ALLOC_CHUNK
291 #define DW_FIELD_ALLOC_CHUNK 4
294 /* The language we are debugging. */
295 static enum language cu_language;
296 static const struct language_defn *cu_language_defn;
298 /* Actually data from the sections. */
299 static char *dwarf_info_buffer;
300 static char *dwarf_abbrev_buffer;
301 static char *dwarf_line_buffer;
303 /* A zeroed version of a partial die for initialization purposes. */
304 static struct partial_die_info zeroed_partial_die;
306 /* The generic symbol table building routines have separate lists for
307 file scope symbols and all all other scopes (local scopes). So
308 we need to select the right one to pass to add_symbol_to_list().
309 We do it by keeping a pointer to the correct list in list_in_scope.
311 FIXME: The original dwarf code just treated the file scope as the first
312 local scope, and all other local scopes as nested local scopes, and worked
313 fine. Check to see if we really need to distinguish these
315 static struct pending **list_in_scope = &file_symbols;
317 /* FIXME: decode_locdesc sets these variables to describe the location
318 to the caller. These ought to be a structure or something. If
319 none of the flags are set, the object lives at the address returned
320 by decode_locdesc. */
322 static int optimized_out; /* No ops in location in expression,
323 so object was optimized out. */
324 static int isreg; /* Object lives in register.
325 decode_locdesc's return value is
326 the register number. */
327 static int offreg; /* Object's address is the sum of the
328 register specified by basereg, plus
329 the offset returned. */
330 static int basereg; /* See `offreg'. */
331 static int isderef; /* Value described by flags above is
332 the address of a pointer to the object. */
333 static int islocal; /* Variable is at the returned offset
334 from the frame start, but there's
335 no identified frame pointer for
336 this function, so we can't say
337 which register it's relative to;
340 /* DW_AT_frame_base values for the current function.
341 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
342 contains the register number for the frame register.
343 frame_base_offset is the offset from the frame register to the
344 virtual stack frame. */
345 static int frame_base_reg;
346 static CORE_ADDR frame_base_offset;
348 /* This value is added to each symbol value. FIXME: Generalize to
349 the section_offsets structure used by dbxread (once this is done,
350 pass the appropriate section number to end_symtab). */
351 static CORE_ADDR baseaddr; /* Add to each symbol value */
353 /* We put a pointer to this structure in the read_symtab_private field
355 The complete dwarf information for an objfile is kept in the
356 psymbol_obstack, so that absolute die references can be handled.
357 Most of the information in this structure is related to an entire
358 object file and could be passed via the sym_private field of the objfile.
359 It is however conceivable that dwarf2 might not be the only type
360 of symbols read from an object file. */
364 /* Pointer to start of dwarf info buffer for the objfile. */
366 char *dwarf_info_buffer;
368 /* Offset in dwarf_info_buffer for this compilation unit. */
370 unsigned long dwarf_info_offset;
372 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
374 char *dwarf_abbrev_buffer;
376 /* Size of dwarf abbreviation section for the objfile. */
378 unsigned int dwarf_abbrev_size;
380 /* Pointer to start of dwarf line buffer for the objfile. */
382 char *dwarf_line_buffer;
385 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
386 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
387 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
388 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
389 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
390 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
392 /* Maintain an array of referenced fundamental types for the current
393 compilation unit being read. For DWARF version 1, we have to construct
394 the fundamental types on the fly, since no information about the
395 fundamental types is supplied. Each such fundamental type is created by
396 calling a language dependent routine to create the type, and then a
397 pointer to that type is then placed in the array at the index specified
398 by it's FT_<TYPENAME> value. The array has a fixed size set by the
399 FT_NUM_MEMBERS compile time constant, which is the number of predefined
400 fundamental types gdb knows how to construct. */
401 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
403 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
404 but this would require a corresponding change in unpack_field_as_long
406 static int bits_per_byte = 8;
408 /* The routines that read and process dies for a C struct or C++ class
409 pass lists of data member fields and lists of member function fields
410 in an instance of a field_info structure, as defined below. */
413 /* List of data member and baseclasses fields. */
416 struct nextfield *next;
423 /* Number of fields. */
426 /* Number of baseclasses. */
429 /* Set if the accesibility of one of the fields is not public. */
430 int non_public_fields;
432 /* Member function fields array, entries are allocated in the order they
433 are encountered in the object file. */
436 struct nextfnfield *next;
437 struct fn_field fnfield;
441 /* Member function fieldlist array, contains name of possibly overloaded
442 member function, number of overloaded member functions and a pointer
443 to the head of the member function field chain. */
448 struct nextfnfield *head;
452 /* Number of entries in the fnfieldlists array. */
456 /* FIXME: Kludge to mark a varargs function type for C++ member function
457 argument processing. */
458 #define TYPE_FLAG_VARARGS (1 << 10)
460 /* Dwarf2 has no clean way to discern C++ static and non-static member
461 functions. G++ helps GDB by marking the first parameter for non-static
462 member functions (which is the this pointer) as artificial.
463 We pass this information between dwarf2_add_member_fn and
464 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
465 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
467 /* Various complaints about symbol reading that don't abort the process */
469 static struct complaint dwarf2_const_ignored =
471 "type qualifier 'const' ignored", 0, 0
473 static struct complaint dwarf2_volatile_ignored =
475 "type qualifier 'volatile' ignored", 0, 0
477 static struct complaint dwarf2_non_const_array_bound_ignored =
479 "non-constant array bounds form '%s' ignored", 0, 0
481 static struct complaint dwarf2_missing_line_number_section =
483 "missing .debug_line section", 0, 0
485 static struct complaint dwarf2_mangled_line_number_section =
487 "mangled .debug_line section", 0, 0
489 static struct complaint dwarf2_unsupported_die_ref_attr =
491 "unsupported die ref attribute form: '%s'", 0, 0
493 static struct complaint dwarf2_unsupported_stack_op =
495 "unsupported stack op: '%s'", 0, 0
497 static struct complaint dwarf2_complex_location_expr =
499 "location expression too complex", 0, 0
501 static struct complaint dwarf2_unsupported_tag =
503 "unsupported tag: '%s'", 0, 0
505 static struct complaint dwarf2_unsupported_at_encoding =
507 "unsupported DW_AT_encoding: '%s'", 0, 0
509 static struct complaint dwarf2_unsupported_at_frame_base =
511 "unsupported DW_AT_frame_base for function '%s'", 0, 0
513 static struct complaint dwarf2_unexpected_tag =
515 "unexepected tag in read_type_die: '%s'", 0, 0
517 static struct complaint dwarf2_missing_at_frame_base =
519 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
521 static struct complaint dwarf2_bad_static_member_name =
523 "unrecognized static data member name '%s'", 0, 0
525 static struct complaint dwarf2_unsupported_accessibility =
527 "unsupported accessibility %d", 0, 0
529 static struct complaint dwarf2_bad_member_name_complaint =
531 "cannot extract member name from '%s'", 0, 0
533 static struct complaint dwarf2_missing_member_fn_type_complaint =
535 "member function type missing for '%s'", 0, 0
537 static struct complaint dwarf2_vtbl_not_found_complaint =
539 "virtual function table pointer not found when defining class '%s'", 0, 0
541 static struct complaint dwarf2_absolute_sibling_complaint =
543 "ignoring absolute DW_AT_sibling", 0, 0
545 static struct complaint dwarf2_const_value_length_mismatch =
547 "const value length mismatch for '%s', got %d, expected %d", 0, 0
549 static struct complaint dwarf2_unsupported_const_value_attr =
551 "unsupported const value attribute form: '%s'", 0, 0
554 /* Externals references. */
555 extern int info_verbose; /* From main.c; nonzero => verbose */
557 /* local function prototypes */
559 static void dwarf2_locate_sections (bfd *, asection *, PTR);
562 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
565 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
567 static char *scan_partial_symbols (char *, struct objfile *,
568 CORE_ADDR *, CORE_ADDR *,
569 const struct comp_unit_head *);
571 static void add_partial_symbol (struct partial_die_info *, struct objfile *,
572 const struct comp_unit_head *);
574 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
576 static void psymtab_to_symtab_1 (struct partial_symtab *);
578 static char *dwarf2_read_section (struct objfile *, file_ptr, unsigned int);
580 static void dwarf2_read_abbrevs (bfd *, unsigned int);
582 static void dwarf2_empty_abbrev_table (PTR);
584 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int);
586 static char *read_partial_die (struct partial_die_info *,
587 bfd *, char *, int *,
588 const struct comp_unit_head *);
590 static char *read_full_die (struct die_info **, bfd *, char *,
591 const struct comp_unit_head *);
593 static char *read_attribute (struct attribute *, struct attr_abbrev *,
594 bfd *, char *, const struct comp_unit_head *);
596 static unsigned int read_1_byte (bfd *, char *);
598 static int read_1_signed_byte (bfd *, char *);
600 static unsigned int read_2_bytes (bfd *, char *);
602 static unsigned int read_4_bytes (bfd *, char *);
604 static unsigned long read_8_bytes (bfd *, char *);
606 static CORE_ADDR read_address (bfd *, char *ptr, const struct comp_unit_head *,
609 static LONGEST read_initial_length (bfd *, char *,
610 struct comp_unit_head *, int *bytes_read);
612 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
615 static char *read_n_bytes (bfd *, char *, unsigned int);
617 static char *read_string (bfd *, char *, unsigned int *);
619 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
621 static long read_signed_leb128 (bfd *, char *, unsigned int *);
623 static void set_cu_language (unsigned int);
625 static struct attribute *dwarf_attr (struct die_info *, unsigned int);
627 static int die_is_declaration (struct die_info *);
629 static void dwarf_decode_lines (unsigned int, char *, bfd *,
630 const struct comp_unit_head *);
632 static void dwarf2_start_subfile (char *, char *);
634 static struct symbol *new_symbol (struct die_info *, struct type *,
635 struct objfile *, const struct comp_unit_head *);
637 static void dwarf2_const_value (struct attribute *, struct symbol *,
638 struct objfile *, const struct comp_unit_head *);
640 static void dwarf2_const_value_data (struct attribute *attr,
644 static struct type *die_type (struct die_info *, struct objfile *,
645 const struct comp_unit_head *);
647 static struct type *die_containing_type (struct die_info *, struct objfile *,
648 const struct comp_unit_head *);
651 static struct type *type_at_offset (unsigned int, struct objfile *);
654 static struct type *tag_type_to_type (struct die_info *, struct objfile *,
655 const struct comp_unit_head *);
657 static void read_type_die (struct die_info *, struct objfile *,
658 const struct comp_unit_head *);
660 static void read_typedef (struct die_info *, struct objfile *,
661 const struct comp_unit_head *);
663 static void read_base_type (struct die_info *, struct objfile *);
665 static void read_file_scope (struct die_info *, struct objfile *,
666 const struct comp_unit_head *);
668 static void read_func_scope (struct die_info *, struct objfile *,
669 const struct comp_unit_head *);
671 static void read_lexical_block_scope (struct die_info *, struct objfile *,
672 const struct comp_unit_head *);
674 static int dwarf2_get_pc_bounds (struct die_info *,
675 CORE_ADDR *, CORE_ADDR *, struct objfile *);
677 static void dwarf2_add_field (struct field_info *, struct die_info *,
678 struct objfile *, const struct comp_unit_head *);
680 static void dwarf2_attach_fields_to_type (struct field_info *,
681 struct type *, struct objfile *);
683 static void dwarf2_add_member_fn (struct field_info *,
684 struct die_info *, struct type *,
685 struct objfile *objfile,
686 const struct comp_unit_head *);
688 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
689 struct type *, struct objfile *);
691 static void read_structure_scope (struct die_info *, struct objfile *,
692 const struct comp_unit_head *);
694 static void read_common_block (struct die_info *, struct objfile *,
695 const struct comp_unit_head *);
697 static void read_enumeration (struct die_info *, struct objfile *,
698 const struct comp_unit_head *);
700 static struct type *dwarf_base_type (int, int, struct objfile *);
702 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct objfile *,
703 const struct comp_unit_head *);
705 static void read_array_type (struct die_info *, struct objfile *,
706 const struct comp_unit_head *);
708 static void read_tag_pointer_type (struct die_info *, struct objfile *,
709 const struct comp_unit_head *);
711 static void read_tag_ptr_to_member_type (struct die_info *, struct objfile *,
712 const struct comp_unit_head *);
714 static void read_tag_reference_type (struct die_info *, struct objfile *,
715 const struct comp_unit_head *);
717 static void read_tag_const_type (struct die_info *, struct objfile *,
718 const struct comp_unit_head *);
720 static void read_tag_volatile_type (struct die_info *, struct objfile *,
721 const struct comp_unit_head *);
723 static void read_tag_string_type (struct die_info *, struct objfile *);
725 static void read_subroutine_type (struct die_info *, struct objfile *,
726 const struct comp_unit_head *);
728 struct die_info *read_comp_unit (char *, bfd *, const struct comp_unit_head *);
730 static void free_die_list (struct die_info *);
732 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
734 static void process_die (struct die_info *, struct objfile *,
735 const struct comp_unit_head *);
737 static char *dwarf2_linkage_name (struct die_info *);
739 static char *dwarf_tag_name (unsigned int);
741 static char *dwarf_attr_name (unsigned int);
743 static char *dwarf_form_name (unsigned int);
745 static char *dwarf_stack_op_name (unsigned int);
747 static char *dwarf_bool_name (unsigned int);
749 static char *dwarf_type_encoding_name (unsigned int);
752 static char *dwarf_cfi_name (unsigned int);
754 struct die_info *copy_die (struct die_info *);
757 struct die_info *sibling_die (struct die_info *);
759 void dump_die (struct die_info *);
761 void dump_die_list (struct die_info *);
763 void store_in_ref_table (unsigned int, struct die_info *);
765 static void dwarf2_empty_hash_tables (void);
767 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
769 struct die_info *follow_die_ref (unsigned int);
771 static struct type *dwarf2_fundamental_type (struct objfile *, int);
773 /* memory allocation interface */
775 static void dwarf2_free_tmp_obstack (PTR);
777 static struct dwarf_block *dwarf_alloc_block (void);
779 static struct abbrev_info *dwarf_alloc_abbrev (void);
781 static struct die_info *dwarf_alloc_die (void);
783 /* Try to locate the sections we need for DWARF 2 debugging
784 information and return true if we have enough to do something. */
787 dwarf2_has_info (bfd *abfd)
789 dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
790 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
791 if (dwarf_info_offset && dwarf_abbrev_offset)
801 /* This function is mapped across the sections and remembers the
802 offset and size of each of the debugging sections we are interested
806 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, PTR ignore_ptr)
808 if (STREQ (sectp->name, INFO_SECTION))
810 dwarf_info_offset = sectp->filepos;
811 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
813 else if (STREQ (sectp->name, ABBREV_SECTION))
815 dwarf_abbrev_offset = sectp->filepos;
816 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
818 else if (STREQ (sectp->name, LINE_SECTION))
820 dwarf_line_offset = sectp->filepos;
821 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
823 else if (STREQ (sectp->name, PUBNAMES_SECTION))
825 dwarf_pubnames_offset = sectp->filepos;
826 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
828 else if (STREQ (sectp->name, ARANGES_SECTION))
830 dwarf_aranges_offset = sectp->filepos;
831 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
833 else if (STREQ (sectp->name, LOC_SECTION))
835 dwarf_loc_offset = sectp->filepos;
836 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
838 else if (STREQ (sectp->name, MACINFO_SECTION))
840 dwarf_macinfo_offset = sectp->filepos;
841 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
843 else if (STREQ (sectp->name, STR_SECTION))
845 dwarf_str_offset = sectp->filepos;
846 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
850 /* Build a partial symbol table. */
853 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
856 /* We definitely need the .debug_info and .debug_abbrev sections */
858 dwarf_info_buffer = dwarf2_read_section (objfile,
861 dwarf_abbrev_buffer = dwarf2_read_section (objfile,
864 dwarf_line_buffer = dwarf2_read_section (objfile,
868 if (mainline || objfile->global_psymbols.size == 0 ||
869 objfile->static_psymbols.size == 0)
871 init_psymbol_list (objfile, 1024);
875 if (dwarf_aranges_offset && dwarf_pubnames_offset)
877 /* Things are significantly easier if we have .debug_aranges and
878 .debug_pubnames sections */
880 dwarf2_build_psymtabs_easy (objfile, mainline);
884 /* only test this case for now */
886 /* In this case we have to work a bit harder */
887 dwarf2_build_psymtabs_hard (objfile, mainline);
892 /* Build the partial symbol table from the information in the
893 .debug_pubnames and .debug_aranges sections. */
896 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
898 bfd *abfd = objfile->obfd;
899 char *aranges_buffer, *pubnames_buffer;
900 char *aranges_ptr, *pubnames_ptr;
901 unsigned int entry_length, version, info_offset, info_size;
903 pubnames_buffer = dwarf2_read_section (objfile,
904 dwarf_pubnames_offset,
905 dwarf_pubnames_size);
906 pubnames_ptr = pubnames_buffer;
907 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
909 struct comp_unit_head cu_header;
912 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
914 pubnames_ptr += bytes_read;
915 version = read_1_byte (abfd, pubnames_ptr);
917 info_offset = read_4_bytes (abfd, pubnames_ptr);
919 info_size = read_4_bytes (abfd, pubnames_ptr);
923 aranges_buffer = dwarf2_read_section (objfile,
924 dwarf_aranges_offset,
930 /* Read in the comp unit header information from the debug_info at
934 read_comp_unit_head (struct comp_unit_head *cu_header,
935 char *info_ptr, bfd *abfd)
939 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
941 info_ptr += bytes_read;
942 cu_header->version = read_2_bytes (abfd, info_ptr);
944 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
946 info_ptr += bytes_read;
947 cu_header->addr_size = read_1_byte (abfd, info_ptr);
949 signed_addr = bfd_get_sign_extend_vma (abfd);
951 internal_error ("read_comp_unit_head: dwarf from non elf file");
952 cu_header->signed_addr_p = signed_addr;
956 /* Build the partial symbol table by doing a quick pass through the
957 .debug_info and .debug_abbrev sections. */
960 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
962 /* Instead of reading this into a big buffer, we should probably use
963 mmap() on architectures that support it. (FIXME) */
964 bfd *abfd = objfile->obfd;
965 char *info_ptr, *abbrev_ptr;
966 char *beg_of_comp_unit;
967 struct partial_die_info comp_unit_die;
968 struct partial_symtab *pst;
969 struct cleanup *back_to;
970 int comp_unit_has_pc_info;
971 CORE_ADDR lowpc, highpc;
973 info_ptr = dwarf_info_buffer;
974 abbrev_ptr = dwarf_abbrev_buffer;
976 obstack_init (&dwarf2_tmp_obstack);
977 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
979 while ((unsigned int) (info_ptr - dwarf_info_buffer)
980 + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
982 struct comp_unit_head cu_header;
983 beg_of_comp_unit = info_ptr;
984 info_ptr = read_comp_unit_head (&cu_header, info_ptr, abfd);
986 if (cu_header.version != 2)
988 error ("Dwarf Error: wrong version in compilation unit header.");
991 if (cu_header.abbrev_offset >= dwarf_abbrev_size)
993 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
994 (long) cu_header.abbrev_offset,
995 (long) (beg_of_comp_unit - dwarf_info_buffer));
998 if (beg_of_comp_unit + cu_header.length + cu_header.initial_length_size
999 > dwarf_info_buffer + dwarf_info_size)
1001 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1002 (long) cu_header.length,
1003 (long) (beg_of_comp_unit - dwarf_info_buffer));
1006 /* Read the abbrevs for this compilation unit into a table */
1007 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
1008 make_cleanup (dwarf2_empty_abbrev_table, NULL);
1010 /* Read the compilation unit die */
1011 info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr,
1012 &comp_unit_has_pc_info, &cu_header);
1014 /* Set the language we're debugging */
1015 set_cu_language (comp_unit_die.language);
1017 /* Allocate a new partial symbol table structure */
1018 pst = start_psymtab_common (objfile, objfile->section_offsets,
1019 comp_unit_die.name ? comp_unit_die.name : "",
1020 comp_unit_die.lowpc,
1021 objfile->global_psymbols.next,
1022 objfile->static_psymbols.next);
1024 pst->read_symtab_private = (char *)
1025 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
1026 cu_header_offset = beg_of_comp_unit - dwarf_info_buffer;
1027 DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
1028 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
1029 DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
1030 DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
1031 DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
1032 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1034 /* Store the function that reads in the rest of the symbol table */
1035 pst->read_symtab = dwarf2_psymtab_to_symtab;
1037 /* Check if comp unit has_children.
1038 If so, read the rest of the partial symbols from this comp unit.
1039 If not, there's no more debug_info for this comp unit. */
1040 if (comp_unit_die.has_children)
1042 info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc,
1045 /* If the compilation unit didn't have an explicit address range,
1046 then use the information extracted from its child dies. */
1047 if (!comp_unit_has_pc_info)
1049 comp_unit_die.lowpc = lowpc;
1050 comp_unit_die.highpc = highpc;
1053 pst->textlow = comp_unit_die.lowpc + baseaddr;
1054 pst->texthigh = comp_unit_die.highpc + baseaddr;
1056 pst->n_global_syms = objfile->global_psymbols.next -
1057 (objfile->global_psymbols.list + pst->globals_offset);
1058 pst->n_static_syms = objfile->static_psymbols.next -
1059 (objfile->static_psymbols.list + pst->statics_offset);
1060 sort_pst_symbols (pst);
1062 /* If there is already a psymtab or symtab for a file of this
1063 name, remove it. (If there is a symtab, more drastic things
1064 also happen.) This happens in VxWorks. */
1065 free_named_symtabs (pst->filename);
1067 info_ptr = beg_of_comp_unit + cu_header.length
1068 + cu_header.initial_length_size;
1070 do_cleanups (back_to);
1073 /* Read in all interesting dies to the end of the compilation unit. */
1076 scan_partial_symbols (char *info_ptr, struct objfile *objfile,
1077 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1078 const struct comp_unit_head *cu_header)
1080 bfd *abfd = objfile->obfd;
1081 struct partial_die_info pdi;
1083 /* This function is called after we've read in the comp_unit_die in
1084 order to read its children. We start the nesting level at 1 since
1085 we have pushed 1 level down in order to read the comp unit's children.
1086 The comp unit itself is at level 0, so we stop reading when we pop
1087 back to that level. */
1089 int nesting_level = 1;
1092 *lowpc = ((CORE_ADDR) -1);
1093 *highpc = ((CORE_ADDR) 0);
1095 while (nesting_level)
1097 info_ptr = read_partial_die (&pdi, abfd, info_ptr,
1098 &has_pc_info, cu_header);
1104 case DW_TAG_subprogram:
1107 if (pdi.lowpc < *lowpc)
1111 if (pdi.highpc > *highpc)
1113 *highpc = pdi.highpc;
1115 if ((pdi.is_external || nesting_level == 1)
1116 && !pdi.is_declaration)
1118 add_partial_symbol (&pdi, objfile, cu_header);
1122 case DW_TAG_variable:
1123 case DW_TAG_typedef:
1124 case DW_TAG_class_type:
1125 case DW_TAG_structure_type:
1126 case DW_TAG_union_type:
1127 case DW_TAG_enumeration_type:
1128 if ((pdi.is_external || nesting_level == 1)
1129 && !pdi.is_declaration)
1131 add_partial_symbol (&pdi, objfile, cu_header);
1134 case DW_TAG_enumerator:
1135 /* File scope enumerators are added to the partial symbol
1137 if (nesting_level == 2)
1138 add_partial_symbol (&pdi, objfile, cu_header);
1140 case DW_TAG_base_type:
1141 /* File scope base type definitions are added to the partial
1143 if (nesting_level == 1)
1144 add_partial_symbol (&pdi, objfile, cu_header);
1151 /* If the die has a sibling, skip to the sibling.
1152 Do not skip enumeration types, we want to record their
1154 if (pdi.sibling && pdi.tag != DW_TAG_enumeration_type)
1156 info_ptr = pdi.sibling;
1158 else if (pdi.has_children)
1160 /* Die has children, but the optional DW_AT_sibling attribute
1171 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1172 from `maint check'. */
1173 if (*lowpc == ((CORE_ADDR) -1))
1179 add_partial_symbol (struct partial_die_info *pdi, struct objfile *objfile,
1180 const struct comp_unit_head *cu_header)
1186 case DW_TAG_subprogram:
1187 if (pdi->is_external)
1189 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1190 mst_text, objfile); */
1191 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1192 VAR_NAMESPACE, LOC_BLOCK,
1193 &objfile->global_psymbols,
1194 0, pdi->lowpc + baseaddr, cu_language, objfile);
1198 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1199 mst_file_text, objfile); */
1200 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1201 VAR_NAMESPACE, LOC_BLOCK,
1202 &objfile->static_psymbols,
1203 0, pdi->lowpc + baseaddr, cu_language, objfile);
1206 case DW_TAG_variable:
1207 if (pdi->is_external)
1210 Don't enter into the minimal symbol tables as there is
1211 a minimal symbol table entry from the ELF symbols already.
1212 Enter into partial symbol table if it has a location
1213 descriptor or a type.
1214 If the location descriptor is missing, new_symbol will create
1215 a LOC_UNRESOLVED symbol, the address of the variable will then
1216 be determined from the minimal symbol table whenever the variable
1218 The address for the partial symbol table entry is not
1219 used by GDB, but it comes in handy for debugging partial symbol
1223 addr = decode_locdesc (pdi->locdesc, objfile, cu_header);
1224 if (pdi->locdesc || pdi->has_type)
1225 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1226 VAR_NAMESPACE, LOC_STATIC,
1227 &objfile->global_psymbols,
1228 0, addr + baseaddr, cu_language, objfile);
1232 /* Static Variable. Skip symbols without location descriptors. */
1233 if (pdi->locdesc == NULL)
1235 addr = decode_locdesc (pdi->locdesc, objfile, cu_header);
1236 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1237 mst_file_data, objfile); */
1238 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1239 VAR_NAMESPACE, LOC_STATIC,
1240 &objfile->static_psymbols,
1241 0, addr + baseaddr, cu_language, objfile);
1244 case DW_TAG_typedef:
1245 case DW_TAG_base_type:
1246 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1247 VAR_NAMESPACE, LOC_TYPEDEF,
1248 &objfile->static_psymbols,
1249 0, (CORE_ADDR) 0, cu_language, objfile);
1251 case DW_TAG_class_type:
1252 case DW_TAG_structure_type:
1253 case DW_TAG_union_type:
1254 case DW_TAG_enumeration_type:
1255 /* Skip aggregate types without children, these are external
1257 if (pdi->has_children == 0)
1259 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1260 STRUCT_NAMESPACE, LOC_TYPEDEF,
1261 &objfile->static_psymbols,
1262 0, (CORE_ADDR) 0, cu_language, objfile);
1264 if (cu_language == language_cplus)
1266 /* For C++, these implicitly act as typedefs as well. */
1267 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1268 VAR_NAMESPACE, LOC_TYPEDEF,
1269 &objfile->static_psymbols,
1270 0, (CORE_ADDR) 0, cu_language, objfile);
1273 case DW_TAG_enumerator:
1274 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1275 VAR_NAMESPACE, LOC_CONST,
1276 &objfile->static_psymbols,
1277 0, (CORE_ADDR) 0, cu_language, objfile);
1284 /* Expand this partial symbol table into a full symbol table. */
1287 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
1289 /* FIXME: This is barely more than a stub. */
1294 warning ("bug: psymtab for %s is already read in.", pst->filename);
1300 printf_filtered ("Reading in symbols for %s...", pst->filename);
1301 gdb_flush (gdb_stdout);
1304 psymtab_to_symtab_1 (pst);
1306 /* Finish up the debug error message. */
1308 printf_filtered ("done.\n");
1314 psymtab_to_symtab_1 (struct partial_symtab *pst)
1316 struct objfile *objfile = pst->objfile;
1317 bfd *abfd = objfile->obfd;
1318 struct comp_unit_head cu_header;
1319 struct die_info *dies;
1320 unsigned long offset;
1321 CORE_ADDR lowpc, highpc;
1322 struct die_info *child_die;
1324 struct symtab *symtab;
1325 struct cleanup *back_to;
1327 /* Set local variables from the partial symbol table info. */
1328 offset = DWARF_INFO_OFFSET (pst);
1329 dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1330 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1331 dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1332 dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1333 baseaddr = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
1334 cu_header_offset = offset;
1335 info_ptr = dwarf_info_buffer + offset;
1337 obstack_init (&dwarf2_tmp_obstack);
1338 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1341 make_cleanup (really_free_pendings, NULL);
1343 /* read in the comp_unit header */
1344 info_ptr = read_comp_unit_head (&cu_header, info_ptr, abfd);
1346 /* Read the abbrevs for this compilation unit */
1347 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
1348 make_cleanup (dwarf2_empty_abbrev_table, NULL);
1350 dies = read_comp_unit (info_ptr, abfd, &cu_header);
1352 make_cleanup_free_die_list (dies);
1354 /* Do line number decoding in read_file_scope () */
1355 process_die (dies, objfile, &cu_header);
1357 if (!dwarf2_get_pc_bounds (dies, &lowpc, &highpc, objfile))
1359 /* Some compilers don't define a DW_AT_high_pc attribute for
1360 the compilation unit. If the DW_AT_high_pc is missing,
1361 synthesize it, by scanning the DIE's below the compilation unit. */
1363 if (dies->has_children)
1365 child_die = dies->next;
1366 while (child_die && child_die->tag)
1368 if (child_die->tag == DW_TAG_subprogram)
1370 CORE_ADDR low, high;
1372 if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile))
1374 highpc = max (highpc, high);
1377 child_die = sibling_die (child_die);
1381 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
1383 /* Set symtab language to language from DW_AT_language.
1384 If the compilation is from a C file generated by language preprocessors,
1385 do not set the language if it was already deduced by start_subfile. */
1387 && !(cu_language == language_c && symtab->language != language_c))
1389 symtab->language = cu_language;
1391 pst->symtab = symtab;
1393 sort_symtab_syms (pst->symtab);
1395 do_cleanups (back_to);
1398 /* Process a die and its children. */
1401 process_die (struct die_info *die, struct objfile *objfile,
1402 const struct comp_unit_head *cu_header)
1406 case DW_TAG_padding:
1408 case DW_TAG_compile_unit:
1409 read_file_scope (die, objfile, cu_header);
1411 case DW_TAG_subprogram:
1412 read_subroutine_type (die, objfile, cu_header);
1413 read_func_scope (die, objfile, cu_header);
1415 case DW_TAG_inlined_subroutine:
1416 /* FIXME: These are ignored for now.
1417 They could be used to set breakpoints on all inlined instances
1418 of a function and make GDB `next' properly over inlined functions. */
1420 case DW_TAG_lexical_block:
1421 read_lexical_block_scope (die, objfile, cu_header);
1423 case DW_TAG_class_type:
1424 case DW_TAG_structure_type:
1425 case DW_TAG_union_type:
1426 read_structure_scope (die, objfile, cu_header);
1428 case DW_TAG_enumeration_type:
1429 read_enumeration (die, objfile, cu_header);
1431 case DW_TAG_subroutine_type:
1432 read_subroutine_type (die, objfile, cu_header);
1434 case DW_TAG_array_type:
1435 read_array_type (die, objfile, cu_header);
1437 case DW_TAG_pointer_type:
1438 read_tag_pointer_type (die, objfile, cu_header);
1440 case DW_TAG_ptr_to_member_type:
1441 read_tag_ptr_to_member_type (die, objfile, cu_header);
1443 case DW_TAG_reference_type:
1444 read_tag_reference_type (die, objfile, cu_header);
1446 case DW_TAG_string_type:
1447 read_tag_string_type (die, objfile);
1449 case DW_TAG_base_type:
1450 read_base_type (die, objfile);
1451 if (dwarf_attr (die, DW_AT_name))
1453 /* Add a typedef symbol for the base type definition. */
1454 new_symbol (die, die->type, objfile, cu_header);
1457 case DW_TAG_common_block:
1458 read_common_block (die, objfile, cu_header);
1460 case DW_TAG_common_inclusion:
1463 new_symbol (die, NULL, objfile, cu_header);
1469 read_file_scope (struct die_info *die, struct objfile *objfile,
1470 const struct comp_unit_head *cu_header)
1472 unsigned int line_offset = 0;
1473 CORE_ADDR lowpc = ((CORE_ADDR) -1);
1474 CORE_ADDR highpc = ((CORE_ADDR) 0);
1475 struct attribute *attr;
1476 char *name = "<unknown>";
1477 char *comp_dir = NULL;
1478 struct die_info *child_die;
1479 bfd *abfd = objfile->obfd;
1481 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1483 if (die->has_children)
1485 child_die = die->next;
1486 while (child_die && child_die->tag)
1488 if (child_die->tag == DW_TAG_subprogram)
1490 CORE_ADDR low, high;
1492 if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile))
1494 lowpc = min (lowpc, low);
1495 highpc = max (highpc, high);
1498 child_die = sibling_die (child_die);
1503 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1504 from finish_block. */
1505 if (lowpc == ((CORE_ADDR) -1))
1510 attr = dwarf_attr (die, DW_AT_name);
1513 name = DW_STRING (attr);
1515 attr = dwarf_attr (die, DW_AT_comp_dir);
1518 comp_dir = DW_STRING (attr);
1521 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1522 directory, get rid of it. */
1523 char *cp = strchr (comp_dir, ':');
1525 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1530 if (objfile->ei.entry_point >= lowpc &&
1531 objfile->ei.entry_point < highpc)
1533 objfile->ei.entry_file_lowpc = lowpc;
1534 objfile->ei.entry_file_highpc = highpc;
1537 attr = dwarf_attr (die, DW_AT_language);
1540 set_cu_language (DW_UNSND (attr));
1543 /* We assume that we're processing GCC output. */
1544 processing_gcc_compilation = 2;
1546 /* FIXME:Do something here. */
1547 if (dip->at_producer != NULL)
1549 handle_producer (dip->at_producer);
1553 /* The compilation unit may be in a different language or objfile,
1554 zero out all remembered fundamental types. */
1555 memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
1557 start_symtab (name, comp_dir, lowpc);
1558 record_debugformat ("DWARF 2");
1560 /* Decode line number information if present. */
1561 attr = dwarf_attr (die, DW_AT_stmt_list);
1564 line_offset = DW_UNSND (attr);
1565 dwarf_decode_lines (line_offset, comp_dir, abfd, cu_header);
1568 /* Process all dies in compilation unit. */
1569 if (die->has_children)
1571 child_die = die->next;
1572 while (child_die && child_die->tag)
1574 process_die (child_die, objfile, cu_header);
1575 child_die = sibling_die (child_die);
1581 read_func_scope (struct die_info *die, struct objfile *objfile,
1582 const struct comp_unit_head *cu_header)
1584 register struct context_stack *new;
1587 struct die_info *child_die;
1588 struct attribute *attr;
1591 name = dwarf2_linkage_name (die);
1593 /* Ignore functions with missing or empty names and functions with
1594 missing or invalid low and high pc attributes. */
1595 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1601 if (objfile->ei.entry_point >= lowpc &&
1602 objfile->ei.entry_point < highpc)
1604 objfile->ei.entry_func_lowpc = lowpc;
1605 objfile->ei.entry_func_highpc = highpc;
1608 /* Decode DW_AT_frame_base location descriptor if present, keep result
1609 for DW_OP_fbreg operands in decode_locdesc. */
1610 frame_base_reg = -1;
1611 frame_base_offset = 0;
1612 attr = dwarf_attr (die, DW_AT_frame_base);
1615 CORE_ADDR addr = decode_locdesc (DW_BLOCK (attr), objfile, cu_header);
1617 complain (&dwarf2_unsupported_at_frame_base, name);
1619 frame_base_reg = addr;
1622 frame_base_reg = basereg;
1623 frame_base_offset = addr;
1626 complain (&dwarf2_unsupported_at_frame_base, name);
1629 new = push_context (0, lowpc);
1630 new->name = new_symbol (die, die->type, objfile, cu_header);
1631 list_in_scope = &local_symbols;
1633 if (die->has_children)
1635 child_die = die->next;
1636 while (child_die && child_die->tag)
1638 process_die (child_die, objfile, cu_header);
1639 child_die = sibling_die (child_die);
1643 new = pop_context ();
1644 /* Make a block for the local symbols within. */
1645 finish_block (new->name, &local_symbols, new->old_blocks,
1646 lowpc, highpc, objfile);
1647 list_in_scope = &file_symbols;
1650 /* Process all the DIES contained within a lexical block scope. Start
1651 a new scope, process the dies, and then close the scope. */
1654 read_lexical_block_scope (struct die_info *die, struct objfile *objfile,
1655 const struct comp_unit_head *cu_header)
1657 register struct context_stack *new;
1658 CORE_ADDR lowpc, highpc;
1659 struct die_info *child_die;
1661 /* Ignore blocks with missing or invalid low and high pc attributes. */
1662 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1667 push_context (0, lowpc);
1668 if (die->has_children)
1670 child_die = die->next;
1671 while (child_die && child_die->tag)
1673 process_die (child_die, objfile, cu_header);
1674 child_die = sibling_die (child_die);
1677 new = pop_context ();
1679 if (local_symbols != NULL)
1681 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
1684 local_symbols = new->locals;
1687 /* Get low and high pc attributes from a die.
1688 Return 1 if the attributes are present and valid, otherwise, return 0. */
1691 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, CORE_ADDR *highpc,
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 (struct field_info *fip, struct die_info *die,
1732 struct objfile *objfile,
1733 const struct comp_unit_head *cu_header)
1735 struct nextfield *new_field;
1736 struct attribute *attr;
1738 char *fieldname = "";
1740 /* Allocate a new field list entry and link it in. */
1741 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
1742 make_cleanup (xfree, new_field);
1743 memset (new_field, 0, sizeof (struct nextfield));
1744 new_field->next = fip->fields;
1745 fip->fields = new_field;
1748 /* Handle accessibility and virtuality of field.
1749 The default accessibility for members is public, the default
1750 accessibility for inheritance is private. */
1751 if (die->tag != DW_TAG_inheritance)
1752 new_field->accessibility = DW_ACCESS_public;
1754 new_field->accessibility = DW_ACCESS_private;
1755 new_field->virtuality = DW_VIRTUALITY_none;
1757 attr = dwarf_attr (die, DW_AT_accessibility);
1759 new_field->accessibility = DW_UNSND (attr);
1760 if (new_field->accessibility != DW_ACCESS_public)
1761 fip->non_public_fields = 1;
1762 attr = dwarf_attr (die, DW_AT_virtuality);
1764 new_field->virtuality = DW_UNSND (attr);
1766 fp = &new_field->field;
1767 if (die->tag == DW_TAG_member)
1769 /* Get type of field. */
1770 fp->type = die_type (die, objfile, cu_header);
1772 /* Get bit size of field (zero if none). */
1773 attr = dwarf_attr (die, DW_AT_bit_size);
1776 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
1780 FIELD_BITSIZE (*fp) = 0;
1783 /* Get bit offset of field. */
1784 attr = dwarf_attr (die, DW_AT_data_member_location);
1787 FIELD_BITPOS (*fp) =
1788 decode_locdesc (DW_BLOCK (attr), objfile, cu_header) * bits_per_byte;
1791 FIELD_BITPOS (*fp) = 0;
1792 attr = dwarf_attr (die, DW_AT_bit_offset);
1795 if (BITS_BIG_ENDIAN)
1797 /* For big endian bits, the DW_AT_bit_offset gives the
1798 additional bit offset from the MSB of the containing
1799 anonymous object to the MSB of the field. We don't
1800 have to do anything special since we don't need to
1801 know the size of the anonymous object. */
1802 FIELD_BITPOS (*fp) += DW_UNSND (attr);
1806 /* For little endian bits, compute the bit offset to the
1807 MSB of the anonymous object, subtract off the number of
1808 bits from the MSB of the field to the MSB of the
1809 object, and then subtract off the number of bits of
1810 the field itself. The result is the bit offset of
1811 the LSB of the field. */
1813 int bit_offset = DW_UNSND (attr);
1815 attr = dwarf_attr (die, DW_AT_byte_size);
1818 /* The size of the anonymous object containing
1819 the bit field is explicit, so use the
1820 indicated size (in bytes). */
1821 anonymous_size = DW_UNSND (attr);
1825 /* The size of the anonymous object containing
1826 the bit field must be inferred from the type
1827 attribute of the data member containing the
1829 anonymous_size = TYPE_LENGTH (fp->type);
1831 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
1832 - bit_offset - FIELD_BITSIZE (*fp);
1836 /* Get name of field. */
1837 attr = dwarf_attr (die, DW_AT_name);
1838 if (attr && DW_STRING (attr))
1839 fieldname = DW_STRING (attr);
1840 fp->name = obsavestring (fieldname, strlen (fieldname),
1841 &objfile->type_obstack);
1843 /* Change accessibility for artificial fields (e.g. virtual table
1844 pointer or virtual base class pointer) to private. */
1845 if (dwarf_attr (die, DW_AT_artificial))
1847 new_field->accessibility = DW_ACCESS_private;
1848 fip->non_public_fields = 1;
1851 else if (die->tag == DW_TAG_variable)
1855 /* C++ static member.
1856 Get name of field. */
1857 attr = dwarf_attr (die, DW_AT_name);
1858 if (attr && DW_STRING (attr))
1859 fieldname = DW_STRING (attr);
1863 /* Get physical name. */
1864 physname = dwarf2_linkage_name (die);
1866 SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
1867 &objfile->type_obstack));
1868 FIELD_TYPE (*fp) = die_type (die, objfile, cu_header);
1869 FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
1870 &objfile->type_obstack);
1872 else if (die->tag == DW_TAG_inheritance)
1874 /* C++ base class field. */
1875 attr = dwarf_attr (die, DW_AT_data_member_location);
1877 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), objfile, cu_header)
1879 FIELD_BITSIZE (*fp) = 0;
1880 FIELD_TYPE (*fp) = die_type (die, objfile, cu_header);
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 (struct field_info *fip, struct type *type,
1890 struct objfile *objfile)
1892 int nfields = fip->nfields;
1894 /* Record the field count, allocate space for the array of fields,
1895 and create blank accessibility bitfields if necessary. */
1896 TYPE_NFIELDS (type) = nfields;
1897 TYPE_FIELDS (type) = (struct field *)
1898 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1899 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
1901 if (fip->non_public_fields)
1903 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1905 TYPE_FIELD_PRIVATE_BITS (type) =
1906 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1907 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
1909 TYPE_FIELD_PROTECTED_BITS (type) =
1910 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1911 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
1913 TYPE_FIELD_IGNORE_BITS (type) =
1914 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1915 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
1918 /* If the type has baseclasses, allocate and clear a bit vector for
1919 TYPE_FIELD_VIRTUAL_BITS. */
1920 if (fip->nbaseclasses)
1922 int num_bytes = B_BYTES (fip->nbaseclasses);
1925 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1926 pointer = (char *) TYPE_ALLOC (type, num_bytes);
1927 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
1928 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
1929 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
1932 /* Copy the saved-up fields into the field vector. Start from the head
1933 of the list, adding to the tail of the field array, so that they end
1934 up in the same order in the array in which they were added to the list. */
1935 while (nfields-- > 0)
1937 TYPE_FIELD (type, nfields) = fip->fields->field;
1938 switch (fip->fields->accessibility)
1940 case DW_ACCESS_private:
1941 SET_TYPE_FIELD_PRIVATE (type, nfields);
1944 case DW_ACCESS_protected:
1945 SET_TYPE_FIELD_PROTECTED (type, nfields);
1948 case DW_ACCESS_public:
1952 /* Unknown accessibility. Complain and treat it as public. */
1954 complain (&dwarf2_unsupported_accessibility,
1955 fip->fields->accessibility);
1959 if (nfields < fip->nbaseclasses)
1961 switch (fip->fields->virtuality)
1963 case DW_VIRTUALITY_virtual:
1964 case DW_VIRTUALITY_pure_virtual:
1965 SET_TYPE_FIELD_VIRTUAL (type, nfields);
1969 fip->fields = fip->fields->next;
1973 /* Add a member function to the proper fieldlist. */
1976 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
1977 struct type *type, struct objfile *objfile,
1978 const struct comp_unit_head *cu_header)
1980 struct attribute *attr;
1981 struct fnfieldlist *flp;
1983 struct fn_field *fnp;
1986 struct nextfnfield *new_fnfield;
1988 /* Get name of member function. */
1989 attr = dwarf_attr (die, DW_AT_name);
1990 if (attr && DW_STRING (attr))
1991 fieldname = DW_STRING (attr);
1995 /* Get the mangled name. */
1996 physname = dwarf2_linkage_name (die);
1998 /* Look up member function name in fieldlist. */
1999 for (i = 0; i < fip->nfnfields; i++)
2001 if (STREQ (fip->fnfieldlists[i].name, fieldname))
2005 /* Create new list element if necessary. */
2006 if (i < fip->nfnfields)
2007 flp = &fip->fnfieldlists[i];
2010 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
2012 fip->fnfieldlists = (struct fnfieldlist *)
2013 xrealloc (fip->fnfieldlists,
2014 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
2015 * sizeof (struct fnfieldlist));
2016 if (fip->nfnfields == 0)
2017 make_cleanup (free_current_contents, &fip->fnfieldlists);
2019 flp = &fip->fnfieldlists[fip->nfnfields];
2020 flp->name = fieldname;
2026 /* Create a new member function field and chain it to the field list
2028 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2029 make_cleanup (xfree, new_fnfield);
2030 memset (new_fnfield, 0, sizeof (struct nextfnfield));
2031 new_fnfield->next = flp->head;
2032 flp->head = new_fnfield;
2035 /* Fill in the member function field info. */
2036 fnp = &new_fnfield->fnfield;
2037 fnp->physname = obsavestring (physname, strlen (physname),
2038 &objfile->type_obstack);
2039 fnp->type = alloc_type (objfile);
2040 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2042 struct type *return_type = TYPE_TARGET_TYPE (die->type);
2043 struct type **arg_types;
2044 int nparams = TYPE_NFIELDS (die->type);
2047 /* Copy argument types from the subroutine type. */
2048 arg_types = (struct type **)
2049 TYPE_ALLOC (fnp->type, (nparams + 1) * sizeof (struct type *));
2050 for (iparams = 0; iparams < nparams; iparams++)
2051 arg_types[iparams] = TYPE_FIELD_TYPE (die->type, iparams);
2053 /* Set last entry in argument type vector. */
2054 if (TYPE_FLAGS (die->type) & TYPE_FLAG_VARARGS)
2055 arg_types[nparams] = NULL;
2057 arg_types[nparams] = dwarf2_fundamental_type (objfile, FT_VOID);
2059 smash_to_method_type (fnp->type, type, return_type, arg_types);
2061 /* Handle static member functions.
2062 Dwarf2 has no clean way to discern C++ static and non-static
2063 member functions. G++ helps GDB by marking the first
2064 parameter for non-static member functions (which is the
2065 this pointer) as artificial. We obtain this information
2066 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2067 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2068 fnp->voffset = VOFFSET_STATIC;
2071 complain (&dwarf2_missing_member_fn_type_complaint, physname);
2073 /* Get fcontext from DW_AT_containing_type if present. */
2074 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2075 fnp->fcontext = die_containing_type (die, objfile, cu_header);
2077 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2078 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2080 /* Get accessibility. */
2081 attr = dwarf_attr (die, DW_AT_accessibility);
2084 switch (DW_UNSND (attr))
2086 case DW_ACCESS_private:
2087 fnp->is_private = 1;
2089 case DW_ACCESS_protected:
2090 fnp->is_protected = 1;
2095 /* Get index in virtual function table if it is a virtual member function. */
2096 attr = dwarf_attr (die, DW_AT_vtable_elem_location);
2098 fnp->voffset = decode_locdesc (DW_BLOCK (attr), objfile, cu_header) + 2;
2101 /* Create the vector of member function fields, and attach it to the type. */
2104 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
2105 struct objfile *objfile)
2107 struct fnfieldlist *flp;
2108 int total_length = 0;
2111 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2112 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2113 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2115 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2117 struct nextfnfield *nfp = flp->head;
2118 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2121 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2122 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2123 fn_flp->fn_fields = (struct fn_field *)
2124 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2125 for (k = flp->length; (k--, nfp); nfp = nfp->next)
2126 fn_flp->fn_fields[k] = nfp->fnfield;
2128 total_length += flp->length;
2131 TYPE_NFN_FIELDS (type) = fip->nfnfields;
2132 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2135 /* Called when we find the DIE that starts a structure or union scope
2136 (definition) to process all dies that define the members of the
2139 NOTE: we need to call struct_type regardless of whether or not the
2140 DIE has an at_name attribute, since it might be an anonymous
2141 structure or union. This gets the type entered into our set of
2144 However, if the structure is incomplete (an opaque struct/union)
2145 then suppress creating a symbol table entry for it since gdb only
2146 wants to find the one with the complete definition. Note that if
2147 it is complete, we just call new_symbol, which does it's own
2148 checking about whether the struct/union is anonymous or not (and
2149 suppresses creating a symbol table entry itself). */
2152 read_structure_scope (struct die_info *die, struct objfile *objfile,
2153 const struct comp_unit_head *cu_header)
2156 struct attribute *attr;
2158 type = alloc_type (objfile);
2160 INIT_CPLUS_SPECIFIC (type);
2161 attr = dwarf_attr (die, DW_AT_name);
2162 if (attr && DW_STRING (attr))
2164 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2165 strlen (DW_STRING (attr)),
2166 &objfile->type_obstack);
2169 if (die->tag == DW_TAG_structure_type)
2171 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2173 else if (die->tag == DW_TAG_union_type)
2175 TYPE_CODE (type) = TYPE_CODE_UNION;
2179 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2181 TYPE_CODE (type) = TYPE_CODE_CLASS;
2184 attr = dwarf_attr (die, DW_AT_byte_size);
2187 TYPE_LENGTH (type) = DW_UNSND (attr);
2191 TYPE_LENGTH (type) = 0;
2194 /* We need to add the type field to the die immediately so we don't
2195 infinitely recurse when dealing with pointers to the structure
2196 type within the structure itself. */
2199 if (die->has_children && ! die_is_declaration (die))
2201 struct field_info fi;
2202 struct die_info *child_die;
2203 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
2205 memset (&fi, 0, sizeof (struct field_info));
2207 child_die = die->next;
2209 while (child_die && child_die->tag)
2211 if (child_die->tag == DW_TAG_member)
2213 dwarf2_add_field (&fi, child_die, objfile, cu_header);
2215 else if (child_die->tag == DW_TAG_variable)
2217 /* C++ static member. */
2218 dwarf2_add_field (&fi, child_die, objfile, cu_header);
2220 else if (child_die->tag == DW_TAG_subprogram)
2222 /* C++ member function. */
2223 process_die (child_die, objfile, cu_header);
2224 dwarf2_add_member_fn (&fi, child_die, type, objfile, cu_header);
2226 else if (child_die->tag == DW_TAG_inheritance)
2228 /* C++ base class field. */
2229 dwarf2_add_field (&fi, child_die, objfile, cu_header);
2233 process_die (child_die, objfile, cu_header);
2235 child_die = sibling_die (child_die);
2238 /* Attach fields and member functions to the type. */
2240 dwarf2_attach_fields_to_type (&fi, type, objfile);
2243 dwarf2_attach_fn_fields_to_type (&fi, type, objfile);
2245 /* Get the type which refers to the base class (possibly this
2246 class itself) which contains the vtable pointer for the current
2247 class from the DW_AT_containing_type attribute. */
2249 if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2251 struct type *t = die_containing_type (die, objfile, cu_header);
2253 TYPE_VPTR_BASETYPE (type) = t;
2256 static const char vptr_name[] =
2257 {'_', 'v', 'p', 't', 'r', '\0'};
2260 /* Our own class provides vtbl ptr. */
2261 for (i = TYPE_NFIELDS (t) - 1;
2262 i >= TYPE_N_BASECLASSES (t);
2265 char *fieldname = TYPE_FIELD_NAME (t, i);
2267 if (STREQN (fieldname, vptr_name, strlen (vptr_name) - 1)
2268 && is_cplus_marker (fieldname[strlen (vptr_name)]))
2270 TYPE_VPTR_FIELDNO (type) = i;
2275 /* Complain if virtual function table field not found. */
2276 if (i < TYPE_N_BASECLASSES (t))
2277 complain (&dwarf2_vtbl_not_found_complaint,
2278 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "");
2282 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2287 new_symbol (die, type, objfile, cu_header);
2289 do_cleanups (back_to);
2293 /* No children, must be stub. */
2294 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2300 /* Given a pointer to a die which begins an enumeration, process all
2301 the dies that define the members of the enumeration.
2303 This will be much nicer in draft 6 of the DWARF spec when our
2304 members will be dies instead squished into the DW_AT_element_list
2307 NOTE: We reverse the order of the element list. */
2310 read_enumeration (struct die_info *die, struct objfile *objfile,
2311 const struct comp_unit_head *cu_header)
2313 struct die_info *child_die;
2315 struct field *fields;
2316 struct attribute *attr;
2319 int unsigned_enum = 1;
2321 type = alloc_type (objfile);
2323 TYPE_CODE (type) = TYPE_CODE_ENUM;
2324 attr = dwarf_attr (die, DW_AT_name);
2325 if (attr && DW_STRING (attr))
2327 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2328 strlen (DW_STRING (attr)),
2329 &objfile->type_obstack);
2332 attr = dwarf_attr (die, DW_AT_byte_size);
2335 TYPE_LENGTH (type) = DW_UNSND (attr);
2339 TYPE_LENGTH (type) = 0;
2344 if (die->has_children)
2346 child_die = die->next;
2347 while (child_die && child_die->tag)
2349 if (child_die->tag != DW_TAG_enumerator)
2351 process_die (child_die, objfile, cu_header);
2355 attr = dwarf_attr (child_die, DW_AT_name);
2358 sym = new_symbol (child_die, type, objfile, cu_header);
2359 if (SYMBOL_VALUE (sym) < 0)
2362 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
2364 fields = (struct field *)
2366 (num_fields + DW_FIELD_ALLOC_CHUNK)
2367 * sizeof (struct field));
2370 FIELD_NAME (fields[num_fields]) = SYMBOL_NAME (sym);
2371 FIELD_TYPE (fields[num_fields]) = NULL;
2372 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
2373 FIELD_BITSIZE (fields[num_fields]) = 0;
2379 child_die = sibling_die (child_die);
2384 TYPE_NFIELDS (type) = num_fields;
2385 TYPE_FIELDS (type) = (struct field *)
2386 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
2387 memcpy (TYPE_FIELDS (type), fields,
2388 sizeof (struct field) * num_fields);
2392 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
2395 new_symbol (die, type, objfile, cu_header);
2398 /* Extract all information from a DW_TAG_array_type DIE and put it in
2399 the DIE's type field. For now, this only handles one dimensional
2403 read_array_type (struct die_info *die, struct objfile *objfile,
2404 const struct comp_unit_head *cu_header)
2406 struct die_info *child_die;
2407 struct type *type = NULL;
2408 struct type *element_type, *range_type, *index_type;
2409 struct type **range_types = NULL;
2410 struct attribute *attr;
2412 struct cleanup *back_to;
2414 /* Return if we've already decoded this type. */
2420 element_type = die_type (die, objfile, cu_header);
2422 /* Irix 6.2 native cc creates array types without children for
2423 arrays with unspecified length. */
2424 if (die->has_children == 0)
2426 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2427 range_type = create_range_type (NULL, index_type, 0, -1);
2428 die->type = create_array_type (NULL, element_type, range_type);
2432 back_to = make_cleanup (null_cleanup, NULL);
2433 child_die = die->next;
2434 while (child_die && child_die->tag)
2436 if (child_die->tag == DW_TAG_subrange_type)
2438 unsigned int low, high;
2440 /* Default bounds to an array with unspecified length. */
2443 if (cu_language == language_fortran)
2445 /* FORTRAN implies a lower bound of 1, if not given. */
2449 index_type = die_type (child_die, objfile, cu_header);
2450 attr = dwarf_attr (child_die, DW_AT_lower_bound);
2453 if (attr->form == DW_FORM_sdata)
2455 low = DW_SND (attr);
2457 else if (attr->form == DW_FORM_udata
2458 || attr->form == DW_FORM_data1
2459 || attr->form == DW_FORM_data2
2460 || attr->form == DW_FORM_data4)
2462 low = DW_UNSND (attr);
2466 complain (&dwarf2_non_const_array_bound_ignored,
2467 dwarf_form_name (attr->form));
2469 die->type = lookup_pointer_type (element_type);
2476 attr = dwarf_attr (child_die, DW_AT_upper_bound);
2479 if (attr->form == DW_FORM_sdata)
2481 high = DW_SND (attr);
2483 else if (attr->form == DW_FORM_udata
2484 || attr->form == DW_FORM_data1
2485 || attr->form == DW_FORM_data2
2486 || attr->form == DW_FORM_data4)
2488 high = DW_UNSND (attr);
2490 else if (attr->form == DW_FORM_block1)
2492 /* GCC encodes arrays with unspecified or dynamic length
2493 with a DW_FORM_block1 attribute.
2494 FIXME: GDB does not yet know how to handle dynamic
2495 arrays properly, treat them as arrays with unspecified
2501 complain (&dwarf2_non_const_array_bound_ignored,
2502 dwarf_form_name (attr->form));
2504 die->type = lookup_pointer_type (element_type);
2512 /* Create a range type and save it for array type creation. */
2513 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
2515 range_types = (struct type **)
2516 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
2517 * sizeof (struct type *));
2519 make_cleanup (free_current_contents, &range_types);
2521 range_types[ndim++] = create_range_type (NULL, index_type, low, high);
2523 child_die = sibling_die (child_die);
2526 /* Dwarf2 dimensions are output from left to right, create the
2527 necessary array types in backwards order. */
2528 type = element_type;
2530 type = create_array_type (NULL, type, range_types[ndim]);
2532 do_cleanups (back_to);
2534 /* Install the type in the die. */
2538 /* First cut: install each common block member as a global variable. */
2541 read_common_block (struct die_info *die, struct objfile *objfile,
2542 const struct comp_unit_head *cu_header)
2544 struct die_info *child_die;
2545 struct attribute *attr;
2547 CORE_ADDR base = (CORE_ADDR) 0;
2549 attr = dwarf_attr (die, DW_AT_location);
2552 base = decode_locdesc (DW_BLOCK (attr), objfile, cu_header);
2554 if (die->has_children)
2556 child_die = die->next;
2557 while (child_die && child_die->tag)
2559 sym = new_symbol (child_die, NULL, objfile, cu_header);
2560 attr = dwarf_attr (child_die, DW_AT_data_member_location);
2563 SYMBOL_VALUE_ADDRESS (sym) =
2564 base + decode_locdesc (DW_BLOCK (attr), objfile, cu_header);
2565 add_symbol_to_list (sym, &global_symbols);
2567 child_die = sibling_die (child_die);
2572 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2573 the user defined type vector. */
2576 read_tag_pointer_type (struct die_info *die, struct objfile *objfile,
2577 const struct comp_unit_head *cu_header)
2580 struct attribute *attr;
2587 type = lookup_pointer_type (die_type (die, objfile, cu_header));
2588 attr = dwarf_attr (die, DW_AT_byte_size);
2591 TYPE_LENGTH (type) = DW_UNSND (attr);
2595 TYPE_LENGTH (type) = cu_header->addr_size;
2600 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2601 the user defined type vector. */
2604 read_tag_ptr_to_member_type (struct die_info *die, struct objfile *objfile,
2605 const struct comp_unit_head *cu_header)
2608 struct type *to_type;
2609 struct type *domain;
2616 type = alloc_type (objfile);
2617 to_type = die_type (die, objfile, cu_header);
2618 domain = die_containing_type (die, objfile, cu_header);
2619 smash_to_member_type (type, domain, to_type);
2624 /* Extract all information from a DW_TAG_reference_type DIE and add to
2625 the user defined type vector. */
2628 read_tag_reference_type (struct die_info *die, struct objfile *objfile,
2629 const struct comp_unit_head *cu_header)
2632 struct attribute *attr;
2639 type = lookup_reference_type (die_type (die, objfile, cu_header));
2640 attr = dwarf_attr (die, DW_AT_byte_size);
2643 TYPE_LENGTH (type) = DW_UNSND (attr);
2647 TYPE_LENGTH (type) = cu_header->addr_size;
2653 read_tag_const_type (struct die_info *die, struct objfile *objfile,
2654 const struct comp_unit_head *cu_header)
2656 struct type *base_type;
2663 base_type = die_type (die, objfile, cu_header);
2664 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
2668 read_tag_volatile_type (struct die_info *die, struct objfile *objfile,
2669 const struct comp_unit_head *cu_header)
2671 struct type *base_type;
2678 base_type = die_type (die, objfile, cu_header);
2679 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
2682 /* Extract all information from a DW_TAG_string_type DIE and add to
2683 the user defined type vector. It isn't really a user defined type,
2684 but it behaves like one, with other DIE's using an AT_user_def_type
2685 attribute to reference it. */
2688 read_tag_string_type (struct die_info *die, struct objfile *objfile)
2690 struct type *type, *range_type, *index_type, *char_type;
2691 struct attribute *attr;
2692 unsigned int length;
2699 attr = dwarf_attr (die, DW_AT_string_length);
2702 length = DW_UNSND (attr);
2708 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2709 range_type = create_range_type (NULL, index_type, 1, length);
2710 char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
2711 type = create_string_type (char_type, range_type);
2715 /* Handle DIES due to C code like:
2719 int (*funcp)(int a, long l);
2723 ('funcp' generates a DW_TAG_subroutine_type DIE)
2727 read_subroutine_type (struct die_info *die, struct objfile *objfile,
2728 const struct comp_unit_head *cu_header)
2730 struct type *type; /* Type that this function returns */
2731 struct type *ftype; /* Function that returns above type */
2732 struct attribute *attr;
2734 /* Decode the type that this subroutine returns */
2739 type = die_type (die, objfile, cu_header);
2740 ftype = lookup_function_type (type);
2742 /* All functions in C++ have prototypes. */
2743 attr = dwarf_attr (die, DW_AT_prototyped);
2744 if ((attr && (DW_UNSND (attr) != 0))
2745 || cu_language == language_cplus)
2746 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
2748 if (die->has_children)
2750 struct die_info *child_die;
2754 /* Count the number of parameters.
2755 FIXME: GDB currently ignores vararg functions, but knows about
2756 vararg member functions. */
2757 child_die = die->next;
2758 while (child_die && child_die->tag)
2760 if (child_die->tag == DW_TAG_formal_parameter)
2762 else if (child_die->tag == DW_TAG_unspecified_parameters)
2763 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
2764 child_die = sibling_die (child_die);
2767 /* Allocate storage for parameters and fill them in. */
2768 TYPE_NFIELDS (ftype) = nparams;
2769 TYPE_FIELDS (ftype) = (struct field *)
2770 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
2772 child_die = die->next;
2773 while (child_die && child_die->tag)
2775 if (child_die->tag == DW_TAG_formal_parameter)
2777 /* Dwarf2 has no clean way to discern C++ static and non-static
2778 member functions. G++ helps GDB by marking the first
2779 parameter for non-static member functions (which is the
2780 this pointer) as artificial. We pass this information
2781 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2782 attr = dwarf_attr (child_die, DW_AT_artificial);
2784 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
2786 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
2787 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, objfile,
2791 child_die = sibling_die (child_die);
2799 read_typedef (struct die_info *die, struct objfile *objfile,
2800 const struct comp_unit_head *cu_header)
2806 struct attribute *attr;
2809 xtype = die_type (die, objfile, cu_header);
2811 type = alloc_type (objfile);
2812 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2813 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2814 TYPE_TARGET_TYPE (type) = xtype;
2815 attr = dwarf_attr (die, DW_AT_name);
2816 if (attr && DW_STRING (attr))
2817 TYPE_NAME (type) = obsavestring (DW_STRING (attr),
2818 strlen (DW_STRING (attr)),
2819 &objfile->type_obstack);
2825 /* Find a representation of a given base type and install
2826 it in the TYPE field of the die. */
2829 read_base_type (struct die_info *die, struct objfile *objfile)
2832 struct attribute *attr;
2833 int encoding = 0, size = 0;
2835 /* If we've already decoded this die, this is a no-op. */
2841 attr = dwarf_attr (die, DW_AT_encoding);
2844 encoding = DW_UNSND (attr);
2846 attr = dwarf_attr (die, DW_AT_byte_size);
2849 size = DW_UNSND (attr);
2851 attr = dwarf_attr (die, DW_AT_name);
2852 if (attr && DW_STRING (attr))
2854 enum type_code code = TYPE_CODE_INT;
2855 int is_unsigned = 0;
2859 case DW_ATE_address:
2860 /* Turn DW_ATE_address into a void * pointer. */
2861 code = TYPE_CODE_PTR;
2864 case DW_ATE_boolean:
2865 code = TYPE_CODE_BOOL;
2868 case DW_ATE_complex_float:
2869 code = TYPE_CODE_COMPLEX;
2872 code = TYPE_CODE_FLT;
2875 case DW_ATE_signed_char:
2877 case DW_ATE_unsigned:
2878 case DW_ATE_unsigned_char:
2882 complain (&dwarf2_unsupported_at_encoding,
2883 dwarf_type_encoding_name (encoding));
2886 type = init_type (code, size, is_unsigned, DW_STRING (attr), objfile);
2887 if (encoding == DW_ATE_address)
2888 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID);
2892 type = dwarf_base_type (encoding, size, objfile);
2897 /* Read a whole compilation unit into a linked list of dies. */
2900 read_comp_unit (char *info_ptr, bfd *abfd,
2901 const struct comp_unit_head *cu_header)
2903 struct die_info *first_die, *last_die, *die;
2907 /* Reset die reference table; we are
2908 building new ones now. */
2909 dwarf2_empty_hash_tables ();
2913 first_die = last_die = NULL;
2916 cur_ptr = read_full_die (&die, abfd, cur_ptr, cu_header);
2917 if (die->has_children)
2928 /* Enter die in reference hash table */
2929 store_in_ref_table (die->offset, die);
2933 first_die = last_die = die;
2937 last_die->next = die;
2941 while (nesting_level > 0);
2945 /* Free a linked list of dies. */
2948 free_die_list (struct die_info *dies)
2950 struct die_info *die, *next;
2963 do_free_die_list_cleanup (void *dies)
2965 free_die_list (dies);
2968 static struct cleanup *
2969 make_cleanup_free_die_list (struct die_info *dies)
2971 return make_cleanup (do_free_die_list_cleanup, dies);
2975 /* Read the contents of the section at OFFSET and of size SIZE from the
2976 object file specified by OBJFILE into the psymbol_obstack and return it. */
2979 dwarf2_read_section (struct objfile *objfile, file_ptr offset,
2982 bfd *abfd = objfile->obfd;
2988 buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
2989 if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
2990 (bfd_read (buf, size, 1, abfd) != size))
2993 error ("Dwarf Error: Can't read DWARF data from '%s'",
2994 bfd_get_filename (abfd));
2999 /* In DWARF version 2, the description of the debugging information is
3000 stored in a separate .debug_abbrev section. Before we read any
3001 dies from a section we read in all abbreviations and install them
3005 dwarf2_read_abbrevs (bfd *abfd, unsigned int offset)
3008 struct abbrev_info *cur_abbrev;
3009 unsigned int abbrev_number, bytes_read, abbrev_name;
3010 unsigned int abbrev_form, hash_number;
3012 /* empty the table */
3013 dwarf2_empty_abbrev_table (NULL);
3015 abbrev_ptr = dwarf_abbrev_buffer + offset;
3016 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3017 abbrev_ptr += bytes_read;
3019 /* loop until we reach an abbrev number of 0 */
3020 while (abbrev_number)
3022 cur_abbrev = dwarf_alloc_abbrev ();
3024 /* read in abbrev header */
3025 cur_abbrev->number = abbrev_number;
3026 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3027 abbrev_ptr += bytes_read;
3028 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
3031 /* now read in declarations */
3032 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3033 abbrev_ptr += bytes_read;
3034 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3035 abbrev_ptr += bytes_read;
3038 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
3040 cur_abbrev->attrs = (struct attr_abbrev *)
3041 xrealloc (cur_abbrev->attrs,
3042 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
3043 * sizeof (struct attr_abbrev));
3045 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
3046 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
3047 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3048 abbrev_ptr += bytes_read;
3049 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3050 abbrev_ptr += bytes_read;
3053 hash_number = abbrev_number % ABBREV_HASH_SIZE;
3054 cur_abbrev->next = dwarf2_abbrevs[hash_number];
3055 dwarf2_abbrevs[hash_number] = cur_abbrev;
3057 /* Get next abbreviation.
3058 Under Irix6 the abbreviations for a compilation unit are not
3059 always properly terminated with an abbrev number of 0.
3060 Exit loop if we encounter an abbreviation which we have
3061 already read (which means we are about to read the abbreviations
3062 for the next compile unit) or if the end of the abbreviation
3063 table is reached. */
3064 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
3065 >= dwarf_abbrev_size)
3067 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3068 abbrev_ptr += bytes_read;
3069 if (dwarf2_lookup_abbrev (abbrev_number) != NULL)
3074 /* Empty the abbrev table for a new compilation unit. */
3078 dwarf2_empty_abbrev_table (PTR ignore)
3081 struct abbrev_info *abbrev, *next;
3083 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
3086 abbrev = dwarf2_abbrevs[i];
3089 next = abbrev->next;
3090 xfree (abbrev->attrs);
3094 dwarf2_abbrevs[i] = NULL;
3098 /* Lookup an abbrev_info structure in the abbrev hash table. */
3100 static struct abbrev_info *
3101 dwarf2_lookup_abbrev (unsigned int number)
3103 unsigned int hash_number;
3104 struct abbrev_info *abbrev;
3106 hash_number = number % ABBREV_HASH_SIZE;
3107 abbrev = dwarf2_abbrevs[hash_number];
3111 if (abbrev->number == number)
3114 abbrev = abbrev->next;
3119 /* Read a minimal amount of information into the minimal die structure. */
3122 read_partial_die (struct partial_die_info *part_die, bfd *abfd,
3123 char *info_ptr, int *has_pc_info,
3124 const struct comp_unit_head *cu_header)
3126 unsigned int abbrev_number, bytes_read, i;
3127 struct abbrev_info *abbrev;
3128 struct attribute attr;
3129 struct attribute spec_attr;
3130 int found_spec_attr = 0;
3131 int has_low_pc_attr = 0;
3132 int has_high_pc_attr = 0;
3134 *part_die = zeroed_partial_die;
3136 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3137 info_ptr += bytes_read;
3141 abbrev = dwarf2_lookup_abbrev (abbrev_number);
3144 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number);
3146 part_die->offset = info_ptr - dwarf_info_buffer;
3147 part_die->tag = abbrev->tag;
3148 part_die->has_children = abbrev->has_children;
3149 part_die->abbrev = abbrev_number;
3151 for (i = 0; i < abbrev->num_attrs; ++i)
3153 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd,
3154 info_ptr, cu_header);
3156 /* Store the data if it is of an attribute we want to keep in a
3157 partial symbol table. */
3162 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3163 if (part_die->name == NULL)
3164 part_die->name = DW_STRING (&attr);
3166 case DW_AT_MIPS_linkage_name:
3167 part_die->name = DW_STRING (&attr);
3170 has_low_pc_attr = 1;
3171 part_die->lowpc = DW_ADDR (&attr);
3174 has_high_pc_attr = 1;
3175 part_die->highpc = DW_ADDR (&attr);
3177 case DW_AT_location:
3178 part_die->locdesc = DW_BLOCK (&attr);
3180 case DW_AT_language:
3181 part_die->language = DW_UNSND (&attr);
3183 case DW_AT_external:
3184 part_die->is_external = DW_UNSND (&attr);
3186 case DW_AT_declaration:
3187 part_die->is_declaration = DW_UNSND (&attr);
3190 part_die->has_type = 1;
3192 case DW_AT_abstract_origin:
3193 case DW_AT_specification:
3194 found_spec_attr = 1;
3198 /* Ignore absolute siblings, they might point outside of
3199 the current compile unit. */
3200 if (attr.form == DW_FORM_ref_addr)
3201 complain (&dwarf2_absolute_sibling_complaint);
3204 dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr);
3211 /* If we found a reference attribute and the die has no name, try
3212 to find a name in the referred to die. */
3214 if (found_spec_attr && part_die->name == NULL)
3216 struct partial_die_info spec_die;
3220 spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr);
3221 read_partial_die (&spec_die, abfd, spec_ptr, &dummy, cu_header);
3224 part_die->name = spec_die.name;
3226 /* Copy DW_AT_external attribute if it is set. */
3227 if (spec_die.is_external)
3228 part_die->is_external = spec_die.is_external;
3232 /* When using the GNU linker, .gnu.linkonce. sections are used to
3233 eliminate duplicate copies of functions and vtables and such.
3234 The linker will arbitrarily choose one and discard the others.
3235 The AT_*_pc values for such functions refer to local labels in
3236 these sections. If the section from that file was discarded, the
3237 labels are not in the output, so the relocs get a value of 0.
3238 If this is a discarded function, mark the pc bounds as invalid,
3239 so that GDB will ignore it. */
3240 if (has_low_pc_attr && has_high_pc_attr
3241 && part_die->lowpc < part_die->highpc
3242 && (part_die->lowpc != 0
3243 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
3248 /* Read the die from the .debug_info section buffer. And set diep to
3249 point to a newly allocated die with its information. */
3252 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
3253 const struct comp_unit_head *cu_header)
3255 unsigned int abbrev_number, bytes_read, i, offset;
3256 struct abbrev_info *abbrev;
3257 struct die_info *die;
3259 offset = info_ptr - dwarf_info_buffer;
3260 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3261 info_ptr += bytes_read;
3264 die = dwarf_alloc_die ();
3266 die->abbrev = abbrev_number;
3272 abbrev = dwarf2_lookup_abbrev (abbrev_number);
3275 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number);
3277 die = dwarf_alloc_die ();
3278 die->offset = offset;
3279 die->tag = abbrev->tag;
3280 die->has_children = abbrev->has_children;
3281 die->abbrev = abbrev_number;
3284 die->num_attrs = abbrev->num_attrs;
3285 die->attrs = (struct attribute *)
3286 xmalloc (die->num_attrs * sizeof (struct attribute));
3288 for (i = 0; i < abbrev->num_attrs; ++i)
3290 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
3291 abfd, info_ptr, cu_header);
3298 /* Read an attribute described by an abbreviated attribute. */
3301 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
3302 bfd *abfd, char *info_ptr,
3303 const struct comp_unit_head *cu_header)
3305 unsigned int bytes_read;
3306 struct dwarf_block *blk;
3308 attr->name = abbrev->name;
3309 attr->form = abbrev->form;
3310 switch (abbrev->form)
3313 case DW_FORM_ref_addr:
3314 DW_ADDR (attr) = read_address (abfd, info_ptr, cu_header, &bytes_read);
3315 info_ptr += bytes_read;
3317 case DW_FORM_block2:
3318 blk = dwarf_alloc_block ();
3319 blk->size = read_2_bytes (abfd, info_ptr);
3321 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3322 info_ptr += blk->size;
3323 DW_BLOCK (attr) = blk;
3325 case DW_FORM_block4:
3326 blk = dwarf_alloc_block ();
3327 blk->size = read_4_bytes (abfd, info_ptr);
3329 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3330 info_ptr += blk->size;
3331 DW_BLOCK (attr) = blk;
3334 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
3338 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
3342 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
3345 case DW_FORM_string:
3346 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
3347 info_ptr += bytes_read;
3350 blk = dwarf_alloc_block ();
3351 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3352 info_ptr += bytes_read;
3353 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3354 info_ptr += blk->size;
3355 DW_BLOCK (attr) = blk;
3357 case DW_FORM_block1:
3358 blk = dwarf_alloc_block ();
3359 blk->size = read_1_byte (abfd, info_ptr);
3361 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3362 info_ptr += blk->size;
3363 DW_BLOCK (attr) = blk;
3366 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3370 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3374 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
3375 info_ptr += bytes_read;
3378 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3379 info_ptr += bytes_read;
3382 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3386 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
3390 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
3394 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
3397 case DW_FORM_ref_udata:
3398 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3399 info_ptr += bytes_read;
3402 case DW_FORM_indirect:
3404 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3405 dwarf_form_name (abbrev->form));
3410 /* read dwarf information from a buffer */
3413 read_1_byte (bfd *abfd, char *buf)
3415 return bfd_get_8 (abfd, (bfd_byte *) buf);
3419 read_1_signed_byte (bfd *abfd, char *buf)
3421 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
3425 read_2_bytes (bfd *abfd, char *buf)
3427 return bfd_get_16 (abfd, (bfd_byte *) buf);
3431 read_2_signed_bytes (bfd *abfd, char *buf)
3433 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
3437 read_4_bytes (bfd *abfd, char *buf)
3439 return bfd_get_32 (abfd, (bfd_byte *) buf);
3443 read_4_signed_bytes (bfd *abfd, char *buf)
3445 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
3448 static unsigned long
3449 read_8_bytes (bfd *abfd, char *buf)
3451 return bfd_get_64 (abfd, (bfd_byte *) buf);
3455 read_address (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
3458 CORE_ADDR retval = 0;
3460 if (cu_header->signed_addr_p)
3462 switch (cu_header->addr_size)
3465 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
3468 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
3471 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
3474 internal_error ("read_address: bad switch, signed");
3479 switch (cu_header->addr_size)
3482 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
3485 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
3488 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
3491 internal_error ("read_address: bad switch, unsigned");
3495 *bytes_read = cu_header->addr_size;
3499 /* Reads the initial length from a section. The (draft) DWARF 2.1
3500 specification allows the initial length to take up either 4 bytes
3501 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3502 bytes describe the length and all offsets will be 8 bytes in length
3505 The value returned via bytes_read should be used to increment
3506 the relevant pointer after calling read_initial_length().
3508 As a side effect, this function sets the fields initial_length_size
3509 and offset_size in cu_header to the values appropriate for the
3510 length field. (The format of the initial length field determines
3511 the width of file offsets to be fetched later with fetch_offset().)
3513 [ Note: read_initial_length() and read_offset() are based on the
3514 document entitled "DWARF Debugging Information Format", revision
3515 2.1, draft 4, dated July 20, 2000. This document was obtained
3518 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3520 This document is only a draft and is subject to change. (So beware.)
3522 - Kevin, Aug 4, 2000
3526 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
3531 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
3533 if (retval == 0xffffffff)
3535 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
3537 if (cu_header != NULL)
3539 cu_header->initial_length_size = 12;
3540 cu_header->offset_size = 8;
3546 if (cu_header != NULL)
3548 cu_header->initial_length_size = 4;
3549 cu_header->offset_size = 4;
3556 /* Read an offset from the data stream. The size of the offset is
3557 given by cu_header->offset_size. */
3560 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
3565 switch (cu_header->offset_size)
3568 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
3572 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
3576 internal_error ("read_offset: bad switch");
3583 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
3585 /* If the size of a host char is 8 bits, we can return a pointer
3586 to the buffer, otherwise we have to copy the data to a buffer
3587 allocated on the temporary obstack. */
3588 #if HOST_CHAR_BIT == 8
3594 ret = obstack_alloc (&dwarf2_tmp_obstack, size);
3595 for (i = 0; i < size; ++i)
3597 ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
3605 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
3607 /* If the size of a host char is 8 bits, we can return a pointer
3608 to the string, otherwise we have to copy the string to a buffer
3609 allocated on the temporary obstack. */
3610 #if HOST_CHAR_BIT == 8
3613 *bytes_read_ptr = 1;
3616 *bytes_read_ptr = strlen (buf) + 1;
3622 while ((byte = bfd_get_8 (abfd, (bfd_byte *) buf)) != 0)
3624 obstack_1grow (&dwarf2_tmp_obstack, byte);
3630 *bytes_read_ptr = 1;
3633 obstack_1grow (&dwarf2_tmp_obstack, '\0');
3634 *bytes_read_ptr = i + 1;
3635 return obstack_finish (&dwarf2_tmp_obstack);
3639 static unsigned long
3640 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
3642 unsigned long result;
3643 unsigned int num_read;
3653 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
3656 result |= ((unsigned long)(byte & 127) << shift);
3657 if ((byte & 128) == 0)
3663 *bytes_read_ptr = num_read;
3668 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
3671 int i, shift, size, num_read;
3681 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
3684 result |= ((long)(byte & 127) << shift);
3686 if ((byte & 128) == 0)
3691 if ((shift < size) && (byte & 0x40))
3693 result |= -(1 << shift);
3695 *bytes_read_ptr = num_read;
3700 set_cu_language (unsigned int lang)
3706 cu_language = language_c;
3708 case DW_LANG_C_plus_plus:
3709 cu_language = language_cplus;
3711 case DW_LANG_Fortran77:
3712 case DW_LANG_Fortran90:
3713 cu_language = language_fortran;
3715 case DW_LANG_Mips_Assembler:
3716 cu_language = language_asm;
3719 case DW_LANG_Cobol74:
3720 case DW_LANG_Cobol85:
3721 case DW_LANG_Pascal83:
3722 case DW_LANG_Modula2:
3724 cu_language = language_unknown;
3727 cu_language_defn = language_def (cu_language);
3730 /* Return the named attribute or NULL if not there. */
3732 static struct attribute *
3733 dwarf_attr (struct die_info *die, unsigned int name)
3736 struct attribute *spec = NULL;
3738 for (i = 0; i < die->num_attrs; ++i)
3740 if (die->attrs[i].name == name)
3742 return &die->attrs[i];
3744 if (die->attrs[i].name == DW_AT_specification
3745 || die->attrs[i].name == DW_AT_abstract_origin)
3746 spec = &die->attrs[i];
3750 struct die_info *ref_die =
3751 follow_die_ref (dwarf2_get_ref_die_offset (spec));
3754 return dwarf_attr (ref_die, name);
3761 die_is_declaration (struct die_info *die)
3763 return (dwarf_attr (die, DW_AT_declaration)
3764 && ! dwarf_attr (die, DW_AT_specification));
3767 /* Decode the line number information for the compilation unit whose
3768 line number info is at OFFSET in the .debug_line section.
3769 The compilation directory of the file is passed in COMP_DIR. */
3773 unsigned int num_files;
3786 unsigned int num_dirs;
3791 dwarf_decode_lines (unsigned int offset, char *comp_dir, bfd *abfd,
3792 const struct comp_unit_head *cu_header)
3796 struct line_head lh;
3797 struct cleanup *back_to;
3798 unsigned int i, bytes_read;
3799 char *cur_file, *cur_dir;
3800 unsigned char op_code, extended_op, adj_opcode;
3802 #define FILE_ALLOC_CHUNK 5
3803 #define DIR_ALLOC_CHUNK 5
3805 struct filenames files;
3806 struct directories dirs;
3808 if (dwarf_line_buffer == NULL)
3810 complain (&dwarf2_missing_line_number_section);
3814 files.num_files = 0;
3820 line_ptr = dwarf_line_buffer + offset;
3822 /* read in the prologue */
3823 lh.total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
3824 line_ptr += bytes_read;
3825 line_end = line_ptr + lh.total_length;
3826 lh.version = read_2_bytes (abfd, line_ptr);
3828 lh.prologue_length = read_offset (abfd, line_ptr, cu_header, &bytes_read);
3829 line_ptr += bytes_read;
3830 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
3832 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
3834 lh.line_base = read_1_signed_byte (abfd, line_ptr);
3836 lh.line_range = read_1_byte (abfd, line_ptr);
3838 lh.opcode_base = read_1_byte (abfd, line_ptr);
3840 lh.standard_opcode_lengths = (unsigned char *)
3841 xmalloc (lh.opcode_base * sizeof (unsigned char));
3842 back_to = make_cleanup (free_current_contents, &lh.standard_opcode_lengths);
3844 lh.standard_opcode_lengths[0] = 1;
3845 for (i = 1; i < lh.opcode_base; ++i)
3847 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
3851 /* Read directory table */
3852 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3854 line_ptr += bytes_read;
3855 if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0)
3857 dirs.dirs = (char **)
3858 xrealloc (dirs.dirs,
3859 (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
3860 if (dirs.num_dirs == 0)
3861 make_cleanup (free_current_contents, &dirs.dirs);
3863 dirs.dirs[dirs.num_dirs++] = cur_dir;
3865 line_ptr += bytes_read;
3867 /* Read file name table */
3868 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3870 line_ptr += bytes_read;
3871 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3873 files.files = (struct fileinfo *)
3874 xrealloc (files.files,
3875 (files.num_files + FILE_ALLOC_CHUNK)
3876 * sizeof (struct fileinfo));
3877 if (files.num_files == 0)
3878 make_cleanup (free_current_contents, &files.files);
3880 files.files[files.num_files].name = cur_file;
3881 files.files[files.num_files].dir =
3882 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3883 line_ptr += bytes_read;
3884 files.files[files.num_files].time =
3885 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3886 line_ptr += bytes_read;
3887 files.files[files.num_files].size =
3888 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3889 line_ptr += bytes_read;
3892 line_ptr += bytes_read;
3894 /* Read the statement sequences until there's nothing left. */
3895 while (line_ptr < line_end)
3897 /* state machine registers */
3898 CORE_ADDR address = 0;
3899 unsigned int file = 1;
3900 unsigned int line = 1;
3901 unsigned int column = 0;
3902 int is_stmt = lh.default_is_stmt;
3903 int basic_block = 0;
3904 int end_sequence = 0;
3906 /* Start a subfile for the current file of the state machine. */
3907 if (files.num_files >= file)
3909 /* The file and directory tables are 0 based, the references
3911 dwarf2_start_subfile (files.files[file - 1].name,
3912 (files.files[file - 1].dir
3913 ? dirs.dirs[files.files[file - 1].dir - 1]
3917 /* Decode the table. */
3918 while (!end_sequence)
3920 op_code = read_1_byte (abfd, line_ptr);
3924 case DW_LNS_extended_op:
3925 line_ptr += 1; /* ignore length */
3926 extended_op = read_1_byte (abfd, line_ptr);
3928 switch (extended_op)
3930 case DW_LNE_end_sequence:
3932 /* Don't call record_line here. The end_sequence
3933 instruction provides the address of the first byte
3934 *after* the last line in the sequence; it's not the
3935 address of any real source line. However, the GDB
3936 linetable structure only records the starts of lines,
3937 not the ends. This is a weakness of GDB. */
3939 case DW_LNE_set_address:
3940 address = read_address (abfd, line_ptr, cu_header, &bytes_read);
3941 line_ptr += bytes_read;
3942 address += baseaddr;
3944 case DW_LNE_define_file:
3945 cur_file = read_string (abfd, line_ptr, &bytes_read);
3946 line_ptr += bytes_read;
3947 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3949 files.files = (struct fileinfo *)
3950 xrealloc (files.files,
3951 (files.num_files + FILE_ALLOC_CHUNK)
3952 * sizeof (struct fileinfo));
3953 if (files.num_files == 0)
3954 make_cleanup (free_current_contents, &files.files);
3956 files.files[files.num_files].name = cur_file;
3957 files.files[files.num_files].dir =
3958 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3959 line_ptr += bytes_read;
3960 files.files[files.num_files].time =
3961 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3962 line_ptr += bytes_read;
3963 files.files[files.num_files].size =
3964 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3965 line_ptr += bytes_read;
3969 complain (&dwarf2_mangled_line_number_section);
3974 record_line (current_subfile, line, address);
3977 case DW_LNS_advance_pc:
3978 address += lh.minimum_instruction_length
3979 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3980 line_ptr += bytes_read;
3982 case DW_LNS_advance_line:
3983 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
3984 line_ptr += bytes_read;
3986 case DW_LNS_set_file:
3987 /* The file and directory tables are 0 based, the references
3989 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3990 line_ptr += bytes_read;
3991 dwarf2_start_subfile
3992 (files.files[file - 1].name,
3993 (files.files[file - 1].dir
3994 ? dirs.dirs[files.files[file - 1].dir - 1]
3997 case DW_LNS_set_column:
3998 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3999 line_ptr += bytes_read;
4001 case DW_LNS_negate_stmt:
4002 is_stmt = (!is_stmt);
4004 case DW_LNS_set_basic_block:
4007 /* Add to the address register of the state machine the
4008 address increment value corresponding to special opcode
4009 255. Ie, this value is scaled by the minimum instruction
4010 length since special opcode 255 would have scaled the
4012 case DW_LNS_const_add_pc:
4013 address += (lh.minimum_instruction_length
4014 * ((255 - lh.opcode_base) / lh.line_range));
4016 case DW_LNS_fixed_advance_pc:
4017 address += read_2_bytes (abfd, line_ptr);
4020 default: /* special operand */
4021 adj_opcode = op_code - lh.opcode_base;
4022 address += (adj_opcode / lh.line_range)
4023 * lh.minimum_instruction_length;
4024 line += lh.line_base + (adj_opcode % lh.line_range);
4025 /* append row to matrix using current values */
4026 record_line (current_subfile, line, address);
4032 do_cleanups (back_to);
4035 /* Start a subfile for DWARF. FILENAME is the name of the file and
4036 DIRNAME the name of the source directory which contains FILENAME
4037 or NULL if not known.
4038 This routine tries to keep line numbers from identical absolute and
4039 relative file names in a common subfile.
4041 Using the `list' example from the GDB testsuite, which resides in
4042 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4043 of /srcdir/list0.c yields the following debugging information for list0.c:
4045 DW_AT_name: /srcdir/list0.c
4046 DW_AT_comp_dir: /compdir
4047 files.files[0].name: list0.h
4048 files.files[0].dir: /srcdir
4049 files.files[1].name: list0.c
4050 files.files[1].dir: /srcdir
4052 The line number information for list0.c has to end up in a single
4053 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4056 dwarf2_start_subfile (char *filename, char *dirname)
4058 /* If the filename isn't absolute, try to match an existing subfile
4059 with the full pathname. */
4061 if (*filename != '/' && dirname != NULL)
4063 struct subfile *subfile;
4064 char *fullname = concat (dirname, "/", filename, NULL);
4066 for (subfile = subfiles; subfile; subfile = subfile->next)
4068 if (STREQ (subfile->name, fullname))
4070 current_subfile = subfile;
4077 start_subfile (filename, dirname);
4080 /* Given a pointer to a DWARF information entry, figure out if we need
4081 to make a symbol table entry for it, and if so, create a new entry
4082 and return a pointer to it.
4083 If TYPE is NULL, determine symbol type from the die, otherwise
4084 used the passed type. */
4086 static struct symbol *
4087 new_symbol (struct die_info *die, struct type *type, struct objfile *objfile,
4088 const struct comp_unit_head *cu_header)
4090 struct symbol *sym = NULL;
4092 struct attribute *attr = NULL;
4093 struct attribute *attr2 = NULL;
4096 name = dwarf2_linkage_name (die);
4099 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
4100 sizeof (struct symbol));
4101 OBJSTAT (objfile, n_syms++);
4102 memset (sym, 0, sizeof (struct symbol));
4103 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
4104 &objfile->symbol_obstack);
4106 /* Default assumptions.
4107 Use the passed type or decode it from the die. */
4108 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4109 SYMBOL_CLASS (sym) = LOC_STATIC;
4111 SYMBOL_TYPE (sym) = type;
4113 SYMBOL_TYPE (sym) = die_type (die, objfile, cu_header);
4114 attr = dwarf_attr (die, DW_AT_decl_line);
4117 SYMBOL_LINE (sym) = DW_UNSND (attr);
4120 /* If this symbol is from a C++ compilation, then attempt to
4121 cache the demangled form for future reference. This is a
4122 typical time versus space tradeoff, that was decided in favor
4123 of time because it sped up C++ symbol lookups by a factor of
4126 SYMBOL_LANGUAGE (sym) = cu_language;
4127 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
4131 attr = dwarf_attr (die, DW_AT_low_pc);
4134 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
4136 SYMBOL_CLASS (sym) = LOC_LABEL;
4138 case DW_TAG_subprogram:
4139 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4141 SYMBOL_CLASS (sym) = LOC_BLOCK;
4142 attr2 = dwarf_attr (die, DW_AT_external);
4143 if (attr2 && (DW_UNSND (attr2) != 0))
4145 add_symbol_to_list (sym, &global_symbols);
4149 add_symbol_to_list (sym, list_in_scope);
4152 case DW_TAG_variable:
4153 /* Compilation with minimal debug info may result in variables
4154 with missing type entries. Change the misleading `void' type
4155 to something sensible. */
4156 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
4157 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
4158 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
4159 "<variable, no debug info>",
4161 attr = dwarf_attr (die, DW_AT_const_value);
4164 dwarf2_const_value (attr, sym, objfile, cu_header);
4165 attr2 = dwarf_attr (die, DW_AT_external);
4166 if (attr2 && (DW_UNSND (attr2) != 0))
4167 add_symbol_to_list (sym, &global_symbols);
4169 add_symbol_to_list (sym, list_in_scope);
4172 attr = dwarf_attr (die, DW_AT_location);
4175 attr2 = dwarf_attr (die, DW_AT_external);
4176 if (attr2 && (DW_UNSND (attr2) != 0))
4178 SYMBOL_VALUE_ADDRESS (sym) =
4179 decode_locdesc (DW_BLOCK (attr), objfile, cu_header);
4180 add_symbol_to_list (sym, &global_symbols);
4182 /* In shared libraries the address of the variable
4183 in the location descriptor might still be relocatable,
4184 so its value could be zero.
4185 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4186 value is zero, the address of the variable will then
4187 be determined from the minimal symbol table whenever
4188 the variable is referenced. */
4189 if (SYMBOL_VALUE_ADDRESS (sym))
4191 fixup_symbol_section (sym, objfile);
4192 SYMBOL_VALUE_ADDRESS (sym) +=
4193 ANOFFSET (objfile->section_offsets,
4194 SYMBOL_SECTION (sym));
4195 SYMBOL_CLASS (sym) = LOC_STATIC;
4198 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
4202 SYMBOL_VALUE (sym) = addr =
4203 decode_locdesc (DW_BLOCK (attr), objfile, cu_header);
4204 add_symbol_to_list (sym, list_in_scope);
4207 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
4211 SYMBOL_CLASS (sym) = LOC_REGISTER;
4212 SYMBOL_VALUE (sym) =
4213 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym));
4217 SYMBOL_CLASS (sym) = LOC_BASEREG;
4218 SYMBOL_BASEREG (sym) = DWARF2_REG_TO_REGNUM (basereg);
4222 SYMBOL_CLASS (sym) = LOC_LOCAL;
4226 fixup_symbol_section (sym, objfile);
4227 SYMBOL_VALUE_ADDRESS (sym) =
4228 addr + ANOFFSET (objfile->section_offsets,
4229 SYMBOL_SECTION (sym));
4230 SYMBOL_CLASS (sym) = LOC_STATIC;
4236 /* We do not know the address of this symbol.
4237 If it is an external symbol and we have type information
4238 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4239 The address of the variable will then be determined from
4240 the minimal symbol table whenever the variable is
4242 attr2 = dwarf_attr (die, DW_AT_external);
4243 if (attr2 && (DW_UNSND (attr2) != 0)
4244 && dwarf_attr (die, DW_AT_type) != NULL)
4246 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
4247 add_symbol_to_list (sym, &global_symbols);
4251 case DW_TAG_formal_parameter:
4252 attr = dwarf_attr (die, DW_AT_location);
4255 SYMBOL_VALUE (sym) =
4256 decode_locdesc (DW_BLOCK (attr), objfile, cu_header);
4259 SYMBOL_CLASS (sym) = LOC_REGPARM;
4260 SYMBOL_VALUE (sym) =
4261 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym));
4267 if (basereg != frame_base_reg)
4268 complain (&dwarf2_complex_location_expr);
4269 SYMBOL_CLASS (sym) = LOC_REF_ARG;
4273 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
4274 SYMBOL_BASEREG (sym) = DWARF2_REG_TO_REGNUM (basereg);
4279 SYMBOL_CLASS (sym) = LOC_ARG;
4282 attr = dwarf_attr (die, DW_AT_const_value);
4285 dwarf2_const_value (attr, sym, objfile, cu_header);
4287 add_symbol_to_list (sym, list_in_scope);
4289 case DW_TAG_unspecified_parameters:
4290 /* From varargs functions; gdb doesn't seem to have any
4291 interest in this information, so just ignore it for now.
4294 case DW_TAG_class_type:
4295 case DW_TAG_structure_type:
4296 case DW_TAG_union_type:
4297 case DW_TAG_enumeration_type:
4298 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4299 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
4300 add_symbol_to_list (sym, list_in_scope);
4302 /* The semantics of C++ state that "struct foo { ... }" also
4303 defines a typedef for "foo". Synthesize a typedef symbol so
4304 that "ptype foo" works as expected. */
4305 if (cu_language == language_cplus)
4307 struct symbol *typedef_sym = (struct symbol *)
4308 obstack_alloc (&objfile->symbol_obstack,
4309 sizeof (struct symbol));
4310 *typedef_sym = *sym;
4311 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
4312 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
4313 TYPE_NAME (SYMBOL_TYPE (sym)) =
4314 obsavestring (SYMBOL_NAME (sym),
4315 strlen (SYMBOL_NAME (sym)),
4316 &objfile->type_obstack);
4317 add_symbol_to_list (typedef_sym, list_in_scope);
4320 case DW_TAG_typedef:
4321 case DW_TAG_base_type:
4322 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4323 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4324 add_symbol_to_list (sym, list_in_scope);
4326 case DW_TAG_enumerator:
4327 attr = dwarf_attr (die, DW_AT_const_value);
4330 dwarf2_const_value (attr, sym, objfile, cu_header);
4332 add_symbol_to_list (sym, list_in_scope);
4335 /* Not a tag we recognize. Hopefully we aren't processing
4336 trash data, but since we must specifically ignore things
4337 we don't recognize, there is nothing else we should do at
4339 complain (&dwarf2_unsupported_tag, dwarf_tag_name (die->tag));
4346 /* Copy constant value from an attribute to a symbol. */
4349 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
4350 struct objfile *objfile,
4351 const struct comp_unit_head *cu_header)
4353 struct dwarf_block *blk;
4358 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
4359 complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym),
4360 cu_header->addr_size, TYPE_LENGTH (SYMBOL_TYPE (sym)));
4361 SYMBOL_VALUE_BYTES (sym) = (char *)
4362 obstack_alloc (&objfile->symbol_obstack, cu_header->addr_size);
4363 store_address (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
4365 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
4367 case DW_FORM_block1:
4368 case DW_FORM_block2:
4369 case DW_FORM_block4:
4371 blk = DW_BLOCK (attr);
4372 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
4373 complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym),
4374 blk->size, TYPE_LENGTH (SYMBOL_TYPE (sym)));
4375 SYMBOL_VALUE_BYTES (sym) = (char *)
4376 obstack_alloc (&objfile->symbol_obstack, blk->size);
4377 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
4378 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
4381 /* The DW_AT_const_value attributes are supposed to carry the
4382 symbol's value "represented as it would be on the target
4383 architecture." By the time we get here, it's already been
4384 converted to host endianness, so we just need to sign- or
4385 zero-extend it as appropriate. */
4387 dwarf2_const_value_data (attr, sym, 8);
4390 dwarf2_const_value_data (attr, sym, 16);
4393 dwarf2_const_value_data (attr, sym, 32);
4396 dwarf2_const_value_data (attr, sym, 64);
4400 SYMBOL_VALUE (sym) = DW_SND (attr);
4401 SYMBOL_CLASS (sym) = LOC_CONST;
4405 SYMBOL_VALUE (sym) = DW_UNSND (attr);
4406 SYMBOL_CLASS (sym) = LOC_CONST;
4410 complain (&dwarf2_unsupported_const_value_attr,
4411 dwarf_form_name (attr->form));
4412 SYMBOL_VALUE (sym) = 0;
4413 SYMBOL_CLASS (sym) = LOC_CONST;
4419 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4420 or zero-extend it as appropriate for the symbol's type. */
4422 dwarf2_const_value_data (struct attribute *attr,
4426 LONGEST l = DW_UNSND (attr);
4428 if (bits < sizeof (l) * 8)
4430 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
4431 l &= ((LONGEST) 1 << bits) - 1;
4433 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
4436 SYMBOL_VALUE (sym) = l;
4437 SYMBOL_CLASS (sym) = LOC_CONST;
4441 /* Return the type of the die in question using its DW_AT_type attribute. */
4443 static struct type *
4444 die_type (struct die_info *die, struct objfile *objfile,
4445 const struct comp_unit_head *cu_header)
4448 struct attribute *type_attr;
4449 struct die_info *type_die;
4452 type_attr = dwarf_attr (die, DW_AT_type);
4455 /* A missing DW_AT_type represents a void type. */
4456 return dwarf2_fundamental_type (objfile, FT_VOID);
4460 ref = dwarf2_get_ref_die_offset (type_attr);
4461 type_die = follow_die_ref (ref);
4464 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
4468 type = tag_type_to_type (type_die, objfile, cu_header);
4471 dump_die (type_die);
4472 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4477 /* Return the containing type of the die in question using its
4478 DW_AT_containing_type attribute. */
4480 static struct type *
4481 die_containing_type (struct die_info *die, struct objfile *objfile,
4482 const struct comp_unit_head *cu_header)
4484 struct type *type = NULL;
4485 struct attribute *type_attr;
4486 struct die_info *type_die = NULL;
4489 type_attr = dwarf_attr (die, DW_AT_containing_type);
4492 ref = dwarf2_get_ref_die_offset (type_attr);
4493 type_die = follow_die_ref (ref);
4496 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
4499 type = tag_type_to_type (type_die, objfile, cu_header);
4504 dump_die (type_die);
4505 error ("Dwarf Error: Problem turning containing type into gdb type.");
4511 static struct type *
4512 type_at_offset (unsigned int offset, struct objfile *objfile)
4514 struct die_info *die;
4517 die = follow_die_ref (offset);
4520 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
4523 type = tag_type_to_type (die, objfile);
4528 static struct type *
4529 tag_type_to_type (struct die_info *die, struct objfile *objfile,
4530 const struct comp_unit_head *cu_header)
4538 read_type_die (die, objfile, cu_header);
4542 error ("Dwarf Error: Cannot find type of die.");
4549 read_type_die (struct die_info *die, struct objfile *objfile,
4550 const struct comp_unit_head *cu_header)
4554 case DW_TAG_class_type:
4555 case DW_TAG_structure_type:
4556 case DW_TAG_union_type:
4557 read_structure_scope (die, objfile, cu_header);
4559 case DW_TAG_enumeration_type:
4560 read_enumeration (die, objfile, cu_header);
4562 case DW_TAG_subprogram:
4563 case DW_TAG_subroutine_type:
4564 read_subroutine_type (die, objfile, cu_header);
4566 case DW_TAG_array_type:
4567 read_array_type (die, objfile, cu_header);
4569 case DW_TAG_pointer_type:
4570 read_tag_pointer_type (die, objfile, cu_header);
4572 case DW_TAG_ptr_to_member_type:
4573 read_tag_ptr_to_member_type (die, objfile, cu_header);
4575 case DW_TAG_reference_type:
4576 read_tag_reference_type (die, objfile, cu_header);
4578 case DW_TAG_const_type:
4579 read_tag_const_type (die, objfile, cu_header);
4581 case DW_TAG_volatile_type:
4582 read_tag_volatile_type (die, objfile, cu_header);
4584 case DW_TAG_string_type:
4585 read_tag_string_type (die, objfile);
4587 case DW_TAG_typedef:
4588 read_typedef (die, objfile, cu_header);
4590 case DW_TAG_base_type:
4591 read_base_type (die, objfile);
4594 complain (&dwarf2_unexpected_tag, dwarf_tag_name (die->tag));
4599 static struct type *
4600 dwarf_base_type (int encoding, int size, struct objfile *objfile)
4602 /* FIXME - this should not produce a new (struct type *)
4603 every time. It should cache base types. */
4607 case DW_ATE_address:
4608 type = dwarf2_fundamental_type (objfile, FT_VOID);
4610 case DW_ATE_boolean:
4611 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN);
4613 case DW_ATE_complex_float:
4616 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX);
4620 type = dwarf2_fundamental_type (objfile, FT_COMPLEX);
4626 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
4630 type = dwarf2_fundamental_type (objfile, FT_FLOAT);
4637 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
4640 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT);
4644 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
4648 case DW_ATE_signed_char:
4649 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
4651 case DW_ATE_unsigned:
4655 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
4658 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT);
4662 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
4666 case DW_ATE_unsigned_char:
4667 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
4670 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
4677 copy_die (struct die_info *old_die)
4679 struct die_info *new_die;
4682 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
4683 memset (new_die, 0, sizeof (struct die_info));
4685 new_die->tag = old_die->tag;
4686 new_die->has_children = old_die->has_children;
4687 new_die->abbrev = old_die->abbrev;
4688 new_die->offset = old_die->offset;
4689 new_die->type = NULL;
4691 num_attrs = old_die->num_attrs;
4692 new_die->num_attrs = num_attrs;
4693 new_die->attrs = (struct attribute *)
4694 xmalloc (num_attrs * sizeof (struct attribute));
4696 for (i = 0; i < old_die->num_attrs; ++i)
4698 new_die->attrs[i].name = old_die->attrs[i].name;
4699 new_die->attrs[i].form = old_die->attrs[i].form;
4700 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
4703 new_die->next = NULL;
4708 /* Return sibling of die, NULL if no sibling. */
4711 sibling_die (struct die_info *die)
4713 int nesting_level = 0;
4715 if (!die->has_children)
4717 if (die->next && (die->next->tag == 0))
4730 if (die->has_children)
4740 while (nesting_level);
4741 if (die && (die->tag == 0))
4752 /* Get linkage name of a die, return NULL if not found. */
4755 dwarf2_linkage_name (struct die_info *die)
4757 struct attribute *attr;
4759 attr = dwarf_attr (die, DW_AT_MIPS_linkage_name);
4760 if (attr && DW_STRING (attr))
4761 return DW_STRING (attr);
4762 attr = dwarf_attr (die, DW_AT_name);
4763 if (attr && DW_STRING (attr))
4764 return DW_STRING (attr);
4768 /* Convert a DIE tag into its string name. */
4771 dwarf_tag_name (register unsigned tag)
4775 case DW_TAG_padding:
4776 return "DW_TAG_padding";
4777 case DW_TAG_array_type:
4778 return "DW_TAG_array_type";
4779 case DW_TAG_class_type:
4780 return "DW_TAG_class_type";
4781 case DW_TAG_entry_point:
4782 return "DW_TAG_entry_point";
4783 case DW_TAG_enumeration_type:
4784 return "DW_TAG_enumeration_type";
4785 case DW_TAG_formal_parameter:
4786 return "DW_TAG_formal_parameter";
4787 case DW_TAG_imported_declaration:
4788 return "DW_TAG_imported_declaration";
4790 return "DW_TAG_label";
4791 case DW_TAG_lexical_block:
4792 return "DW_TAG_lexical_block";
4794 return "DW_TAG_member";
4795 case DW_TAG_pointer_type:
4796 return "DW_TAG_pointer_type";
4797 case DW_TAG_reference_type:
4798 return "DW_TAG_reference_type";
4799 case DW_TAG_compile_unit:
4800 return "DW_TAG_compile_unit";
4801 case DW_TAG_string_type:
4802 return "DW_TAG_string_type";
4803 case DW_TAG_structure_type:
4804 return "DW_TAG_structure_type";
4805 case DW_TAG_subroutine_type:
4806 return "DW_TAG_subroutine_type";
4807 case DW_TAG_typedef:
4808 return "DW_TAG_typedef";
4809 case DW_TAG_union_type:
4810 return "DW_TAG_union_type";
4811 case DW_TAG_unspecified_parameters:
4812 return "DW_TAG_unspecified_parameters";
4813 case DW_TAG_variant:
4814 return "DW_TAG_variant";
4815 case DW_TAG_common_block:
4816 return "DW_TAG_common_block";
4817 case DW_TAG_common_inclusion:
4818 return "DW_TAG_common_inclusion";
4819 case DW_TAG_inheritance:
4820 return "DW_TAG_inheritance";
4821 case DW_TAG_inlined_subroutine:
4822 return "DW_TAG_inlined_subroutine";
4824 return "DW_TAG_module";
4825 case DW_TAG_ptr_to_member_type:
4826 return "DW_TAG_ptr_to_member_type";
4827 case DW_TAG_set_type:
4828 return "DW_TAG_set_type";
4829 case DW_TAG_subrange_type:
4830 return "DW_TAG_subrange_type";
4831 case DW_TAG_with_stmt:
4832 return "DW_TAG_with_stmt";
4833 case DW_TAG_access_declaration:
4834 return "DW_TAG_access_declaration";
4835 case DW_TAG_base_type:
4836 return "DW_TAG_base_type";
4837 case DW_TAG_catch_block:
4838 return "DW_TAG_catch_block";
4839 case DW_TAG_const_type:
4840 return "DW_TAG_const_type";
4841 case DW_TAG_constant:
4842 return "DW_TAG_constant";
4843 case DW_TAG_enumerator:
4844 return "DW_TAG_enumerator";
4845 case DW_TAG_file_type:
4846 return "DW_TAG_file_type";
4848 return "DW_TAG_friend";
4849 case DW_TAG_namelist:
4850 return "DW_TAG_namelist";
4851 case DW_TAG_namelist_item:
4852 return "DW_TAG_namelist_item";
4853 case DW_TAG_packed_type:
4854 return "DW_TAG_packed_type";
4855 case DW_TAG_subprogram:
4856 return "DW_TAG_subprogram";
4857 case DW_TAG_template_type_param:
4858 return "DW_TAG_template_type_param";
4859 case DW_TAG_template_value_param:
4860 return "DW_TAG_template_value_param";
4861 case DW_TAG_thrown_type:
4862 return "DW_TAG_thrown_type";
4863 case DW_TAG_try_block:
4864 return "DW_TAG_try_block";
4865 case DW_TAG_variant_part:
4866 return "DW_TAG_variant_part";
4867 case DW_TAG_variable:
4868 return "DW_TAG_variable";
4869 case DW_TAG_volatile_type:
4870 return "DW_TAG_volatile_type";
4871 case DW_TAG_MIPS_loop:
4872 return "DW_TAG_MIPS_loop";
4873 case DW_TAG_format_label:
4874 return "DW_TAG_format_label";
4875 case DW_TAG_function_template:
4876 return "DW_TAG_function_template";
4877 case DW_TAG_class_template:
4878 return "DW_TAG_class_template";
4880 return "DW_TAG_<unknown>";
4884 /* Convert a DWARF attribute code into its string name. */
4887 dwarf_attr_name (register unsigned attr)
4892 return "DW_AT_sibling";
4893 case DW_AT_location:
4894 return "DW_AT_location";
4896 return "DW_AT_name";
4897 case DW_AT_ordering:
4898 return "DW_AT_ordering";
4899 case DW_AT_subscr_data:
4900 return "DW_AT_subscr_data";
4901 case DW_AT_byte_size:
4902 return "DW_AT_byte_size";
4903 case DW_AT_bit_offset:
4904 return "DW_AT_bit_offset";
4905 case DW_AT_bit_size:
4906 return "DW_AT_bit_size";
4907 case DW_AT_element_list:
4908 return "DW_AT_element_list";
4909 case DW_AT_stmt_list:
4910 return "DW_AT_stmt_list";
4912 return "DW_AT_low_pc";
4914 return "DW_AT_high_pc";
4915 case DW_AT_language:
4916 return "DW_AT_language";
4918 return "DW_AT_member";
4920 return "DW_AT_discr";
4921 case DW_AT_discr_value:
4922 return "DW_AT_discr_value";
4923 case DW_AT_visibility:
4924 return "DW_AT_visibility";
4926 return "DW_AT_import";
4927 case DW_AT_string_length:
4928 return "DW_AT_string_length";
4929 case DW_AT_common_reference:
4930 return "DW_AT_common_reference";
4931 case DW_AT_comp_dir:
4932 return "DW_AT_comp_dir";
4933 case DW_AT_const_value:
4934 return "DW_AT_const_value";
4935 case DW_AT_containing_type:
4936 return "DW_AT_containing_type";
4937 case DW_AT_default_value:
4938 return "DW_AT_default_value";
4940 return "DW_AT_inline";
4941 case DW_AT_is_optional:
4942 return "DW_AT_is_optional";
4943 case DW_AT_lower_bound:
4944 return "DW_AT_lower_bound";
4945 case DW_AT_producer:
4946 return "DW_AT_producer";
4947 case DW_AT_prototyped:
4948 return "DW_AT_prototyped";
4949 case DW_AT_return_addr:
4950 return "DW_AT_return_addr";
4951 case DW_AT_start_scope:
4952 return "DW_AT_start_scope";
4953 case DW_AT_stride_size:
4954 return "DW_AT_stride_size";
4955 case DW_AT_upper_bound:
4956 return "DW_AT_upper_bound";
4957 case DW_AT_abstract_origin:
4958 return "DW_AT_abstract_origin";
4959 case DW_AT_accessibility:
4960 return "DW_AT_accessibility";
4961 case DW_AT_address_class:
4962 return "DW_AT_address_class";
4963 case DW_AT_artificial:
4964 return "DW_AT_artificial";
4965 case DW_AT_base_types:
4966 return "DW_AT_base_types";
4967 case DW_AT_calling_convention:
4968 return "DW_AT_calling_convention";
4970 return "DW_AT_count";
4971 case DW_AT_data_member_location:
4972 return "DW_AT_data_member_location";
4973 case DW_AT_decl_column:
4974 return "DW_AT_decl_column";
4975 case DW_AT_decl_file:
4976 return "DW_AT_decl_file";
4977 case DW_AT_decl_line:
4978 return "DW_AT_decl_line";
4979 case DW_AT_declaration:
4980 return "DW_AT_declaration";
4981 case DW_AT_discr_list:
4982 return "DW_AT_discr_list";
4983 case DW_AT_encoding:
4984 return "DW_AT_encoding";
4985 case DW_AT_external:
4986 return "DW_AT_external";
4987 case DW_AT_frame_base:
4988 return "DW_AT_frame_base";
4990 return "DW_AT_friend";
4991 case DW_AT_identifier_case:
4992 return "DW_AT_identifier_case";
4993 case DW_AT_macro_info:
4994 return "DW_AT_macro_info";
4995 case DW_AT_namelist_items:
4996 return "DW_AT_namelist_items";
4997 case DW_AT_priority:
4998 return "DW_AT_priority";
5000 return "DW_AT_segment";
5001 case DW_AT_specification:
5002 return "DW_AT_specification";
5003 case DW_AT_static_link:
5004 return "DW_AT_static_link";
5006 return "DW_AT_type";
5007 case DW_AT_use_location:
5008 return "DW_AT_use_location";
5009 case DW_AT_variable_parameter:
5010 return "DW_AT_variable_parameter";
5011 case DW_AT_virtuality:
5012 return "DW_AT_virtuality";
5013 case DW_AT_vtable_elem_location:
5014 return "DW_AT_vtable_elem_location";
5017 case DW_AT_MIPS_fde:
5018 return "DW_AT_MIPS_fde";
5019 case DW_AT_MIPS_loop_begin:
5020 return "DW_AT_MIPS_loop_begin";
5021 case DW_AT_MIPS_tail_loop_begin:
5022 return "DW_AT_MIPS_tail_loop_begin";
5023 case DW_AT_MIPS_epilog_begin:
5024 return "DW_AT_MIPS_epilog_begin";
5025 case DW_AT_MIPS_loop_unroll_factor:
5026 return "DW_AT_MIPS_loop_unroll_factor";
5027 case DW_AT_MIPS_software_pipeline_depth:
5028 return "DW_AT_MIPS_software_pipeline_depth";
5029 case DW_AT_MIPS_linkage_name:
5030 return "DW_AT_MIPS_linkage_name";
5033 case DW_AT_sf_names:
5034 return "DW_AT_sf_names";
5035 case DW_AT_src_info:
5036 return "DW_AT_src_info";
5037 case DW_AT_mac_info:
5038 return "DW_AT_mac_info";
5039 case DW_AT_src_coords:
5040 return "DW_AT_src_coords";
5041 case DW_AT_body_begin:
5042 return "DW_AT_body_begin";
5043 case DW_AT_body_end:
5044 return "DW_AT_body_end";
5046 return "DW_AT_<unknown>";
5050 /* Convert a DWARF value form code into its string name. */
5053 dwarf_form_name (register unsigned form)
5058 return "DW_FORM_addr";
5059 case DW_FORM_block2:
5060 return "DW_FORM_block2";
5061 case DW_FORM_block4:
5062 return "DW_FORM_block4";
5064 return "DW_FORM_data2";
5066 return "DW_FORM_data4";
5068 return "DW_FORM_data8";
5069 case DW_FORM_string:
5070 return "DW_FORM_string";
5072 return "DW_FORM_block";
5073 case DW_FORM_block1:
5074 return "DW_FORM_block1";
5076 return "DW_FORM_data1";
5078 return "DW_FORM_flag";
5080 return "DW_FORM_sdata";
5082 return "DW_FORM_strp";
5084 return "DW_FORM_udata";
5085 case DW_FORM_ref_addr:
5086 return "DW_FORM_ref_addr";
5088 return "DW_FORM_ref1";
5090 return "DW_FORM_ref2";
5092 return "DW_FORM_ref4";
5094 return "DW_FORM_ref8";
5095 case DW_FORM_ref_udata:
5096 return "DW_FORM_ref_udata";
5097 case DW_FORM_indirect:
5098 return "DW_FORM_indirect";
5100 return "DW_FORM_<unknown>";
5104 /* Convert a DWARF stack opcode into its string name. */
5107 dwarf_stack_op_name (register unsigned op)
5112 return "DW_OP_addr";
5114 return "DW_OP_deref";
5116 return "DW_OP_const1u";
5118 return "DW_OP_const1s";
5120 return "DW_OP_const2u";
5122 return "DW_OP_const2s";
5124 return "DW_OP_const4u";
5126 return "DW_OP_const4s";
5128 return "DW_OP_const8u";
5130 return "DW_OP_const8s";
5132 return "DW_OP_constu";
5134 return "DW_OP_consts";
5138 return "DW_OP_drop";
5140 return "DW_OP_over";
5142 return "DW_OP_pick";
5144 return "DW_OP_swap";
5148 return "DW_OP_xderef";
5156 return "DW_OP_minus";
5168 return "DW_OP_plus";
5169 case DW_OP_plus_uconst:
5170 return "DW_OP_plus_uconst";
5176 return "DW_OP_shra";
5194 return "DW_OP_skip";
5196 return "DW_OP_lit0";
5198 return "DW_OP_lit1";
5200 return "DW_OP_lit2";
5202 return "DW_OP_lit3";
5204 return "DW_OP_lit4";
5206 return "DW_OP_lit5";
5208 return "DW_OP_lit6";
5210 return "DW_OP_lit7";
5212 return "DW_OP_lit8";
5214 return "DW_OP_lit9";
5216 return "DW_OP_lit10";
5218 return "DW_OP_lit11";
5220 return "DW_OP_lit12";
5222 return "DW_OP_lit13";
5224 return "DW_OP_lit14";
5226 return "DW_OP_lit15";
5228 return "DW_OP_lit16";
5230 return "DW_OP_lit17";
5232 return "DW_OP_lit18";
5234 return "DW_OP_lit19";
5236 return "DW_OP_lit20";
5238 return "DW_OP_lit21";
5240 return "DW_OP_lit22";
5242 return "DW_OP_lit23";
5244 return "DW_OP_lit24";
5246 return "DW_OP_lit25";
5248 return "DW_OP_lit26";
5250 return "DW_OP_lit27";
5252 return "DW_OP_lit28";
5254 return "DW_OP_lit29";
5256 return "DW_OP_lit30";
5258 return "DW_OP_lit31";
5260 return "DW_OP_reg0";
5262 return "DW_OP_reg1";
5264 return "DW_OP_reg2";
5266 return "DW_OP_reg3";
5268 return "DW_OP_reg4";
5270 return "DW_OP_reg5";
5272 return "DW_OP_reg6";
5274 return "DW_OP_reg7";
5276 return "DW_OP_reg8";
5278 return "DW_OP_reg9";
5280 return "DW_OP_reg10";
5282 return "DW_OP_reg11";
5284 return "DW_OP_reg12";
5286 return "DW_OP_reg13";
5288 return "DW_OP_reg14";
5290 return "DW_OP_reg15";
5292 return "DW_OP_reg16";
5294 return "DW_OP_reg17";
5296 return "DW_OP_reg18";
5298 return "DW_OP_reg19";
5300 return "DW_OP_reg20";
5302 return "DW_OP_reg21";
5304 return "DW_OP_reg22";
5306 return "DW_OP_reg23";
5308 return "DW_OP_reg24";
5310 return "DW_OP_reg25";
5312 return "DW_OP_reg26";
5314 return "DW_OP_reg27";
5316 return "DW_OP_reg28";
5318 return "DW_OP_reg29";
5320 return "DW_OP_reg30";
5322 return "DW_OP_reg31";
5324 return "DW_OP_breg0";
5326 return "DW_OP_breg1";
5328 return "DW_OP_breg2";
5330 return "DW_OP_breg3";
5332 return "DW_OP_breg4";
5334 return "DW_OP_breg5";
5336 return "DW_OP_breg6";
5338 return "DW_OP_breg7";
5340 return "DW_OP_breg8";
5342 return "DW_OP_breg9";
5344 return "DW_OP_breg10";
5346 return "DW_OP_breg11";
5348 return "DW_OP_breg12";
5350 return "DW_OP_breg13";
5352 return "DW_OP_breg14";
5354 return "DW_OP_breg15";
5356 return "DW_OP_breg16";
5358 return "DW_OP_breg17";
5360 return "DW_OP_breg18";
5362 return "DW_OP_breg19";
5364 return "DW_OP_breg20";
5366 return "DW_OP_breg21";
5368 return "DW_OP_breg22";
5370 return "DW_OP_breg23";
5372 return "DW_OP_breg24";
5374 return "DW_OP_breg25";
5376 return "DW_OP_breg26";
5378 return "DW_OP_breg27";
5380 return "DW_OP_breg28";
5382 return "DW_OP_breg29";
5384 return "DW_OP_breg30";
5386 return "DW_OP_breg31";
5388 return "DW_OP_regx";
5390 return "DW_OP_fbreg";
5392 return "DW_OP_bregx";
5394 return "DW_OP_piece";
5395 case DW_OP_deref_size:
5396 return "DW_OP_deref_size";
5397 case DW_OP_xderef_size:
5398 return "DW_OP_xderef_size";
5402 return "OP_<unknown>";
5407 dwarf_bool_name (unsigned mybool)
5415 /* Convert a DWARF type code into its string name. */
5418 dwarf_type_encoding_name (register unsigned enc)
5422 case DW_ATE_address:
5423 return "DW_ATE_address";
5424 case DW_ATE_boolean:
5425 return "DW_ATE_boolean";
5426 case DW_ATE_complex_float:
5427 return "DW_ATE_complex_float";
5429 return "DW_ATE_float";
5431 return "DW_ATE_signed";
5432 case DW_ATE_signed_char:
5433 return "DW_ATE_signed_char";
5434 case DW_ATE_unsigned:
5435 return "DW_ATE_unsigned";
5436 case DW_ATE_unsigned_char:
5437 return "DW_ATE_unsigned_char";
5439 return "DW_ATE_<unknown>";
5443 /* Convert a DWARF call frame info operation to its string name. */
5447 dwarf_cfi_name (register unsigned cfi_opc)
5451 case DW_CFA_advance_loc:
5452 return "DW_CFA_advance_loc";
5454 return "DW_CFA_offset";
5455 case DW_CFA_restore:
5456 return "DW_CFA_restore";
5458 return "DW_CFA_nop";
5459 case DW_CFA_set_loc:
5460 return "DW_CFA_set_loc";
5461 case DW_CFA_advance_loc1:
5462 return "DW_CFA_advance_loc1";
5463 case DW_CFA_advance_loc2:
5464 return "DW_CFA_advance_loc2";
5465 case DW_CFA_advance_loc4:
5466 return "DW_CFA_advance_loc4";
5467 case DW_CFA_offset_extended:
5468 return "DW_CFA_offset_extended";
5469 case DW_CFA_restore_extended:
5470 return "DW_CFA_restore_extended";
5471 case DW_CFA_undefined:
5472 return "DW_CFA_undefined";
5473 case DW_CFA_same_value:
5474 return "DW_CFA_same_value";
5475 case DW_CFA_register:
5476 return "DW_CFA_register";
5477 case DW_CFA_remember_state:
5478 return "DW_CFA_remember_state";
5479 case DW_CFA_restore_state:
5480 return "DW_CFA_restore_state";
5481 case DW_CFA_def_cfa:
5482 return "DW_CFA_def_cfa";
5483 case DW_CFA_def_cfa_register:
5484 return "DW_CFA_def_cfa_register";
5485 case DW_CFA_def_cfa_offset:
5486 return "DW_CFA_def_cfa_offset";
5487 /* SGI/MIPS specific */
5488 case DW_CFA_MIPS_advance_loc8:
5489 return "DW_CFA_MIPS_advance_loc8";
5491 return "DW_CFA_<unknown>";
5497 dump_die (struct die_info *die)
5501 fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n",
5502 dwarf_tag_name (die->tag), die->abbrev, die->offset);
5503 fprintf (stderr, "\thas children: %s\n",
5504 dwarf_bool_name (die->has_children));
5506 fprintf (stderr, "\tattributes:\n");
5507 for (i = 0; i < die->num_attrs; ++i)
5509 fprintf (stderr, "\t\t%s (%s) ",
5510 dwarf_attr_name (die->attrs[i].name),
5511 dwarf_form_name (die->attrs[i].form));
5512 switch (die->attrs[i].form)
5514 case DW_FORM_ref_addr:
5516 fprintf (stderr, "address: ");
5517 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
5519 case DW_FORM_block2:
5520 case DW_FORM_block4:
5522 case DW_FORM_block1:
5523 fprintf (stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
5534 fprintf (stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
5536 case DW_FORM_string:
5537 fprintf (stderr, "string: \"%s\"",
5538 DW_STRING (&die->attrs[i])
5539 ? DW_STRING (&die->attrs[i]) : "");
5542 if (DW_UNSND (&die->attrs[i]))
5543 fprintf (stderr, "flag: TRUE");
5545 fprintf (stderr, "flag: FALSE");
5547 case DW_FORM_strp: /* we do not support separate string
5549 case DW_FORM_indirect: /* we do not handle indirect yet */
5551 fprintf (stderr, "unsupported attribute form: %d.",
5552 die->attrs[i].form);
5554 fprintf (stderr, "\n");
5559 dump_die_list (struct die_info *die)
5569 store_in_ref_table (unsigned int offset, struct die_info *die)
5572 struct die_info *old;
5574 h = (offset % REF_HASH_SIZE);
5575 old = die_ref_table[h];
5576 die->next_ref = old;
5577 die_ref_table[h] = die;
5582 dwarf2_empty_hash_tables (void)
5584 memset (die_ref_table, 0, sizeof (die_ref_table));
5588 dwarf2_get_ref_die_offset (struct attribute *attr)
5590 unsigned int result = 0;
5594 case DW_FORM_ref_addr:
5595 result = DW_ADDR (attr);
5601 case DW_FORM_ref_udata:
5602 result = cu_header_offset + DW_UNSND (attr);
5605 complain (&dwarf2_unsupported_die_ref_attr, dwarf_form_name (attr->form));
5611 follow_die_ref (unsigned int offset)
5613 struct die_info *die;
5616 h = (offset % REF_HASH_SIZE);
5617 die = die_ref_table[h];
5620 if (die->offset == offset)
5624 die = die->next_ref;
5629 static struct type *
5630 dwarf2_fundamental_type (struct objfile *objfile, int typeid)
5632 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
5634 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5638 /* Look for this particular type in the fundamental type vector. If
5639 one is not found, create and install one appropriate for the
5640 current language and the current target machine. */
5642 if (ftypes[typeid] == NULL)
5644 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
5647 return (ftypes[typeid]);
5650 /* Decode simple location descriptions.
5651 Given a pointer to a dwarf block that defines a location, compute
5652 the location and return the value.
5654 FIXME: This is a kludge until we figure out a better
5655 way to handle the location descriptions.
5656 Gdb's design does not mesh well with the DWARF2 notion of a location
5657 computing interpreter, which is a shame because the flexibility goes unused.
5658 FIXME: Implement more operations as necessary.
5660 A location description containing no operations indicates that the
5661 object is optimized out. The global optimized_out flag is set for
5662 those, the return value is meaningless.
5664 When the result is a register number, the global isreg flag is set,
5665 otherwise it is cleared.
5667 When the result is a base register offset, the global offreg flag is set
5668 and the register number is returned in basereg, otherwise it is cleared.
5670 When the DW_OP_fbreg operation is encountered without a corresponding
5671 DW_AT_frame_base attribute, the global islocal flag is set.
5672 Hopefully the machine dependent code knows how to set up a virtual
5673 frame pointer for the local references.
5675 Note that stack[0] is unused except as a default error return.
5676 Note that stack overflow is not yet handled. */
5679 decode_locdesc (struct dwarf_block *blk, struct objfile *objfile,
5680 const struct comp_unit_head *cu_header)
5683 int size = blk->size;
5684 char *data = blk->data;
5685 CORE_ADDR stack[64];
5687 unsigned int bytes_read, unsnd;
5738 stack[++stacki] = op - DW_OP_reg0;
5743 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5745 #if defined(HARRIS_TARGET) && defined(_M88K)
5746 /* The Harris 88110 gdb ports have long kept their special reg
5747 numbers between their gp-regs and their x-regs. This is
5748 not how our dwarf is generated. Punt. */
5751 stack[++stacki] = unsnd;
5787 basereg = op - DW_OP_breg0;
5788 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5794 basereg = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5796 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5801 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5803 if (frame_base_reg >= 0)
5806 basereg = frame_base_reg;
5807 stack[stacki] += frame_base_offset;
5811 complain (&dwarf2_missing_at_frame_base);
5817 stack[++stacki] = read_address (objfile->obfd, &data[i],
5818 cu_header, &bytes_read);
5823 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
5828 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
5833 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
5838 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
5843 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
5848 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
5853 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
5859 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5864 stack[stacki - 1] += stack[stacki];
5868 case DW_OP_plus_uconst:
5869 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5874 stack[stacki - 1] = stack[stacki] - stack[stacki - 1];
5880 /* If we're not the last op, then we definitely can't encode
5881 this using GDB's address_class enum. */
5883 complain (&dwarf2_complex_location_expr);
5887 complain (&dwarf2_unsupported_stack_op, dwarf_stack_op_name (op));
5888 return (stack[stacki]);
5891 return (stack[stacki]);
5894 /* memory allocation interface */
5898 dwarf2_free_tmp_obstack (PTR ignore)
5900 obstack_free (&dwarf2_tmp_obstack, NULL);
5903 static struct dwarf_block *
5904 dwarf_alloc_block (void)
5906 struct dwarf_block *blk;
5908 blk = (struct dwarf_block *)
5909 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
5913 static struct abbrev_info *
5914 dwarf_alloc_abbrev (void)
5916 struct abbrev_info *abbrev;
5918 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
5919 memset (abbrev, 0, sizeof (struct abbrev_info));
5923 static struct die_info *
5924 dwarf_alloc_die (void)
5926 struct die_info *die;
5928 die = (struct die_info *) xmalloc (sizeof (struct die_info));
5929 memset (die, 0, sizeof (struct die_info));