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"
40 #include "gdb_string.h"
41 #include <sys/types.h>
43 /* .debug_info header for a compilation unit
44 Because of alignment constraints, this structure has padding and cannot
45 be mapped directly onto the beginning of the .debug_info section. */
46 typedef struct comp_unit_header
48 unsigned int length; /* length of the .debug_info
50 unsigned short version; /* version number -- 2 for DWARF
52 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
53 unsigned char addr_size; /* byte size of an address -- 4 */
56 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
58 /* .debug_pubnames header
59 Because of alignment constraints, this structure has padding and cannot
60 be mapped directly onto the beginning of the .debug_info section. */
61 typedef struct pubnames_header
63 unsigned int length; /* length of the .debug_pubnames
65 unsigned char version; /* version number -- 2 for DWARF
67 unsigned int info_offset; /* offset into .debug_info section */
68 unsigned int info_size; /* byte size of .debug_info section
72 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
74 /* .debug_pubnames header
75 Because of alignment constraints, this structure has padding and cannot
76 be mapped directly onto the beginning of the .debug_info section. */
77 typedef struct aranges_header
79 unsigned int length; /* byte len of the .debug_aranges
81 unsigned short version; /* version number -- 2 for DWARF
83 unsigned int info_offset; /* offset into .debug_info section */
84 unsigned char addr_size; /* byte size of an address */
85 unsigned char seg_size; /* byte size of segment descriptor */
88 #define _ACTUAL_ARANGES_HEADER_SIZE 12
90 /* .debug_line statement program prologue
91 Because of alignment constraints, this structure has padding and cannot
92 be mapped directly onto the beginning of the .debug_info section. */
93 typedef struct statement_prologue
95 unsigned int total_length; /* byte length of the statement
97 unsigned short version; /* version number -- 2 for DWARF
99 unsigned int prologue_length; /* # bytes between prologue &
101 unsigned char minimum_instruction_length; /* byte size of
103 unsigned char default_is_stmt; /* initial value of is_stmt
106 unsigned char line_range;
107 unsigned char opcode_base; /* number assigned to first special
109 unsigned char *standard_opcode_lengths;
113 /* offsets and sizes of debugging sections */
115 static file_ptr dwarf_info_offset;
116 static file_ptr dwarf_abbrev_offset;
117 static file_ptr dwarf_line_offset;
118 static file_ptr dwarf_pubnames_offset;
119 static file_ptr dwarf_aranges_offset;
120 static file_ptr dwarf_loc_offset;
121 static file_ptr dwarf_macinfo_offset;
122 static file_ptr dwarf_str_offset;
124 static unsigned int dwarf_info_size;
125 static unsigned int dwarf_abbrev_size;
126 static unsigned int dwarf_line_size;
127 static unsigned int dwarf_pubnames_size;
128 static unsigned int dwarf_aranges_size;
129 static unsigned int dwarf_loc_size;
130 static unsigned int dwarf_macinfo_size;
131 static unsigned int dwarf_str_size;
133 /* names of the debugging sections */
135 #define INFO_SECTION ".debug_info"
136 #define ABBREV_SECTION ".debug_abbrev"
137 #define LINE_SECTION ".debug_line"
138 #define PUBNAMES_SECTION ".debug_pubnames"
139 #define ARANGES_SECTION ".debug_aranges"
140 #define LOC_SECTION ".debug_loc"
141 #define MACINFO_SECTION ".debug_macinfo"
142 #define STR_SECTION ".debug_str"
144 /* Get at parts of an attribute structure */
146 #define DW_STRING(attr) ((attr)->u.str)
147 #define DW_UNSND(attr) ((attr)->u.unsnd)
148 #define DW_BLOCK(attr) ((attr)->u.blk)
149 #define DW_SND(attr) ((attr)->u.snd)
150 #define DW_ADDR(attr) ((attr)->u.addr)
152 /* local data types */
154 /* The data in a compilation unit header looks like this. */
155 struct comp_unit_head
160 unsigned char addr_size;
163 /* The data in the .debug_line statement prologue looks like this. */
166 unsigned int total_length;
167 unsigned short version;
168 unsigned int prologue_length;
169 unsigned char minimum_instruction_length;
170 unsigned char default_is_stmt;
172 unsigned char line_range;
173 unsigned char opcode_base;
174 unsigned char *standard_opcode_lengths;
177 /* When we construct a partial symbol table entry we only
178 need this much information. */
179 struct partial_die_info
182 unsigned char has_children;
183 unsigned char is_external;
189 struct dwarf_block *locdesc;
190 unsigned int language;
194 /* This data structure holds the information of an abbrev. */
197 unsigned int number; /* number identifying abbrev */
198 unsigned int tag; /* dwarf tag */
199 int has_children; /* boolean */
200 unsigned int num_attrs; /* number of attributes */
201 struct attr_abbrev *attrs; /* an array of attribute descriptions */
202 struct abbrev_info *next; /* next in chain */
211 /* This data structure holds a complete die structure. */
214 unsigned short tag; /* Tag indicating type of die */
215 unsigned short has_children; /* Does the die have children */
216 unsigned int abbrev; /* Abbrev number */
217 unsigned int offset; /* Offset in .debug_info section */
218 unsigned int num_attrs; /* Number of attributes */
219 struct attribute *attrs; /* An array of attributes */
220 struct die_info *next_ref; /* Next die in ref hash table */
221 struct die_info *next; /* Next die in linked list */
222 struct type *type; /* Cached type information */
225 /* Attributes have a name and a value */
233 struct dwarf_block *blk;
241 /* Blocks are a bunch of untyped bytes. */
248 /* We only hold one compilation unit's abbrevs in
249 memory at any one time. */
250 #ifndef ABBREV_HASH_SIZE
251 #define ABBREV_HASH_SIZE 121
253 #ifndef ATTR_ALLOC_CHUNK
254 #define ATTR_ALLOC_CHUNK 4
257 /* FIXME: do away with this */
259 #ifndef DWARF2_MAX_STRING_SIZE
260 #define DWARF2_MAX_STRING_SIZE 1024
263 static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
265 /* A hash table of die offsets for following references. */
266 #ifndef REF_HASH_SIZE
267 #define REF_HASH_SIZE 1021
270 static struct die_info *die_ref_table[REF_HASH_SIZE];
272 /* Allocate fields for structs, unions and enums in this size. */
273 #ifndef DW_FIELD_ALLOC_CHUNK
274 #define DW_FIELD_ALLOC_CHUNK 4
277 /* The language we are debugging. */
278 static enum language cu_language;
279 static const struct language_defn *cu_language_defn;
281 /* Actually data from the sections. */
282 static char *dwarf_info_buffer;
283 static char *dwarf_abbrev_buffer;
284 static char *dwarf_line_buffer;
286 /* A zeroed version of several structures for initialization purposes. */
287 static struct partial_die_info zeroed_partial_die;
288 static struct die_info zeroed_die;
290 /* The generic symbol table building routines have separate lists for
291 file scope symbols and all all other scopes (local scopes). So
292 we need to select the right one to pass to add_symbol_to_list().
293 We do it by keeping a pointer to the correct list in list_in_scope.
295 FIXME: The original dwarf code just treated the file scope as the first
296 local scope, and all other local scopes as nested local scopes, and worked
297 fine. Check to see if we really need to distinguish these
299 static struct pending **list_in_scope = &file_symbols;
300 static int isreg; /* Kludge to identify register
302 static int offreg; /* Kludge to identify basereg
305 /* This value is added to each symbol value. FIXME: Generalize to
306 the section_offsets structure used by dbxread (once this is done,
307 pass the appropriate section number to end_symtab). */
308 static CORE_ADDR baseaddr; /* Add to each symbol value */
310 /* Maintain an array of referenced fundamental types for the current
311 compilation unit being read. For DWARF version 1, we have to construct
312 the fundamental types on the fly, since no information about the
313 fundamental types is supplied. Each such fundamental type is created by
314 calling a language dependent routine to create the type, and then a
315 pointer to that type is then placed in the array at the index specified
316 by it's FT_<TYPENAME> value. The array has a fixed size set by the
317 FT_NUM_MEMBERS compile time constant, which is the number of predefined
318 fundamental types gdb knows how to construct. */
319 static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
321 /* FIXME - set from bfd function */
322 static int bits_per_byte = 8;
324 /* Keep track of whether we have given a warning about not
325 handling DW_TAG_const_type dies. */
326 static int tag_const_warning_given = 0;
328 /* Keep track of whether we have given a warning about not
329 handling DW_TAG_volatile_type dies. */
330 static int tag_volatile_warning_given = 0;
332 /* Keep track of constant array bound warning. */
333 static int array_bound_warning_given = 0;
335 /* Remember the addr_size read from the dwarf.
336 If a target expects to link compilation units with differing address
337 sizes, gdb needs to be sure that the appropriate size is here for
338 whatever scope is currently getting read. */
339 static int address_size;
341 /* Externals references. */
342 extern int info_verbose; /* From main.c; nonzero => verbose */
344 /* local function prototypes */
346 static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR));
348 static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *,
349 struct section_offsets *,
351 static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *,
352 struct section_offsets *,
355 static char *scan_partial_symbols PARAMS ((char *, struct objfile *,
356 CORE_ADDR *, CORE_ADDR *));
358 static void add_partial_symbol PARAMS ((struct partial_die_info *,
361 static void dwarf2_psymtab_to_symtab PARAMS ((struct partial_symtab *));
363 static void psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
365 static void add_die_to_symtab PARAMS ((struct die_info *, struct objfile *));
367 static char *dwarf2_read_section PARAMS ((bfd *, file_ptr, unsigned int));
369 static void dwarf2_read_abbrevs PARAMS ((bfd *, unsigned int));
371 static void dwarf2_empty_abbrev_table PARAMS ((void));
373 static struct abbrev_info *dwarf2_lookup_abbrev PARAMS ((unsigned int));
375 static char *read_partial_die PARAMS ((struct partial_die_info *,
376 bfd *, char *, int *));
378 static char *read_full_die PARAMS ((struct die_info **, bfd *, char *));
380 static unsigned int read_1_byte PARAMS ((bfd *, char *));
382 static unsigned int read_2_bytes PARAMS ((bfd *, char *));
384 static unsigned int read_4_bytes PARAMS ((bfd *, char *));
386 static unsigned int read_8_bytes PARAMS ((bfd *, char *));
388 static CORE_ADDR read_address PARAMS ((bfd *, char *));
390 static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
392 static char *read_string PARAMS ((bfd *, char *, unsigned int *));
394 static unsigned int read_unsigned_leb128 PARAMS ((bfd *, char *,
397 static int read_signed_leb128 PARAMS ((bfd *, char *, unsigned int *));
399 static void set_cu_language PARAMS ((unsigned int));
401 static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
402 enum minimal_symbol_type,
405 static int convert_locdesc PARAMS ((struct dwarf_block *));
407 static struct attribute *dwarf_attr PARAMS ((struct die_info *,
410 static void dwarf_decode_lines PARAMS ((unsigned int, bfd *));
412 static struct symbol *new_symbol PARAMS ((struct die_info * die, struct objfile * objfile));
414 static struct type *die_type PARAMS ((struct die_info * die, struct objfile * objfile));
416 static struct type *type_at_offset PARAMS ((unsigned int offset, struct objfile * objfile));
418 static struct type *tag_type_to_type PARAMS ((struct die_info * die, struct objfile * objfile));
420 static void read_type_die PARAMS ((struct die_info * die, struct objfile * objfile));
422 static void read_typedef PARAMS ((struct die_info * die, struct objfile * objfile));
424 static void read_base_type PARAMS ((struct die_info * die, struct objfile * objfile));
426 static void read_file_scope PARAMS ((struct die_info * die, struct objfile * objfile));
428 static void read_func_scope PARAMS ((struct die_info * die, struct objfile * objfile));
430 static void read_lexical_block_scope PARAMS ((struct die_info * die,
431 struct objfile * objfile));
433 static void read_structure_scope PARAMS ((struct die_info * die, struct objfile * objfile));
435 static void read_common_block PARAMS ((struct die_info * die, struct objfile * objfile));
437 static void read_enumeration PARAMS ((struct die_info * die, struct objfile * objfile));
439 static struct type * dwarf_base_type PARAMS ((int encoding, int size));
441 static CORE_ADDR decode_locdesc PARAMS ((struct dwarf_block *,
444 static char *create_name PARAMS ((char *, struct obstack *));
446 static void dwarf_read_array_type PARAMS ((struct die_info * die,
447 struct objfile * objfile));
449 static void read_tag_pointer_type PARAMS ((struct die_info * die,
450 struct objfile * objfile));
452 static void read_tag_const_type PARAMS ((struct die_info * die,
453 struct objfile * objfile));
455 static void read_tag_volatile_type PARAMS ((struct die_info * die,
456 struct objfile * objfile));
458 static void read_tag_string_type PARAMS ((struct die_info * die,
459 struct objfile * objfile));
461 static void read_subroutine_type PARAMS ((struct die_info * die,
462 struct objfile * objfile));
464 struct die_info *read_comp_unit PARAMS ((char *info_ptr, bfd * abfd));
466 static void free_die_list PARAMS ((struct die_info * dies));
468 static void process_die PARAMS ((struct die_info *, struct objfile *));
470 static char *dwarf_tag_name PARAMS ((unsigned tag));
472 static char *dwarf_attr_name PARAMS ((unsigned attr));
474 static char *dwarf_form_name PARAMS ((unsigned form));
476 static char *dwarf_stack_op_name PARAMS ((unsigned op));
478 static char *dwarf_bool_name PARAMS ((unsigned bool));
480 static char *dwarf_bool_name PARAMS ((unsigned tag));
482 static char *dwarf_type_encoding_name PARAMS ((unsigned enc));
484 static char *dwarf_cfi_name PARAMS ((unsigned cfi_opc));
486 struct die_info *copy_die PARAMS ((struct die_info *old_die));
488 struct die_info *sibling_die PARAMS ((struct die_info *die));
490 void dump_die PARAMS ((struct die_info *die));
492 void dump_die_list PARAMS ((struct die_info *dies));
494 void store_in_ref_table PARAMS ((unsigned int, struct die_info *));
496 struct die_info *follow_die_ref PARAMS ((unsigned int offset));
498 static struct type *dwarf2_fundamental_type PARAMS ((struct objfile *, int));
500 /* memory allocation interface */
502 static struct type *dwarf_alloc_type PARAMS ((struct objfile *));
504 static struct abbrev_info *dwarf_alloc_abbrev PARAMS ((void));
506 static struct dwarf_block *dwarf_alloc_block PARAMS ((void));
508 static struct die_info *dwarf_alloc_die PARAMS ((void));
510 /* Try to locate the sections we need for DWARF 2 debugging
511 information and return true if we have enough to do something. */
514 dwarf2_has_info (abfd)
517 dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
518 bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
519 if (dwarf_info_offset && dwarf_abbrev_offset && dwarf_line_offset)
529 /* This function is mapped across the sections and remembers the
530 offset and size of each of the debugging sections we are interested
534 dwarf2_locate_sections (ignore_abfd, sectp, ignore_ptr)
539 if (STREQ (sectp->name, INFO_SECTION))
541 dwarf_info_offset = sectp->filepos;
542 dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
544 else if (STREQ (sectp->name, ABBREV_SECTION))
546 dwarf_abbrev_offset = sectp->filepos;
547 dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
549 else if (STREQ (sectp->name, LINE_SECTION))
551 dwarf_line_offset = sectp->filepos;
552 dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
554 else if (STREQ (sectp->name, PUBNAMES_SECTION))
556 dwarf_pubnames_offset = sectp->filepos;
557 dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
559 else if (STREQ (sectp->name, ARANGES_SECTION))
561 dwarf_aranges_offset = sectp->filepos;
562 dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
564 else if (STREQ (sectp->name, LOC_SECTION))
566 dwarf_loc_offset = sectp->filepos;
567 dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
569 else if (STREQ (sectp->name, MACINFO_SECTION))
571 dwarf_macinfo_offset = sectp->filepos;
572 dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
574 else if (STREQ (sectp->name, STR_SECTION))
576 dwarf_str_offset = sectp->filepos;
577 dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
581 /* Build a partial symbol table. */
584 dwarf2_build_psymtabs (objfile, section_offsets, mainline)
585 struct objfile *objfile;
586 struct section_offsets *section_offsets;
589 bfd *abfd = objfile->obfd;
591 /* We definitely need the .debug_info, .debug_abbrev, and .debug_line
594 dwarf_info_buffer = dwarf2_read_section (abfd,
597 dwarf_abbrev_buffer = dwarf2_read_section (abfd,
600 dwarf_line_buffer = dwarf2_read_section (abfd,
604 if (mainline || objfile->global_psymbols.size == 0 ||
605 objfile->static_psymbols.size == 0)
607 init_psymbol_list (objfile, 1024);
611 if (dwarf_aranges_offset && dwarf_pubnames_offset)
613 /* Things are significanlty easier if we have .debug_aranges and
614 .debug_pubnames sections */
616 dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline);
620 /* only test this case for now */
622 /* In this case we have to work a bit harder */
623 dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline);
627 /* Build the partial symbol table from the information in the
628 .debug_pubnames and .debug_aranges sections. */
631 dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline)
632 struct objfile *objfile;
633 struct section_offsets *section_offsets;
636 bfd *abfd = objfile->obfd;
637 char *aranges_buffer, *pubnames_buffer;
638 char *aranges_ptr, *pubnames_ptr;
639 unsigned int entry_length, version, info_offset, info_size;
641 pubnames_buffer = dwarf2_read_section (abfd,
642 dwarf_pubnames_offset,
643 dwarf_pubnames_size);
644 pubnames_ptr = pubnames_buffer;
645 while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
647 entry_length = read_4_bytes (abfd, pubnames_ptr);
649 version = read_1_byte (abfd, pubnames_ptr);
651 info_offset = read_4_bytes (abfd, pubnames_ptr);
653 info_size = read_4_bytes (abfd, pubnames_ptr);
657 aranges_buffer = dwarf2_read_section (abfd,
658 dwarf_aranges_offset,
663 /* Build the partial symbol table by doing a quick pass through the
664 .debug_info and .debug_abbrev sections. */
667 dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline)
668 struct objfile *objfile;
669 struct section_offsets *section_offsets;
672 /* Instead of reading this into a big buffer, we should probably use
673 mmap() on architectures that support it. (FIXME) */
674 bfd *abfd = objfile->obfd;
675 char *info_ptr, *abbrev_ptr;
676 char *beg_of_comp_unit, *comp_unit_die_offset;
677 struct comp_unit_head cu_header;
678 struct partial_die_info comp_unit_die;
679 struct partial_symtab *pst;
680 struct cleanup *back_to;
681 int comp_unit_has_pc_info;
683 CORE_ADDR lowpc, highpc;
685 comp_unit_die = zeroed_partial_die;
686 info_ptr = dwarf_info_buffer;
687 abbrev_ptr = dwarf_abbrev_buffer;
689 while ((info_ptr - dwarf_info_buffer)
690 + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
692 beg_of_comp_unit = info_ptr;
693 cu_header.length = read_4_bytes (abfd, info_ptr);
695 cu_header.version = read_2_bytes (abfd, info_ptr);
697 cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
699 cu_header.addr_size = read_1_byte (abfd, info_ptr);
701 address_size = cu_header.addr_size;
703 if (cu_header.version != 2)
705 error ("Dwarf Error: wrong version in compilation unit header.");
709 /* Read the abbrevs for this compilation unit into a table */
710 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
711 back_to = make_cleanup (dwarf2_empty_abbrev_table, NULL);
713 /* Read the compilation unit die */
714 info_ptr = read_partial_die (&comp_unit_die, abfd,
715 info_ptr, &comp_unit_has_pc_info);
717 /* Set the language we're debugging */
718 set_cu_language (comp_unit_die.language);
720 /* Allocate a new partial symbol table structure */
721 pst = start_psymtab_common (objfile, section_offsets,
724 objfile->global_psymbols.next,
725 objfile->static_psymbols.next);
727 /* Store offset in the .debug_info section of the comp_unit_die. */
728 pst->read_symtab_private = (char *)
729 (beg_of_comp_unit - dwarf_info_buffer);
731 /* Store the function that reads in the rest of the symbol table */
732 pst->read_symtab = dwarf2_psymtab_to_symtab;
734 /* Read the rest of the partial symbols from this comp unit */
735 info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc);
737 /* If the compilation unit didn't have an explicit address range,
738 then use the information extracted from its child dies. */
739 if (!comp_unit_has_pc_info)
741 comp_unit_die.lowpc = lowpc;
742 comp_unit_die.highpc = highpc;
744 pst->textlow = comp_unit_die.lowpc;
745 pst->texthigh = comp_unit_die.highpc;
747 pst->n_global_syms = objfile->global_psymbols.next -
748 (objfile->global_psymbols.list + pst->globals_offset);
749 pst->n_static_syms = objfile->static_psymbols.next -
750 (objfile->static_psymbols.list + pst->statics_offset);
751 sort_pst_symbols (pst);
753 /* If there is already a psymtab or symtab for a file of this
754 name, remove it. (If there is a symtab, more drastic things
755 also happen.) This happens in VxWorks. */
756 free_named_symtabs (pst->filename);
758 info_ptr = beg_of_comp_unit + cu_header.length + 4;
760 do_cleanups (back_to);
763 /* Read in all interesting dies to the end of the compilation unit. */
766 scan_partial_symbols (info_ptr, objfile, lowpc, highpc)
768 struct objfile *objfile;
772 /* FIXME: This should free the attributes of the partial die structure
773 when it is done with them (is there a more efficient way
775 bfd *abfd = objfile->obfd;
776 struct partial_die_info pdi;
777 int nesting_level = 1; /* we've already read in comp_unit_die */
780 pdi = zeroed_partial_die;
781 *lowpc = ((CORE_ADDR) -1);
782 *highpc = ((CORE_ADDR) 0);
785 info_ptr = read_partial_die (&pdi, abfd, info_ptr, &has_pc_info);
788 case DW_TAG_subprogram:
789 case DW_TAG_variable:
791 case DW_TAG_class_type:
792 case DW_TAG_structure_type:
793 case DW_TAG_union_type:
794 if (pdi.is_external || nesting_level == 1)
798 add_partial_symbol (&pdi, objfile);
803 if (pdi.lowpc < *lowpc)
807 if (pdi.highpc > *lowpc)
809 *highpc = pdi.highpc;
813 if (pdi.has_children)
822 while (nesting_level);
827 add_partial_symbol (pdi, objfile)
828 struct partial_die_info *pdi;
829 struct objfile *objfile;
833 case DW_TAG_subprogram:
834 if (pdi->is_external)
836 record_minimal_symbol (pdi->name, pdi->lowpc,
838 add_psymbol_to_list (pdi->name, strlen (pdi->name),
839 VAR_NAMESPACE, LOC_BLOCK,
840 &objfile->global_psymbols,
841 0, pdi->lowpc, cu_language, objfile);
845 add_psymbol_to_list (pdi->name, strlen (pdi->name),
846 VAR_NAMESPACE, LOC_BLOCK,
847 &objfile->static_psymbols,
848 0, pdi->lowpc, cu_language, objfile);
851 case DW_TAG_variable:
852 if (pdi->is_external)
854 record_minimal_symbol (pdi->name, convert_locdesc (pdi->locdesc),
856 add_psymbol_to_list (pdi->name, strlen (pdi->name),
857 VAR_NAMESPACE, LOC_STATIC,
858 &objfile->global_psymbols,
859 0, 0, cu_language, objfile);
863 add_psymbol_to_list (pdi->name, strlen (pdi->name),
864 VAR_NAMESPACE, LOC_STATIC,
865 &objfile->static_psymbols,
866 0, 0, cu_language, objfile);
870 add_psymbol_to_list (pdi->name, strlen (pdi->name),
871 VAR_NAMESPACE, LOC_TYPEDEF,
872 &objfile->static_psymbols,
873 0, 0, cu_language, objfile);
875 case DW_TAG_class_type:
876 case DW_TAG_structure_type:
877 case DW_TAG_union_type:
878 case DW_TAG_enumeration_type:
879 add_psymbol_to_list (pdi->name, strlen (pdi->name),
880 STRUCT_NAMESPACE, LOC_TYPEDEF,
881 &objfile->static_psymbols,
882 0, 0, cu_language, objfile);
883 if (cu_language == language_cplus)
885 /* For C++, these implicitly act as typedefs as well. */
886 add_psymbol_to_list (pdi->name, strlen (pdi->name),
887 VAR_NAMESPACE, LOC_TYPEDEF,
888 &objfile->static_psymbols,
889 0, 0, cu_language, objfile);
895 /* Expand this partial symbol table into a full symbol table. */
898 dwarf2_psymtab_to_symtab (pst)
899 struct partial_symtab *pst;
901 /* FIXME: This is barely more than a stub. */
906 warning ("bug: psymtab for %s is already read in.", pst->filename);
910 psymtab_to_symtab_1 (pst);
916 psymtab_to_symtab_1 (pst)
917 struct partial_symtab *pst;
919 struct objfile *objfile = pst->objfile;
920 bfd *abfd = objfile->obfd;
921 struct comp_unit_head cu_header;
922 struct die_info *dies;
923 struct attribute *attr;
924 unsigned long offset;
925 unsigned long int nesting_level;
927 struct attribute *high_pc_attr;
928 struct die_info *child_die;
930 struct context_stack *context;
931 struct symtab *symtab;
932 struct cleanup *abbrev_cleanup, *die_cleanup;
934 /* Get the offset of this compilation units debug info */
935 offset = (unsigned long) pst->read_symtab_private;
936 info_ptr = dwarf_info_buffer + offset;
938 /* read in the comp_unit header */
939 cu_header.length = read_4_bytes (abfd, info_ptr);
941 cu_header.version = read_2_bytes (abfd, info_ptr);
943 cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
945 cu_header.addr_size = read_1_byte (abfd, info_ptr);
948 /* Read the abbrevs for this compilation unit */
949 dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
950 abbrev_cleanup = make_cleanup (dwarf2_empty_abbrev_table, NULL);
952 dies = read_comp_unit (info_ptr, abfd);
954 die_cleanup = make_cleanup (free_die_list, dies);
956 /* Do line number decoding in read_file_scope () */
957 process_die (dies, objfile);
959 attr = dwarf_attr (dies, DW_AT_high_pc);
962 highpc = DW_ADDR (attr);
966 /* Some compilers don't define a DW_AT_high_pc attribute for
967 the compilation unit. If the DW_AT_high_pc is missing,
968 synthesize it, by scanning the DIE's below the compilation unit. */
970 if (dies->has_children)
972 child_die = dies->next;
973 while (child_die && child_die->tag)
975 if (child_die->tag == DW_TAG_subprogram)
977 high_pc_attr = dwarf_attr (child_die, DW_AT_high_pc);
980 highpc = max (highpc, DW_ADDR (high_pc_attr));
983 child_die = sibling_die (child_die);
988 symtab = end_symtab (highpc, objfile, 0);
991 symtab->language = cu_language;
993 pst->symtab = symtab;
997 printf_filtered ("Sorting symbol table...");
1001 sort_symtab_syms (pst->symtab);
1002 do_cleanups (abbrev_cleanup);
1005 /* Process a die and its children. */
1008 process_die (die, objfile)
1009 struct die_info *die;
1010 struct objfile *objfile;
1014 case DW_TAG_padding:
1016 case DW_TAG_compile_unit:
1017 read_file_scope (die, objfile);
1019 case DW_TAG_subprogram:
1020 if (dwarf_attr (die, DW_AT_low_pc))
1022 read_func_scope (die, objfile);
1025 case DW_TAG_lexical_block:
1026 read_lexical_block_scope (die, objfile);
1028 case DW_TAG_class_type:
1029 case DW_TAG_structure_type:
1030 case DW_TAG_union_type:
1031 read_structure_scope (die, objfile);
1033 case DW_TAG_enumeration_type:
1034 read_enumeration (die, objfile);
1036 case DW_TAG_subroutine_type:
1037 read_subroutine_type (die, objfile);
1039 case DW_TAG_array_type:
1040 dwarf_read_array_type (die, objfile);
1042 case DW_TAG_pointer_type:
1043 read_tag_pointer_type (die, objfile);
1045 case DW_TAG_string_type:
1046 read_tag_string_type (die, objfile);
1048 case DW_TAG_base_type:
1049 read_base_type (die, objfile);
1051 case DW_TAG_common_block:
1052 read_common_block (die, objfile);
1054 case DW_TAG_common_inclusion:
1057 new_symbol (die, objfile);
1063 read_file_scope (die, objfile)
1064 struct die_info *die;
1065 struct objfile *objfile;
1067 unsigned int line_offset = 0;
1068 CORE_ADDR lowpc = ((CORE_ADDR) -1);
1069 CORE_ADDR highpc = ((CORE_ADDR) 0);
1070 struct attribute *attr, *low_pc_attr, *high_pc_attr;
1072 char *comp_dir = NULL;
1073 struct die_info *child_die;
1074 bfd *abfd = objfile->obfd;
1076 low_pc_attr = dwarf_attr (die, DW_AT_low_pc);
1079 lowpc = DW_ADDR (low_pc_attr);
1081 high_pc_attr = dwarf_attr (die, DW_AT_high_pc);
1084 highpc = DW_ADDR (high_pc_attr);
1086 if (!low_pc_attr || !high_pc_attr)
1088 if (die->has_children)
1090 child_die = die->next;
1091 while (child_die && child_die->tag)
1093 if (child_die->tag == DW_TAG_subprogram)
1095 low_pc_attr = dwarf_attr (child_die, DW_AT_low_pc);
1098 lowpc = min (lowpc, DW_ADDR (low_pc_attr));
1100 high_pc_attr = dwarf_attr (child_die, DW_AT_high_pc);
1103 highpc = max (highpc, DW_ADDR (high_pc_attr));
1106 child_die = sibling_die (child_die);
1111 attr = dwarf_attr (die, DW_AT_name);
1114 name = DW_STRING (attr);
1116 attr = dwarf_attr (die, DW_AT_comp_dir);
1119 comp_dir = DW_STRING (attr);
1122 if (objfile->ei.entry_point >= lowpc &&
1123 objfile->ei.entry_point < highpc)
1125 objfile->ei.entry_file_lowpc = lowpc;
1126 objfile->ei.entry_file_highpc = highpc;
1129 attr = dwarf_attr (die, DW_AT_language);
1132 set_cu_language (DW_UNSND (attr));
1136 /* FIXME:Do something here. */
1137 if (dip->at_producer != NULL)
1139 handle_producer (dip->at_producer);
1143 start_symtab (name, comp_dir, lowpc);
1145 /* Decode line number information. */
1146 attr = dwarf_attr (die, DW_AT_stmt_list);
1150 "Dwarf Error: No line number information for compilation unit: %s.",
1153 line_offset = DW_UNSND (attr);
1154 dwarf_decode_lines (line_offset, abfd);
1156 /* Process all dies in compilation unit. */
1157 if (die->has_children)
1159 child_die = die->next;
1160 while (child_die && child_die->tag)
1162 process_die (child_die, objfile);
1163 child_die = sibling_die (child_die);
1169 read_func_scope (die, objfile)
1170 struct die_info *die;
1171 struct objfile *objfile;
1173 register struct context_stack *new;
1174 CORE_ADDR lowpc = 0;
1175 CORE_ADDR highpc = 0;
1176 struct die_info *child_die;
1177 struct attribute *attr;
1178 struct minimal_symbol *min_sym;
1181 attr = dwarf_attr (die, DW_AT_name);
1184 name = DW_STRING (attr);
1187 attr = dwarf_attr (die, DW_AT_low_pc);
1190 lowpc = DW_ADDR (attr);
1193 attr = dwarf_attr (die, DW_AT_high_pc);
1196 highpc = DW_ADDR (attr);
1199 if (objfile->ei.entry_point >= lowpc &&
1200 objfile->ei.entry_point < highpc)
1202 objfile->ei.entry_func_lowpc = lowpc;
1203 objfile->ei.entry_func_highpc = highpc;
1206 if (STREQ (name, "main")) /* FIXME: hardwired name */
1208 objfile->ei.main_func_lowpc = lowpc;
1209 objfile->ei.main_func_highpc = highpc;
1211 new = push_context (0, lowpc);
1212 new->name = new_symbol (die, objfile);
1213 list_in_scope = &local_symbols;
1215 if (die->has_children)
1217 child_die = die->next;
1218 while (child_die && child_die->tag)
1220 process_die (child_die, objfile);
1221 child_die = sibling_die (child_die);
1225 new = pop_context ();
1226 /* Make a block for the local symbols within. */
1227 finish_block (new->name, &local_symbols, new->old_blocks,
1228 lowpc, highpc, objfile);
1229 list_in_scope = &file_symbols;
1232 /* Process all the DIES contained within a lexical block scope. Start
1233 a new scope, process the dies, and then close the scope. */
1236 read_lexical_block_scope (die, objfile)
1237 struct die_info *die;
1238 struct objfile *objfile;
1240 register struct context_stack *new;
1241 CORE_ADDR lowpc = 0, highpc = 0;
1242 struct attribute *attr;
1243 struct die_info *child_die;
1245 attr = dwarf_attr (die, DW_AT_low_pc);
1248 lowpc = DW_ADDR (attr);
1250 attr = dwarf_attr (die, DW_AT_high_pc);
1253 highpc = DW_ADDR (attr);
1256 push_context (0, lowpc);
1257 if (die->has_children)
1259 child_die = die->next;
1260 while (child_die && child_die->tag)
1262 process_die (child_die, objfile);
1263 child_die = sibling_die (child_die);
1266 new = pop_context ();
1268 if (local_symbols != NULL)
1270 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
1273 local_symbols = new->locals;
1276 /* Called when we find the DIE that starts a structure or union scope
1277 (definition) to process all dies that define the members of the
1280 NOTE: we need to call struct_type regardless of whether or not the
1281 DIE has an at_name attribute, since it might be an anonymous
1282 structure or union. This gets the type entered into our set of
1285 However, if the structure is incomplete (an opaque struct/union)
1286 then suppress creating a symbol table entry for it since gdb only
1287 wants to find the one with the complete definition. Note that if
1288 it is complete, we just call new_symbol, which does it's own
1289 checking about whether the struct/union is anonymous or not (and
1290 suppresses creating a symbol table entry itself). */
1293 read_structure_scope (die, objfile)
1294 struct die_info *die;
1295 struct objfile *objfile;
1297 struct type *type, *member_type;
1298 struct field *fields;
1299 struct die_info *child_die;
1300 struct attribute *attr;
1304 type = dwarf_alloc_type (objfile);
1306 INIT_CPLUS_SPECIFIC (type);
1307 attr = dwarf_attr (die, DW_AT_name);
1309 if (die->tag == DW_TAG_structure_type)
1311 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1314 TYPE_NAME (type) = obconcat (&objfile->type_obstack,
1315 "struct", " ", DW_STRING (attr));
1320 /* die->tag == DW_TAG_union_type */
1321 TYPE_CODE (type) = TYPE_CODE_UNION;
1324 TYPE_NAME (type) = obconcat (&objfile->type_obstack,
1325 "union", " ", DW_STRING (attr));
1329 attr = dwarf_attr (die, DW_AT_byte_size);
1332 TYPE_LENGTH (type) = DW_UNSND (attr);
1336 TYPE_LENGTH (type) = 0;
1339 /* We need to add the type field to the die immediately so we don't
1340 infinitely recurse when dealing with pointers to the structure
1341 type within the structure itself. */
1346 if (die->has_children)
1348 child_die = die->next;
1349 while (child_die && child_die->tag)
1351 if (child_die->tag != DW_TAG_member)
1353 process_die (child_die, objfile);
1357 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1359 fields = (struct field *)
1361 (num_fields + DW_FIELD_ALLOC_CHUNK)
1362 * sizeof (struct field));
1365 /* Get bit offset of field */
1366 attr = dwarf_attr (child_die, DW_AT_bit_offset);
1369 fields[num_fields].bitpos = DW_UNSND (attr);
1373 fields[num_fields].bitpos = 0;
1375 attr = dwarf_attr (child_die, DW_AT_data_member_location);
1378 fields[num_fields].bitpos +=
1379 decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1382 /* Get bit size of field (zero if none). */
1383 attr = dwarf_attr (child_die, DW_AT_bit_size);
1386 fields[num_fields].bitsize = DW_UNSND (attr);
1390 fields[num_fields].bitsize = 0;
1393 /* Get type of member. */
1394 member_type = die_type (child_die, objfile);
1395 fields[num_fields].type = member_type;
1397 /* Get name of member. */
1398 attr = dwarf_attr (child_die, DW_AT_name);
1401 fields[num_fields].name = obsavestring (DW_STRING (attr),
1402 strlen (DW_STRING (attr)),
1403 &objfile->type_obstack);
1405 fields[num_fields].name = strdup (DW_STRING (attr));
1410 child_die = sibling_die (child_die);
1412 type->nfields = num_fields;
1413 type->fields = fields;
1417 /* No children, must be stub. */
1418 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1422 sym = new_symbol (die, objfile);
1425 SYMBOL_TYPE (sym) = type;
1429 /* Given a pointer to a die which begins an enumeration, process all
1430 the dies that define the members of the enumeration.
1432 This will be much nicer in draft 6 of the DWARF spec when our
1433 members will be dies instead squished into the DW_AT_element_list
1436 NOTE: We reverse the order of the element list. */
1439 read_enumeration (die, objfile)
1440 struct die_info *die;
1441 struct objfile *objfile;
1443 struct die_info *child_die;
1445 struct field *fields;
1446 struct attribute *attr;
1448 struct dwarf_block *blk;
1450 unsigned int size, bytes_read, i;
1452 type = dwarf_alloc_type (objfile);
1454 TYPE_CODE (type) = TYPE_CODE_ENUM;
1455 attr = dwarf_attr (die, DW_AT_name);
1458 TYPE_NAME (type) = obconcat (&objfile->type_obstack,
1459 "enum ", " ", DW_STRING (attr));
1462 attr = dwarf_attr (die, DW_AT_byte_size);
1465 TYPE_LENGTH (type) = DW_UNSND (attr);
1469 TYPE_LENGTH (type) = 0;
1474 if (die->has_children)
1476 child_die = die->next;
1477 while (child_die && child_die->tag)
1479 if (child_die->tag != DW_TAG_enumerator)
1481 process_die (child_die, objfile);
1485 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1487 fields = (struct field *)
1489 (num_fields + DW_FIELD_ALLOC_CHUNK)
1490 * sizeof (struct field));
1493 /* Handcraft a new symbol for this enum member. */
1494 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1495 sizeof (struct symbol));
1496 memset (sym, 0, sizeof (struct symbol));
1498 fields[num_fields].type = NULL;
1499 fields[num_fields].bitsize = 0;
1500 attr = dwarf_attr (child_die, DW_AT_name);
1503 fields[num_fields].name = strdup (DW_STRING (attr));
1504 SYMBOL_NAME (sym) = strdup (fields[num_fields].name);
1506 attr = dwarf_attr (child_die, DW_AT_const_value);
1509 fields[num_fields].bitpos = DW_UNSND (attr);
1510 SYMBOL_VALUE (sym) = DW_UNSND (attr);
1514 SYMBOL_NAME (sym) = create_name (elist->str,
1515 &objfile->symbol_obstack);
1517 SYMBOL_INIT_LANGUAGE_SPECIFIC (sym, cu_language);
1518 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1519 SYMBOL_CLASS (sym) = LOC_CONST;
1520 SYMBOL_TYPE (sym) = type;
1521 add_symbol_to_list (sym, list_in_scope);
1526 child_die = sibling_die (child_die);
1528 type->fields = fields;
1529 type->nfields = num_fields;
1532 sym = new_symbol (die, objfile);
1535 SYMBOL_TYPE (sym) = type;
1539 /* Extract all information from a DW_TAG_array_type DIE and put it in
1540 the DIE's type field. For now, this only handles one dimensional
1544 dwarf_read_array_type (die, objfile)
1545 struct die_info *die;
1546 struct objfile *objfile;
1548 struct die_info *child_die;
1549 struct type *type, *element_type, *range_type, *index_type;
1550 struct attribute *attr;
1551 struct dwarf_block *blk;
1552 unsigned int size, i, type_form, bytes_read;
1553 unsigned int index_spec, lo_spec, hi_spec, type_ref;
1554 unsigned int low, high;
1556 /* Return if we've already decoded this type. */
1562 element_type = die_type (die, objfile);
1566 if (cu_language == DW_LANG_Fortran77 || cu_language == DW_LANG_Fortran90)
1568 /* FORTRAN implies a lower bound of 1, if not given. */
1572 child_die = die->next;
1573 while (child_die && child_die->tag)
1575 if (child_die->tag == DW_TAG_subrange_type)
1577 index_type = die_type (child_die, objfile);
1578 attr = dwarf_attr (child_die, DW_AT_lower_bound);
1581 if (attr->form == DW_FORM_sdata)
1583 low = DW_SND (attr);
1585 else if (attr->form == DW_FORM_udata
1586 || attr->form == DW_FORM_data1
1587 || attr->form == DW_FORM_data2
1588 || attr->form == DW_FORM_data4)
1590 low = DW_UNSND (attr);
1594 if (!array_bound_warning_given)
1596 warning ("Non-constant array bounds ignored.");
1597 array_bound_warning_given = 1;
1600 type = dwarf_alloc_type (objfile);
1601 TYPE_TARGET_TYPE (type) = element_type;
1602 TYPE_OBJFILE (type) = objfile;
1603 TYPE_LENGTH (type) = 4;
1604 TYPE_CODE (type) = TYPE_CODE_PTR;
1605 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1606 TYPE_POINTER_TYPE (element_type) = type;
1613 attr = dwarf_attr (child_die, DW_AT_upper_bound);
1616 if (attr->form == DW_FORM_sdata)
1618 high = DW_SND (attr);
1620 else if (attr->form == DW_FORM_udata
1621 || attr->form == DW_FORM_data1
1622 || attr->form == DW_FORM_data2
1623 || attr->form == DW_FORM_data4)
1625 high = DW_UNSND (attr);
1629 if (!array_bound_warning_given)
1631 warning ("Non-constant array bounds ignored.");
1632 array_bound_warning_given = 1;
1635 type = dwarf_alloc_type (objfile);
1636 TYPE_TARGET_TYPE (type) = element_type;
1637 TYPE_OBJFILE (type) = objfile;
1638 TYPE_LENGTH (type) = 4;
1639 TYPE_CODE (type) = TYPE_CODE_PTR;
1640 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1641 TYPE_POINTER_TYPE (element_type) = type;
1649 range_type = create_range_type (NULL, index_type, low, high);
1650 type = create_array_type (NULL, element_type, range_type);
1651 element_type = type;
1652 child_die = sibling_die (child_die);
1655 /* Install the type in the die. */
1659 /* First cut: install each common block member as a global variable. */
1662 read_common_block (die, objfile)
1663 struct die_info *die;
1664 struct objfile *objfile;
1666 struct die_info *child_die;
1667 struct attribute *attr;
1671 attr = dwarf_attr (die, DW_AT_location);
1674 base = decode_locdesc (DW_BLOCK (attr), objfile);
1676 if (die->has_children)
1678 child_die = die->next;
1679 while (child_die && child_die->tag)
1681 sym = new_symbol (child_die, objfile);
1682 attr = dwarf_attr (child_die, DW_AT_data_member_location);
1685 SYMBOL_VALUE_ADDRESS (sym) =
1686 base + decode_locdesc (DW_BLOCK (attr), objfile);
1687 add_symbol_to_list (sym, &global_symbols);
1689 child_die = sibling_die (child_die);
1694 /* Extract all information from a DW_TAG_pointer_type DIE and add to
1695 the user defined type vector. */
1698 read_tag_pointer_type (die, objfile)
1699 struct die_info *die;
1700 struct objfile *objfile;
1702 struct type *type, *pointed_to_type;
1703 struct attribute *attr;
1710 pointed_to_type = die_type (die, objfile);
1712 type = dwarf_alloc_type (objfile);
1713 TYPE_TARGET_TYPE (type) = pointed_to_type;
1714 TYPE_OBJFILE (type) = objfile;
1715 attr = dwarf_attr (die, DW_AT_byte_size);
1718 TYPE_LENGTH (type) = DW_UNSND (attr);
1722 TYPE_LENGTH (type) = address_size;
1724 TYPE_CODE (type) = TYPE_CODE_PTR;
1725 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1727 TYPE_POINTER_TYPE (pointed_to_type) = type;
1732 read_tag_const_type (die, objfile)
1733 struct die_info *die;
1734 struct objfile *objfile;
1741 if (!tag_const_warning_given)
1743 warning ("gdb ignores `const' qualifiers.");
1744 tag_const_warning_given = 1;
1747 die->type = die_type (die, objfile);
1751 read_tag_volatile_type (die, objfile)
1752 struct die_info *die;
1753 struct objfile *objfile;
1760 if (!tag_volatile_warning_given)
1762 warning ("gdb ignores `volatile' qualifiers.");
1763 tag_volatile_warning_given = 1;
1766 die->type = die_type (die, objfile);
1769 /* Extract all information from a DW_TAG_string_type DIE and add to
1770 the user defined type vector. It isn't really a user defined type,
1771 but it behaves like one, with other DIE's using an AT_user_def_type
1772 attribute to reference it. */
1775 read_tag_string_type (die, objfile)
1776 struct die_info *die;
1777 struct objfile *objfile;
1779 struct type *type, *range_type, *index_type, *char_type;
1780 struct attribute *attr;
1781 unsigned int length;
1788 attr = dwarf_attr (die, DW_AT_string_length);
1791 length = DW_UNSND (attr);
1797 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
1798 range_type = create_range_type (NULL, index_type, 1, length);
1799 char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
1800 type = create_string_type (char_type, range_type);
1804 /* Handle DIES due to C code like:
1808 int (*funcp)(int a, long l);
1812 ('funcp' generates a DW_TAG_subroutine_type DIE)
1814 NOTE: parameter DIES are currently ignored. See if gdb has a way to
1815 include this info in it's type system, and decode them if so. Is
1816 this what the type structure's "arg_types" field is for? (FIXME) */
1819 read_subroutine_type (die, objfile)
1820 struct die_info *die;
1821 struct objfile *objfile;
1823 struct type *type; /* Type that this function returns */
1824 struct type *ftype; /* Function that returns above type */
1826 /* Decode the type that this subroutine returns */
1831 type = die_type (die, objfile);
1832 ftype = lookup_function_type (type);
1834 TYPE_TARGET_TYPE (ftype) = type;
1835 TYPE_LENGTH (ftype) = 1;
1836 TYPE_CODE (ftype) = TYPE_CODE_FUNC;
1837 TYPE_OBJFILE (ftype) = objfile;
1843 read_typedef (die, objfile)
1844 struct die_info *die;
1845 struct objfile *objfile;
1851 type = die_type (die, objfile);
1856 /* Find a representation of a given base type and install
1857 it in the TYPE field of the die. */
1860 read_base_type (die, objfile)
1861 struct die_info *die;
1862 struct objfile *objfile;
1865 struct attribute *attr;
1866 int encoding = 0, size = 0;
1868 /* If we've already decoded this die, this is a no-op. */
1874 attr = dwarf_attr (die, DW_AT_encoding);
1877 encoding = DW_UNSND (attr);
1879 attr = dwarf_attr (die, DW_AT_byte_size);
1882 size = DW_UNSND (attr);
1884 type = dwarf_base_type (encoding, size);
1888 /* Read a whole compilation unit into a linked list of dies. */
1891 read_comp_unit (info_ptr, abfd)
1895 struct die_info *first_die, *last_die, *die;
1901 first_die = last_die = NULL;
1904 cur_ptr = read_full_die (&die, abfd, cur_ptr);
1905 if (die->has_children)
1916 /* Enter die in reference hash table */
1917 store_in_ref_table (die->offset, die);
1921 first_die = last_die = die;
1925 last_die->next = die;
1929 while (nesting_level > 0);
1933 /* Free a linked list of dies. */
1936 free_die_list (dies)
1937 struct die_info *dies;
1939 struct die_info *die, *next;
1951 /* Read the contents of the section at OFFSET and of size SIZE in the
1952 object file specified by ABFD into a buffer of bytes and return it. */
1955 dwarf2_read_section (abfd, offset, size)
1962 buf = xmalloc (size);
1963 if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
1964 (bfd_read (buf, size, 1, abfd) != size))
1968 error ("Dwarf Error: Can't read DWARF data from '%s'",
1969 bfd_get_filename (abfd));
1974 /* In DWARF version 2, the description of the debugging information is
1975 stored in a separate .debug_abbrev section. Before we read any
1976 dies from a section we read in all abbreviations and install them
1980 dwarf2_read_abbrevs (abfd, offset)
1982 unsigned int offset;
1985 struct abbrev_info *cur_abbrev;
1986 unsigned int abbrev_number, bytes_read, abbrev_name;
1987 unsigned int abbrev_form, hash_number;
1989 /* empty the table */
1990 dwarf2_empty_abbrev_table ();
1992 abbrev_ptr = dwarf_abbrev_buffer + offset;
1993 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
1994 abbrev_ptr += bytes_read;
1996 /* loop until we reach an abbrev number of 0 */
1997 while (abbrev_number)
1999 cur_abbrev = dwarf_alloc_abbrev ();
2001 /* read in abbrev header */
2002 cur_abbrev->number = abbrev_number;
2003 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2004 abbrev_ptr += bytes_read;
2005 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
2008 /* now read in declarations */
2009 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2010 abbrev_ptr += bytes_read;
2011 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2012 abbrev_ptr += bytes_read;
2015 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
2017 cur_abbrev->attrs = xrealloc (cur_abbrev->attrs,
2018 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
2019 * sizeof (struct attr_abbrev));
2021 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
2022 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
2023 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2024 abbrev_ptr += bytes_read;
2025 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2026 abbrev_ptr += bytes_read;
2029 hash_number = abbrev_number % ABBREV_HASH_SIZE;
2030 cur_abbrev->next = dwarf2_abbrevs[hash_number];
2031 dwarf2_abbrevs[hash_number] = cur_abbrev;
2033 /* get next abbrev */
2034 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2035 abbrev_ptr += bytes_read;
2039 /* Empty the abbrev table for a new compilation unit. */
2042 dwarf2_empty_abbrev_table ()
2045 struct abbrev_info *abbrev, *next;
2047 for (i = 0; i < ABBREV_HASH_SIZE; ++i)
2050 abbrev = dwarf2_abbrevs[i];
2053 next = abbrev->next;
2054 free (abbrev->attrs);
2058 dwarf2_abbrevs[i] = NULL;
2062 /* Lookup an abbrev_info structure in the abbrev hash table. */
2064 static struct abbrev_info *
2065 dwarf2_lookup_abbrev (number)
2066 unsigned int number;
2068 unsigned int hash_number;
2069 struct abbrev_info *abbrev;
2071 hash_number = number % ABBREV_HASH_SIZE;
2072 abbrev = dwarf2_abbrevs[hash_number];
2076 if (abbrev->number == number)
2079 abbrev = abbrev->next;
2084 /* Read a minimal amount of information into the minimal die structure. */
2087 read_partial_die (part_die, abfd, info_ptr, has_pc_info)
2088 struct partial_die_info *part_die;
2093 unsigned int abbrev_number, bytes_read, i;
2094 struct abbrev_info *abbrev;
2096 int has_low_pc_attr = 0;
2097 int has_high_pc_attr = 0;
2100 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2101 info_ptr += bytes_read;
2105 part_die->has_children = 0;
2106 part_die->abbrev = abbrev_number;
2110 abbrev = dwarf2_lookup_abbrev (abbrev_number);
2113 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number);
2115 part_die->offset = info_ptr - dwarf_info_buffer;
2116 part_die->tag = abbrev->tag;
2117 part_die->has_children = abbrev->has_children;
2118 part_die->is_external = 0;
2119 part_die->abbrev = abbrev_number;
2123 struct dwarf_block *blk = 0;
2124 CORE_ADDR addr = ((CORE_ADDR) -1);
2125 unsigned int unsnd = ((unsigned int) -1);
2128 for (i = 0; i < abbrev->num_attrs; ++i)
2130 /* read the correct type of data */
2131 switch (abbrev->attrs[i].form)
2134 addr = read_address (abfd, info_ptr);
2135 info_ptr += address_size;
2137 case DW_FORM_ref_addr:
2138 addr = read_address (abfd, info_ptr);
2139 info_ptr += address_size;
2141 case DW_FORM_block2:
2142 blk = dwarf_alloc_block ();
2143 blk->size = read_2_bytes (abfd, info_ptr);
2145 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2146 info_ptr += blk->size;
2148 case DW_FORM_block4:
2149 blk = dwarf_alloc_block ();
2150 blk->size = read_4_bytes (abfd, info_ptr);
2152 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2153 info_ptr += blk->size;
2156 unsnd = read_2_bytes (abfd, info_ptr);
2160 unsnd = read_4_bytes (abfd, info_ptr);
2164 unsnd = read_8_bytes (abfd, info_ptr);
2167 case DW_FORM_string:
2168 str = read_string (abfd, info_ptr, &bytes_read);
2169 info_ptr += bytes_read;
2172 blk = dwarf_alloc_block ();
2173 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2174 info_ptr += bytes_read;
2175 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2176 info_ptr += blk->size;
2178 case DW_FORM_block1:
2179 blk = dwarf_alloc_block ();
2180 blk->size = read_1_byte (abfd, info_ptr);
2182 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2183 info_ptr += blk->size;
2186 unsnd = read_1_byte (abfd, info_ptr);
2190 unsnd = read_1_byte (abfd, info_ptr);
2194 unsnd = read_2_bytes (abfd, info_ptr);
2198 unsnd = read_4_bytes (abfd, info_ptr);
2201 case DW_FORM_ref_udata:
2202 unsnd = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2203 info_ptr += bytes_read;
2206 unsnd = read_1_byte (abfd, info_ptr);
2210 snd = read_signed_leb128 (abfd, info_ptr, &bytes_read);
2211 info_ptr += bytes_read;
2214 unsnd = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2215 info_ptr += bytes_read;
2217 case DW_FORM_indirect:
2220 "Dwarf Error: Cannot handle %s in DWARF reader.",
2221 dwarf_form_name (abbrev->attrs[i].form));
2225 /* store the data if it is of an attribute we want to keep in a
2226 partial symbol table */
2227 switch (abbrev->attrs[i].name)
2230 part_die->name = str;
2233 has_low_pc_attr = 1;
2234 part_die->lowpc = addr;
2237 has_high_pc_attr = 1;
2238 part_die->highpc = addr;
2240 case DW_AT_location:
2241 part_die->locdesc = blk;
2243 case DW_AT_language:
2244 part_die->language = unsnd;
2246 case DW_AT_external:
2247 part_die->is_external = unsnd;
2251 *has_pc_info = has_low_pc_attr && has_high_pc_attr;
2255 /* Read the die from the .debug_info section buffer. And set diep to
2256 point to a newly allocated die with its information. */
2259 read_full_die (diep, abfd, info_ptr)
2260 struct die_info **diep;
2264 unsigned int abbrev_number, bytes_read, i, offset;
2265 struct abbrev_info *abbrev;
2266 struct die_info *die;
2269 offset = info_ptr - dwarf_info_buffer;
2270 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2271 info_ptr += bytes_read;
2274 die = dwarf_alloc_die ();
2276 die->abbrev = abbrev_number;
2282 abbrev = dwarf2_lookup_abbrev (abbrev_number);
2285 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number);
2287 die = dwarf_alloc_die ();
2288 die->offset = offset;
2289 die->tag = abbrev->tag;
2290 die->has_children = abbrev->has_children;
2291 die->abbrev = abbrev_number;
2294 die->num_attrs = abbrev->num_attrs;
2295 die->attrs = xmalloc (die->num_attrs * sizeof (struct attribute));
2299 struct dwarf_block *blk;
2304 for (i = 0; i < abbrev->num_attrs; ++i)
2306 /* read the correct type of data */
2308 die->attrs[i].name = abbrev->attrs[i].name;
2309 die->attrs[i].form = abbrev->attrs[i].form;
2311 switch (abbrev->attrs[i].form)
2314 case DW_FORM_ref_addr:
2315 die->attrs[i].u.addr = read_address (abfd, info_ptr);
2316 info_ptr += address_size;
2318 case DW_FORM_block2:
2319 blk = dwarf_alloc_block ();
2320 blk->size = read_2_bytes (abfd, info_ptr);
2322 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2323 info_ptr += blk->size;
2324 die->attrs[i].u.blk = blk;
2326 case DW_FORM_block4:
2327 blk = dwarf_alloc_block ();
2328 blk->size = read_4_bytes (abfd, info_ptr);
2330 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2331 info_ptr += blk->size;
2332 die->attrs[i].u.blk = blk;
2335 die->attrs[i].u.unsnd = read_2_bytes (abfd, info_ptr);
2339 die->attrs[i].u.unsnd = read_4_bytes (abfd, info_ptr);
2343 die->attrs[i].u.unsnd = read_8_bytes (abfd, info_ptr);
2346 case DW_FORM_string:
2347 die->attrs[i].u.str = read_string (abfd, info_ptr, &bytes_read);
2348 info_ptr += bytes_read;
2351 blk = dwarf_alloc_block ();
2352 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2353 info_ptr += bytes_read;
2354 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2355 info_ptr += blk->size;
2356 die->attrs[i].u.blk = blk;
2358 case DW_FORM_block1:
2359 blk = dwarf_alloc_block ();
2360 blk->size = read_1_byte (abfd, info_ptr);
2362 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2363 info_ptr += blk->size;
2364 die->attrs[i].u.blk = blk;
2367 die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2371 die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2375 die->attrs[i].u.unsnd = read_2_bytes (abfd, info_ptr);
2379 die->attrs[i].u.unsnd = read_4_bytes (abfd, info_ptr);
2382 case DW_FORM_ref_udata:
2383 die->attrs[i].u.unsnd = read_unsigned_leb128 (abfd,
2386 info_ptr += bytes_read;
2389 die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2393 die->attrs[i].u.snd = read_signed_leb128 (abfd,
2396 info_ptr += bytes_read;
2399 die->attrs[i].u.unsnd = read_unsigned_leb128 (abfd,
2402 info_ptr += bytes_read;
2404 case DW_FORM_indirect:
2407 "Dwarf Error: Cannot handle %s in DWARF reader.",
2408 dwarf_form_name (abbrev->attrs[i].form));
2418 /* read dwarf information from a buffer */
2421 read_1_byte (abfd, buf)
2425 return bfd_get_8 (abfd, (bfd_byte *) buf);
2429 read_2_bytes (abfd, buf)
2433 return bfd_get_16 (abfd, (bfd_byte *) buf);
2437 read_4_bytes (abfd, buf)
2441 return bfd_get_32 (abfd, (bfd_byte *) buf);
2445 read_8_bytes (abfd, buf)
2449 return bfd_get_64 (abfd, (bfd_byte *) buf);
2453 read_address (abfd, buf)
2457 CORE_ADDR retval = 0;
2459 if (address_size == 4)
2461 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
2462 } else { /* *THE* alternative is 8, right? */
2463 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
2469 read_n_bytes (abfd, buf, size)
2477 ret = xmalloc (size);
2478 for (i = 0; i < size; ++i)
2480 ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
2486 /* FIXME : hardwired string size limit */
2489 read_string (abfd, buf, bytes_read_ptr)
2492 unsigned int *bytes_read_ptr;
2494 char ret_buf[DWARF2_MAX_STRING_SIZE], *ret, byte;
2500 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2502 ret_buf[i++] = byte;
2507 *bytes_read_ptr = 1;
2511 strncpy (ret, ret_buf, i);
2512 *bytes_read_ptr = i;
2517 read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
2520 unsigned int *bytes_read_ptr;
2522 unsigned int result, num_read;
2532 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2535 result |= ((byte & 127) << shift);
2536 if ((byte & 128) == 0)
2542 *bytes_read_ptr = num_read;
2547 read_signed_leb128 (abfd, buf, bytes_read_ptr)
2550 unsigned int *bytes_read_ptr;
2553 int i, shift, size, num_read;
2563 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2566 result |= ((byte & 127) << shift);
2568 if ((byte & 128) == 0)
2573 if ((shift < size) && (byte & 0x40))
2575 result |= -(1 << shift);
2577 *bytes_read_ptr = num_read;
2582 set_cu_language (lang)
2589 case DW_LANG_Fortran77:
2590 cu_language = language_c;
2592 case DW_LANG_C_plus_plus:
2593 cu_language = language_cplus;
2596 case DW_LANG_Cobol74:
2597 case DW_LANG_Cobol85:
2599 case DW_LANG_Fortran77: /* moved up top for now */
2601 case DW_LANG_Fortran90:
2602 case DW_LANG_Pascal83:
2603 case DW_LANG_Modula2:
2605 cu_language = language_unknown;
2608 cu_language_defn = language_def (cu_language);
2612 record_minimal_symbol (name, address, ms_type, objfile)
2615 enum minimal_symbol_type ms_type;
2616 struct objfile *objfile;
2618 name = obsavestring (name, strlen (name), &objfile->symbol_obstack);
2619 prim_record_minimal_symbol (name, address, ms_type, objfile);
2622 /* Converts a location description into gdb form. */
2625 convert_locdesc (blk)
2626 struct dwarf_block *blk;
2628 /* FIXME : this is only a stub! */
2632 /* Return the named attribute or NULL if not there. */
2634 static struct attribute *
2635 dwarf_attr (die, name)
2636 struct die_info *die;
2641 for (i = 0; i < die->num_attrs; ++i)
2643 if (die->attrs[i].name == name)
2645 return &die->attrs[i];
2651 /* Decode the line number information for the compilation unit whose
2652 line number info is at OFFSET in the .debug_line section. */
2674 dwarf_decode_lines (offset, abfd)
2675 unsigned int offset;
2679 struct line_head lh;
2680 struct cleanup *back_to;
2681 unsigned int i, bytes_read;
2682 char *cur_file, *cur_dir;
2683 unsigned char op_code, extended_op, adj_opcode;
2685 #define FILE_ALLOC_CHUNK 5
2686 #define DIR_ALLOC_CHUNK 5
2688 struct filenames files;
2689 struct directories dirs;
2691 /* state machine registers */
2692 unsigned int address = 0;
2693 unsigned int file = 1;
2694 unsigned int line = 1;
2695 unsigned int column = 0;
2696 int is_stmt; /* initialized below */
2697 int basic_block = 0;
2698 int beg_of_comp_unit = 0; /* is this right? */
2699 int end_sequence = 0;
2701 files.num_files = 0;
2707 line_ptr = dwarf_line_buffer + offset;
2709 /* read in the prologue */
2710 lh.total_length = read_4_bytes (abfd, line_ptr);
2712 lh.version = read_2_bytes (abfd, line_ptr);
2714 lh.prologue_length = read_4_bytes (abfd, line_ptr);
2716 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
2718 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
2719 is_stmt = lh.default_is_stmt;
2721 lh.line_base = read_1_byte (abfd, line_ptr);
2723 lh.line_range = read_1_byte (abfd, line_ptr);
2725 lh.opcode_base = read_1_byte (abfd, line_ptr);
2727 lh.standard_opcode_lengths = (unsigned char *)
2728 xmalloc (lh.opcode_base * sizeof (unsigned char));
2729 back_to = make_cleanup (free, lh.standard_opcode_lengths);
2731 lh.standard_opcode_lengths[0] = 1;
2732 for (i = 1; i < lh.opcode_base; ++i)
2734 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
2738 /* Read directory table */
2739 while (cur_dir = read_string (abfd, line_ptr, &bytes_read))
2741 line_ptr += bytes_read;
2742 if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0)
2744 dirs.dirs = xrealloc (dirs.dirs,
2745 (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
2747 dirs.dirs[dirs.num_dirs++] = cur_dir;
2749 line_ptr += bytes_read;
2751 /* Read file name table */
2752 while (cur_file = read_string (abfd, line_ptr, &bytes_read))
2754 line_ptr += bytes_read;
2755 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
2757 files.files = xrealloc (files.files,
2758 (files.num_files + FILE_ALLOC_CHUNK) * sizeof (struct fileinfo));
2760 files.files[files.num_files].name = cur_file;
2761 files.files[files.num_files].dir = read_unsigned_leb128 (abfd,
2762 line_ptr, &bytes_read);
2763 line_ptr += bytes_read;
2764 files.files[files.num_files].time = read_unsigned_leb128 (abfd,
2765 line_ptr, &bytes_read);
2766 line_ptr += bytes_read;
2767 files.files[files.num_files].size = read_unsigned_leb128 (abfd,
2768 line_ptr, &bytes_read);
2769 line_ptr += bytes_read;
2772 line_ptr += bytes_read;
2774 /* Decode the table. */
2775 if (lh.total_length - (lh.prologue_length + 4 + 2) >= 4)
2778 op_code = read_1_byte (abfd, line_ptr);
2782 case DW_LNS_extended_op:
2783 line_ptr += 1; /* ignore length */
2784 extended_op = read_1_byte (abfd, line_ptr);
2786 switch (extended_op)
2788 case DW_LNE_end_sequence:
2790 record_line (current_subfile, line, address);
2791 return; /* return! */
2793 case DW_LNE_set_address:
2794 address = read_address (abfd, line_ptr);
2795 line_ptr += address_size;
2797 case DW_LNE_define_file:
2798 cur_file = read_string (abfd, line_ptr, &bytes_read);
2799 line_ptr += bytes_read;
2800 if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
2802 files.files = xrealloc (files.files,
2803 (files.num_files + FILE_ALLOC_CHUNK)
2804 * sizeof (struct fileinfo));
2806 files.files[files.num_files].name = cur_file;
2807 files.files[files.num_files].dir = read_unsigned_leb128 (
2808 abfd, line_ptr, &bytes_read);
2809 line_ptr += bytes_read;
2810 files.files[files.num_files].time = read_unsigned_leb128 (abfd,
2811 line_ptr, &bytes_read);
2812 line_ptr += bytes_read;
2813 files.files[files.num_files].size = read_unsigned_leb128 (abfd,
2814 line_ptr, &bytes_read);
2815 line_ptr += bytes_read;
2818 error ("Dwarf Error: Mangled .debug_line section.");
2823 record_line (current_subfile, line, address);
2826 case DW_LNS_advance_pc:
2827 address += lh.minimum_instruction_length
2828 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2829 line_ptr += bytes_read;
2831 case DW_LNS_advance_line:
2832 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
2833 line_ptr += bytes_read;
2835 case DW_LNS_set_file:
2836 /* The file table is 0 based and the references are 1
2837 based, thus the subtraction of `1' at the end of the
2839 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read) - 1;
2840 start_subfile (files.files[file].name,
2841 (files.files[file].dir ?
2842 dirs.dirs[files.files[file].dir] : 0));
2843 line_ptr += bytes_read;
2845 case DW_LNS_set_column:
2846 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2847 line_ptr += bytes_read;
2849 case DW_LNS_negate_stmt:
2850 is_stmt = (!is_stmt);
2852 case DW_LNS_set_basic_block:
2855 case DW_LNS_const_add_pc:
2856 address += (255 - lh.opcode_base) / lh.line_range;
2858 case DW_LNS_fixed_advance_pc:
2859 address += read_2_bytes (abfd, line_ptr);
2862 default: /* special operand */
2863 adj_opcode = op_code - lh.opcode_base;
2864 address += (adj_opcode / lh.line_range)
2865 * lh.minimum_instruction_length;
2866 line += lh.line_base + (adj_opcode % lh.line_range);
2867 /* append row to matrix using current values */
2868 record_line (current_subfile, line, address);
2873 do_cleanups (back_to);
2876 /* Given a pointer to a DWARF information entry, figure out if we need
2877 to make a symbol table entry for it, and if so, create a new entry
2878 and return a pointer to it. */
2880 static struct symbol *
2881 new_symbol (die, objfile)
2882 struct die_info *die;
2883 struct objfile *objfile;
2885 struct symbol *sym = NULL;
2886 struct attribute *attr = NULL;
2887 struct attribute *attr2 = NULL;
2890 attr = dwarf_attr (die, DW_AT_name);
2894 sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
2895 sizeof (struct symbol));
2897 sym = (struct symbol *) xmalloc (sizeof (struct symbol));
2898 memset (sym, 0, sizeof (struct symbol));
2900 SYMBOL_NAME (sym) = create_name (DW_STRING (attr),
2901 &objfile->symbol_obstack);
2903 SYMBOL_NAME (sym) = strdup (DW_STRING (attr));
2904 /* default assumptions */
2905 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2906 SYMBOL_CLASS (sym) = LOC_STATIC;
2907 SYMBOL_TYPE (sym) = die_type (die, objfile);
2909 /* If this symbol is from a C++ compilation, then attempt to
2910 cache the demangled form for future reference. This is a
2911 typical time versus space tradeoff, that was decided in favor
2912 of time because it sped up C++ symbol lookups by a factor of
2915 SYMBOL_LANGUAGE (sym) = cu_language;
2916 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
2920 attr = dwarf_attr (die, DW_AT_low_pc);
2923 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr);
2925 SYMBOL_CLASS (sym) = LOC_LABEL;
2927 case DW_TAG_subprogram:
2928 attr = dwarf_attr (die, DW_AT_low_pc);
2931 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr);
2933 SYMBOL_TYPE (sym) = make_function_type (die_type (die, objfile),
2935 SYMBOL_CLASS (sym) = LOC_BLOCK;
2936 attr2 = dwarf_attr (die, DW_AT_external);
2937 if (attr2 && (DW_UNSND (attr2) != 0))
2939 add_symbol_to_list (sym, &global_symbols);
2943 add_symbol_to_list (sym, list_in_scope);
2946 case DW_TAG_variable:
2947 attr = dwarf_attr (die, DW_AT_location);
2950 attr2 = dwarf_attr (die, DW_AT_external);
2951 if (attr2 && (DW_UNSND (attr2) != 0))
2953 SYMBOL_VALUE_ADDRESS (sym) =
2954 decode_locdesc (DW_BLOCK (attr), objfile);
2955 add_symbol_to_list (sym, &global_symbols);
2956 SYMBOL_CLASS (sym) = LOC_STATIC;
2957 SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
2961 SYMBOL_VALUE (sym) = addr =
2962 decode_locdesc (DW_BLOCK (attr), objfile);
2963 add_symbol_to_list (sym, list_in_scope);
2966 SYMBOL_CLASS (sym) = LOC_REGISTER;
2970 SYMBOL_CLASS (sym) = LOC_LOCAL;
2974 SYMBOL_CLASS (sym) = LOC_STATIC;
2975 SYMBOL_VALUE_ADDRESS (sym) = addr + baseaddr;
2980 case DW_TAG_formal_parameter:
2981 attr = dwarf_attr (die, DW_AT_location);
2984 SYMBOL_VALUE (sym) = decode_locdesc (DW_BLOCK (attr), objfile);
2986 add_symbol_to_list (sym, list_in_scope);
2989 SYMBOL_CLASS (sym) = LOC_REGPARM;
2993 SYMBOL_CLASS (sym) = LOC_ARG;
2996 case DW_TAG_unspecified_parameters:
2997 /* From varargs functions; gdb doesn't seem to have any
2998 interest in this information, so just ignore it for now.
3001 case DW_TAG_class_type:
3002 case DW_TAG_structure_type:
3003 case DW_TAG_union_type:
3004 case DW_TAG_enumeration_type:
3005 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3006 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
3007 add_symbol_to_list (sym, list_in_scope);
3009 case DW_TAG_typedef:
3010 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3011 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3012 add_symbol_to_list (sym, list_in_scope);
3015 /* Not a tag we recognize. Hopefully we aren't processing
3016 trash data, but since we must specifically ignore things
3017 we don't recognize, there is nothing else we should do at
3025 /* Return the type of the die in question using its DW_AT_type attribute. */
3027 static struct type *
3028 die_type (die, objfile)
3029 struct die_info *die;
3030 struct objfile *objfile;
3033 struct attribute *attr, *type_attr;
3034 struct die_info *type_die;
3035 unsigned int size = 0, encoding = 0, ref;
3037 type_attr = dwarf_attr (die, DW_AT_type);
3040 type = dwarf_base_type (0, 0);
3045 ref = DW_UNSND (type_attr);
3046 type_die = follow_die_ref (ref);
3049 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
3053 type = tag_type_to_type (type_die, objfile);
3056 error ("Dwarf Error: Problem turning type die at offset into gdb type:");
3057 dump_die (type_die);
3062 static struct type *
3063 type_at_offset (offset, objfile)
3064 unsigned int offset;
3065 struct objfile *objfile;
3067 struct die_info *die;
3070 die = follow_die_ref (offset);
3073 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
3076 type = tag_type_to_type (die, objfile);
3080 static struct type *
3081 tag_type_to_type (die, objfile)
3082 struct die_info *die;
3083 struct objfile *objfile;
3091 read_type_die (die, objfile);
3095 error ("Dwarf Error: Cannot find type of die:");
3102 read_type_die (die, objfile)
3103 struct die_info *die;
3104 struct objfile *objfile;
3108 case DW_TAG_class_type:
3109 case DW_TAG_structure_type:
3110 case DW_TAG_union_type:
3111 read_structure_scope (die, objfile);
3113 case DW_TAG_enumeration_type:
3114 read_enumeration (die, objfile);
3116 case DW_TAG_subroutine_type:
3117 read_subroutine_type (die, objfile);
3119 case DW_TAG_array_type:
3120 dwarf_read_array_type (die, objfile);
3122 case DW_TAG_pointer_type:
3123 read_tag_pointer_type (die, objfile);
3125 case DW_TAG_const_type:
3126 read_tag_const_type (die, objfile);
3128 case DW_TAG_volatile_type:
3129 read_tag_volatile_type (die, objfile);
3131 case DW_TAG_string_type:
3132 read_tag_string_type (die, objfile);
3134 case DW_TAG_typedef:
3135 read_typedef (die, objfile);
3137 case DW_TAG_base_type:
3138 read_base_type (die, objfile);
3140 case DW_TAG_padding:
3141 case DW_TAG_compile_unit:
3142 case DW_TAG_subprogram:
3143 case DW_TAG_lexical_block:
3149 static struct type *
3150 dwarf_base_type (encoding, size)
3154 /* FIXME - this should not produce a new (struct type *)
3155 every time. It should cache base types. */
3159 case DW_ATE_address:
3160 type = dwarf2_fundamental_type (current_objfile, FT_VOID);
3162 case DW_ATE_boolean:
3163 type = dwarf2_fundamental_type (current_objfile, FT_BOOLEAN);
3165 case DW_ATE_complex_float:
3168 type = dwarf2_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
3172 type = dwarf2_fundamental_type (current_objfile, FT_COMPLEX);
3178 type = dwarf2_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
3182 type = dwarf2_fundamental_type (current_objfile, FT_FLOAT);
3189 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3192 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_SHORT);
3196 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3200 case DW_ATE_signed_char:
3201 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3203 case DW_ATE_unsigned:
3207 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3210 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_SHORT);
3214 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
3218 case DW_ATE_unsigned_char:
3219 type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3222 type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3227 /* Given a pointer to a string and a pointer to an obstack, allocates
3228 a fresh copy of the string on the specified obstack. */
3231 create_name (name, obstackp)
3233 struct obstack *obstackp;
3238 length = strlen (name) + 1;
3239 newname = (char *) obstack_alloc (obstackp, length);
3240 strcpy (newname, name);
3246 struct die_info *old_die;
3248 struct die_info *new_die;
3251 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
3252 memset (new_die, 0, sizeof (struct die_info));
3254 new_die->tag = old_die->tag;
3255 new_die->has_children = old_die->has_children;
3256 new_die->abbrev = old_die->abbrev;
3257 new_die->offset = old_die->offset;
3258 new_die->type = NULL;
3260 num_attrs = old_die->num_attrs;
3261 new_die->num_attrs = num_attrs;
3262 new_die->attrs = (struct attribute *)
3263 xmalloc (num_attrs * sizeof (struct attribute));
3265 for (i = 0; i < old_die->num_attrs; ++i)
3267 new_die->attrs[i].name = old_die->attrs[i].name;
3268 new_die->attrs[i].form = old_die->attrs[i].form;
3269 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
3272 new_die->next = NULL;
3276 /* Return sibling of die, NULL if no sibling. */
3280 struct die_info *die;
3282 struct die_info *new;
3283 int nesting_level = 0;
3285 if (!die->has_children)
3287 if (die->next && (die->next->tag == 0))
3300 if (die->has_children)
3310 while (nesting_level);
3311 if (die && (die->tag == 0))
3322 /* Convert a DIE tag into its string name. */
3325 dwarf_tag_name (tag)
3326 register unsigned tag;
3330 case DW_TAG_padding:
3331 return "DW_TAG_padding";
3332 case DW_TAG_array_type:
3333 return "DW_TAG_array_type";
3334 case DW_TAG_class_type:
3335 return "DW_TAG_class_type";
3336 case DW_TAG_entry_point:
3337 return "DW_TAG_entry_point";
3338 case DW_TAG_enumeration_type:
3339 return "DW_TAG_enumeration_type";
3340 case DW_TAG_formal_parameter:
3341 return "DW_TAG_formal_parameter";
3342 case DW_TAG_imported_declaration:
3343 return "DW_TAG_imported_declaration";
3345 return "DW_TAG_label";
3346 case DW_TAG_lexical_block:
3347 return "DW_TAG_lexical_block";
3349 return "DW_TAG_member";
3350 case DW_TAG_pointer_type:
3351 return "DW_TAG_pointer_type";
3352 case DW_TAG_reference_type:
3353 return "DW_TAG_reference_type";
3354 case DW_TAG_compile_unit:
3355 return "DW_TAG_compile_unit";
3356 case DW_TAG_string_type:
3357 return "DW_TAG_string_type";
3358 case DW_TAG_structure_type:
3359 return "DW_TAG_structure_type";
3360 case DW_TAG_subroutine_type:
3361 return "DW_TAG_subroutine_type";
3362 case DW_TAG_typedef:
3363 return "DW_TAG_typedef";
3364 case DW_TAG_union_type:
3365 return "DW_TAG_union_type";
3366 case DW_TAG_unspecified_parameters:
3367 return "DW_TAG_unspecified_parameters";
3368 case DW_TAG_variant:
3369 return "DW_TAG_variant";
3370 case DW_TAG_common_block:
3371 return "DW_TAG_common_block";
3372 case DW_TAG_common_inclusion:
3373 return "DW_TAG_common_inclusion";
3374 case DW_TAG_inheritance:
3375 return "DW_TAG_inheritance";
3376 case DW_TAG_inlined_subroutine:
3377 return "DW_TAG_inlined_subroutine";
3379 return "DW_TAG_module";
3380 case DW_TAG_ptr_to_member_type:
3381 return "DW_TAG_ptr_to_member_type";
3382 case DW_TAG_set_type:
3383 return "DW_TAG_set_type";
3384 case DW_TAG_subrange_type:
3385 return "DW_TAG_subrange_type";
3386 case DW_TAG_with_stmt:
3387 return "DW_TAG_with_stmt";
3388 case DW_TAG_access_declaration:
3389 return "DW_TAG_access_declaration";
3390 case DW_TAG_base_type:
3391 return "DW_TAG_base_type";
3392 case DW_TAG_catch_block:
3393 return "DW_TAG_catch_block";
3394 case DW_TAG_const_type:
3395 return "DW_TAG_const_type";
3396 case DW_TAG_constant:
3397 return "DW_TAG_constant";
3398 case DW_TAG_enumerator:
3399 return "DW_TAG_enumerator";
3400 case DW_TAG_file_type:
3401 return "DW_TAG_file_type";
3403 return "DW_TAG_friend";
3404 case DW_TAG_namelist:
3405 return "DW_TAG_namelist";
3406 case DW_TAG_namelist_item:
3407 return "DW_TAG_namelist_item";
3408 case DW_TAG_packed_type:
3409 return "DW_TAG_packed_type";
3410 case DW_TAG_subprogram:
3411 return "DW_TAG_subprogram";
3412 case DW_TAG_template_type_param:
3413 return "DW_TAG_template_type_param";
3414 case DW_TAG_template_value_param:
3415 return "DW_TAG_template_value_param";
3416 case DW_TAG_thrown_type:
3417 return "DW_TAG_thrown_type";
3418 case DW_TAG_try_block:
3419 return "DW_TAG_try_block";
3420 case DW_TAG_variant_part:
3421 return "DW_TAG_variant_part";
3422 case DW_TAG_variable:
3423 return "DW_TAG_variable";
3424 case DW_TAG_volatile_type:
3425 return "DW_TAG_volatile_type";
3426 case DW_TAG_MIPS_loop:
3427 return "DW_TAG_MIPS_loop";
3428 case DW_TAG_format_label:
3429 return "DW_TAG_format_label";
3430 case DW_TAG_function_template:
3431 return "DW_TAG_function_template";
3432 case DW_TAG_class_template:
3433 return "DW_TAG_class_template";
3435 return "DW_TAG_<unknown>";
3439 /* Convert a DWARF attribute code into its string name. */
3442 dwarf_attr_name (attr)
3443 register unsigned attr;
3448 return "DW_AT_sibling";
3449 case DW_AT_location:
3450 return "DW_AT_location";
3452 return "DW_AT_name";
3453 case DW_AT_ordering:
3454 return "DW_AT_ordering";
3455 case DW_AT_subscr_data:
3456 return "DW_AT_subscr_data";
3457 case DW_AT_byte_size:
3458 return "DW_AT_byte_size";
3459 case DW_AT_bit_offset:
3460 return "DW_AT_bit_offset";
3461 case DW_AT_bit_size:
3462 return "DW_AT_bit_size";
3463 case DW_AT_element_list:
3464 return "DW_AT_element_list";
3465 case DW_AT_stmt_list:
3466 return "DW_AT_stmt_list";
3468 return "DW_AT_low_pc";
3470 return "DW_AT_high_pc";
3471 case DW_AT_language:
3472 return "DW_AT_language";
3474 return "DW_AT_member";
3476 return "DW_AT_discr";
3477 case DW_AT_discr_value:
3478 return "DW_AT_discr_value";
3479 case DW_AT_visibility:
3480 return "DW_AT_visibility";
3482 return "DW_AT_import";
3483 case DW_AT_string_length:
3484 return "DW_AT_string_length";
3485 case DW_AT_common_reference:
3486 return "DW_AT_common_reference";
3487 case DW_AT_comp_dir:
3488 return "DW_AT_comp_dir";
3489 case DW_AT_const_value:
3490 return "DW_AT_const_value";
3491 case DW_AT_containing_type:
3492 return "DW_AT_containing_type";
3493 case DW_AT_default_value:
3494 return "DW_AT_default_value";
3496 return "DW_AT_inline";
3497 case DW_AT_is_optional:
3498 return "DW_AT_is_optional";
3499 case DW_AT_lower_bound:
3500 return "DW_AT_lower_bound";
3501 case DW_AT_producer:
3502 return "DW_AT_producer";
3503 case DW_AT_prototyped:
3504 return "DW_AT_prototyped";
3505 case DW_AT_return_addr:
3506 return "DW_AT_return_addr";
3507 case DW_AT_start_scope:
3508 return "DW_AT_start_scope";
3509 case DW_AT_stride_size:
3510 return "DW_AT_stride_size";
3511 case DW_AT_upper_bound:
3512 return "DW_AT_upper_bound";
3513 case DW_AT_abstract_origin:
3514 return "DW_AT_abstract_origin";
3515 case DW_AT_accessibility:
3516 return "DW_AT_accessibility";
3517 case DW_AT_address_class:
3518 return "DW_AT_address_class";
3519 case DW_AT_artificial:
3520 return "DW_AT_artificial";
3521 case DW_AT_base_types:
3522 return "DW_AT_base_types";
3523 case DW_AT_calling_convention:
3524 return "DW_AT_calling_convention";
3526 return "DW_AT_count";
3527 case DW_AT_data_member_location:
3528 return "DW_AT_data_member_location";
3529 case DW_AT_decl_column:
3530 return "DW_AT_decl_column";
3531 case DW_AT_decl_file:
3532 return "DW_AT_decl_file";
3533 case DW_AT_decl_line:
3534 return "DW_AT_decl_line";
3535 case DW_AT_declaration:
3536 return "DW_AT_declaration";
3537 case DW_AT_discr_list:
3538 return "DW_AT_discr_list";
3539 case DW_AT_encoding:
3540 return "DW_AT_encoding";
3541 case DW_AT_external:
3542 return "DW_AT_external";
3543 case DW_AT_frame_base:
3544 return "DW_AT_frame_base";
3546 return "DW_AT_friend";
3547 case DW_AT_identifier_case:
3548 return "DW_AT_identifier_case";
3549 case DW_AT_macro_info:
3550 return "DW_AT_macro_info";
3551 case DW_AT_namelist_items:
3552 return "DW_AT_namelist_items";
3553 case DW_AT_priority:
3554 return "DW_AT_priority";
3556 return "DW_AT_segment";
3557 case DW_AT_specification:
3558 return "DW_AT_specification";
3559 case DW_AT_static_link:
3560 return "DW_AT_static_link";
3562 return "DW_AT_type";
3563 case DW_AT_use_location:
3564 return "DW_AT_use_location";
3565 case DW_AT_variable_parameter:
3566 return "DW_AT_variable_parameter";
3567 case DW_AT_virtuality:
3568 return "DW_AT_virtuality";
3569 case DW_AT_vtable_elem_location:
3570 return "DW_AT_vtable_elem_location";
3573 case DW_AT_MIPS_fde:
3574 return "DW_AT_MIPS_fde";
3575 case DW_AT_MIPS_loop_begin:
3576 return "DW_AT_MIPS_loop_begin";
3577 case DW_AT_MIPS_tail_loop_begin:
3578 return "DW_AT_MIPS_tail_loop_begin";
3579 case DW_AT_MIPS_epilog_begin:
3580 return "DW_AT_MIPS_epilog_begin";
3581 case DW_AT_MIPS_loop_unroll_factor:
3582 return "DW_AT_MIPS_loop_unroll_factor";
3583 case DW_AT_MIPS_software_pipeline_depth:
3584 return "DW_AT_MIPS_software_pipeline_depth";
3585 case DW_AT_MIPS_linkage_name:
3586 return "DW_AT_MIPS_linkage_name";
3589 case DW_AT_sf_names:
3590 return "DW_AT_sf_names";
3591 case DW_AT_src_info:
3592 return "DW_AT_src_info";
3593 case DW_AT_mac_info:
3594 return "DW_AT_mac_info";
3595 case DW_AT_src_coords:
3596 return "DW_AT_src_coords";
3597 case DW_AT_body_begin:
3598 return "DW_AT_body_begin";
3599 case DW_AT_body_end:
3600 return "DW_AT_body_end";
3602 return "DW_AT_<unknown>";
3606 /* Convert a DWARF value form code into its string name. */
3609 dwarf_form_name (form)
3610 register unsigned form;
3615 return "DW_FORM_addr";
3616 case DW_FORM_block2:
3617 return "DW_FORM_block2";
3618 case DW_FORM_block4:
3619 return "DW_FORM_block4";
3621 return "DW_FORM_data2";
3623 return "DW_FORM_data4";
3625 return "DW_FORM_data8";
3626 case DW_FORM_string:
3627 return "DW_FORM_string";
3629 return "DW_FORM_block";
3630 case DW_FORM_block1:
3631 return "DW_FORM_block1";
3633 return "DW_FORM_data1";
3635 return "DW_FORM_flag";
3637 return "DW_FORM_sdata";
3639 return "DW_FORM_strp";
3641 return "DW_FORM_udata";
3642 case DW_FORM_ref_addr:
3643 return "DW_FORM_ref_addr";
3645 return "DW_FORM_ref1";
3647 return "DW_FORM_ref2";
3649 return "DW_FORM_ref4";
3651 return "DW_FORM_ref8";
3652 case DW_FORM_ref_udata:
3653 return "DW_FORM_ref_udata";
3654 case DW_FORM_indirect:
3655 return "DW_FORM_indirect";
3657 return "DW_FORM_<unknown>";
3661 /* Convert a DWARF stack opcode into its string name. */
3664 dwarf_stack_op_name (op)
3665 register unsigned op;
3670 return "DW_OP_addr";
3672 return "DW_OP_deref";
3674 return "DW_OP_const1u";
3676 return "DW_OP_const1s";
3678 return "DW_OP_const2u";
3680 return "DW_OP_const2s";
3682 return "DW_OP_const4u";
3684 return "DW_OP_const4s";
3686 return "DW_OP_const8u";
3688 return "DW_OP_const8s";
3690 return "DW_OP_constu";
3692 return "DW_OP_consts";
3696 return "DW_OP_drop";
3698 return "DW_OP_over";
3700 return "DW_OP_pick";
3702 return "DW_OP_swap";
3706 return "DW_OP_xderef";
3714 return "DW_OP_minus";
3726 return "DW_OP_plus";
3727 case DW_OP_plus_uconst:
3728 return "DW_OP_plus_uconst";
3734 return "DW_OP_shra";
3752 return "DW_OP_skip";
3754 return "DW_OP_lit0";
3756 return "DW_OP_lit1";
3758 return "DW_OP_lit2";
3760 return "DW_OP_lit3";
3762 return "DW_OP_lit4";
3764 return "DW_OP_lit5";
3766 return "DW_OP_lit6";
3768 return "DW_OP_lit7";
3770 return "DW_OP_lit8";
3772 return "DW_OP_lit9";
3774 return "DW_OP_lit10";
3776 return "DW_OP_lit11";
3778 return "DW_OP_lit12";
3780 return "DW_OP_lit13";
3782 return "DW_OP_lit14";
3784 return "DW_OP_lit15";
3786 return "DW_OP_lit16";
3788 return "DW_OP_lit17";
3790 return "DW_OP_lit18";
3792 return "DW_OP_lit19";
3794 return "DW_OP_lit20";
3796 return "DW_OP_lit21";
3798 return "DW_OP_lit22";
3800 return "DW_OP_lit23";
3802 return "DW_OP_lit24";
3804 return "DW_OP_lit25";
3806 return "DW_OP_lit26";
3808 return "DW_OP_lit27";
3810 return "DW_OP_lit28";
3812 return "DW_OP_lit29";
3814 return "DW_OP_lit30";
3816 return "DW_OP_lit31";
3818 return "DW_OP_reg0";
3820 return "DW_OP_reg1";
3822 return "DW_OP_reg2";
3824 return "DW_OP_reg3";
3826 return "DW_OP_reg4";
3828 return "DW_OP_reg5";
3830 return "DW_OP_reg6";
3832 return "DW_OP_reg7";
3834 return "DW_OP_reg8";
3836 return "DW_OP_reg9";
3838 return "DW_OP_reg10";
3840 return "DW_OP_reg11";
3842 return "DW_OP_reg12";
3844 return "DW_OP_reg13";
3846 return "DW_OP_reg14";
3848 return "DW_OP_reg15";
3850 return "DW_OP_reg16";
3852 return "DW_OP_reg17";
3854 return "DW_OP_reg18";
3856 return "DW_OP_reg19";
3858 return "DW_OP_reg20";
3860 return "DW_OP_reg21";
3862 return "DW_OP_reg22";
3864 return "DW_OP_reg23";
3866 return "DW_OP_reg24";
3868 return "DW_OP_reg25";
3870 return "DW_OP_reg26";
3872 return "DW_OP_reg27";
3874 return "DW_OP_reg28";
3876 return "DW_OP_reg29";
3878 return "DW_OP_reg30";
3880 return "DW_OP_reg31";
3882 return "DW_OP_breg0";
3884 return "DW_OP_breg1";
3886 return "DW_OP_breg2";
3888 return "DW_OP_breg3";
3890 return "DW_OP_breg4";
3892 return "DW_OP_breg5";
3894 return "DW_OP_breg6";
3896 return "DW_OP_breg7";
3898 return "DW_OP_breg8";
3900 return "DW_OP_breg9";
3902 return "DW_OP_breg10";
3904 return "DW_OP_breg11";
3906 return "DW_OP_breg12";
3908 return "DW_OP_breg13";
3910 return "DW_OP_breg14";
3912 return "DW_OP_breg15";
3914 return "DW_OP_breg16";
3916 return "DW_OP_breg17";
3918 return "DW_OP_breg18";
3920 return "DW_OP_breg19";
3922 return "DW_OP_breg20";
3924 return "DW_OP_breg21";
3926 return "DW_OP_breg22";
3928 return "DW_OP_breg23";
3930 return "DW_OP_breg24";
3932 return "DW_OP_breg25";
3934 return "DW_OP_breg26";
3936 return "DW_OP_breg27";
3938 return "DW_OP_breg28";
3940 return "DW_OP_breg29";
3942 return "DW_OP_breg30";
3944 return "DW_OP_breg31";
3946 return "DW_OP_regx";
3948 return "DW_OP_fbreg";
3950 return "DW_OP_bregx";
3952 return "DW_OP_piece";
3953 case DW_OP_deref_size:
3954 return "DW_OP_deref_size";
3955 case DW_OP_xderef_size:
3956 return "DW_OP_xderef_size";
3960 return "OP_<unknown>";
3965 dwarf_bool_name (bool)
3974 /* Convert a DWARF type code into its string name. */
3977 dwarf_type_encoding_name (enc)
3978 register unsigned enc;
3982 case DW_ATE_address:
3983 return "DW_ATE_address";
3984 case DW_ATE_boolean:
3985 return "DW_ATE_boolean";
3986 case DW_ATE_complex_float:
3987 return "DW_ATE_complex_float";
3989 return "DW_ATE_float";
3991 return "DW_ATE_signed";
3992 case DW_ATE_signed_char:
3993 return "DW_ATE_signed_char";
3994 case DW_ATE_unsigned:
3995 return "DW_ATE_unsigned";
3996 case DW_ATE_unsigned_char:
3997 return "DW_ATE_unsigned_char";
3999 return "DW_ATE_<unknown>";
4003 /* Convert a DWARF call frame info operation to its string name. */
4006 dwarf_cfi_name (cfi_opc)
4007 register unsigned cfi_opc;
4011 case DW_CFA_advance_loc:
4012 return "DW_CFA_advance_loc";
4014 return "DW_CFA_offset";
4015 case DW_CFA_restore:
4016 return "DW_CFA_restore";
4018 return "DW_CFA_nop";
4019 case DW_CFA_set_loc:
4020 return "DW_CFA_set_loc";
4021 case DW_CFA_advance_loc1:
4022 return "DW_CFA_advance_loc1";
4023 case DW_CFA_advance_loc2:
4024 return "DW_CFA_advance_loc2";
4025 case DW_CFA_advance_loc4:
4026 return "DW_CFA_advance_loc4";
4027 case DW_CFA_offset_extended:
4028 return "DW_CFA_offset_extended";
4029 case DW_CFA_restore_extended:
4030 return "DW_CFA_restore_extended";
4031 case DW_CFA_undefined:
4032 return "DW_CFA_undefined";
4033 case DW_CFA_same_value:
4034 return "DW_CFA_same_value";
4035 case DW_CFA_register:
4036 return "DW_CFA_register";
4037 case DW_CFA_remember_state:
4038 return "DW_CFA_remember_state";
4039 case DW_CFA_restore_state:
4040 return "DW_CFA_restore_state";
4041 case DW_CFA_def_cfa:
4042 return "DW_CFA_def_cfa";
4043 case DW_CFA_def_cfa_register:
4044 return "DW_CFA_def_cfa_register";
4045 case DW_CFA_def_cfa_offset:
4046 return "DW_CFA_def_cfa_offset";
4047 /* SGI/MIPS specific */
4048 case DW_CFA_MIPS_advance_loc8:
4049 return "DW_CFA_MIPS_advance_loc8";
4051 return "DW_CFA_<unknown>";
4057 struct die_info *die;
4061 fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n",
4062 dwarf_tag_name (die->tag), die->abbrev, die->offset);
4063 fprintf (stderr, "\thas children: %s\n",
4064 dwarf_bool_name (die->has_children));
4066 fprintf (stderr, "\tattributes:\n");
4067 for (i = 0; i < die->num_attrs; ++i)
4069 fprintf (stderr, "\t\t%s (%s) ",
4070 dwarf_attr_name (die->attrs[i].name),
4071 dwarf_form_name (die->attrs[i].form));
4072 switch (die->attrs[i].form)
4074 case DW_FORM_ref_addr:
4076 fprintf (stderr, sizeof (CORE_ADDR) > sizeof (long) ?
4077 "address: 0x%LLx" : "address: 0x%x",
4078 die->attrs[i].u.addr);
4080 case DW_FORM_block2:
4081 case DW_FORM_block4:
4083 case DW_FORM_block1:
4084 fprintf (stderr, "block: size %d",
4085 die->attrs[i].u.blk->size);
4095 fprintf (stderr, "constant: %d", die->attrs[i].u.unsnd);
4097 case DW_FORM_string:
4098 fprintf (stderr, "string: \"%s\"", die->attrs[i].u.str);
4101 if (die->attrs[i].u.unsnd)
4102 fprintf (stderr, "flag: TRUE");
4104 fprintf (stderr, "flag: FALSE");
4106 case DW_FORM_strp: /* we do not support separate string
4108 case DW_FORM_indirect: /* we do not handle indirect yet */
4109 case DW_FORM_data8: /* we do not have 64 bit quantities */
4110 error ("Dwarf Error: Unsupported attribute form: %d.",
4111 die->attrs[i].form);
4113 fprintf (stderr, "\n");
4119 struct die_info *die;
4129 store_in_ref_table (offset, die)
4130 unsigned int offset;
4131 struct die_info *die;
4134 struct die_info *old;
4136 h = (offset % REF_HASH_SIZE);
4137 old = die_ref_table[h];
4138 die->next_ref = old;
4139 die_ref_table[h] = die;
4143 follow_die_ref (offset)
4144 unsigned int offset;
4146 struct die_info *die;
4149 h = (offset % REF_HASH_SIZE);
4150 die = die_ref_table[h];
4153 if (die->offset == offset)
4157 die = die->next_ref;
4162 static struct type *
4163 dwarf2_fundamental_type (objfile, typeid)
4164 struct objfile *objfile;
4167 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
4169 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
4173 /* Look for this particular type in the fundamental type vector. If
4174 one is not found, create and install one appropriate for the
4175 current language and the current target machine. */
4177 if (ftypes[typeid] == NULL)
4179 ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
4182 return (ftypes[typeid]);
4185 /* Decode simple location descriptions.
4186 There are three cases:
4187 An address: return the address.
4188 An address relative to frame pointer: return the offset.
4189 A register: return register number and set isreg to true.
4190 A constant followed by plus: return the constant. */
4193 decode_locdesc (blk, objfile)
4194 struct dwarf_block *blk;
4195 struct objfile *objfile;
4198 int size = blk->size;
4199 char *data = blk->data;
4200 unsigned int bytes_read, unsnd;
4205 char bytes[sizeof (CORE_ADDR)];
4213 /* FIXME: handle more general forms of location descriptors. */
4318 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
4320 #if defined(HARRIS_TARGET) && defined(_M88K)
4321 /* The Harris 88110 gdb ports have long kept their special reg
4322 numbers between their gp-regs and their x-regs. This is
4323 not how our dwarf is generated. Punt. */
4332 snd = read_signed_leb128 (NULL, (data + i), &bytes_read);
4338 return read_address (objfile->obfd, &data[i]);
4341 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
4353 /* memory allocation interface */
4355 static struct type *
4356 dwarf_alloc_type (objfile)
4357 struct objfile *objfile;
4361 type = (struct type *) xmalloc (sizeof (struct type));
4362 memset (type, 0, sizeof (struct type));
4365 type = alloc_type (objfile);
4371 static struct abbrev_info *
4372 dwarf_alloc_abbrev ()
4374 struct abbrev_info *abbrev;
4376 abbrev = xmalloc (sizeof (struct abbrev_info));
4377 memset (abbrev, 0, sizeof (struct abbrev_info));
4381 static struct dwarf_block *
4382 dwarf_alloc_block ()
4384 struct dwarf_block *blk;
4386 blk = (struct dwarf_block *) xmalloc (sizeof (struct dwarf_block));
4390 static struct die_info *
4393 struct die_info *die;
4395 die = (struct die_info *) xmalloc (sizeof (struct die_info));
4396 memset (die, 0, sizeof (struct die_info));