1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996 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, Boston, MA 02111-1307, USA. */
33 #include "elf/dwarf2.h"
36 #include "expression.h"
38 #include "complaints.h"
41 #include "gdb_string.h"
42 #include <sys/types.h>
44 /* .debug_info header for a compilation unit
45 Because of alignment constraints, this structure has padding and cannot
46 be mapped directly onto the beginning of the .debug_info section. */
47 typedef struct comp_unit_header
49 unsigned int length; /* length of the .debug_info
51 unsigned short version; /* version number -- 2 for DWARF
53 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
54 unsigned char addr_size; /* byte size of an address -- 4 */
57 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
59 /* .debug_pubnames header
60 Because of alignment constraints, this structure has padding and cannot
61 be mapped directly onto the beginning of the .debug_info section. */
62 typedef struct pubnames_header
64 unsigned int length; /* length of the .debug_pubnames
66 unsigned char version; /* version number -- 2 for DWARF
68 unsigned int info_offset; /* offset into .debug_info section */
69 unsigned int info_size; /* byte size of .debug_info section
73 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
75 /* .debug_pubnames header
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct aranges_header
80 unsigned int length; /* byte len of the .debug_aranges
82 unsigned short version; /* version number -- 2 for DWARF
84 unsigned int info_offset; /* offset into .debug_info section */
85 unsigned char addr_size; /* byte size of an address */
86 unsigned char seg_size; /* byte size of segment descriptor */
89 #define _ACTUAL_ARANGES_HEADER_SIZE 12
91 /* .debug_line statement program prologue
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct statement_prologue
96 unsigned int total_length; /* byte length of the statement
98 unsigned short version; /* version number -- 2 for DWARF
100 unsigned int prologue_length; /* # bytes between prologue &
102 unsigned char minimum_instruction_length; /* byte size of
104 unsigned char default_is_stmt; /* initial value of is_stmt
107 unsigned char line_range;
108 unsigned char opcode_base; /* number assigned to first special
110 unsigned char *standard_opcode_lengths;
114 /* offsets and sizes of debugging sections */
116 static file_ptr dwarf_info_offset;
117 static file_ptr dwarf_abbrev_offset;
118 static file_ptr dwarf_line_offset;
119 static file_ptr dwarf_pubnames_offset;
120 static file_ptr dwarf_aranges_offset;
121 static file_ptr dwarf_loc_offset;
122 static file_ptr dwarf_macinfo_offset;
123 static file_ptr dwarf_str_offset;
125 static unsigned int dwarf_info_size;
126 static unsigned int dwarf_abbrev_size;
127 static unsigned int dwarf_line_size;
128 static unsigned int dwarf_pubnames_size;
129 static unsigned int dwarf_aranges_size;
130 static unsigned int dwarf_loc_size;
131 static unsigned int dwarf_macinfo_size;
132 static unsigned int dwarf_str_size;
134 /* names of the debugging sections */
136 #define INFO_SECTION ".debug_info"
137 #define ABBREV_SECTION ".debug_abbrev"
138 #define LINE_SECTION ".debug_line"
139 #define PUBNAMES_SECTION ".debug_pubnames"
140 #define ARANGES_SECTION ".debug_aranges"
141 #define LOC_SECTION ".debug_loc"
142 #define MACINFO_SECTION ".debug_macinfo"
143 #define STR_SECTION ".debug_str"
145 /* Get at parts of an attribute structure */
147 #define DW_STRING(attr) ((attr)->u.str)
148 #define DW_UNSND(attr) ((attr)->u.unsnd)
149 #define DW_BLOCK(attr) ((attr)->u.blk)
150 #define DW_SND(attr) ((attr)->u.snd)
151 #define DW_ADDR(attr) ((attr)->u.addr)
153 /* local data types */
155 /* The data in a compilation unit header looks like this. */
156 struct comp_unit_head
161 unsigned char addr_size;
164 /* The data in the .debug_line statement prologue looks like this. */
167 unsigned int total_length;
168 unsigned short version;
169 unsigned int prologue_length;
170 unsigned char minimum_instruction_length;
171 unsigned char default_is_stmt;
173 unsigned char line_range;
174 unsigned char opcode_base;
175 unsigned char *standard_opcode_lengths;
178 /* When we construct a partial symbol table entry we only
179 need this much information. */
180 struct partial_die_info
183 unsigned char has_children;
184 unsigned char is_external;
185 unsigned char is_declaration;
191 struct dwarf_block *locdesc;
192 unsigned int language;
196 /* This data structure holds the information of an abbrev. */
199 unsigned int number; /* number identifying abbrev */
200 unsigned int tag; /* dwarf tag */
201 int has_children; /* boolean */
202 unsigned int num_attrs; /* number of attributes */
203 struct attr_abbrev *attrs; /* an array of attribute descriptions */
204 struct abbrev_info *next; /* next in chain */
213 /* This data structure holds a complete die structure. */
216 unsigned short tag; /* Tag indicating type of die */
217 unsigned short has_children; /* Does the die have children */
218 unsigned int abbrev; /* Abbrev number */
219 unsigned int offset; /* Offset in .debug_info section */
220 unsigned int num_attrs; /* Number of attributes */
221 struct attribute *attrs; /* An array of attributes */
222 struct die_info *next_ref; /* Next die in ref hash table */
223 struct die_info *next; /* Next die in linked list */
224 struct type *type; /* Cached type information */
227 /* Attributes have a name and a value */
235 struct dwarf_block *blk;
243 /* Blocks are a bunch of untyped bytes. */
250 /* We only hold one compilation unit's abbrevs in
251 memory at any one time. */
252 #ifndef ABBREV_HASH_SIZE
253 #define ABBREV_HASH_SIZE 121
255 #ifndef ATTR_ALLOC_CHUNK
256 #define ATTR_ALLOC_CHUNK 4
259 static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
261 /* A hash table of die offsets for following references. */
262 #ifndef REF_HASH_SIZE
263 #define REF_HASH_SIZE 1021
266 static struct die_info *die_ref_table[REF_HASH_SIZE];
268 /* Obstack for allocating temporary storage used during symbol reading. */
269 static struct obstack dwarf2_tmp_obstack;
271 /* Offset to the first byte of the current compilation unit header,
272 for resolving relative reference dies. */
273 static unsigned int cu_header_offset;
275 /* Allocate fields for structs, unions and enums in this size. */
276 #ifndef DW_FIELD_ALLOC_CHUNK
277 #define DW_FIELD_ALLOC_CHUNK 4
280 /* The language we are debugging. */
281 static enum language cu_language;
282 static const struct language_defn *cu_language_defn;
284 /* Actually data from the sections. */
285 static char *dwarf_info_buffer;
286 static char *dwarf_abbrev_buffer;
287 static char *dwarf_line_buffer;
289 /* A zeroed version of a partial die for initialization purposes. */
290 static struct partial_die_info zeroed_partial_die;
292 /* The generic symbol table building routines have separate lists for
293 file scope symbols and all all other scopes (local scopes). So
294 we need to select the right one to pass to add_symbol_to_list().
295 We do it by keeping a pointer to the correct list in list_in_scope.
297 FIXME: The original dwarf code just treated the file scope as the first
298 local scope, and all other local scopes as nested local scopes, and worked
299 fine. Check to see if we really need to distinguish these
301 static struct pending **list_in_scope = &file_symbols;
303 /* FIXME: The following variables pass additional information from
304 decode_locdesc to the caller. */
305 static int optimized_out; /* Kludge to identify optimized out variables */
306 static int isreg; /* Kludge to identify register variables */
307 static int offreg; /* Kludge to identify basereg references */
308 static int basereg; /* Which base register is it relative to? */
309 static int islocal; /* Kludge to identify local variables */
311 /* DW_AT_frame_base values for the current function.
312 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
313 contains the register number for the frame register.
314 frame_base_offset is the offset from the frame register to the
315 virtual stack frame. */
316 static int frame_base_reg;
317 static CORE_ADDR frame_base_offset;
319 /* This value is added to each symbol value. FIXME: Generalize to
320 the section_offsets structure used by dbxread (once this is done,
321 pass the appropriate section number to end_symtab). */
322 static CORE_ADDR baseaddr; /* Add to each symbol value */
324 /* We put a pointer to this structure in the read_symtab_private field
326 The complete dwarf information for an objfile is kept in the
327 psymbol_obstack, so that absolute die references can be handled.
328 Most of the information in this structure is related to an entire
329 object file and could be passed via the sym_private field of the objfile.
330 It is however conceivable that dwarf2 might not be the only type
331 of symbols read from an object file. */
335 /* Pointer to start of dwarf info buffer for the objfile. */
337 char *dwarf_info_buffer;
339 /* Offset in dwarf_info_buffer for this compilation unit. */
341 unsigned long dwarf_info_offset;
343 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
345 char *dwarf_abbrev_buffer;
347 /* Size of dwarf abbreviation section for the objfile. */
349 unsigned int dwarf_abbrev_size;
351 /* Pointer to start of dwarf line buffer for the objfile. */
353 char *dwarf_line_buffer;
356 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
357 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
358 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
359 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
360 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
361 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
363 /* Maintain an array of referenced fundamental types for the current
364 compilation unit being read. For DWARF version 1, we have to construct
365 the fundamental types on the fly, since no information about the
366 fundamental types is supplied. Each such fundamental type is created by
367 calling a language dependent routine to create the type, and then a
368 pointer to that type is then placed in the array at the index specified
369 by it's FT_<TYPENAME> value. The array has a fixed size set by the
370 FT_NUM_MEMBERS compile time constant, which is the number of predefined
371 fundamental types gdb knows how to construct. */
372 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
374 /* FIXME - set from bfd function */
375 static int bits_per_byte = 8;
377 /* Various complaints about symbol reading that don't abort the process */
379 static struct complaint dwarf2_const_ignored =
381 "type qualifier 'const' ignored", 0, 0
383 static struct complaint dwarf2_volatile_ignored =
385 "type qualifier 'volatile' ignored", 0, 0
387 static struct complaint dwarf2_non_const_array_bound_ignored =
389 "non-constant array bounds form %s ignored", 0, 0
391 static struct complaint dwarf2_missing_line_number_section =
393 "missing .debug_line section", 0, 0
395 static struct complaint dwarf2_mangled_line_number_section =
397 "mangled .debug_line section", 0, 0
399 static struct complaint dwarf2_unsupported_die_ref_attr =
401 "unsupported die ref attribute form: %s", 0, 0
403 static struct complaint dwarf2_unsupported_stack_op =
405 "unsupported stack op: '%s'", 0, 0
407 static struct complaint dwarf2_unsupported_tag =
409 "unsupported tag: '%s'", 0, 0
411 static struct complaint dwarf2_unsupported_at_encoding =
413 "unsupported DW_AT_encoding: '%s'", 0, 0
415 static struct complaint dwarf2_unsupported_at_frame_base =
417 "unsupported DW_AT_frame_base for function '%s'", 0, 0
419 static struct complaint dwarf2_missing_at_frame_base =
421 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
423 static struct complaint dwarf2_bad_static_member_name =
425 "unrecognized static data member name %s", 0, 0
428 /* Remember the addr_size read from the dwarf.
429 If a target expects to link compilation units with differing address
430 sizes, gdb needs to be sure that the appropriate size is here for
431 whatever scope is currently getting read. */
432 static int address_size;
434 /* Externals references. */
435 extern int info_verbose; /* From main.c; nonzero => verbose */
437 /* local function prototypes */
439 static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR));
442 static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *,
443 struct section_offsets *,
447 static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *,
448 struct section_offsets *,
451 static char *scan_partial_symbols PARAMS ((char *, struct objfile *,
452 CORE_ADDR *, CORE_ADDR *));
454 static void add_partial_symbol PARAMS ((struct partial_die_info *,
457 static void dwarf2_psymtab_to_symtab PARAMS ((struct partial_symtab *));
459 static void psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
461 static char *dwarf2_read_section PARAMS ((struct objfile *, file_ptr,
464 static void dwarf2_read_abbrevs PARAMS ((bfd *, unsigned int));
466 static void dwarf2_empty_abbrev_table PARAMS ((PTR));
468 static struct abbrev_info *dwarf2_lookup_abbrev PARAMS ((unsigned int));
470 static char *read_partial_die PARAMS ((struct partial_die_info *,
471 bfd *, char *, int *));
473 static char *read_full_die PARAMS ((struct die_info **, bfd *, char *));
475 static unsigned int read_1_byte PARAMS ((bfd *, char *));
477 static int read_1_signed_byte PARAMS ((bfd *, char *));
479 static unsigned int read_2_bytes PARAMS ((bfd *, char *));
481 static unsigned int read_4_bytes PARAMS ((bfd *, char *));
483 static unsigned int read_8_bytes PARAMS ((bfd *, char *));
485 static CORE_ADDR read_address PARAMS ((bfd *, char *));
487 static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
489 static char *read_string PARAMS ((bfd *, char *, unsigned int *));
491 static unsigned int read_unsigned_leb128 PARAMS ((bfd *, char *,
494 static int read_signed_leb128 PARAMS ((bfd *, char *, unsigned int *));
496 static void set_cu_language PARAMS ((unsigned int));
498 static struct attribute *dwarf_attr PARAMS ((struct die_info *,
501 static void dwarf_decode_lines PARAMS ((unsigned int, char *, bfd *));
503 static void dwarf2_start_subfile PARAMS ((char *, char *));
505 static struct symbol *new_symbol PARAMS ((struct die_info *, struct type *,
508 static struct type *die_type PARAMS ((struct die_info *, struct objfile *));
510 static struct type *die_containing_type PARAMS ((struct die_info *,
514 static struct type *type_at_offset PARAMS ((unsigned int, struct objfile *));
517 static struct type *tag_type_to_type PARAMS ((struct die_info *,
520 static void read_type_die PARAMS ((struct die_info *, struct objfile *));
522 static void read_typedef PARAMS ((struct die_info *, struct objfile *));
524 static void read_base_type PARAMS ((struct die_info *, struct objfile *));
526 static void read_file_scope PARAMS ((struct die_info *, struct objfile *));
528 static void read_func_scope PARAMS ((struct die_info *, struct objfile *));
530 static void read_lexical_block_scope PARAMS ((struct die_info *,
533 static void read_structure_scope PARAMS ((struct die_info *, struct objfile *));
535 static void read_common_block PARAMS ((struct die_info *, struct objfile *));
537 static void read_enumeration PARAMS ((struct die_info *, struct objfile *));
539 static struct type * dwarf_base_type PARAMS ((int, int));
541 static CORE_ADDR decode_locdesc PARAMS ((struct dwarf_block *,
544 static void dwarf_read_array_type PARAMS ((struct die_info *,
547 static void read_tag_pointer_type PARAMS ((struct die_info *,
550 static void read_tag_ptr_to_member_type PARAMS ((struct die_info *,
553 static void read_tag_reference_type PARAMS ((struct die_info *,
556 static void read_tag_const_type PARAMS ((struct die_info *, struct objfile *));
558 static void read_tag_volatile_type PARAMS ((struct die_info *,
561 static void read_tag_string_type PARAMS ((struct die_info *,
564 static void read_subroutine_type PARAMS ((struct die_info *,
567 struct die_info *read_comp_unit PARAMS ((char *, bfd *));
569 static void free_die_list PARAMS ((struct die_info *));
571 static void process_die PARAMS ((struct die_info *, struct objfile *));
573 static char *dwarf_tag_name PARAMS ((unsigned int));
575 static char *dwarf_attr_name PARAMS ((unsigned int));
577 static char *dwarf_form_name PARAMS ((unsigned int));
579 static char *dwarf_stack_op_name PARAMS ((unsigned int));
581 static char *dwarf_bool_name PARAMS ((unsigned int));
583 static char *dwarf_bool_name PARAMS ((unsigned int));
585 static char *dwarf_type_encoding_name PARAMS ((unsigned int));
588 static char *dwarf_cfi_name PARAMS ((unsigned int));
590 struct die_info *copy_die PARAMS ((struct die_info *));
593 struct die_info *sibling_die PARAMS ((struct die_info *));
595 void dump_die PARAMS ((struct die_info *));
597 void dump_die_list PARAMS ((struct die_info *));
599 void store_in_ref_table PARAMS ((unsigned int, struct die_info *));
601 static void dwarf2_empty_die_ref_table PARAMS ((void));
603 static unsigned int dwarf2_get_ref_die_offset PARAMS ((struct attribute *));
605 struct die_info *follow_die_ref PARAMS ((unsigned int));
607 static struct type *dwarf2_fundamental_type PARAMS ((struct objfile *, int));
609 /* memory allocation interface */
611 static void dwarf2_free_tmp_obstack PARAMS ((PTR));
613 static struct dwarf_block *dwarf_alloc_block PARAMS ((void));
615 static struct abbrev_info *dwarf_alloc_abbrev PARAMS ((void));
617 static struct die_info *dwarf_alloc_die PARAMS ((void));
619 /* Try to locate the sections we need for DWARF 2 debugging
620 information and return true if we have enough to do something. */
623 dwarf2_has_info (abfd)
626 dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
627 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
628 if (dwarf_info_offset && dwarf_abbrev_offset)
638 /* This function is mapped across the sections and remembers the
639 offset and size of each of the debugging sections we are interested
643 dwarf2_locate_sections (ignore_abfd, sectp, ignore_ptr)
648 if (STREQ (sectp->name, INFO_SECTION))
650 dwarf_info_offset = sectp->filepos;
651 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
653 else if (STREQ (sectp->name, ABBREV_SECTION))
655 dwarf_abbrev_offset = sectp->filepos;
656 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
658 else if (STREQ (sectp->name, LINE_SECTION))
660 dwarf_line_offset = sectp->filepos;
661 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
663 else if (STREQ (sectp->name, PUBNAMES_SECTION))
665 dwarf_pubnames_offset = sectp->filepos;
666 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
668 else if (STREQ (sectp->name, ARANGES_SECTION))
670 dwarf_aranges_offset = sectp->filepos;
671 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
673 else if (STREQ (sectp->name, LOC_SECTION))
675 dwarf_loc_offset = sectp->filepos;
676 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
678 else if (STREQ (sectp->name, MACINFO_SECTION))
680 dwarf_macinfo_offset = sectp->filepos;
681 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
683 else if (STREQ (sectp->name, STR_SECTION))
685 dwarf_str_offset = sectp->filepos;
686 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
690 /* Build a partial symbol table. */
693 dwarf2_build_psymtabs (objfile, section_offsets, mainline)
694 struct objfile *objfile;
695 struct section_offsets *section_offsets;
699 /* We definitely need the .debug_info and .debug_abbrev sections */
701 dwarf_info_buffer = dwarf2_read_section (objfile,
704 dwarf_abbrev_buffer = dwarf2_read_section (objfile,
707 dwarf_line_buffer = dwarf2_read_section (objfile,
711 if (mainline || objfile->global_psymbols.size == 0 ||
712 objfile->static_psymbols.size == 0)
714 init_psymbol_list (objfile, 1024);
718 if (dwarf_aranges_offset && dwarf_pubnames_offset)
720 /* Things are significanlty easier if we have .debug_aranges and
721 .debug_pubnames sections */
723 dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline);
727 /* only test this case for now */
729 /* In this case we have to work a bit harder */
730 dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline);
735 /* Build the partial symbol table from the information in the
736 .debug_pubnames and .debug_aranges sections. */
739 dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline)
740 struct objfile *objfile;
741 struct section_offsets *section_offsets;
744 bfd *abfd = objfile->obfd;
745 char *aranges_buffer, *pubnames_buffer;
746 char *aranges_ptr, *pubnames_ptr;
747 unsigned int entry_length, version, info_offset, info_size;
749 pubnames_buffer = dwarf2_read_section (objfile,
750 dwarf_pubnames_offset,
751 dwarf_pubnames_size);
752 pubnames_ptr = pubnames_buffer;
753 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
755 entry_length = read_4_bytes (abfd, pubnames_ptr);
757 version = read_1_byte (abfd, pubnames_ptr);
759 info_offset = read_4_bytes (abfd, pubnames_ptr);
761 info_size = read_4_bytes (abfd, pubnames_ptr);
765 aranges_buffer = dwarf2_read_section (objfile,
766 dwarf_aranges_offset,
772 /* Build the partial symbol table by doing a quick pass through the
773 .debug_info and .debug_abbrev sections. */
776 dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline)
777 struct objfile *objfile;
778 struct section_offsets *section_offsets;
781 /* Instead of reading this into a big buffer, we should probably use
782 mmap() on architectures that support it. (FIXME) */
783 bfd *abfd = objfile->obfd;
784 char *info_ptr, *abbrev_ptr;
785 char *beg_of_comp_unit;
786 struct comp_unit_head cu_header;
787 struct partial_die_info comp_unit_die;
788 struct partial_symtab *pst;
789 struct cleanup *back_to;
790 int comp_unit_has_pc_info;
791 CORE_ADDR lowpc, highpc;
793 info_ptr = dwarf_info_buffer;
794 abbrev_ptr = dwarf_abbrev_buffer;
796 obstack_init (&dwarf2_tmp_obstack);
797 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
799 while ((unsigned int) (info_ptr - dwarf_info_buffer)
800 + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
802 beg_of_comp_unit = info_ptr;
803 cu_header.length = read_4_bytes (abfd, info_ptr);
805 cu_header.version = read_2_bytes (abfd, info_ptr);
807 cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
809 cu_header.addr_size = read_1_byte (abfd, info_ptr);
811 address_size = cu_header.addr_size;
813 if (cu_header.version != 2)
815 error ("Dwarf Error: wrong version in compilation unit header.");
819 /* Read the abbrevs for this compilation unit into a table */
820 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
821 make_cleanup (dwarf2_empty_abbrev_table, NULL);
823 /* Read the compilation unit die */
824 info_ptr = read_partial_die (&comp_unit_die, abfd,
825 info_ptr, &comp_unit_has_pc_info);
827 /* Set the language we're debugging */
828 set_cu_language (comp_unit_die.language);
830 /* Allocate a new partial symbol table structure */
831 pst = start_psymtab_common (objfile, section_offsets,
834 objfile->global_psymbols.next,
835 objfile->static_psymbols.next);
837 pst->read_symtab_private = (char *)
838 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
839 DWARF_INFO_BUFFER(pst) = dwarf_info_buffer;
840 DWARF_INFO_OFFSET(pst) = beg_of_comp_unit - dwarf_info_buffer;
841 DWARF_ABBREV_BUFFER(pst) = dwarf_abbrev_buffer;
842 DWARF_ABBREV_SIZE(pst) = dwarf_abbrev_size;
843 DWARF_LINE_BUFFER(pst) = dwarf_line_buffer;
844 baseaddr = ANOFFSET (section_offsets, 0);
846 /* Store the function that reads in the rest of the symbol table */
847 pst->read_symtab = dwarf2_psymtab_to_symtab;
849 /* Read the rest of the partial symbols from this comp unit */
850 info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc);
852 /* If the compilation unit didn't have an explicit address range,
853 then use the information extracted from its child dies. */
854 if (!comp_unit_has_pc_info)
856 comp_unit_die.lowpc = lowpc;
857 comp_unit_die.highpc = highpc;
859 pst->textlow = comp_unit_die.lowpc + baseaddr;
860 pst->texthigh = comp_unit_die.highpc + baseaddr;
862 pst->n_global_syms = objfile->global_psymbols.next -
863 (objfile->global_psymbols.list + pst->globals_offset);
864 pst->n_static_syms = objfile->static_psymbols.next -
865 (objfile->static_psymbols.list + pst->statics_offset);
866 sort_pst_symbols (pst);
868 /* If there is already a psymtab or symtab for a file of this
869 name, remove it. (If there is a symtab, more drastic things
870 also happen.) This happens in VxWorks. */
871 free_named_symtabs (pst->filename);
873 info_ptr = beg_of_comp_unit + cu_header.length + 4;
875 do_cleanups (back_to);
878 /* Read in all interesting dies to the end of the compilation unit. */
881 scan_partial_symbols (info_ptr, objfile, lowpc, highpc)
883 struct objfile *objfile;
887 bfd *abfd = objfile->obfd;
888 struct partial_die_info pdi;
889 int nesting_level = 1; /* we've already read in comp_unit_die */
892 *lowpc = ((CORE_ADDR) -1);
893 *highpc = ((CORE_ADDR) 0);
896 info_ptr = read_partial_die (&pdi, abfd, info_ptr, &has_pc_info);
899 case DW_TAG_subprogram:
900 case DW_TAG_variable:
902 case DW_TAG_class_type:
903 case DW_TAG_structure_type:
904 case DW_TAG_union_type:
905 case DW_TAG_enumeration_type:
906 if (pdi.is_external || nesting_level == 1)
908 if (pdi.name && !pdi.is_declaration)
910 add_partial_symbol (&pdi, objfile);
915 if (pdi.lowpc < *lowpc)
919 if (pdi.highpc > *highpc)
921 *highpc = pdi.highpc;
925 case DW_TAG_enumerator:
926 /* File scope enumerators are added to the partial symbol table. */
927 if (pdi.name && nesting_level == 2)
928 add_partial_symbol (&pdi, objfile);
931 if (pdi.has_children)
940 while (nesting_level);
942 /* If we didn't find a lowpc, set it to highpc to avoid complaints
943 from `maint check. */
944 if (*lowpc == ((CORE_ADDR) -1))
950 add_partial_symbol (pdi, objfile)
951 struct partial_die_info *pdi;
952 struct objfile *objfile;
956 case DW_TAG_subprogram:
957 if (pdi->is_external)
959 prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
961 add_psymbol_to_list (pdi->name, strlen (pdi->name),
962 VAR_NAMESPACE, LOC_BLOCK,
963 &objfile->global_psymbols,
964 0, pdi->lowpc + baseaddr, cu_language, objfile);
968 prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
969 mst_file_text, objfile);
970 add_psymbol_to_list (pdi->name, strlen (pdi->name),
971 VAR_NAMESPACE, LOC_BLOCK,
972 &objfile->static_psymbols,
973 0, pdi->lowpc + baseaddr, cu_language, objfile);
976 case DW_TAG_variable:
977 /* Skip symbols without location desciptors, these are external
979 if (pdi->locdesc == NULL)
981 if (pdi->is_external)
983 prim_record_minimal_symbol (pdi->name,
984 decode_locdesc (pdi->locdesc, objfile)
987 add_psymbol_to_list (pdi->name, strlen (pdi->name),
988 VAR_NAMESPACE, LOC_STATIC,
989 &objfile->global_psymbols,
990 0, (CORE_ADDR) 0, cu_language, objfile);
994 prim_record_minimal_symbol (pdi->name,
995 decode_locdesc (pdi->locdesc, objfile)
997 mst_file_data, objfile);
998 add_psymbol_to_list (pdi->name, strlen (pdi->name),
999 VAR_NAMESPACE, LOC_STATIC,
1000 &objfile->static_psymbols,
1001 0, (CORE_ADDR) 0, cu_language, objfile);
1004 case DW_TAG_typedef:
1005 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1006 VAR_NAMESPACE, LOC_TYPEDEF,
1007 &objfile->static_psymbols,
1008 0, (CORE_ADDR) 0, cu_language, objfile);
1010 case DW_TAG_class_type:
1011 case DW_TAG_structure_type:
1012 case DW_TAG_union_type:
1013 case DW_TAG_enumeration_type:
1014 /* Skip aggregate types without children, these are external
1016 if (pdi->has_children == 0)
1018 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1019 STRUCT_NAMESPACE, LOC_TYPEDEF,
1020 &objfile->static_psymbols,
1021 0, (CORE_ADDR) 0, cu_language, objfile);
1023 if (cu_language == language_cplus)
1025 /* For C++, these implicitly act as typedefs as well. */
1026 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1027 VAR_NAMESPACE, LOC_TYPEDEF,
1028 &objfile->static_psymbols,
1029 0, (CORE_ADDR) 0, cu_language, objfile);
1032 case DW_TAG_enumerator:
1033 add_psymbol_to_list (pdi->name, strlen (pdi->name),
1034 VAR_NAMESPACE, LOC_CONST,
1035 &objfile->static_psymbols,
1036 0, (CORE_ADDR) 0, cu_language, objfile);
1041 /* Expand this partial symbol table into a full symbol table. */
1044 dwarf2_psymtab_to_symtab (pst)
1045 struct partial_symtab *pst;
1047 /* FIXME: This is barely more than a stub. */
1052 warning ("bug: psymtab for %s is already read in.", pst->filename);
1058 printf_filtered ("Reading in symbols for %s...", pst->filename);
1059 gdb_flush (gdb_stdout);
1062 psymtab_to_symtab_1 (pst);
1064 /* Finish up the debug error message. */
1066 printf_filtered ("done.\n");
1072 psymtab_to_symtab_1 (pst)
1073 struct partial_symtab *pst;
1075 struct objfile *objfile = pst->objfile;
1076 bfd *abfd = objfile->obfd;
1077 struct comp_unit_head cu_header;
1078 struct die_info *dies;
1079 struct attribute *attr;
1080 unsigned long offset;
1082 struct attribute *high_pc_attr;
1083 struct die_info *child_die;
1085 struct symtab *symtab;
1086 struct cleanup *back_to;
1088 /* Set local variables from the partial symbol table info. */
1089 offset = DWARF_INFO_OFFSET(pst);
1090 dwarf_info_buffer = DWARF_INFO_BUFFER(pst);
1091 dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER(pst);
1092 dwarf_abbrev_size = DWARF_ABBREV_SIZE(pst);
1093 dwarf_line_buffer = DWARF_LINE_BUFFER(pst);
1094 baseaddr = ANOFFSET (pst->section_offsets, 0);
1095 cu_header_offset = offset;
1096 info_ptr = dwarf_info_buffer + offset;
1098 obstack_init (&dwarf2_tmp_obstack);
1099 back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1102 make_cleanup (really_free_pendings, NULL);
1104 /* read in the comp_unit header */
1105 cu_header.length = read_4_bytes (abfd, info_ptr);
1107 cu_header.version = read_2_bytes (abfd, info_ptr);
1109 cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
1111 cu_header.addr_size = read_1_byte (abfd, info_ptr);
1114 /* Read the abbrevs for this compilation unit */
1115 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
1116 make_cleanup (dwarf2_empty_abbrev_table, NULL);
1118 dies = read_comp_unit (info_ptr, abfd);
1120 make_cleanup (free_die_list, dies);
1122 /* Do line number decoding in read_file_scope () */
1123 process_die (dies, objfile);
1125 attr = dwarf_attr (dies, DW_AT_high_pc);
1128 highpc = DW_ADDR (attr);
1132 /* Some compilers don't define a DW_AT_high_pc attribute for
1133 the compilation unit. If the DW_AT_high_pc is missing,
1134 synthesize it, by scanning the DIE's below the compilation unit. */
1136 if (dies->has_children)
1138 child_die = dies->next;
1139 while (child_die && child_die->tag)
1141 if (child_die->tag == DW_TAG_subprogram)
1143 high_pc_attr = dwarf_attr (child_die, DW_AT_high_pc);
1146 highpc = max (highpc, DW_ADDR (high_pc_attr));
1149 child_die = sibling_die (child_die);
1153 symtab = end_symtab (highpc + baseaddr, objfile, 0);
1155 /* Set symtab language to language from DW_AT_language.
1156 If the compilation is from a C file generated by language preprocessors,
1157 do not set the language if it was already deduced by start_subfile. */
1159 && !(cu_language == language_c && symtab->language != language_c))
1161 symtab->language = cu_language;
1163 pst->symtab = symtab;
1165 sort_symtab_syms (pst->symtab);
1167 do_cleanups (back_to);
1170 /* Process a die and its children. */
1173 process_die (die, objfile)
1174 struct die_info *die;
1175 struct objfile *objfile;
1179 case DW_TAG_padding:
1181 case DW_TAG_compile_unit:
1182 read_file_scope (die, objfile);
1184 case DW_TAG_subprogram:
1185 read_subroutine_type (die, objfile);
1186 if (dwarf_attr (die, DW_AT_low_pc))
1188 read_func_scope (die, objfile);
1191 case DW_TAG_lexical_block:
1192 read_lexical_block_scope (die, objfile);
1194 case DW_TAG_class_type:
1195 case DW_TAG_structure_type:
1196 case DW_TAG_union_type:
1197 read_structure_scope (die, objfile);
1199 case DW_TAG_enumeration_type:
1200 read_enumeration (die, objfile);
1202 case DW_TAG_subroutine_type:
1203 read_subroutine_type (die, objfile);
1205 case DW_TAG_array_type:
1206 dwarf_read_array_type (die, objfile);
1208 case DW_TAG_pointer_type:
1209 read_tag_pointer_type (die, objfile);
1211 case DW_TAG_ptr_to_member_type:
1212 read_tag_ptr_to_member_type (die, objfile);
1214 case DW_TAG_reference_type:
1215 read_tag_reference_type (die, objfile);
1217 case DW_TAG_string_type:
1218 read_tag_string_type (die, objfile);
1220 case DW_TAG_base_type:
1221 read_base_type (die, objfile);
1223 case DW_TAG_common_block:
1224 read_common_block (die, objfile);
1226 case DW_TAG_common_inclusion:
1229 new_symbol (die, NULL, objfile);
1235 read_file_scope (die, objfile)
1236 struct die_info *die;
1237 struct objfile *objfile;
1239 unsigned int line_offset = 0;
1240 CORE_ADDR lowpc = ((CORE_ADDR) -1);
1241 CORE_ADDR highpc = ((CORE_ADDR) 0);
1242 struct attribute *attr, *low_pc_attr, *high_pc_attr;
1243 char *name = "<unknown>";
1244 char *comp_dir = NULL;
1245 struct die_info *child_die;
1246 bfd *abfd = objfile->obfd;
1248 low_pc_attr = dwarf_attr (die, DW_AT_low_pc);
1251 lowpc = DW_ADDR (low_pc_attr);
1253 high_pc_attr = dwarf_attr (die, DW_AT_high_pc);
1256 highpc = DW_ADDR (high_pc_attr);
1258 if (!low_pc_attr || !high_pc_attr)
1260 if (die->has_children)
1262 child_die = die->next;
1263 while (child_die && child_die->tag)
1265 if (child_die->tag == DW_TAG_subprogram)
1267 low_pc_attr = dwarf_attr (child_die, DW_AT_low_pc);
1270 lowpc = min (lowpc, DW_ADDR (low_pc_attr));
1272 high_pc_attr = dwarf_attr (child_die, DW_AT_high_pc);
1275 highpc = max (highpc, DW_ADDR (high_pc_attr));
1278 child_die = sibling_die (child_die);
1283 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1284 from finish_block. */
1285 if (lowpc == ((CORE_ADDR) -1))
1290 attr = dwarf_attr (die, DW_AT_name);
1293 name = DW_STRING (attr);
1295 attr = dwarf_attr (die, DW_AT_comp_dir);
1298 comp_dir = DW_STRING (attr);
1301 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1302 directory, get rid of it. */
1303 char *cp = strchr (comp_dir, ':');
1305 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1310 if (objfile->ei.entry_point >= lowpc &&
1311 objfile->ei.entry_point < highpc)
1313 objfile->ei.entry_file_lowpc = lowpc;
1314 objfile->ei.entry_file_highpc = highpc;
1317 attr = dwarf_attr (die, DW_AT_language);
1320 set_cu_language (DW_UNSND (attr));
1324 /* FIXME:Do something here. */
1325 if (dip->at_producer != NULL)
1327 handle_producer (dip->at_producer);
1331 /* The compilation unit may be in a different language or objfile,
1332 zero out all remembered fundamental types. */
1333 memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
1335 start_symtab (name, comp_dir, lowpc);
1337 /* Decode line number information if present. */
1338 attr = dwarf_attr (die, DW_AT_stmt_list);
1341 line_offset = DW_UNSND (attr);
1342 dwarf_decode_lines (line_offset, comp_dir, abfd);
1345 /* Process all dies in compilation unit. */
1346 if (die->has_children)
1348 child_die = die->next;
1349 while (child_die && child_die->tag)
1351 process_die (child_die, objfile);
1352 child_die = sibling_die (child_die);
1358 read_func_scope (die, objfile)
1359 struct die_info *die;
1360 struct objfile *objfile;
1362 register struct context_stack *new;
1363 CORE_ADDR lowpc = 0;
1364 CORE_ADDR highpc = 0;
1365 struct die_info *child_die;
1366 struct attribute *attr;
1367 char *name = "<unknown>";
1369 attr = dwarf_attr (die, DW_AT_name);
1372 name = DW_STRING (attr);
1375 attr = dwarf_attr (die, DW_AT_low_pc);
1378 lowpc = DW_ADDR (attr);
1381 attr = dwarf_attr (die, DW_AT_high_pc);
1384 highpc = DW_ADDR (attr);
1389 if (objfile->ei.entry_point >= lowpc &&
1390 objfile->ei.entry_point < highpc)
1392 objfile->ei.entry_func_lowpc = lowpc;
1393 objfile->ei.entry_func_highpc = highpc;
1396 if (STREQ (name, "main")) /* FIXME: hardwired name */
1398 objfile->ei.main_func_lowpc = lowpc;
1399 objfile->ei.main_func_highpc = highpc;
1402 /* Decode DW_AT_frame_base location descriptor if present, keep result
1403 for DW_OP_fbreg operands in decode_locdesc. */
1404 frame_base_reg = -1;
1405 frame_base_offset = 0;
1406 attr = dwarf_attr (die, DW_AT_frame_base);
1409 CORE_ADDR addr = decode_locdesc (DW_BLOCK (attr), objfile);
1411 frame_base_reg = addr;
1414 frame_base_reg = basereg;
1415 frame_base_offset = addr;
1418 complain (&dwarf2_unsupported_at_frame_base, name);
1421 new = push_context (0, lowpc);
1422 new->name = new_symbol (die, die->type, objfile);
1423 list_in_scope = &local_symbols;
1425 if (die->has_children)
1427 child_die = die->next;
1428 while (child_die && child_die->tag)
1430 process_die (child_die, objfile);
1431 child_die = sibling_die (child_die);
1435 new = pop_context ();
1436 /* Make a block for the local symbols within. */
1437 finish_block (new->name, &local_symbols, new->old_blocks,
1438 lowpc, highpc, objfile);
1439 list_in_scope = &file_symbols;
1442 /* Process all the DIES contained within a lexical block scope. Start
1443 a new scope, process the dies, and then close the scope. */
1446 read_lexical_block_scope (die, objfile)
1447 struct die_info *die;
1448 struct objfile *objfile;
1450 register struct context_stack *new;
1451 CORE_ADDR lowpc = 0, highpc = 0;
1452 struct attribute *attr;
1453 struct die_info *child_die;
1455 attr = dwarf_attr (die, DW_AT_low_pc);
1458 lowpc = DW_ADDR (attr);
1460 attr = dwarf_attr (die, DW_AT_high_pc);
1463 highpc = DW_ADDR (attr);
1468 push_context (0, lowpc);
1469 if (die->has_children)
1471 child_die = die->next;
1472 while (child_die && child_die->tag)
1474 process_die (child_die, objfile);
1475 child_die = sibling_die (child_die);
1478 new = pop_context ();
1480 if (local_symbols != NULL)
1482 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
1485 local_symbols = new->locals;
1488 /* Called when we find the DIE that starts a structure or union scope
1489 (definition) to process all dies that define the members of the
1492 NOTE: we need to call struct_type regardless of whether or not the
1493 DIE has an at_name attribute, since it might be an anonymous
1494 structure or union. This gets the type entered into our set of
1497 However, if the structure is incomplete (an opaque struct/union)
1498 then suppress creating a symbol table entry for it since gdb only
1499 wants to find the one with the complete definition. Note that if
1500 it is complete, we just call new_symbol, which does it's own
1501 checking about whether the struct/union is anonymous or not (and
1502 suppresses creating a symbol table entry itself). */
1505 read_structure_scope (die, objfile)
1506 struct die_info *die;
1507 struct objfile *objfile;
1510 struct field *fields;
1511 struct die_info *child_die;
1512 struct attribute *attr;
1516 type = alloc_type (objfile);
1518 INIT_CPLUS_SPECIFIC (type);
1519 attr = dwarf_attr (die, DW_AT_name);
1522 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
1523 strlen (DW_STRING (attr)),
1524 &objfile->type_obstack);
1527 if (die->tag == DW_TAG_structure_type)
1529 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1531 else if (die->tag == DW_TAG_union_type)
1533 TYPE_CODE (type) = TYPE_CODE_UNION;
1537 /* FIXME: This should be changed to TYPE_CODE_CLASS when the rest
1538 of GDB knows how to handle it. */
1539 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1542 attr = dwarf_attr (die, DW_AT_byte_size);
1545 TYPE_LENGTH (type) = DW_UNSND (attr);
1549 TYPE_LENGTH (type) = 0;
1552 /* We need to add the type field to the die immediately so we don't
1553 infinitely recurse when dealing with pointers to the structure
1554 type within the structure itself. */
1559 if (die->has_children)
1561 child_die = die->next;
1562 while (child_die && child_die->tag)
1564 if (child_die->tag == DW_TAG_member)
1566 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1568 fields = (struct field *)
1570 (num_fields + DW_FIELD_ALLOC_CHUNK)
1571 * sizeof (struct field));
1574 /* Get bit offset of field */
1575 attr = dwarf_attr (child_die, DW_AT_bit_offset);
1578 fields[num_fields].bitpos = DW_UNSND (attr);
1582 fields[num_fields].bitpos = 0;
1584 attr = dwarf_attr (child_die, DW_AT_data_member_location);
1587 fields[num_fields].bitpos +=
1588 decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1591 /* Get bit size of field (zero if none). */
1592 attr = dwarf_attr (child_die, DW_AT_bit_size);
1595 fields[num_fields].bitsize = DW_UNSND (attr);
1599 fields[num_fields].bitsize = 0;
1602 /* Get type of member. */
1603 fields[num_fields].type = die_type (child_die, objfile);
1605 /* Get name of member. */
1606 attr = dwarf_attr (child_die, DW_AT_name);
1609 fields[num_fields].name =
1610 obsavestring (DW_STRING (attr),
1611 strlen (DW_STRING (attr)),
1612 &objfile->type_obstack);
1616 else if (child_die->tag == DW_TAG_variable)
1618 char *physname = NULL;
1619 char *fieldname = NULL;
1621 /* C++ static member.
1622 Get physical name, extract field name from physical name. */
1623 attr = dwarf_attr (child_die, DW_AT_name);
1628 physname = DW_STRING (attr);
1631 while (*cp && !is_cplus_marker (*cp))
1637 if (physname && fieldname)
1639 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1641 fields = (struct field *)
1643 (num_fields + DW_FIELD_ALLOC_CHUNK)
1644 * sizeof (struct field));
1646 fields[num_fields].bitpos = -1;
1647 fields[num_fields].bitsize = (long)
1648 obsavestring (physname, strlen (physname),
1649 &objfile->type_obstack);
1650 fields[num_fields].type = die_type (child_die, objfile);
1651 fields[num_fields].name =
1652 obsavestring (fieldname, strlen (fieldname),
1653 &objfile->type_obstack);
1658 complain (&dwarf2_bad_static_member_name,
1659 physname ? physname : "<NULL>");
1662 else if (child_die->tag == DW_TAG_subprogram)
1664 /* FIXME: C++ member function. */
1665 process_die (child_die, objfile);
1667 else if (child_die->tag == DW_TAG_inheritance)
1669 /* FIXME: C++ inheritance information. */
1673 process_die (child_die, objfile);
1675 child_die = sibling_die (child_die);
1679 TYPE_NFIELDS (type) = num_fields;
1680 TYPE_FIELDS (type) = (struct field *)
1681 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
1682 memcpy (TYPE_FIELDS (type), fields,
1683 sizeof (struct field) * num_fields);
1687 sym = new_symbol (die, type, objfile);
1691 /* No children, must be stub. */
1692 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1698 /* Given a pointer to a die which begins an enumeration, process all
1699 the dies that define the members of the enumeration.
1701 This will be much nicer in draft 6 of the DWARF spec when our
1702 members will be dies instead squished into the DW_AT_element_list
1705 NOTE: We reverse the order of the element list. */
1708 read_enumeration (die, objfile)
1709 struct die_info *die;
1710 struct objfile *objfile;
1712 struct die_info *child_die;
1714 struct field *fields;
1715 struct attribute *attr;
1718 int unsigned_enum = 1;
1720 type = alloc_type (objfile);
1722 TYPE_CODE (type) = TYPE_CODE_ENUM;
1723 attr = dwarf_attr (die, DW_AT_name);
1726 TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
1727 strlen (DW_STRING (attr)),
1728 &objfile->type_obstack);
1731 attr = dwarf_attr (die, DW_AT_byte_size);
1734 TYPE_LENGTH (type) = DW_UNSND (attr);
1738 TYPE_LENGTH (type) = 0;
1743 if (die->has_children)
1745 child_die = die->next;
1746 while (child_die && child_die->tag)
1748 if (child_die->tag != DW_TAG_enumerator)
1750 process_die (child_die, objfile);
1754 attr = dwarf_attr (child_die, DW_AT_name);
1757 sym = new_symbol (child_die, type, objfile);
1758 if (SYMBOL_VALUE (sym) < 0)
1761 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1763 fields = (struct field *)
1765 (num_fields + DW_FIELD_ALLOC_CHUNK)
1766 * sizeof (struct field));
1769 fields[num_fields].name = SYMBOL_NAME (sym);
1770 fields[num_fields].type = NULL;
1771 fields[num_fields].bitpos = SYMBOL_VALUE (sym);
1772 fields[num_fields].bitsize = 0;
1778 child_die = sibling_die (child_die);
1783 TYPE_NFIELDS (type) = num_fields;
1784 TYPE_FIELDS (type) = (struct field *)
1785 TYPE_ALLOC (type, sizeof (struct field) * num_fields);
1786 memcpy (TYPE_FIELDS (type), fields,
1787 sizeof (struct field) * num_fields);
1791 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1794 sym = new_symbol (die, type, objfile);
1797 /* Extract all information from a DW_TAG_array_type DIE and put it in
1798 the DIE's type field. For now, this only handles one dimensional
1802 dwarf_read_array_type (die, objfile)
1803 struct die_info *die;
1804 struct objfile *objfile;
1806 struct die_info *child_die;
1807 struct type *type = NULL;
1808 struct type *element_type, *range_type, *index_type;
1809 struct attribute *attr;
1810 unsigned int low, high;
1812 /* Return if we've already decoded this type. */
1818 element_type = die_type (die, objfile);
1820 /* Irix 6.2 native cc creates array types without children for
1821 variable length arrays. */
1822 if (die->has_children == 0)
1824 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
1825 range_type = create_range_type (NULL, index_type, 0, -1);
1826 die->type = create_array_type (NULL, element_type, range_type);
1832 if (cu_language == DW_LANG_Fortran77 || cu_language == DW_LANG_Fortran90)
1834 /* FORTRAN implies a lower bound of 1, if not given. */
1838 child_die = die->next;
1839 while (child_die && child_die->tag)
1841 if (child_die->tag == DW_TAG_subrange_type)
1843 index_type = die_type (child_die, objfile);
1844 attr = dwarf_attr (child_die, DW_AT_lower_bound);
1847 if (attr->form == DW_FORM_sdata)
1849 low = DW_SND (attr);
1851 else if (attr->form == DW_FORM_udata
1852 || attr->form == DW_FORM_data1
1853 || attr->form == DW_FORM_data2
1854 || attr->form == DW_FORM_data4)
1856 low = DW_UNSND (attr);
1860 complain (&dwarf2_non_const_array_bound_ignored,
1861 dwarf_form_name (attr->form));
1863 die->type = lookup_pointer_type (element_type);
1870 attr = dwarf_attr (child_die, DW_AT_upper_bound);
1873 if (attr->form == DW_FORM_sdata)
1875 high = DW_SND (attr);
1877 else if (attr->form == DW_FORM_udata
1878 || attr->form == DW_FORM_data1
1879 || attr->form == DW_FORM_data2
1880 || attr->form == DW_FORM_data4)
1882 high = DW_UNSND (attr);
1884 else if (attr->form == DW_FORM_block1)
1886 /* GCC encodes arrays with unspecified or dynamic length
1887 with a DW_FORM_block1 attribute.
1888 FIXME: GDB does not yet know how to handle dynamic
1889 arrays properly, treat them as arrays with unspecified
1895 complain (&dwarf2_non_const_array_bound_ignored,
1896 dwarf_form_name (attr->form));
1898 die->type = lookup_pointer_type (element_type);
1905 range_type = create_range_type (NULL, index_type, low, high);
1906 type = create_array_type (NULL, element_type, range_type);
1907 element_type = type;
1909 child_die = sibling_die (child_die);
1911 /* Install the type in the die. */
1915 /* First cut: install each common block member as a global variable. */
1918 read_common_block (die, objfile)
1919 struct die_info *die;
1920 struct objfile *objfile;
1922 struct die_info *child_die;
1923 struct attribute *attr;
1925 CORE_ADDR base = (CORE_ADDR) 0;
1927 attr = dwarf_attr (die, DW_AT_location);
1930 base = decode_locdesc (DW_BLOCK (attr), objfile);
1932 if (die->has_children)
1934 child_die = die->next;
1935 while (child_die && child_die->tag)
1937 sym = new_symbol (child_die, NULL, objfile);
1938 attr = dwarf_attr (child_die, DW_AT_data_member_location);
1941 SYMBOL_VALUE_ADDRESS (sym) =
1942 base + decode_locdesc (DW_BLOCK (attr), objfile);
1943 add_symbol_to_list (sym, &global_symbols);
1945 child_die = sibling_die (child_die);
1950 /* Extract all information from a DW_TAG_pointer_type DIE and add to
1951 the user defined type vector. */
1954 read_tag_pointer_type (die, objfile)
1955 struct die_info *die;
1956 struct objfile *objfile;
1959 struct attribute *attr;
1966 type = lookup_pointer_type (die_type (die, objfile));
1967 attr = dwarf_attr (die, DW_AT_byte_size);
1970 TYPE_LENGTH (type) = DW_UNSND (attr);
1974 TYPE_LENGTH (type) = address_size;
1979 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
1980 the user defined type vector. */
1983 read_tag_ptr_to_member_type (die, objfile)
1984 struct die_info *die;
1985 struct objfile *objfile;
1988 struct type *to_type;
1989 struct type *domain;
1996 type = alloc_type (objfile);
1997 to_type = die_type (die, objfile);
1998 domain = die_containing_type (die, objfile);
1999 smash_to_member_type (type, domain, to_type);
2004 /* Extract all information from a DW_TAG_reference_type DIE and add to
2005 the user defined type vector. */
2008 read_tag_reference_type (die, objfile)
2009 struct die_info *die;
2010 struct objfile *objfile;
2013 struct attribute *attr;
2020 type = lookup_reference_type (die_type (die, objfile));
2021 attr = dwarf_attr (die, DW_AT_byte_size);
2024 TYPE_LENGTH (type) = DW_UNSND (attr);
2028 TYPE_LENGTH (type) = address_size;
2034 read_tag_const_type (die, objfile)
2035 struct die_info *die;
2036 struct objfile *objfile;
2043 complain (&dwarf2_const_ignored);
2044 die->type = die_type (die, objfile);
2048 read_tag_volatile_type (die, objfile)
2049 struct die_info *die;
2050 struct objfile *objfile;
2057 complain (&dwarf2_volatile_ignored);
2058 die->type = die_type (die, objfile);
2061 /* Extract all information from a DW_TAG_string_type DIE and add to
2062 the user defined type vector. It isn't really a user defined type,
2063 but it behaves like one, with other DIE's using an AT_user_def_type
2064 attribute to reference it. */
2067 read_tag_string_type (die, objfile)
2068 struct die_info *die;
2069 struct objfile *objfile;
2071 struct type *type, *range_type, *index_type, *char_type;
2072 struct attribute *attr;
2073 unsigned int length;
2080 attr = dwarf_attr (die, DW_AT_string_length);
2083 length = DW_UNSND (attr);
2089 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2090 range_type = create_range_type (NULL, index_type, 1, length);
2091 char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
2092 type = create_string_type (char_type, range_type);
2096 /* Handle DIES due to C code like:
2100 int (*funcp)(int a, long l);
2104 ('funcp' generates a DW_TAG_subroutine_type DIE)
2108 read_subroutine_type (die, objfile)
2109 struct die_info *die;
2110 struct objfile *objfile;
2112 struct type *type; /* Type that this function returns */
2113 struct type *ftype; /* Function that returns above type */
2115 /* Decode the type that this subroutine returns */
2120 type = die_type (die, objfile);
2121 ftype = lookup_function_type (type);
2123 if (die->has_children)
2125 struct die_info *child_die;
2129 /* Count the number of parameters.
2130 FIXME: GDB currently has no way to deal with ellipsis,
2131 represented by DW_TAG_unspecified_parameters. */
2132 child_die = die->next;
2133 while (child_die && child_die->tag)
2135 if (child_die->tag == DW_TAG_formal_parameter)
2137 child_die = sibling_die (child_die);
2140 /* Allocate storage for parameters and fill them in. */
2141 TYPE_NFIELDS (ftype) = nparams;
2142 TYPE_FIELDS (ftype) = (struct field *)
2143 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
2145 child_die = die->next;
2146 while (child_die && child_die->tag)
2148 if (child_die->tag == DW_TAG_formal_parameter)
2150 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, objfile);
2153 child_die = sibling_die (child_die);
2161 read_typedef (die, objfile)
2162 struct die_info *die;
2163 struct objfile *objfile;
2169 struct attribute *attr;
2172 xtype = die_type (die, objfile);
2174 type = alloc_type (objfile);
2175 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2176 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2177 TYPE_TARGET_TYPE (type) = xtype;
2178 attr = dwarf_attr (die, DW_AT_name);
2180 TYPE_NAME (type) = obsavestring (DW_STRING (attr),
2181 strlen (DW_STRING (attr)),
2182 &objfile->type_obstack);
2188 /* Find a representation of a given base type and install
2189 it in the TYPE field of the die. */
2192 read_base_type (die, objfile)
2193 struct die_info *die;
2194 struct objfile *objfile;
2197 struct attribute *attr;
2198 int encoding = 0, size = 0;
2200 /* If we've already decoded this die, this is a no-op. */
2206 attr = dwarf_attr (die, DW_AT_encoding);
2209 encoding = DW_UNSND (attr);
2211 attr = dwarf_attr (die, DW_AT_byte_size);
2214 size = DW_UNSND (attr);
2216 attr = dwarf_attr (die, DW_AT_name);
2219 enum type_code code = TYPE_CODE_INT;
2220 int is_unsigned = 0;
2224 case DW_ATE_address:
2225 /* Turn DW_ATE_address into a void * pointer. */
2226 code = TYPE_CODE_PTR;
2229 case DW_ATE_boolean:
2230 code = TYPE_CODE_BOOL;
2232 case DW_ATE_complex_float:
2233 code = TYPE_CODE_COMPLEX;
2236 code = TYPE_CODE_FLT;
2239 case DW_ATE_signed_char:
2241 case DW_ATE_unsigned:
2242 case DW_ATE_unsigned_char:
2246 complain (&dwarf2_unsupported_at_encoding,
2247 dwarf_type_encoding_name (encoding));
2250 type = init_type (code, size, is_unsigned, DW_STRING (attr), objfile);
2251 if (encoding == DW_ATE_address)
2252 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID);
2256 type = dwarf_base_type (encoding, size);
2261 /* Read a whole compilation unit into a linked list of dies. */
2264 read_comp_unit (info_ptr, abfd)
2268 struct die_info *first_die, *last_die, *die;
2272 /* Reset die reference table, we are building a new one now. */
2273 dwarf2_empty_die_ref_table ();
2277 first_die = last_die = NULL;
2280 cur_ptr = read_full_die (&die, abfd, cur_ptr);
2281 if (die->has_children)
2292 /* Enter die in reference hash table */
2293 store_in_ref_table (die->offset, die);
2297 first_die = last_die = die;
2301 last_die->next = die;
2305 while (nesting_level > 0);
2309 /* Free a linked list of dies. */
2312 free_die_list (dies)
2313 struct die_info *dies;
2315 struct die_info *die, *next;
2327 /* Read the contents of the section at OFFSET and of size SIZE from the
2328 object file specified by OBJFILE into the psymbol_obstack and return it. */
2331 dwarf2_read_section (objfile, offset, size)
2332 struct objfile *objfile;
2336 bfd *abfd = objfile->obfd;
2342 buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
2343 if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
2344 (bfd_read (buf, size, 1, abfd) != size))
2347 error ("Dwarf Error: Can't read DWARF data from '%s'",
2348 bfd_get_filename (abfd));
2353 /* In DWARF version 2, the description of the debugging information is
2354 stored in a separate .debug_abbrev section. Before we read any
2355 dies from a section we read in all abbreviations and install them
2359 dwarf2_read_abbrevs (abfd, offset)
2361 unsigned int offset;
2364 struct abbrev_info *cur_abbrev;
2365 unsigned int abbrev_number, bytes_read, abbrev_name;
2366 unsigned int abbrev_form, hash_number;
2368 /* empty the table */
2369 dwarf2_empty_abbrev_table (NULL);
2371 abbrev_ptr = dwarf_abbrev_buffer + offset;
2372 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2373 abbrev_ptr += bytes_read;
2375 /* loop until we reach an abbrev number of 0 */
2376 while (abbrev_number)
2378 cur_abbrev = dwarf_alloc_abbrev ();
2380 /* read in abbrev header */
2381 cur_abbrev->number = abbrev_number;
2382 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2383 abbrev_ptr += bytes_read;
2384 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
2387 /* now read in declarations */
2388 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2389 abbrev_ptr += bytes_read;
2390 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2391 abbrev_ptr += bytes_read;
2394 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
2396 cur_abbrev->attrs = (struct attr_abbrev *)
2397 xrealloc (cur_abbrev->attrs,
2398 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
2399 * sizeof (struct attr_abbrev));
2401 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
2402 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
2403 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2404 abbrev_ptr += bytes_read;
2405 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2406 abbrev_ptr += bytes_read;
2409 hash_number = abbrev_number % ABBREV_HASH_SIZE;
2410 cur_abbrev->next = dwarf2_abbrevs[hash_number];
2411 dwarf2_abbrevs[hash_number] = cur_abbrev;
2413 /* Get next abbreviation.
2414 Under Irix6 the abbreviations for a compilation unit are not
2415 always properly terminated with an abbrev number of 0.
2416 Exit loop if we encounter an abbreviation which we have
2417 already read (which means we are about to read the abbreviations
2418 for the next compile unit) or if the end of the abbreviation
2419 table is reached. */
2420 if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
2421 >= dwarf_abbrev_size)
2423 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2424 abbrev_ptr += bytes_read;
2425 if (dwarf2_lookup_abbrev (abbrev_number) != NULL)
2430 /* Empty the abbrev table for a new compilation unit. */
2434 dwarf2_empty_abbrev_table (ignore)
2438 struct abbrev_info *abbrev, *next;
2440 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
2443 abbrev = dwarf2_abbrevs[i];
2446 next = abbrev->next;
2447 free (abbrev->attrs);
2451 dwarf2_abbrevs[i] = NULL;
2455 /* Lookup an abbrev_info structure in the abbrev hash table. */
2457 static struct abbrev_info *
2458 dwarf2_lookup_abbrev (number)
2459 unsigned int number;
2461 unsigned int hash_number;
2462 struct abbrev_info *abbrev;
2464 hash_number = number % ABBREV_HASH_SIZE;
2465 abbrev = dwarf2_abbrevs[hash_number];
2469 if (abbrev->number == number)
2472 abbrev = abbrev->next;
2477 /* Read a minimal amount of information into the minimal die structure. */
2480 read_partial_die (part_die, abfd, info_ptr, has_pc_info)
2481 struct partial_die_info *part_die;
2486 unsigned int abbrev_number, bytes_read, i;
2487 struct abbrev_info *abbrev;
2489 int has_low_pc_attr = 0;
2490 int has_high_pc_attr = 0;
2492 *part_die = zeroed_partial_die;
2494 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2495 info_ptr += bytes_read;
2499 abbrev = dwarf2_lookup_abbrev (abbrev_number);
2502 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number);
2504 part_die->offset = info_ptr - dwarf_info_buffer;
2505 part_die->tag = abbrev->tag;
2506 part_die->has_children = abbrev->has_children;
2507 part_die->abbrev = abbrev_number;
2511 struct dwarf_block *blk = 0;
2512 CORE_ADDR addr = ((CORE_ADDR) -1);
2513 unsigned int unsnd = ((unsigned int) -1);
2516 for (i = 0; i < abbrev->num_attrs; ++i)
2518 /* read the correct type of data */
2519 switch (abbrev->attrs[i].form)
2522 addr = read_address (abfd, info_ptr);
2523 info_ptr += address_size;
2525 case DW_FORM_ref_addr:
2526 addr = read_address (abfd, info_ptr);
2527 info_ptr += address_size;
2529 case DW_FORM_block2:
2530 blk = dwarf_alloc_block ();
2531 blk->size = read_2_bytes (abfd, info_ptr);
2533 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2534 info_ptr += blk->size;
2536 case DW_FORM_block4:
2537 blk = dwarf_alloc_block ();
2538 blk->size = read_4_bytes (abfd, info_ptr);
2540 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2541 info_ptr += blk->size;
2544 unsnd = read_2_bytes (abfd, info_ptr);
2548 unsnd = read_4_bytes (abfd, info_ptr);
2552 unsnd = read_8_bytes (abfd, info_ptr);
2555 case DW_FORM_string:
2556 str = read_string (abfd, info_ptr, &bytes_read);
2557 info_ptr += bytes_read;
2560 blk = dwarf_alloc_block ();
2561 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2562 info_ptr += bytes_read;
2563 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2564 info_ptr += blk->size;
2566 case DW_FORM_block1:
2567 blk = dwarf_alloc_block ();
2568 blk->size = read_1_byte (abfd, info_ptr);
2570 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2571 info_ptr += blk->size;
2574 unsnd = read_1_byte (abfd, info_ptr);
2578 unsnd = read_1_byte (abfd, info_ptr);
2582 unsnd = read_2_bytes (abfd, info_ptr);
2586 unsnd = read_4_bytes (abfd, info_ptr);
2589 case DW_FORM_ref_udata:
2590 unsnd = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2591 info_ptr += bytes_read;
2594 unsnd = read_1_byte (abfd, info_ptr);
2598 snd = read_signed_leb128 (abfd, info_ptr, &bytes_read);
2599 info_ptr += bytes_read;
2602 unsnd = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2603 info_ptr += bytes_read;
2605 case DW_FORM_indirect:
2608 "Dwarf Error: Cannot handle %s in DWARF reader.",
2609 dwarf_form_name (abbrev->attrs[i].form));
2613 /* store the data if it is of an attribute we want to keep in a
2614 partial symbol table */
2615 switch (abbrev->attrs[i].name)
2618 part_die->name = str;
2621 has_low_pc_attr = 1;
2622 part_die->lowpc = addr;
2625 has_high_pc_attr = 1;
2626 part_die->highpc = addr;
2628 case DW_AT_location:
2629 part_die->locdesc = blk;
2631 case DW_AT_language:
2632 part_die->language = unsnd;
2634 case DW_AT_external:
2635 part_die->is_external = unsnd;
2637 case DW_AT_declaration:
2638 part_die->is_declaration = unsnd;
2643 *has_pc_info = has_low_pc_attr && has_high_pc_attr;
2647 /* Read the die from the .debug_info section buffer. And set diep to
2648 point to a newly allocated die with its information. */
2651 read_full_die (diep, abfd, info_ptr)
2652 struct die_info **diep;
2656 unsigned int abbrev_number, bytes_read, i, offset;
2657 struct abbrev_info *abbrev;
2658 struct die_info *die;
2661 offset = info_ptr - dwarf_info_buffer;
2662 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2663 info_ptr += bytes_read;
2666 die = dwarf_alloc_die ();
2668 die->abbrev = abbrev_number;
2674 abbrev = dwarf2_lookup_abbrev (abbrev_number);
2677 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number);
2679 die = dwarf_alloc_die ();
2680 die->offset = offset;
2681 die->tag = abbrev->tag;
2682 die->has_children = abbrev->has_children;
2683 die->abbrev = abbrev_number;
2686 die->num_attrs = abbrev->num_attrs;
2687 die->attrs = (struct attribute *)
2688 xmalloc (die->num_attrs * sizeof (struct attribute));
2691 struct dwarf_block *blk;
2693 for (i = 0; i < abbrev->num_attrs; ++i)
2695 /* read the correct type of data */
2697 die->attrs[i].name = abbrev->attrs[i].name;
2698 die->attrs[i].form = abbrev->attrs[i].form;
2700 switch (abbrev->attrs[i].form)
2703 case DW_FORM_ref_addr:
2704 die->attrs[i].u.addr = read_address (abfd, info_ptr);
2705 info_ptr += address_size;
2707 case DW_FORM_block2:
2708 blk = dwarf_alloc_block ();
2709 blk->size = read_2_bytes (abfd, info_ptr);
2711 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2712 info_ptr += blk->size;
2713 die->attrs[i].u.blk = blk;
2715 case DW_FORM_block4:
2716 blk = dwarf_alloc_block ();
2717 blk->size = read_4_bytes (abfd, info_ptr);
2719 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2720 info_ptr += blk->size;
2721 die->attrs[i].u.blk = blk;
2724 die->attrs[i].u.unsnd = read_2_bytes (abfd, info_ptr);
2728 die->attrs[i].u.unsnd = read_4_bytes (abfd, info_ptr);
2732 die->attrs[i].u.unsnd = read_8_bytes (abfd, info_ptr);
2735 case DW_FORM_string:
2736 die->attrs[i].u.str = read_string (abfd, info_ptr, &bytes_read);
2737 info_ptr += bytes_read;
2740 blk = dwarf_alloc_block ();
2741 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2742 info_ptr += bytes_read;
2743 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2744 info_ptr += blk->size;
2745 die->attrs[i].u.blk = blk;
2747 case DW_FORM_block1:
2748 blk = dwarf_alloc_block ();
2749 blk->size = read_1_byte (abfd, info_ptr);
2751 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2752 info_ptr += blk->size;
2753 die->attrs[i].u.blk = blk;
2756 die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2760 die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2764 die->attrs[i].u.unsnd = read_2_bytes (abfd, info_ptr);
2768 die->attrs[i].u.unsnd = read_4_bytes (abfd, info_ptr);
2771 case DW_FORM_ref_udata:
2772 die->attrs[i].u.unsnd = read_unsigned_leb128 (abfd,
2775 info_ptr += bytes_read;
2778 die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2782 die->attrs[i].u.snd = read_signed_leb128 (abfd,
2785 info_ptr += bytes_read;
2788 die->attrs[i].u.unsnd = read_unsigned_leb128 (abfd,
2791 info_ptr += bytes_read;
2793 case DW_FORM_indirect:
2796 "Dwarf Error: Cannot handle %s in DWARF reader.",
2797 dwarf_form_name (abbrev->attrs[i].form));
2807 /* read dwarf information from a buffer */
2810 read_1_byte (abfd, buf)
2814 return bfd_get_8 (abfd, (bfd_byte *) buf);
2818 read_1_signed_byte (abfd, buf)
2822 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
2826 read_2_bytes (abfd, buf)
2830 return bfd_get_16 (abfd, (bfd_byte *) buf);
2834 read_2_signed_bytes (abfd, buf)
2838 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
2842 read_4_bytes (abfd, buf)
2846 return bfd_get_32 (abfd, (bfd_byte *) buf);
2850 read_4_signed_bytes (abfd, buf)
2854 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
2858 read_8_bytes (abfd, buf)
2862 return bfd_get_64 (abfd, (bfd_byte *) buf);
2866 read_address (abfd, buf)
2870 CORE_ADDR retval = 0;
2872 if (address_size == 4)
2874 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
2875 } else { /* *THE* alternative is 8, right? */
2876 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
2882 read_n_bytes (abfd, buf, size)
2887 /* If the size of a host char is 8 bits, we can return a pointer
2888 to the buffer, otherwise we have to copy the data to a buffer
2889 allocated on the temporary obstack. */
2890 #if HOST_CHAR_BIT == 8
2896 ret = obstack_alloc (&dwarf2_tmp_obstack, size);
2897 for (i = 0; i < size; ++i)
2899 ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
2907 read_string (abfd, buf, bytes_read_ptr)
2910 unsigned int *bytes_read_ptr;
2912 /* If the size of a host char is 8 bits, we can return a pointer
2913 to the string, otherwise we have to copy the string to a buffer
2914 allocated on the temporary obstack. */
2915 #if HOST_CHAR_BIT == 8
2918 *bytes_read_ptr = 1;
2921 *bytes_read_ptr = strlen (buf) + 1;
2927 while ((byte = bfd_get_8 (abfd, (bfd_byte *) buf)) != 0)
2929 obstack_1grow (&dwarf2_tmp_obstack, byte);
2935 *bytes_read_ptr = 1;
2938 obstack_1grow (&dwarf2_tmp_obstack, '\0');
2939 *bytes_read_ptr = i + 1;
2940 return obstack_finish (&dwarf2_tmp_obstack);
2945 read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
2948 unsigned int *bytes_read_ptr;
2950 unsigned int result, num_read;
2960 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2963 result |= ((byte & 127) << shift);
2964 if ((byte & 128) == 0)
2970 *bytes_read_ptr = num_read;
2975 read_signed_leb128 (abfd, buf, bytes_read_ptr)
2978 unsigned int *bytes_read_ptr;
2981 int i, shift, size, num_read;
2991 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2994 result |= ((byte & 127) << shift);
2996 if ((byte & 128) == 0)
3001 if ((shift < size) && (byte & 0x40))
3003 result |= -(1 << shift);
3005 *bytes_read_ptr = num_read;
3010 set_cu_language (lang)
3017 case DW_LANG_Fortran77:
3018 cu_language = language_c;
3020 case DW_LANG_C_plus_plus:
3021 cu_language = language_cplus;
3023 case DW_LANG_Mips_Assembler:
3024 cu_language = language_asm;
3027 case DW_LANG_Cobol74:
3028 case DW_LANG_Cobol85:
3030 case DW_LANG_Fortran77: /* moved up top for now */
3032 case DW_LANG_Fortran90:
3033 case DW_LANG_Pascal83:
3034 case DW_LANG_Modula2:
3036 cu_language = language_unknown;
3039 cu_language_defn = language_def (cu_language);
3042 /* Return the named attribute or NULL if not there. */
3044 static struct attribute *
3045 dwarf_attr (die, name)
3046 struct die_info *die;
3050 struct attribute *spec = NULL;
3052 for (i = 0; i < die->num_attrs; ++i)
3054 if (die->attrs[i].name == name)
3056 return &die->attrs[i];
3058 if (die->attrs[i].name == DW_AT_specification
3059 || die->attrs[i].name == DW_AT_abstract_origin)
3060 spec = &die->attrs[i];
3064 struct die_info *ref_die =
3065 follow_die_ref (dwarf2_get_ref_die_offset (spec));
3068 return dwarf_attr (ref_die, name);
3074 /* Decode the line number information for the compilation unit whose
3075 line number info is at OFFSET in the .debug_line section.
3076 The compilation directory of the file is passed in COMP_DIR. */
3080 unsigned int num_files;
3093 unsigned int num_dirs;
3098 dwarf_decode_lines (offset, comp_dir, abfd)
3099 unsigned int offset;
3105 struct line_head lh;
3106 struct cleanup *back_to;
3107 unsigned int i, bytes_read;
3108 char *cur_file, *cur_dir;
3109 unsigned char op_code, extended_op, adj_opcode;
3111 #define FILE_ALLOC_CHUNK 5
3112 #define DIR_ALLOC_CHUNK 5
3114 struct filenames files;
3115 struct directories dirs;
3117 if (dwarf_line_buffer == NULL)
3119 complain (&dwarf2_missing_line_number_section);
3123 files.num_files = 0;
3129 line_ptr = dwarf_line_buffer + offset;
3131 /* read in the prologue */
3132 lh.total_length = read_4_bytes (abfd, line_ptr);
3134 line_end = line_ptr + lh.total_length;
3135 lh.version = read_2_bytes (abfd, line_ptr);
3137 lh.prologue_length = read_4_bytes (abfd, line_ptr);
3139 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
3141 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
3143 lh.line_base = read_1_signed_byte (abfd, line_ptr);
3145 lh.line_range = read_1_byte (abfd, line_ptr);
3147 lh.opcode_base = read_1_byte (abfd, line_ptr);
3149 lh.standard_opcode_lengths = (unsigned char *)
3150 xmalloc (lh.opcode_base * sizeof (unsigned char));
3151 back_to = make_cleanup (free_current_contents, &lh.standard_opcode_lengths);
3153 lh.standard_opcode_lengths[0] = 1;
3154 for (i = 1; i < lh.opcode_base; ++i)
3156 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
3160 /* Read directory table */
3161 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3163 line_ptr += bytes_read;
3164 if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0)
3166 dirs.dirs = (char **)
3167 xrealloc (dirs.dirs,
3168 (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
3169 if (dirs.num_dirs == 0)
3170 make_cleanup (free_current_contents, &dirs.dirs);
3172 dirs.dirs[dirs.num_dirs++] = cur_dir;
3174 line_ptr += bytes_read;
3176 /* Read file name table */
3177 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3179 line_ptr += bytes_read;
3180 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3182 files.files = (struct fileinfo *)
3183 xrealloc (files.files,
3184 (files.num_files + FILE_ALLOC_CHUNK)
3185 * sizeof (struct fileinfo));
3186 if (files.num_files == 0)
3187 make_cleanup (free_current_contents, &files.files);
3189 files.files[files.num_files].name = cur_file;
3190 files.files[files.num_files].dir =
3191 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3192 line_ptr += bytes_read;
3193 files.files[files.num_files].time =
3194 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3195 line_ptr += bytes_read;
3196 files.files[files.num_files].size =
3197 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3198 line_ptr += bytes_read;
3201 line_ptr += bytes_read;
3203 /* Read the statement sequences until there's nothing left. */
3204 while (line_ptr < line_end)
3206 /* state machine registers */
3207 unsigned int address = 0;
3208 unsigned int file = 1;
3209 unsigned int line = 1;
3210 unsigned int column = 0;
3211 int is_stmt = lh.default_is_stmt;
3212 int basic_block = 0;
3213 int end_sequence = 0;
3215 /* Start a subfile for the current file of the state machine. */
3216 if (files.num_files >= file)
3218 /* The file and directory tables are 0 based, the references
3220 dwarf2_start_subfile (files.files[file - 1].name,
3221 (files.files[file - 1].dir
3222 ? dirs.dirs[files.files[file - 1].dir - 1]
3226 /* Decode the table. */
3227 while (! end_sequence)
3229 op_code = read_1_byte (abfd, line_ptr);
3233 case DW_LNS_extended_op:
3234 line_ptr += 1; /* ignore length */
3235 extended_op = read_1_byte (abfd, line_ptr);
3237 switch (extended_op)
3239 case DW_LNE_end_sequence:
3241 record_line (current_subfile, line, address);
3243 case DW_LNE_set_address:
3244 address = read_address (abfd, line_ptr) + baseaddr;
3245 line_ptr += address_size;
3247 case DW_LNE_define_file:
3248 cur_file = read_string (abfd, line_ptr, &bytes_read);
3249 line_ptr += bytes_read;
3250 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3252 files.files = (struct fileinfo *)
3253 xrealloc (files.files,
3254 (files.num_files + FILE_ALLOC_CHUNK)
3255 * sizeof (struct fileinfo));
3256 if (files.num_files == 0)
3257 make_cleanup (free_current_contents, &files.files);
3259 files.files[files.num_files].name = cur_file;
3260 files.files[files.num_files].dir =
3261 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3262 line_ptr += bytes_read;
3263 files.files[files.num_files].time =
3264 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3265 line_ptr += bytes_read;
3266 files.files[files.num_files].size =
3267 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3268 line_ptr += bytes_read;
3272 complain (&dwarf2_mangled_line_number_section);
3277 record_line (current_subfile, line, address);
3280 case DW_LNS_advance_pc:
3281 address += lh.minimum_instruction_length
3282 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3283 line_ptr += bytes_read;
3285 case DW_LNS_advance_line:
3286 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
3287 line_ptr += bytes_read;
3289 case DW_LNS_set_file:
3290 /* The file and directory tables are 0 based, the references
3292 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3293 line_ptr += bytes_read;
3294 dwarf2_start_subfile
3295 (files.files[file - 1].name,
3296 (files.files[file - 1].dir
3297 ? dirs.dirs[files.files[file - 1].dir - 1]
3300 case DW_LNS_set_column:
3301 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3302 line_ptr += bytes_read;
3304 case DW_LNS_negate_stmt:
3305 is_stmt = (!is_stmt);
3307 case DW_LNS_set_basic_block:
3310 case DW_LNS_const_add_pc:
3311 address += (255 - lh.opcode_base) / lh.line_range;
3313 case DW_LNS_fixed_advance_pc:
3314 address += read_2_bytes (abfd, line_ptr);
3317 default: /* special operand */
3318 adj_opcode = op_code - lh.opcode_base;
3319 address += (adj_opcode / lh.line_range)
3320 * lh.minimum_instruction_length;
3321 line += lh.line_base + (adj_opcode % lh.line_range);
3322 /* append row to matrix using current values */
3323 record_line (current_subfile, line, address);
3329 do_cleanups (back_to);
3332 /* Start a subfile for DWARF. FILENAME is the name of the file and
3333 DIRNAME the name of the source directory which contains FILENAME
3334 or NULL if not known.
3335 This routine tries to keep line numbers from identical absolute and
3336 relative file names in a common subfile.
3338 Using the `list' example from the GDB testsuite, which resides in
3339 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3340 of /srcdir/list0.c yields the following debugging information for list0.c:
3342 DW_AT_name: /srcdir/list0.c
3343 DW_AT_comp_dir: /compdir
3344 files.files[0].name: list0.h
3345 files.files[0].dir: /srcdir
3346 files.files[1].name: list0.c
3347 files.files[1].dir: /srcdir
3349 The line number information for list0.c has to end up in a single
3350 subfile, so that `break /srcdir/list0.c:1' works as expected. */
3353 dwarf2_start_subfile (filename, dirname)
3357 /* If the filename isn't absolute, try to match an existing subfile
3358 with the full pathname. */
3360 if (*filename != '/' && dirname != NULL)
3362 struct subfile *subfile;
3363 char *fullname = concat (dirname, "/", filename, NULL);
3365 for (subfile = subfiles; subfile; subfile = subfile->next)
3367 if (STREQ (subfile->name, fullname))
3369 current_subfile = subfile;
3376 start_subfile (filename, dirname);
3379 /* Given a pointer to a DWARF information entry, figure out if we need
3380 to make a symbol table entry for it, and if so, create a new entry
3381 and return a pointer to it.
3382 If TYPE is NULL, determine symbol type from the die, otherwise
3383 used the passed type.
3386 static struct symbol *
3387 new_symbol (die, type, objfile)
3388 struct die_info *die;
3390 struct objfile *objfile;
3392 struct symbol *sym = NULL;
3393 struct attribute *attr = NULL;
3394 struct attribute *attr2 = NULL;
3397 attr = dwarf_attr (die, DW_AT_name);
3400 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
3401 sizeof (struct symbol));
3402 OBJSTAT (objfile, n_syms++);
3403 memset (sym, 0, sizeof (struct symbol));
3404 SYMBOL_NAME (sym) = obsavestring (DW_STRING (attr),
3405 strlen (DW_STRING (attr)),
3406 &objfile->symbol_obstack);
3408 /* Default assumptions.
3409 Use the passed type or decode it from the die. */
3410 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3411 SYMBOL_CLASS (sym) = LOC_STATIC;
3413 SYMBOL_TYPE (sym) = type;
3415 SYMBOL_TYPE (sym) = die_type (die, objfile);
3416 attr = dwarf_attr (die, DW_AT_decl_line);
3419 SYMBOL_LINE (sym) = DW_UNSND (attr);
3422 /* If this symbol is from a C++ compilation, then attempt to
3423 cache the demangled form for future reference. This is a
3424 typical time versus space tradeoff, that was decided in favor
3425 of time because it sped up C++ symbol lookups by a factor of
3428 SYMBOL_LANGUAGE (sym) = cu_language;
3429 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
3433 attr = dwarf_attr (die, DW_AT_low_pc);
3436 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr);
3438 SYMBOL_CLASS (sym) = LOC_LABEL;
3440 case DW_TAG_subprogram:
3441 attr = dwarf_attr (die, DW_AT_low_pc);
3444 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr);
3446 SYMBOL_CLASS (sym) = LOC_BLOCK;
3447 attr2 = dwarf_attr (die, DW_AT_external);
3448 if (attr2 && (DW_UNSND (attr2) != 0))
3450 add_symbol_to_list (sym, &global_symbols);
3454 add_symbol_to_list (sym, list_in_scope);
3457 case DW_TAG_variable:
3458 /* Compilation with minimal debug info may result in variables
3459 with missing type entries. Change the misleading `void' type
3460 to something sensible. */
3461 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
3462 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
3463 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
3464 "<variable, no debug info>",
3466 attr = dwarf_attr (die, DW_AT_location);
3469 attr2 = dwarf_attr (die, DW_AT_external);
3470 if (attr2 && (DW_UNSND (attr2) != 0))
3472 SYMBOL_VALUE_ADDRESS (sym) =
3473 decode_locdesc (DW_BLOCK (attr), objfile);
3474 add_symbol_to_list (sym, &global_symbols);
3475 SYMBOL_CLASS (sym) = LOC_STATIC;
3476 SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
3480 SYMBOL_VALUE (sym) = addr =
3481 decode_locdesc (DW_BLOCK (attr), objfile);
3482 add_symbol_to_list (sym, list_in_scope);
3485 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
3489 SYMBOL_CLASS (sym) = LOC_REGISTER;
3493 SYMBOL_CLASS (sym) = LOC_BASEREG;
3494 SYMBOL_BASEREG (sym) = basereg;
3498 SYMBOL_CLASS (sym) = LOC_LOCAL;
3502 SYMBOL_CLASS (sym) = LOC_STATIC;
3503 SYMBOL_VALUE_ADDRESS (sym) = addr + baseaddr;
3509 /* We do not know the address of this symbol.
3510 If it is an external symbol and we have type information
3511 it, enter the symbol as a LOC_UNRESOLVED symbol.
3512 The address of the variable will then be determined from
3513 the minimal symbol table whenever the variable is
3515 attr2 = dwarf_attr (die, DW_AT_external);
3516 if (attr2 && (DW_UNSND (attr2) != 0)
3517 && dwarf_attr (die, DW_AT_type) != NULL)
3519 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
3520 add_symbol_to_list (sym, &global_symbols);
3524 case DW_TAG_formal_parameter:
3525 attr = dwarf_attr (die, DW_AT_location);
3528 SYMBOL_VALUE (sym) = decode_locdesc (DW_BLOCK (attr), objfile);
3530 add_symbol_to_list (sym, list_in_scope);
3533 SYMBOL_CLASS (sym) = LOC_REGPARM;
3537 SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
3538 SYMBOL_BASEREG (sym) = basereg;
3542 SYMBOL_CLASS (sym) = LOC_ARG;
3545 case DW_TAG_unspecified_parameters:
3546 /* From varargs functions; gdb doesn't seem to have any
3547 interest in this information, so just ignore it for now.
3550 case DW_TAG_class_type:
3551 case DW_TAG_structure_type:
3552 case DW_TAG_union_type:
3553 case DW_TAG_enumeration_type:
3554 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3555 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
3556 add_symbol_to_list (sym, list_in_scope);
3558 /* The semantics of C++ state that "struct foo { ... }" also
3559 defines a typedef for "foo". Synthesize a typedef symbol so
3560 that "ptype foo" works as expected. */
3561 if (cu_language == language_cplus)
3563 struct symbol *typedef_sym = (struct symbol *)
3564 obstack_alloc (&objfile->symbol_obstack,
3565 sizeof (struct symbol));
3566 *typedef_sym = *sym;
3567 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
3568 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
3569 TYPE_NAME (SYMBOL_TYPE (sym)) =
3570 obsavestring (SYMBOL_NAME (sym),
3571 strlen (SYMBOL_NAME (sym)),
3572 &objfile->type_obstack);
3573 add_symbol_to_list (typedef_sym, list_in_scope);
3576 case DW_TAG_typedef:
3577 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3578 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3579 add_symbol_to_list (sym, list_in_scope);
3581 case DW_TAG_enumerator:
3582 SYMBOL_CLASS (sym) = LOC_CONST;
3583 attr = dwarf_attr (die, DW_AT_const_value);
3586 SYMBOL_VALUE (sym) = DW_UNSND (attr);
3588 add_symbol_to_list (sym, list_in_scope);
3591 /* Not a tag we recognize. Hopefully we aren't processing
3592 trash data, but since we must specifically ignore things
3593 we don't recognize, there is nothing else we should do at
3595 complain (&dwarf2_unsupported_tag, dwarf_tag_name (die->tag));
3602 /* Return the type of the die in question using its DW_AT_type attribute. */
3604 static struct type *
3605 die_type (die, objfile)
3606 struct die_info *die;
3607 struct objfile *objfile;
3610 struct attribute *type_attr;
3611 struct die_info *type_die;
3614 type_attr = dwarf_attr (die, DW_AT_type);
3617 /* A missing DW_AT_type represents a void type. */
3618 return dwarf2_fundamental_type (objfile, FT_VOID);
3622 ref = dwarf2_get_ref_die_offset (type_attr);
3623 type_die = follow_die_ref (ref);
3626 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
3630 type = tag_type_to_type (type_die, objfile);
3633 dump_die (type_die);
3634 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
3639 /* Return the containing type of the die in question using its
3640 DW_AT_containing_type attribute. */
3642 static struct type *
3643 die_containing_type (die, objfile)
3644 struct die_info *die;
3645 struct objfile *objfile;
3647 struct type *type = NULL;
3648 struct attribute *type_attr;
3649 struct die_info *type_die = NULL;
3652 type_attr = dwarf_attr (die, DW_AT_containing_type);
3655 ref = dwarf2_get_ref_die_offset (type_attr);
3656 type_die = follow_die_ref (ref);
3659 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
3662 type = tag_type_to_type (type_die, objfile);
3667 dump_die (type_die);
3668 error ("Dwarf Error: Problem turning containing type into gdb type.");
3674 static struct type *
3675 type_at_offset (offset, objfile)
3676 unsigned int offset;
3677 struct objfile *objfile;
3679 struct die_info *die;
3682 die = follow_die_ref (offset);
3685 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
3688 type = tag_type_to_type (die, objfile);
3693 static struct type *
3694 tag_type_to_type (die, objfile)
3695 struct die_info *die;
3696 struct objfile *objfile;
3704 read_type_die (die, objfile);
3708 error ("Dwarf Error: Cannot find type of die.");
3715 read_type_die (die, objfile)
3716 struct die_info *die;
3717 struct objfile *objfile;
3721 case DW_TAG_class_type:
3722 case DW_TAG_structure_type:
3723 case DW_TAG_union_type:
3724 read_structure_scope (die, objfile);
3726 case DW_TAG_enumeration_type:
3727 read_enumeration (die, objfile);
3729 case DW_TAG_subprogram:
3730 case DW_TAG_subroutine_type:
3731 read_subroutine_type (die, objfile);
3733 case DW_TAG_array_type:
3734 dwarf_read_array_type (die, objfile);
3736 case DW_TAG_pointer_type:
3737 read_tag_pointer_type (die, objfile);
3739 case DW_TAG_ptr_to_member_type:
3740 read_tag_ptr_to_member_type (die, objfile);
3742 case DW_TAG_reference_type:
3743 read_tag_reference_type (die, objfile);
3745 case DW_TAG_const_type:
3746 read_tag_const_type (die, objfile);
3748 case DW_TAG_volatile_type:
3749 read_tag_volatile_type (die, objfile);
3751 case DW_TAG_string_type:
3752 read_tag_string_type (die, objfile);
3754 case DW_TAG_typedef:
3755 read_typedef (die, objfile);
3757 case DW_TAG_base_type:
3758 read_base_type (die, objfile);
3760 case DW_TAG_padding:
3761 case DW_TAG_compile_unit:
3762 case DW_TAG_lexical_block:
3768 static struct type *
3769 dwarf_base_type (encoding, size)
3773 /* FIXME - this should not produce a new (struct type *)
3774 every time. It should cache base types. */
3778 case DW_ATE_address:
3779 type = dwarf2_fundamental_type (current_objfile, FT_VOID);
3781 case DW_ATE_boolean:
3782 type = dwarf2_fundamental_type (current_objfile, FT_BOOLEAN);
3784 case DW_ATE_complex_float:
3787 type = dwarf2_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
3791 type = dwarf2_fundamental_type (current_objfile, FT_COMPLEX);
3797 type = dwarf2_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
3801 type = dwarf2_fundamental_type (current_objfile, FT_FLOAT);
3808 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3811 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_SHORT);
3815 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3819 case DW_ATE_signed_char:
3820 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3822 case DW_ATE_unsigned:
3826 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3829 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
3833 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
3837 case DW_ATE_unsigned_char:
3838 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3841 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3849 struct die_info *old_die;
3851 struct die_info *new_die;
3854 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
3855 memset (new_die, 0, sizeof (struct die_info));
3857 new_die->tag = old_die->tag;
3858 new_die->has_children = old_die->has_children;
3859 new_die->abbrev = old_die->abbrev;
3860 new_die->offset = old_die->offset;
3861 new_die->type = NULL;
3863 num_attrs = old_die->num_attrs;
3864 new_die->num_attrs = num_attrs;
3865 new_die->attrs = (struct attribute *)
3866 xmalloc (num_attrs * sizeof (struct attribute));
3868 for (i = 0; i < old_die->num_attrs; ++i)
3870 new_die->attrs[i].name = old_die->attrs[i].name;
3871 new_die->attrs[i].form = old_die->attrs[i].form;
3872 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
3875 new_die->next = NULL;
3880 /* Return sibling of die, NULL if no sibling. */
3884 struct die_info *die;
3886 int nesting_level = 0;
3888 if (!die->has_children)
3890 if (die->next && (die->next->tag == 0))
3903 if (die->has_children)
3913 while (nesting_level);
3914 if (die && (die->tag == 0))
3925 /* Convert a DIE tag into its string name. */
3928 dwarf_tag_name (tag)
3929 register unsigned tag;
3933 case DW_TAG_padding:
3934 return "DW_TAG_padding";
3935 case DW_TAG_array_type:
3936 return "DW_TAG_array_type";
3937 case DW_TAG_class_type:
3938 return "DW_TAG_class_type";
3939 case DW_TAG_entry_point:
3940 return "DW_TAG_entry_point";
3941 case DW_TAG_enumeration_type:
3942 return "DW_TAG_enumeration_type";
3943 case DW_TAG_formal_parameter:
3944 return "DW_TAG_formal_parameter";
3945 case DW_TAG_imported_declaration:
3946 return "DW_TAG_imported_declaration";
3948 return "DW_TAG_label";
3949 case DW_TAG_lexical_block:
3950 return "DW_TAG_lexical_block";
3952 return "DW_TAG_member";
3953 case DW_TAG_pointer_type:
3954 return "DW_TAG_pointer_type";
3955 case DW_TAG_reference_type:
3956 return "DW_TAG_reference_type";
3957 case DW_TAG_compile_unit:
3958 return "DW_TAG_compile_unit";
3959 case DW_TAG_string_type:
3960 return "DW_TAG_string_type";
3961 case DW_TAG_structure_type:
3962 return "DW_TAG_structure_type";
3963 case DW_TAG_subroutine_type:
3964 return "DW_TAG_subroutine_type";
3965 case DW_TAG_typedef:
3966 return "DW_TAG_typedef";
3967 case DW_TAG_union_type:
3968 return "DW_TAG_union_type";
3969 case DW_TAG_unspecified_parameters:
3970 return "DW_TAG_unspecified_parameters";
3971 case DW_TAG_variant:
3972 return "DW_TAG_variant";
3973 case DW_TAG_common_block:
3974 return "DW_TAG_common_block";
3975 case DW_TAG_common_inclusion:
3976 return "DW_TAG_common_inclusion";
3977 case DW_TAG_inheritance:
3978 return "DW_TAG_inheritance";
3979 case DW_TAG_inlined_subroutine:
3980 return "DW_TAG_inlined_subroutine";
3982 return "DW_TAG_module";
3983 case DW_TAG_ptr_to_member_type:
3984 return "DW_TAG_ptr_to_member_type";
3985 case DW_TAG_set_type:
3986 return "DW_TAG_set_type";
3987 case DW_TAG_subrange_type:
3988 return "DW_TAG_subrange_type";
3989 case DW_TAG_with_stmt:
3990 return "DW_TAG_with_stmt";
3991 case DW_TAG_access_declaration:
3992 return "DW_TAG_access_declaration";
3993 case DW_TAG_base_type:
3994 return "DW_TAG_base_type";
3995 case DW_TAG_catch_block:
3996 return "DW_TAG_catch_block";
3997 case DW_TAG_const_type:
3998 return "DW_TAG_const_type";
3999 case DW_TAG_constant:
4000 return "DW_TAG_constant";
4001 case DW_TAG_enumerator:
4002 return "DW_TAG_enumerator";
4003 case DW_TAG_file_type:
4004 return "DW_TAG_file_type";
4006 return "DW_TAG_friend";
4007 case DW_TAG_namelist:
4008 return "DW_TAG_namelist";
4009 case DW_TAG_namelist_item:
4010 return "DW_TAG_namelist_item";
4011 case DW_TAG_packed_type:
4012 return "DW_TAG_packed_type";
4013 case DW_TAG_subprogram:
4014 return "DW_TAG_subprogram";
4015 case DW_TAG_template_type_param:
4016 return "DW_TAG_template_type_param";
4017 case DW_TAG_template_value_param:
4018 return "DW_TAG_template_value_param";
4019 case DW_TAG_thrown_type:
4020 return "DW_TAG_thrown_type";
4021 case DW_TAG_try_block:
4022 return "DW_TAG_try_block";
4023 case DW_TAG_variant_part:
4024 return "DW_TAG_variant_part";
4025 case DW_TAG_variable:
4026 return "DW_TAG_variable";
4027 case DW_TAG_volatile_type:
4028 return "DW_TAG_volatile_type";
4029 case DW_TAG_MIPS_loop:
4030 return "DW_TAG_MIPS_loop";
4031 case DW_TAG_format_label:
4032 return "DW_TAG_format_label";
4033 case DW_TAG_function_template:
4034 return "DW_TAG_function_template";
4035 case DW_TAG_class_template:
4036 return "DW_TAG_class_template";
4038 return "DW_TAG_<unknown>";
4042 /* Convert a DWARF attribute code into its string name. */
4045 dwarf_attr_name (attr)
4046 register unsigned attr;
4051 return "DW_AT_sibling";
4052 case DW_AT_location:
4053 return "DW_AT_location";
4055 return "DW_AT_name";
4056 case DW_AT_ordering:
4057 return "DW_AT_ordering";
4058 case DW_AT_subscr_data:
4059 return "DW_AT_subscr_data";
4060 case DW_AT_byte_size:
4061 return "DW_AT_byte_size";
4062 case DW_AT_bit_offset:
4063 return "DW_AT_bit_offset";
4064 case DW_AT_bit_size:
4065 return "DW_AT_bit_size";
4066 case DW_AT_element_list:
4067 return "DW_AT_element_list";
4068 case DW_AT_stmt_list:
4069 return "DW_AT_stmt_list";
4071 return "DW_AT_low_pc";
4073 return "DW_AT_high_pc";
4074 case DW_AT_language:
4075 return "DW_AT_language";
4077 return "DW_AT_member";
4079 return "DW_AT_discr";
4080 case DW_AT_discr_value:
4081 return "DW_AT_discr_value";
4082 case DW_AT_visibility:
4083 return "DW_AT_visibility";
4085 return "DW_AT_import";
4086 case DW_AT_string_length:
4087 return "DW_AT_string_length";
4088 case DW_AT_common_reference:
4089 return "DW_AT_common_reference";
4090 case DW_AT_comp_dir:
4091 return "DW_AT_comp_dir";
4092 case DW_AT_const_value:
4093 return "DW_AT_const_value";
4094 case DW_AT_containing_type:
4095 return "DW_AT_containing_type";
4096 case DW_AT_default_value:
4097 return "DW_AT_default_value";
4099 return "DW_AT_inline";
4100 case DW_AT_is_optional:
4101 return "DW_AT_is_optional";
4102 case DW_AT_lower_bound:
4103 return "DW_AT_lower_bound";
4104 case DW_AT_producer:
4105 return "DW_AT_producer";
4106 case DW_AT_prototyped:
4107 return "DW_AT_prototyped";
4108 case DW_AT_return_addr:
4109 return "DW_AT_return_addr";
4110 case DW_AT_start_scope:
4111 return "DW_AT_start_scope";
4112 case DW_AT_stride_size:
4113 return "DW_AT_stride_size";
4114 case DW_AT_upper_bound:
4115 return "DW_AT_upper_bound";
4116 case DW_AT_abstract_origin:
4117 return "DW_AT_abstract_origin";
4118 case DW_AT_accessibility:
4119 return "DW_AT_accessibility";
4120 case DW_AT_address_class:
4121 return "DW_AT_address_class";
4122 case DW_AT_artificial:
4123 return "DW_AT_artificial";
4124 case DW_AT_base_types:
4125 return "DW_AT_base_types";
4126 case DW_AT_calling_convention:
4127 return "DW_AT_calling_convention";
4129 return "DW_AT_count";
4130 case DW_AT_data_member_location:
4131 return "DW_AT_data_member_location";
4132 case DW_AT_decl_column:
4133 return "DW_AT_decl_column";
4134 case DW_AT_decl_file:
4135 return "DW_AT_decl_file";
4136 case DW_AT_decl_line:
4137 return "DW_AT_decl_line";
4138 case DW_AT_declaration:
4139 return "DW_AT_declaration";
4140 case DW_AT_discr_list:
4141 return "DW_AT_discr_list";
4142 case DW_AT_encoding:
4143 return "DW_AT_encoding";
4144 case DW_AT_external:
4145 return "DW_AT_external";
4146 case DW_AT_frame_base:
4147 return "DW_AT_frame_base";
4149 return "DW_AT_friend";
4150 case DW_AT_identifier_case:
4151 return "DW_AT_identifier_case";
4152 case DW_AT_macro_info:
4153 return "DW_AT_macro_info";
4154 case DW_AT_namelist_items:
4155 return "DW_AT_namelist_items";
4156 case DW_AT_priority:
4157 return "DW_AT_priority";
4159 return "DW_AT_segment";
4160 case DW_AT_specification:
4161 return "DW_AT_specification";
4162 case DW_AT_static_link:
4163 return "DW_AT_static_link";
4165 return "DW_AT_type";
4166 case DW_AT_use_location:
4167 return "DW_AT_use_location";
4168 case DW_AT_variable_parameter:
4169 return "DW_AT_variable_parameter";
4170 case DW_AT_virtuality:
4171 return "DW_AT_virtuality";
4172 case DW_AT_vtable_elem_location:
4173 return "DW_AT_vtable_elem_location";
4176 case DW_AT_MIPS_fde:
4177 return "DW_AT_MIPS_fde";
4178 case DW_AT_MIPS_loop_begin:
4179 return "DW_AT_MIPS_loop_begin";
4180 case DW_AT_MIPS_tail_loop_begin:
4181 return "DW_AT_MIPS_tail_loop_begin";
4182 case DW_AT_MIPS_epilog_begin:
4183 return "DW_AT_MIPS_epilog_begin";
4184 case DW_AT_MIPS_loop_unroll_factor:
4185 return "DW_AT_MIPS_loop_unroll_factor";
4186 case DW_AT_MIPS_software_pipeline_depth:
4187 return "DW_AT_MIPS_software_pipeline_depth";
4188 case DW_AT_MIPS_linkage_name:
4189 return "DW_AT_MIPS_linkage_name";
4192 case DW_AT_sf_names:
4193 return "DW_AT_sf_names";
4194 case DW_AT_src_info:
4195 return "DW_AT_src_info";
4196 case DW_AT_mac_info:
4197 return "DW_AT_mac_info";
4198 case DW_AT_src_coords:
4199 return "DW_AT_src_coords";
4200 case DW_AT_body_begin:
4201 return "DW_AT_body_begin";
4202 case DW_AT_body_end:
4203 return "DW_AT_body_end";
4205 return "DW_AT_<unknown>";
4209 /* Convert a DWARF value form code into its string name. */
4212 dwarf_form_name (form)
4213 register unsigned form;
4218 return "DW_FORM_addr";
4219 case DW_FORM_block2:
4220 return "DW_FORM_block2";
4221 case DW_FORM_block4:
4222 return "DW_FORM_block4";
4224 return "DW_FORM_data2";
4226 return "DW_FORM_data4";
4228 return "DW_FORM_data8";
4229 case DW_FORM_string:
4230 return "DW_FORM_string";
4232 return "DW_FORM_block";
4233 case DW_FORM_block1:
4234 return "DW_FORM_block1";
4236 return "DW_FORM_data1";
4238 return "DW_FORM_flag";
4240 return "DW_FORM_sdata";
4242 return "DW_FORM_strp";
4244 return "DW_FORM_udata";
4245 case DW_FORM_ref_addr:
4246 return "DW_FORM_ref_addr";
4248 return "DW_FORM_ref1";
4250 return "DW_FORM_ref2";
4252 return "DW_FORM_ref4";
4254 return "DW_FORM_ref8";
4255 case DW_FORM_ref_udata:
4256 return "DW_FORM_ref_udata";
4257 case DW_FORM_indirect:
4258 return "DW_FORM_indirect";
4260 return "DW_FORM_<unknown>";
4264 /* Convert a DWARF stack opcode into its string name. */
4267 dwarf_stack_op_name (op)
4268 register unsigned op;
4273 return "DW_OP_addr";
4275 return "DW_OP_deref";
4277 return "DW_OP_const1u";
4279 return "DW_OP_const1s";
4281 return "DW_OP_const2u";
4283 return "DW_OP_const2s";
4285 return "DW_OP_const4u";
4287 return "DW_OP_const4s";
4289 return "DW_OP_const8u";
4291 return "DW_OP_const8s";
4293 return "DW_OP_constu";
4295 return "DW_OP_consts";
4299 return "DW_OP_drop";
4301 return "DW_OP_over";
4303 return "DW_OP_pick";
4305 return "DW_OP_swap";
4309 return "DW_OP_xderef";
4317 return "DW_OP_minus";
4329 return "DW_OP_plus";
4330 case DW_OP_plus_uconst:
4331 return "DW_OP_plus_uconst";
4337 return "DW_OP_shra";
4355 return "DW_OP_skip";
4357 return "DW_OP_lit0";
4359 return "DW_OP_lit1";
4361 return "DW_OP_lit2";
4363 return "DW_OP_lit3";
4365 return "DW_OP_lit4";
4367 return "DW_OP_lit5";
4369 return "DW_OP_lit6";
4371 return "DW_OP_lit7";
4373 return "DW_OP_lit8";
4375 return "DW_OP_lit9";
4377 return "DW_OP_lit10";
4379 return "DW_OP_lit11";
4381 return "DW_OP_lit12";
4383 return "DW_OP_lit13";
4385 return "DW_OP_lit14";
4387 return "DW_OP_lit15";
4389 return "DW_OP_lit16";
4391 return "DW_OP_lit17";
4393 return "DW_OP_lit18";
4395 return "DW_OP_lit19";
4397 return "DW_OP_lit20";
4399 return "DW_OP_lit21";
4401 return "DW_OP_lit22";
4403 return "DW_OP_lit23";
4405 return "DW_OP_lit24";
4407 return "DW_OP_lit25";
4409 return "DW_OP_lit26";
4411 return "DW_OP_lit27";
4413 return "DW_OP_lit28";
4415 return "DW_OP_lit29";
4417 return "DW_OP_lit30";
4419 return "DW_OP_lit31";
4421 return "DW_OP_reg0";
4423 return "DW_OP_reg1";
4425 return "DW_OP_reg2";
4427 return "DW_OP_reg3";
4429 return "DW_OP_reg4";
4431 return "DW_OP_reg5";
4433 return "DW_OP_reg6";
4435 return "DW_OP_reg7";
4437 return "DW_OP_reg8";
4439 return "DW_OP_reg9";
4441 return "DW_OP_reg10";
4443 return "DW_OP_reg11";
4445 return "DW_OP_reg12";
4447 return "DW_OP_reg13";
4449 return "DW_OP_reg14";
4451 return "DW_OP_reg15";
4453 return "DW_OP_reg16";
4455 return "DW_OP_reg17";
4457 return "DW_OP_reg18";
4459 return "DW_OP_reg19";
4461 return "DW_OP_reg20";
4463 return "DW_OP_reg21";
4465 return "DW_OP_reg22";
4467 return "DW_OP_reg23";
4469 return "DW_OP_reg24";
4471 return "DW_OP_reg25";
4473 return "DW_OP_reg26";
4475 return "DW_OP_reg27";
4477 return "DW_OP_reg28";
4479 return "DW_OP_reg29";
4481 return "DW_OP_reg30";
4483 return "DW_OP_reg31";
4485 return "DW_OP_breg0";
4487 return "DW_OP_breg1";
4489 return "DW_OP_breg2";
4491 return "DW_OP_breg3";
4493 return "DW_OP_breg4";
4495 return "DW_OP_breg5";
4497 return "DW_OP_breg6";
4499 return "DW_OP_breg7";
4501 return "DW_OP_breg8";
4503 return "DW_OP_breg9";
4505 return "DW_OP_breg10";
4507 return "DW_OP_breg11";
4509 return "DW_OP_breg12";
4511 return "DW_OP_breg13";
4513 return "DW_OP_breg14";
4515 return "DW_OP_breg15";
4517 return "DW_OP_breg16";
4519 return "DW_OP_breg17";
4521 return "DW_OP_breg18";
4523 return "DW_OP_breg19";
4525 return "DW_OP_breg20";
4527 return "DW_OP_breg21";
4529 return "DW_OP_breg22";
4531 return "DW_OP_breg23";
4533 return "DW_OP_breg24";
4535 return "DW_OP_breg25";
4537 return "DW_OP_breg26";
4539 return "DW_OP_breg27";
4541 return "DW_OP_breg28";
4543 return "DW_OP_breg29";
4545 return "DW_OP_breg30";
4547 return "DW_OP_breg31";
4549 return "DW_OP_regx";
4551 return "DW_OP_fbreg";
4553 return "DW_OP_bregx";
4555 return "DW_OP_piece";
4556 case DW_OP_deref_size:
4557 return "DW_OP_deref_size";
4558 case DW_OP_xderef_size:
4559 return "DW_OP_xderef_size";
4563 return "OP_<unknown>";
4568 dwarf_bool_name (bool)
4577 /* Convert a DWARF type code into its string name. */
4580 dwarf_type_encoding_name (enc)
4581 register unsigned enc;
4585 case DW_ATE_address:
4586 return "DW_ATE_address";
4587 case DW_ATE_boolean:
4588 return "DW_ATE_boolean";
4589 case DW_ATE_complex_float:
4590 return "DW_ATE_complex_float";
4592 return "DW_ATE_float";
4594 return "DW_ATE_signed";
4595 case DW_ATE_signed_char:
4596 return "DW_ATE_signed_char";
4597 case DW_ATE_unsigned:
4598 return "DW_ATE_unsigned";
4599 case DW_ATE_unsigned_char:
4600 return "DW_ATE_unsigned_char";
4602 return "DW_ATE_<unknown>";
4606 /* Convert a DWARF call frame info operation to its string name. */
4610 dwarf_cfi_name (cfi_opc)
4611 register unsigned cfi_opc;
4615 case DW_CFA_advance_loc:
4616 return "DW_CFA_advance_loc";
4618 return "DW_CFA_offset";
4619 case DW_CFA_restore:
4620 return "DW_CFA_restore";
4622 return "DW_CFA_nop";
4623 case DW_CFA_set_loc:
4624 return "DW_CFA_set_loc";
4625 case DW_CFA_advance_loc1:
4626 return "DW_CFA_advance_loc1";
4627 case DW_CFA_advance_loc2:
4628 return "DW_CFA_advance_loc2";
4629 case DW_CFA_advance_loc4:
4630 return "DW_CFA_advance_loc4";
4631 case DW_CFA_offset_extended:
4632 return "DW_CFA_offset_extended";
4633 case DW_CFA_restore_extended:
4634 return "DW_CFA_restore_extended";
4635 case DW_CFA_undefined:
4636 return "DW_CFA_undefined";
4637 case DW_CFA_same_value:
4638 return "DW_CFA_same_value";
4639 case DW_CFA_register:
4640 return "DW_CFA_register";
4641 case DW_CFA_remember_state:
4642 return "DW_CFA_remember_state";
4643 case DW_CFA_restore_state:
4644 return "DW_CFA_restore_state";
4645 case DW_CFA_def_cfa:
4646 return "DW_CFA_def_cfa";
4647 case DW_CFA_def_cfa_register:
4648 return "DW_CFA_def_cfa_register";
4649 case DW_CFA_def_cfa_offset:
4650 return "DW_CFA_def_cfa_offset";
4651 /* SGI/MIPS specific */
4652 case DW_CFA_MIPS_advance_loc8:
4653 return "DW_CFA_MIPS_advance_loc8";
4655 return "DW_CFA_<unknown>";
4662 struct die_info *die;
4666 fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n",
4667 dwarf_tag_name (die->tag), die->abbrev, die->offset);
4668 fprintf (stderr, "\thas children: %s\n",
4669 dwarf_bool_name (die->has_children));
4671 fprintf (stderr, "\tattributes:\n");
4672 for (i = 0; i < die->num_attrs; ++i)
4674 fprintf (stderr, "\t\t%s (%s) ",
4675 dwarf_attr_name (die->attrs[i].name),
4676 dwarf_form_name (die->attrs[i].form));
4677 switch (die->attrs[i].form)
4679 case DW_FORM_ref_addr:
4681 fprintf (stderr, "address: ");
4682 print_address_numeric (die->attrs[i].u.addr, 1, stderr);
4684 case DW_FORM_block2:
4685 case DW_FORM_block4:
4687 case DW_FORM_block1:
4688 fprintf (stderr, "block: size %d",
4689 die->attrs[i].u.blk->size);
4699 fprintf (stderr, "constant: %d", die->attrs[i].u.unsnd);
4701 case DW_FORM_string:
4702 fprintf (stderr, "string: \"%s\"", die->attrs[i].u.str);
4705 if (die->attrs[i].u.unsnd)
4706 fprintf (stderr, "flag: TRUE");
4708 fprintf (stderr, "flag: FALSE");
4710 case DW_FORM_strp: /* we do not support separate string
4712 case DW_FORM_indirect: /* we do not handle indirect yet */
4713 case DW_FORM_data8: /* we do not have 64 bit quantities */
4715 fprintf (stderr, "unsupported attribute form: %d.",
4716 die->attrs[i].form);
4718 fprintf (stderr, "\n");
4724 struct die_info *die;
4734 store_in_ref_table (offset, die)
4735 unsigned int offset;
4736 struct die_info *die;
4739 struct die_info *old;
4741 h = (offset % REF_HASH_SIZE);
4742 old = die_ref_table[h];
4743 die->next_ref = old;
4744 die_ref_table[h] = die;
4749 dwarf2_empty_die_ref_table ()
4751 memset (die_ref_table, 0, sizeof (die_ref_table));
4755 dwarf2_get_ref_die_offset (attr)
4756 struct attribute *attr;
4758 unsigned int result = 0;
4762 case DW_FORM_ref_addr:
4763 result = DW_ADDR (attr);
4768 case DW_FORM_ref_udata:
4769 result = cu_header_offset + DW_UNSND (attr);
4772 complain (&dwarf2_unsupported_die_ref_attr, dwarf_form_name (attr->form));
4778 follow_die_ref (offset)
4779 unsigned int offset;
4781 struct die_info *die;
4784 h = (offset % REF_HASH_SIZE);
4785 die = die_ref_table[h];
4788 if (die->offset == offset)
4792 die = die->next_ref;
4797 static struct type *
4798 dwarf2_fundamental_type (objfile, typeid)
4799 struct objfile *objfile;
4802 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
4804 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
4808 /* Look for this particular type in the fundamental type vector. If
4809 one is not found, create and install one appropriate for the
4810 current language and the current target machine. */
4812 if (ftypes[typeid] == NULL)
4814 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
4817 return (ftypes[typeid]);
4820 /* Decode simple location descriptions.
4821 Given a pointer to a dwarf block that defines a location, compute
4822 the location and return the value.
4824 FIXME: This is a kludge until we figure out a better
4825 way to handle the location descriptions.
4826 Gdb's design does not mesh well with the DWARF2 notion of a location
4827 computing interpreter, which is a shame because the flexibility goes unused.
4828 FIXME: Implement more operations as necessary.
4830 A location description containing no operations indicates that the
4831 object is optimized out. The global optimized_out flag is set for
4832 those, the return value is meaningless.
4834 When the result is a register number, the global isreg flag is set,
4835 otherwise it is cleared.
4837 When the result is a base register offset, the global offreg flag is set
4838 and the register number is returned in basereg, otherwise it is cleared.
4840 When the DW_OP_fbreg operation is encountered without a corresponding
4841 DW_AT_frame_base attribute, the global islocal flag is set.
4842 Hopefully the machine dependent code knows how to set up a virtual
4843 frame pointer for the local references.
4845 Note that stack[0] is unused except as a default error return.
4846 Note that stack overflow is not yet handled. */
4849 decode_locdesc (blk, objfile)
4850 struct dwarf_block *blk;
4851 struct objfile *objfile;
4854 int size = blk->size;
4855 char *data = blk->data;
4856 CORE_ADDR stack[64];
4858 unsigned int bytes_read, unsnd;
4908 stack[++stacki] = op - DW_OP_reg0;
4913 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
4915 #if defined(HARRIS_TARGET) && defined(_M88K)
4916 /* The Harris 88110 gdb ports have long kept their special reg
4917 numbers between their gp-regs and their x-regs. This is
4918 not how our dwarf is generated. Punt. */
4921 stack[++stacki] = unsnd;
4957 basereg = op - DW_OP_breg0;
4958 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
4963 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
4965 if (frame_base_reg >= 0)
4968 basereg = frame_base_reg;
4969 stack[stacki] += frame_base_offset;
4973 complain (&dwarf2_missing_at_frame_base);
4979 stack[++stacki] = read_address (objfile->obfd, &data[i]);
4984 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
4989 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
4994 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
4999 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
5004 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
5009 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
5014 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
5020 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5025 stack[stacki - 1] += stack[stacki];
5030 stack[stacki - 1] = stack[stacki] - stack[stacki - 1];
5035 complain (&dwarf2_unsupported_stack_op, dwarf_stack_op_name(op));
5036 return (stack[stacki]);
5039 return (stack[stacki]);
5042 /* memory allocation interface */
5046 dwarf2_free_tmp_obstack (ignore)
5049 obstack_free (&dwarf2_tmp_obstack, NULL);
5052 static struct dwarf_block *
5053 dwarf_alloc_block ()
5055 struct dwarf_block *blk;
5057 blk = (struct dwarf_block *)
5058 obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
5062 static struct abbrev_info *
5063 dwarf_alloc_abbrev ()
5065 struct abbrev_info *abbrev;
5067 abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
5068 memset (abbrev, 0, sizeof (struct abbrev_info));
5072 static struct die_info *
5075 struct die_info *die;
5077 die = (struct die_info *) xmalloc (sizeof (struct die_info));
5078 memset (die, 0, sizeof (struct die_info));