xref: /openbsd-src/gnu/usr.bin/binutils/gdb/dwarf2read.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /* DWARF 2 debugging format support for GDB.
2    Copyright 1994, 1995, 1996 Free Software Foundation, Inc.
3 
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
9    support in dwarfread.c
10 
11 This file is part of GDB.
12 
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.
17 
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.
22 
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.  */
26 
27 #include "defs.h"
28 #include "bfd.h"
29 #include "symtab.h"
30 #include "gdbtypes.h"
31 #include "symfile.h"
32 #include "objfiles.h"
33 #include "elf/dwarf2.h"
34 #include "buildsym.h"
35 #include "demangle.h"
36 #include "expression.h"
37 #include "language.h"
38 
39 #include <fcntl.h>
40 #include "gdb_string.h"
41 #include <sys/types.h>
42 
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
47   {
48     unsigned int length;	/* length of the .debug_info
49 				   contribution */
50     unsigned short version;	/* version number -- 2 for DWARF
51 				   version 2 */
52     unsigned int abbrev_offset;	/* offset into .debug_abbrev section */
53     unsigned char addr_size;	/* byte size of an address -- 4 */
54   }
55 _COMP_UNIT_HEADER;
56 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
57 
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
62   {
63     unsigned int length;	/* length of the .debug_pubnames
64 				   contribution  */
65     unsigned char version;	/* version number -- 2 for DWARF
66 				   version 2 */
67     unsigned int info_offset;	/* offset into .debug_info section */
68     unsigned int info_size;	/* byte size of .debug_info section
69 				   portion */
70   }
71 _PUBNAMES_HEADER;
72 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
73 
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
78   {
79     unsigned int length;	/* byte len of the .debug_aranges
80 				   contribution */
81     unsigned short version;	/* version number -- 2 for DWARF
82 				   version 2 */
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 */
86   }
87 _ARANGES_HEADER;
88 #define _ACTUAL_ARANGES_HEADER_SIZE 12
89 
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
94   {
95     unsigned int total_length;	/* byte length of the statement
96 				   information */
97     unsigned short version;	/* version number -- 2 for DWARF
98 				   version 2 */
99     unsigned int prologue_length;	/* # bytes between prologue &
100 					   stmt program */
101     unsigned char minimum_instruction_length;	/* byte size of
102 						   smallest instr */
103     unsigned char default_is_stmt;	/* initial value of is_stmt
104 					   register */
105     char line_base;
106     unsigned char line_range;
107     unsigned char opcode_base;	/* number assigned to first special
108 				   opcode */
109     unsigned char *standard_opcode_lengths;
110   }
111 _STATEMENT_PROLOGUE;
112 
113 /* offsets and sizes of debugging sections */
114 
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;
123 
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;
132 
133 /* names of the debugging sections */
134 
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"
143 
144 /* Get at parts of an attribute structure */
145 
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)
151 
152 /* local data types */
153 
154 /* The data in a compilation unit header looks like this.  */
155 struct comp_unit_head
156   {
157     int length;
158     short version;
159     int abbrev_offset;
160     unsigned char addr_size;
161   };
162 
163 /* The data in the .debug_line statement prologue looks like this.  */
164 struct line_head
165   {
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;
171     char line_base;
172     unsigned char line_range;
173     unsigned char opcode_base;
174     unsigned char *standard_opcode_lengths;
175   };
176 
177 /* When we construct a partial symbol table entry we only
178    need this much information. */
179 struct partial_die_info
180   {
181     unsigned short tag;
182     unsigned char has_children;
183     unsigned char is_external;
184     unsigned int offset;
185     unsigned int abbrev;
186     char *name;
187     CORE_ADDR lowpc;
188     CORE_ADDR highpc;
189     struct dwarf_block *locdesc;
190     unsigned int language;
191     int value;
192   };
193 
194 /* This data structure holds the information of an abbrev. */
195 struct abbrev_info
196   {
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 */
203   };
204 
205 struct attr_abbrev
206   {
207     unsigned int name;
208     unsigned int form;
209   };
210 
211 /* This data structure holds a complete die structure. */
212 struct die_info
213   {
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 */
223   };
224 
225 /* Attributes have a name and a value */
226 struct attribute
227   {
228     unsigned short name;
229     unsigned short form;
230     union
231       {
232 	char *str;
233 	struct dwarf_block *blk;
234 	unsigned int unsnd;
235 	int snd;
236 	CORE_ADDR addr;
237       }
238     u;
239   };
240 
241 /* Blocks are a bunch of untyped bytes. */
242 struct dwarf_block
243   {
244     unsigned int size;
245     char *data;
246   };
247 
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
252 #endif
253 #ifndef ATTR_ALLOC_CHUNK
254 #define ATTR_ALLOC_CHUNK 4
255 #endif
256 
257 /* FIXME: do away with this */
258 
259 #ifndef DWARF2_MAX_STRING_SIZE
260 #define DWARF2_MAX_STRING_SIZE 1024
261 #endif
262 
263 static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
264 
265 /* A hash table of die offsets for following references.  */
266 #ifndef REF_HASH_SIZE
267 #define REF_HASH_SIZE 1021
268 #endif
269 
270 static struct die_info *die_ref_table[REF_HASH_SIZE];
271 
272 /* Allocate fields for structs, unions and enums in this size.  */
273 #ifndef DW_FIELD_ALLOC_CHUNK
274 #define DW_FIELD_ALLOC_CHUNK 4
275 #endif
276 
277 /* The language we are debugging.  */
278 static enum language cu_language;
279 static const struct language_defn *cu_language_defn;
280 
281 /* Actually data from the sections.  */
282 static char *dwarf_info_buffer;
283 static char *dwarf_abbrev_buffer;
284 static char *dwarf_line_buffer;
285 
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;
289 
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.
294 
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
298    in buildsym.c.  */
299 static struct pending **list_in_scope = &file_symbols;
300 static int isreg;		/* Kludge to identify register
301 				   variables */
302 static int offreg;		/* Kludge to identify basereg
303 				   references */
304 
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 */
309 
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 */
320 
321 /* FIXME - set from bfd function */
322 static int bits_per_byte = 8;
323 
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;
327 
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;
331 
332 /* Keep track of constant array bound warning.  */
333 static int array_bound_warning_given = 0;
334 
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;
340 
341 /* Externals references.  */
342 extern int info_verbose;	/* From main.c; nonzero => verbose */
343 
344 /* local function prototypes */
345 
346 static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR));
347 
348 static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *,
349 						struct section_offsets *,
350 						int));
351 static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *,
352 						struct section_offsets *,
353 						int));
354 
355 static char *scan_partial_symbols PARAMS ((char *, struct objfile *,
356 					   CORE_ADDR *, CORE_ADDR *));
357 
358 static void add_partial_symbol PARAMS ((struct partial_die_info *,
359 					struct objfile *));
360 
361 static void dwarf2_psymtab_to_symtab PARAMS ((struct partial_symtab *));
362 
363 static void psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
364 
365 static void add_die_to_symtab PARAMS ((struct die_info *, struct objfile *));
366 
367 static char *dwarf2_read_section PARAMS ((bfd *, file_ptr, unsigned int));
368 
369 static void dwarf2_read_abbrevs PARAMS ((bfd *, unsigned int));
370 
371 static void dwarf2_empty_abbrev_table PARAMS ((void));
372 
373 static struct abbrev_info *dwarf2_lookup_abbrev PARAMS ((unsigned int));
374 
375 static char *read_partial_die PARAMS ((struct partial_die_info *,
376 				       bfd *, char *, int *));
377 
378 static char *read_full_die PARAMS ((struct die_info **, bfd *, char *));
379 
380 static unsigned int read_1_byte PARAMS ((bfd *, char *));
381 
382 static unsigned int read_2_bytes PARAMS ((bfd *, char *));
383 
384 static unsigned int read_4_bytes PARAMS ((bfd *, char *));
385 
386 static unsigned int read_8_bytes PARAMS ((bfd *, char *));
387 
388 static CORE_ADDR read_address PARAMS ((bfd *, char *));
389 
390 static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
391 
392 static char *read_string PARAMS ((bfd *, char *, unsigned int *));
393 
394 static unsigned int read_unsigned_leb128 PARAMS ((bfd *, char *,
395 						  unsigned int *));
396 
397 static int read_signed_leb128 PARAMS ((bfd *, char *, unsigned int *));
398 
399 static void set_cu_language PARAMS ((unsigned int));
400 
401 static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
402 					   enum minimal_symbol_type,
403 					   struct objfile *));
404 
405 static int convert_locdesc PARAMS ((struct dwarf_block *));
406 
407 static struct attribute *dwarf_attr PARAMS ((struct die_info *,
408 					     unsigned int));
409 
410 static void dwarf_decode_lines PARAMS ((unsigned int, bfd *));
411 
412 static struct symbol *new_symbol PARAMS ((struct die_info * die, struct objfile * objfile));
413 
414 static struct type *die_type PARAMS ((struct die_info * die, struct objfile * objfile));
415 
416 static struct type *type_at_offset PARAMS ((unsigned int offset, struct objfile * objfile));
417 
418 static struct type *tag_type_to_type PARAMS ((struct die_info * die, struct objfile * objfile));
419 
420 static void read_type_die PARAMS ((struct die_info * die, struct objfile * objfile));
421 
422 static void read_typedef PARAMS ((struct die_info * die, struct objfile * objfile));
423 
424 static void read_base_type PARAMS ((struct die_info * die, struct objfile * objfile));
425 
426 static void read_file_scope PARAMS ((struct die_info * die, struct objfile * objfile));
427 
428 static void read_func_scope PARAMS ((struct die_info * die, struct objfile * objfile));
429 
430 static void read_lexical_block_scope PARAMS ((struct die_info * die,
431 					      struct objfile * objfile));
432 
433 static void read_structure_scope PARAMS ((struct die_info * die, struct objfile * objfile));
434 
435 static void read_common_block PARAMS ((struct die_info * die, struct objfile * objfile));
436 
437 static void read_enumeration PARAMS ((struct die_info * die, struct objfile * objfile));
438 
439 static struct type * dwarf_base_type PARAMS ((int encoding, int size));
440 
441 static CORE_ADDR decode_locdesc PARAMS ((struct dwarf_block *,
442 					 struct objfile *));
443 
444 static char *create_name PARAMS ((char *, struct obstack *));
445 
446 static void dwarf_read_array_type PARAMS ((struct die_info * die,
447 					   struct objfile * objfile));
448 
449 static void read_tag_pointer_type PARAMS ((struct die_info * die,
450 					   struct objfile * objfile));
451 
452 static void read_tag_const_type PARAMS ((struct die_info * die,
453 					 struct objfile * objfile));
454 
455 static void read_tag_volatile_type PARAMS ((struct die_info * die,
456 					    struct objfile * objfile));
457 
458 static void read_tag_string_type PARAMS ((struct die_info * die,
459 					  struct objfile * objfile));
460 
461 static void read_subroutine_type PARAMS ((struct die_info * die,
462 					  struct objfile * objfile));
463 
464 struct die_info *read_comp_unit PARAMS ((char *info_ptr, bfd * abfd));
465 
466 static void free_die_list PARAMS ((struct die_info * dies));
467 
468 static void process_die PARAMS ((struct die_info *, struct objfile *));
469 
470 static char *dwarf_tag_name PARAMS ((unsigned tag));
471 
472 static char *dwarf_attr_name PARAMS ((unsigned attr));
473 
474 static char *dwarf_form_name PARAMS ((unsigned form));
475 
476 static char *dwarf_stack_op_name PARAMS ((unsigned op));
477 
478 static char *dwarf_bool_name PARAMS ((unsigned bool));
479 
480 static char *dwarf_bool_name PARAMS ((unsigned tag));
481 
482 static char *dwarf_type_encoding_name PARAMS ((unsigned enc));
483 
484 static char *dwarf_cfi_name PARAMS ((unsigned cfi_opc));
485 
486 struct die_info *copy_die PARAMS ((struct die_info *old_die));
487 
488 struct die_info *sibling_die PARAMS ((struct die_info *die));
489 
490 void dump_die PARAMS ((struct die_info *die));
491 
492 void dump_die_list PARAMS ((struct die_info *dies));
493 
494 void store_in_ref_table PARAMS ((unsigned int, struct die_info *));
495 
496 struct die_info *follow_die_ref PARAMS ((unsigned int offset));
497 
498 static struct type *dwarf2_fundamental_type PARAMS ((struct objfile *, int));
499 
500 /* memory allocation interface */
501 
502 static struct type *dwarf_alloc_type PARAMS ((struct objfile *));
503 
504 static struct abbrev_info *dwarf_alloc_abbrev PARAMS ((void));
505 
506 static struct dwarf_block *dwarf_alloc_block PARAMS ((void));
507 
508 static struct die_info *dwarf_alloc_die PARAMS ((void));
509 
510 /* Try to locate the sections we need for DWARF 2 debugging
511    information and return true if we have enough to do something.  */
512 
513 int
514 dwarf2_has_info (abfd)
515      bfd *abfd;
516 {
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)
520     {
521       return 1;
522     }
523   else
524     {
525       return 0;
526     }
527 }
528 
529 /* This function is mapped across the sections and remembers the
530    offset and size of each of the debugging sections we are interested
531    in.  */
532 
533 static void
534 dwarf2_locate_sections (ignore_abfd, sectp, ignore_ptr)
535      bfd *ignore_abfd;
536      asection *sectp;
537      PTR ignore_ptr;
538 {
539   if (STREQ (sectp->name, INFO_SECTION))
540     {
541       dwarf_info_offset = sectp->filepos;
542       dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
543     }
544   else if (STREQ (sectp->name, ABBREV_SECTION))
545     {
546       dwarf_abbrev_offset = sectp->filepos;
547       dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
548     }
549   else if (STREQ (sectp->name, LINE_SECTION))
550     {
551       dwarf_line_offset = sectp->filepos;
552       dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
553     }
554   else if (STREQ (sectp->name, PUBNAMES_SECTION))
555     {
556       dwarf_pubnames_offset = sectp->filepos;
557       dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
558     }
559   else if (STREQ (sectp->name, ARANGES_SECTION))
560     {
561       dwarf_aranges_offset = sectp->filepos;
562       dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
563     }
564   else if (STREQ (sectp->name, LOC_SECTION))
565     {
566       dwarf_loc_offset = sectp->filepos;
567       dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
568     }
569   else if (STREQ (sectp->name, MACINFO_SECTION))
570     {
571       dwarf_macinfo_offset = sectp->filepos;
572       dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
573     }
574   else if (STREQ (sectp->name, STR_SECTION))
575     {
576       dwarf_str_offset = sectp->filepos;
577       dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
578     }
579 }
580 
581 /* Build a partial symbol table.  */
582 
583 void
584 dwarf2_build_psymtabs (objfile, section_offsets, mainline)
585     struct objfile *objfile;
586     struct section_offsets *section_offsets;
587     int mainline;
588 {
589   bfd *abfd = objfile->obfd;
590 
591   /* We definitely need the .debug_info, .debug_abbrev, and .debug_line
592      sections */
593 
594   dwarf_info_buffer = dwarf2_read_section (abfd,
595 					   dwarf_info_offset,
596 					   dwarf_info_size);
597   dwarf_abbrev_buffer = dwarf2_read_section (abfd,
598 					     dwarf_abbrev_offset,
599 					     dwarf_abbrev_size);
600   dwarf_line_buffer = dwarf2_read_section (abfd,
601 					   dwarf_line_offset,
602 					   dwarf_line_size);
603 
604   if (mainline || objfile->global_psymbols.size == 0 ||
605       objfile->static_psymbols.size == 0)
606     {
607       init_psymbol_list (objfile, 1024);
608     }
609 
610 #if 0
611   if (dwarf_aranges_offset && dwarf_pubnames_offset)
612     {
613       /* Things are significanlty easier if we have .debug_aranges and
614          .debug_pubnames sections */
615 
616       dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline);
617     }
618   else
619 #endif
620     /* only test this case for now */
621     {
622       /* In this case we have to work a bit harder */
623       dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline);
624     }
625 }
626 
627 /* Build the partial symbol table from the information in the
628    .debug_pubnames and .debug_aranges sections.  */
629 
630 static void
631 dwarf2_build_psymtabs_easy (objfile, section_offsets, mainline)
632      struct objfile *objfile;
633      struct section_offsets *section_offsets;
634      int mainline;
635 {
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;
640 
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)
646     {
647       entry_length = read_4_bytes (abfd, pubnames_ptr);
648       pubnames_ptr += 4;
649       version = read_1_byte (abfd, pubnames_ptr);
650       pubnames_ptr += 1;
651       info_offset = read_4_bytes (abfd, pubnames_ptr);
652       pubnames_ptr += 4;
653       info_size = read_4_bytes (abfd, pubnames_ptr);
654       pubnames_ptr += 4;
655     }
656 
657   aranges_buffer = dwarf2_read_section (abfd,
658 					dwarf_aranges_offset,
659 					dwarf_aranges_size);
660 
661 }
662 
663 /* Build the partial symbol table by doing a quick pass through the
664    .debug_info and .debug_abbrev sections.  */
665 
666 static void
667 dwarf2_build_psymtabs_hard (objfile, section_offsets, mainline)
668      struct objfile *objfile;
669      struct section_offsets *section_offsets;
670      int mainline;
671 {
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;
682   int has_pc_info;
683   CORE_ADDR lowpc, highpc;
684 
685   comp_unit_die = zeroed_partial_die;
686   info_ptr = dwarf_info_buffer;
687   abbrev_ptr = dwarf_abbrev_buffer;
688 
689   while ((info_ptr - dwarf_info_buffer)
690 	  + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
691     {
692       beg_of_comp_unit = info_ptr;
693       cu_header.length = read_4_bytes (abfd, info_ptr);
694       info_ptr += 4;
695       cu_header.version = read_2_bytes (abfd, info_ptr);
696       info_ptr += 2;
697       cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
698       info_ptr += 4;
699       cu_header.addr_size = read_1_byte (abfd, info_ptr);
700       info_ptr += 1;
701       address_size = cu_header.addr_size;
702 
703       if (cu_header.version != 2)
704 	{
705 	  error ("Dwarf Error: wrong version in compilation unit header.");
706 	  return;
707 	}
708 
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);
712 
713       /* Read the compilation unit die */
714       info_ptr = read_partial_die (&comp_unit_die, abfd,
715 				   info_ptr, &comp_unit_has_pc_info);
716 
717       /* Set the language we're debugging */
718       set_cu_language (comp_unit_die.language);
719 
720       /* Allocate a new partial symbol table structure */
721       pst = start_psymtab_common (objfile, section_offsets,
722 			          comp_unit_die.name,
723 				  comp_unit_die.lowpc,
724 				  objfile->global_psymbols.next,
725 				  objfile->static_psymbols.next);
726 
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);
730 
731       /* Store the function that reads in the rest of the symbol table */
732       pst->read_symtab = dwarf2_psymtab_to_symtab;
733 
734       /* Read the rest of the partial symbols from this comp unit */
735       info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc);
736 
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)
740 	{
741 	  comp_unit_die.lowpc  = lowpc;
742 	  comp_unit_die.highpc = highpc;
743         }
744       pst->textlow  = comp_unit_die.lowpc;
745       pst->texthigh = comp_unit_die.highpc;
746 
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);
752 
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);
757 
758       info_ptr = beg_of_comp_unit + cu_header.length + 4;
759     }
760   do_cleanups (back_to);
761 }
762 
763 /* Read in all interesting dies to the end of the compilation unit.  */
764 
765 static char *
766 scan_partial_symbols (info_ptr, objfile, lowpc, highpc)
767      char *info_ptr;
768      struct objfile *objfile;
769      CORE_ADDR *lowpc;
770      CORE_ADDR *highpc;
771 {
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
774      to do this). */
775   bfd *abfd = objfile->obfd;
776   struct partial_die_info pdi;
777   int nesting_level = 1;	/* we've already read in comp_unit_die */
778   int has_pc_info;
779 
780   pdi = zeroed_partial_die;
781   *lowpc  = ((CORE_ADDR) -1);
782   *highpc = ((CORE_ADDR) 0);
783   do
784     {
785       info_ptr = read_partial_die (&pdi, abfd, info_ptr, &has_pc_info);
786       switch (pdi.tag)
787 	{
788 	case DW_TAG_subprogram:
789 	case DW_TAG_variable:
790 	case DW_TAG_typedef:
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)
795 	    {
796 	      if (pdi.name)
797 		{
798 		  add_partial_symbol (&pdi, objfile);
799 		}
800 	    }
801 	   if (has_pc_info)
802 	     {
803 	       if (pdi.lowpc < *lowpc)
804 		 {
805 		   *lowpc = pdi.lowpc;
806 		 }
807 	       if (pdi.highpc > *lowpc)
808 		 {
809 		   *highpc = pdi.highpc;
810 		 }
811 	     }
812 	}
813       if (pdi.has_children)
814 	{
815 	  nesting_level++;
816 	}
817       if (pdi.tag == 0)
818 	{
819 	  nesting_level--;
820 	}
821     }
822   while (nesting_level);
823   return info_ptr;
824 }
825 
826 static void
827 add_partial_symbol (pdi, objfile)
828      struct partial_die_info *pdi;
829      struct objfile *objfile;
830 {
831   switch (pdi->tag)
832     {
833     case DW_TAG_subprogram:
834       if (pdi->is_external)
835 	{
836 	  record_minimal_symbol (pdi->name, pdi->lowpc,
837 				 mst_text, objfile);
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);
842 	}
843       else
844 	{
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);
849 	}
850       break;
851     case DW_TAG_variable:
852       if (pdi->is_external)
853 	{
854 	  record_minimal_symbol (pdi->name, convert_locdesc (pdi->locdesc),
855 				 mst_data, objfile);
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);
860 	}
861       else
862 	{
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);
867 	}
868       break;
869     case DW_TAG_typedef:
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);
874       break;
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)
884 	{
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);
890 	}
891       break;
892     }
893 }
894 
895 /* Expand this partial symbol table into a full symbol table.  */
896 
897 static void
898 dwarf2_psymtab_to_symtab (pst)
899      struct partial_symtab *pst;
900 {
901   /* FIXME: This is barely more than a stub.  */
902   if (pst != NULL)
903     {
904       if (pst->readin)
905 	{
906 	  warning ("bug: psymtab for %s is already read in.", pst->filename);
907 	}
908       else
909 	{
910 	  psymtab_to_symtab_1 (pst);
911 	}
912     }
913 }
914 
915 static void
916 psymtab_to_symtab_1 (pst)
917      struct partial_symtab *pst;
918 {
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;
926   CORE_ADDR highpc;
927   struct attribute *high_pc_attr;
928   struct die_info *child_die;
929   char *info_ptr;
930   struct context_stack *context;
931   struct symtab *symtab;
932   struct cleanup *abbrev_cleanup, *die_cleanup;
933 
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;
937 
938   /* read in the comp_unit header  */
939   cu_header.length = read_4_bytes (abfd, info_ptr);
940   info_ptr += 4;
941   cu_header.version = read_2_bytes (abfd, info_ptr);
942   info_ptr += 2;
943   cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
944   info_ptr += 4;
945   cu_header.addr_size = read_1_byte (abfd, info_ptr);
946   info_ptr += 1;
947 
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);
951 
952   dies = read_comp_unit (info_ptr, abfd);
953 
954   die_cleanup = make_cleanup (free_die_list, dies);
955 
956   /* Do line number decoding in read_file_scope () */
957   process_die (dies, objfile);
958 
959   attr = dwarf_attr (dies, DW_AT_high_pc);
960   if (attr)
961     {
962       highpc = DW_ADDR (attr);
963     }
964   else
965     {
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.  */
969       highpc = 0;
970       if (dies->has_children)
971 	{
972 	  child_die = dies->next;
973 	  while (child_die && child_die->tag)
974 	    {
975 	      if (child_die->tag == DW_TAG_subprogram)
976 		{
977 		  high_pc_attr = dwarf_attr (child_die, DW_AT_high_pc);
978 		  if (high_pc_attr)
979 		    {
980 		      highpc = max (highpc, DW_ADDR (high_pc_attr));
981 		    }
982 		}
983 	      child_die = sibling_die (child_die);
984 	    }
985 	}
986     }
987 
988   symtab = end_symtab (highpc, objfile, 0);
989   if (symtab != NULL)
990     {
991       symtab->language = cu_language;
992     }
993   pst->symtab = symtab;
994   pst->readin = 1;
995   if (info_verbose)
996     {
997       printf_filtered ("Sorting symbol table...");
998       wrap_here ("");
999       fflush (stdout);
1000     }
1001   sort_symtab_syms (pst->symtab);
1002   do_cleanups (abbrev_cleanup);
1003 }
1004 
1005 /* Process a die and its children.  */
1006 
1007 static void
1008 process_die (die, objfile)
1009      struct die_info *die;
1010      struct objfile *objfile;
1011 {
1012   switch (die->tag)
1013     {
1014     case DW_TAG_padding:
1015       break;
1016     case DW_TAG_compile_unit:
1017       read_file_scope (die, objfile);
1018       break;
1019     case DW_TAG_subprogram:
1020       if (dwarf_attr (die, DW_AT_low_pc))
1021 	{
1022 	  read_func_scope (die, objfile);
1023 	}
1024       break;
1025     case DW_TAG_lexical_block:
1026       read_lexical_block_scope (die, objfile);
1027       break;
1028     case DW_TAG_class_type:
1029     case DW_TAG_structure_type:
1030     case DW_TAG_union_type:
1031       read_structure_scope (die, objfile);
1032       break;
1033     case DW_TAG_enumeration_type:
1034       read_enumeration (die, objfile);
1035       break;
1036     case DW_TAG_subroutine_type:
1037       read_subroutine_type (die, objfile);
1038       break;
1039     case DW_TAG_array_type:
1040       dwarf_read_array_type (die, objfile);
1041       break;
1042     case DW_TAG_pointer_type:
1043       read_tag_pointer_type (die, objfile);
1044       break;
1045     case DW_TAG_string_type:
1046       read_tag_string_type (die, objfile);
1047       break;
1048     case DW_TAG_base_type:
1049       read_base_type (die, objfile);
1050       break;
1051     case DW_TAG_common_block:
1052       read_common_block (die, objfile);
1053       break;
1054     case DW_TAG_common_inclusion:
1055       break;
1056     default:
1057       new_symbol (die, objfile);
1058       break;
1059     }
1060 }
1061 
1062 static void
1063 read_file_scope (die, objfile)
1064      struct die_info *die;
1065      struct objfile *objfile;
1066 {
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;
1071   char *name = NULL;
1072   char *comp_dir = NULL;
1073   struct die_info *child_die;
1074   bfd *abfd = objfile->obfd;
1075 
1076   low_pc_attr = dwarf_attr (die, DW_AT_low_pc);
1077   if (low_pc_attr)
1078     {
1079       lowpc = DW_ADDR (low_pc_attr);
1080     }
1081   high_pc_attr = dwarf_attr (die, DW_AT_high_pc);
1082   if (high_pc_attr)
1083     {
1084       highpc = DW_ADDR (high_pc_attr);
1085     }
1086   if (!low_pc_attr || !high_pc_attr)
1087     {
1088       if (die->has_children)
1089 	{
1090 	  child_die = die->next;
1091 	  while (child_die && child_die->tag)
1092 	    {
1093 	      if (child_die->tag == DW_TAG_subprogram)
1094 		{
1095 		  low_pc_attr = dwarf_attr (child_die, DW_AT_low_pc);
1096 		  if (low_pc_attr)
1097 		    {
1098 		      lowpc = min (lowpc, DW_ADDR (low_pc_attr));
1099 		    }
1100 		  high_pc_attr = dwarf_attr (child_die, DW_AT_high_pc);
1101 		  if (high_pc_attr)
1102 		    {
1103 		      highpc = max (highpc, DW_ADDR (high_pc_attr));
1104 		    }
1105 		}
1106 	      child_die = sibling_die (child_die);
1107 	    }
1108 	}
1109     }
1110 
1111   attr = dwarf_attr (die, DW_AT_name);
1112   if (attr)
1113     {
1114       name = DW_STRING (attr);
1115     }
1116   attr = dwarf_attr (die, DW_AT_comp_dir);
1117   if (attr)
1118     {
1119       comp_dir = DW_STRING (attr);
1120     }
1121 
1122   if (objfile->ei.entry_point >= lowpc &&
1123       objfile->ei.entry_point < highpc)
1124     {
1125       objfile->ei.entry_file_lowpc = lowpc;
1126       objfile->ei.entry_file_highpc = highpc;
1127     }
1128 
1129   attr = dwarf_attr (die, DW_AT_language);
1130   if (attr)
1131     {
1132       set_cu_language (DW_UNSND (attr));
1133     }
1134 
1135 #if 0
1136     /* FIXME:Do something here.  */
1137     if (dip->at_producer != NULL)
1138     {
1139       handle_producer (dip->at_producer);
1140     }
1141 #endif
1142 
1143   start_symtab (name, comp_dir, lowpc);
1144 
1145   /* Decode line number information.  */
1146   attr = dwarf_attr (die, DW_AT_stmt_list);
1147   if (!attr)
1148     {
1149       error (
1150         "Dwarf Error: No line number information for compilation unit: %s.",
1151         name);
1152     }
1153   line_offset = DW_UNSND (attr);
1154   dwarf_decode_lines (line_offset, abfd);
1155 
1156   /* Process all dies in compilation unit.  */
1157   if (die->has_children)
1158     {
1159       child_die = die->next;
1160       while (child_die && child_die->tag)
1161 	{
1162 	  process_die (child_die, objfile);
1163 	  child_die = sibling_die (child_die);
1164 	}
1165     }
1166 }
1167 
1168 static void
1169 read_func_scope (die, objfile)
1170      struct die_info *die;
1171      struct objfile *objfile;
1172 {
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;
1179   char *name = NULL;
1180 
1181   attr = dwarf_attr (die, DW_AT_name);
1182   if (attr)
1183     {
1184       name = DW_STRING (attr);
1185     }
1186 
1187   attr = dwarf_attr (die, DW_AT_low_pc);
1188   if (attr)
1189     {
1190       lowpc = DW_ADDR (attr);
1191     }
1192 
1193   attr = dwarf_attr (die, DW_AT_high_pc);
1194   if (attr)
1195     {
1196       highpc = DW_ADDR (attr);
1197     }
1198 
1199   if (objfile->ei.entry_point >= lowpc &&
1200       objfile->ei.entry_point < highpc)
1201     {
1202       objfile->ei.entry_func_lowpc = lowpc;
1203       objfile->ei.entry_func_highpc = highpc;
1204     }
1205 
1206   if (STREQ (name, "main"))	/* FIXME: hardwired name */
1207     {
1208       objfile->ei.main_func_lowpc = lowpc;
1209       objfile->ei.main_func_highpc = highpc;
1210     }
1211   new = push_context (0, lowpc);
1212   new->name = new_symbol (die, objfile);
1213   list_in_scope = &local_symbols;
1214 
1215   if (die->has_children)
1216     {
1217       child_die = die->next;
1218       while (child_die && child_die->tag)
1219 	{
1220 	  process_die (child_die, objfile);
1221 	  child_die = sibling_die (child_die);
1222 	}
1223     }
1224 
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;
1230 }
1231 
1232 /* Process all the DIES contained within a lexical block scope.  Start
1233    a new scope, process the dies, and then close the scope.  */
1234 
1235 static void
1236 read_lexical_block_scope (die, objfile)
1237      struct die_info *die;
1238      struct objfile *objfile;
1239 {
1240   register struct context_stack *new;
1241   CORE_ADDR lowpc = 0, highpc = 0;
1242   struct attribute *attr;
1243   struct die_info *child_die;
1244 
1245   attr = dwarf_attr (die, DW_AT_low_pc);
1246   if (attr)
1247     {
1248       lowpc = DW_ADDR (attr);
1249     }
1250   attr = dwarf_attr (die, DW_AT_high_pc);
1251   if (attr)
1252     {
1253       highpc = DW_ADDR (attr);
1254     }
1255 
1256   push_context (0, lowpc);
1257   if (die->has_children)
1258     {
1259       child_die = die->next;
1260       while (child_die && child_die->tag)
1261 	{
1262 	  process_die (child_die, objfile);
1263 	  child_die = sibling_die (child_die);
1264 	}
1265     }
1266   new = pop_context ();
1267 
1268   if (local_symbols != NULL)
1269     {
1270       finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
1271 		    highpc, objfile);
1272     }
1273   local_symbols = new->locals;
1274 }
1275 
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
1278    structure or union.
1279 
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
1283    user defined types.
1284 
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).  */
1291 
1292 static void
1293 read_structure_scope (die, objfile)
1294      struct die_info *die;
1295      struct objfile *objfile;
1296 {
1297   struct type *type, *member_type;
1298   struct field *fields;
1299   struct die_info *child_die;
1300   struct attribute *attr;
1301   struct symbol *sym;
1302   int num_fields;
1303 
1304   type = dwarf_alloc_type (objfile);
1305 
1306   INIT_CPLUS_SPECIFIC (type);
1307   attr = dwarf_attr (die, DW_AT_name);
1308 
1309   if (die->tag == DW_TAG_structure_type)
1310     {
1311       TYPE_CODE (type) = TYPE_CODE_STRUCT;
1312       if (attr)
1313 	{
1314 	  TYPE_NAME (type) = obconcat (&objfile->type_obstack,
1315 				     "struct", " ", DW_STRING (attr));
1316 	}
1317     }
1318   else
1319     {
1320       /* die->tag == DW_TAG_union_type */
1321       TYPE_CODE (type) = TYPE_CODE_UNION;
1322       if (attr)
1323 	{
1324 	  TYPE_NAME (type) = obconcat (&objfile->type_obstack,
1325 				       "union", " ", DW_STRING (attr));
1326 	}
1327     }
1328 
1329   attr = dwarf_attr (die, DW_AT_byte_size);
1330   if (attr)
1331     {
1332       TYPE_LENGTH (type) = DW_UNSND (attr);
1333     }
1334   else
1335     {
1336       TYPE_LENGTH (type) = 0;
1337     }
1338 
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. */
1342   die->type = type;
1343 
1344   num_fields = 0;
1345   fields = NULL;
1346   if (die->has_children)
1347     {
1348       child_die = die->next;
1349       while (child_die && child_die->tag)
1350 	{
1351 	  if (child_die->tag != DW_TAG_member)
1352 	    {
1353 	      process_die (child_die, objfile);
1354 	    }
1355 	  else
1356 	    {
1357 	      if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1358 		{
1359 		  fields = (struct field *)
1360 		    xrealloc (fields,
1361 			      (num_fields + DW_FIELD_ALLOC_CHUNK)
1362 			       * sizeof (struct field));
1363 		}
1364 
1365 	      /* Get bit offset of field */
1366 	      attr = dwarf_attr (child_die, DW_AT_bit_offset);
1367 	      if (attr)
1368 		{
1369 		  fields[num_fields].bitpos = DW_UNSND (attr);
1370 		}
1371 	      else
1372 		{
1373 		  fields[num_fields].bitpos = 0;
1374 		}
1375 	      attr = dwarf_attr (child_die, DW_AT_data_member_location);
1376 	      if (attr)
1377 		{
1378 		  fields[num_fields].bitpos +=
1379 		    decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1380 		}
1381 
1382 	      /* Get bit size of field (zero if none). */
1383 	      attr = dwarf_attr (child_die, DW_AT_bit_size);
1384 	      if (attr)
1385 		{
1386 		  fields[num_fields].bitsize = DW_UNSND (attr);
1387 		}
1388 	      else
1389 		{
1390 		  fields[num_fields].bitsize = 0;
1391 		}
1392 
1393 	      /* Get type of member. */
1394 	      member_type = die_type (child_die, objfile);
1395 	      fields[num_fields].type = member_type;
1396 
1397 	      /* Get name of member. */
1398 	      attr = dwarf_attr (child_die, DW_AT_name);
1399 	      if (attr)
1400 		{
1401 		  fields[num_fields].name = obsavestring (DW_STRING (attr),
1402 					    strlen (DW_STRING (attr)),
1403 					      &objfile->type_obstack);
1404 #if 0
1405 		  fields[num_fields].name = strdup (DW_STRING (attr));
1406 #endif
1407 		}
1408 	      num_fields++;
1409 	    }
1410 	  child_die = sibling_die (child_die);
1411 	}
1412       type->nfields = num_fields;
1413       type->fields = fields;
1414     }
1415   else
1416     {
1417       /* No children, must be stub. */
1418       TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1419     }
1420 
1421   die->type = type;
1422   sym = new_symbol (die, objfile);
1423   if (sym != NULL)
1424     {
1425       SYMBOL_TYPE (sym) = type;
1426     }
1427 }
1428 
1429 /* Given a pointer to a die which begins an enumeration, process all
1430    the dies that define the members of the enumeration.
1431 
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
1434    attribute.
1435 
1436    NOTE: We reverse the order of the element list.  */
1437 
1438 static void
1439 read_enumeration (die, objfile)
1440      struct die_info *die;
1441      struct objfile *objfile;
1442 {
1443   struct die_info *child_die;
1444   struct type *type;
1445   struct field *fields;
1446   struct attribute *attr;
1447   struct symbol *sym;
1448   struct dwarf_block *blk;
1449   int num_fields;
1450   unsigned int size, bytes_read, i;
1451 
1452   type = dwarf_alloc_type (objfile);
1453 
1454   TYPE_CODE (type) = TYPE_CODE_ENUM;
1455   attr = dwarf_attr (die, DW_AT_name);
1456   if (attr)
1457     {
1458       TYPE_NAME (type) = obconcat (&objfile->type_obstack,
1459 				   "enum ", " ", DW_STRING (attr));
1460     }
1461 
1462   attr = dwarf_attr (die, DW_AT_byte_size);
1463   if (attr)
1464     {
1465       TYPE_LENGTH (type) = DW_UNSND (attr);
1466     }
1467   else
1468     {
1469       TYPE_LENGTH (type) = 0;
1470     }
1471 
1472   num_fields = 0;
1473   fields = NULL;
1474   if (die->has_children)
1475     {
1476       child_die = die->next;
1477       while (child_die && child_die->tag)
1478 	{
1479 	  if (child_die->tag != DW_TAG_enumerator)
1480 	    {
1481 	      process_die (child_die, objfile);
1482 	    }
1483 	  else
1484 	    {
1485 	      if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
1486 		{
1487 		  fields = (struct field *)
1488 		    xrealloc (fields,
1489 		      (num_fields + DW_FIELD_ALLOC_CHUNK)
1490 			* sizeof (struct field));
1491 		}
1492 
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));
1497 
1498 	      fields[num_fields].type = NULL;
1499 	      fields[num_fields].bitsize = 0;
1500 	      attr = dwarf_attr (child_die, DW_AT_name);
1501 	      if (attr)
1502 		{
1503 		  fields[num_fields].name = strdup (DW_STRING (attr));
1504 		  SYMBOL_NAME (sym) = strdup (fields[num_fields].name);
1505 		}
1506 	      attr = dwarf_attr (child_die, DW_AT_const_value);
1507 	      if (attr)
1508 		{
1509 		  fields[num_fields].bitpos = DW_UNSND (attr);
1510 		  SYMBOL_VALUE (sym) = DW_UNSND (attr);
1511 		}
1512 
1513 #if 0
1514 	      SYMBOL_NAME (sym) = create_name (elist->str,
1515 					    &objfile->symbol_obstack);
1516 #endif
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);
1522 
1523 	      num_fields++;
1524 	    }
1525 
1526 	  child_die = sibling_die (child_die);
1527 	}
1528       type->fields = fields;
1529       type->nfields = num_fields;
1530     }
1531   die->type = type;
1532   sym = new_symbol (die, objfile);
1533   if (sym != NULL)
1534     {
1535       SYMBOL_TYPE (sym) = type;
1536     }
1537 }
1538 
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
1541    arrays.  */
1542 
1543 static void
1544 dwarf_read_array_type (die, objfile)
1545      struct die_info *die;
1546      struct objfile *objfile;
1547 {
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;
1555 
1556   /* Return if we've already decoded this type. */
1557   if (die->type)
1558     {
1559       return;
1560     }
1561 
1562   element_type = die_type (die, objfile);
1563 
1564   low = 0;
1565   high = 1;
1566   if (cu_language == DW_LANG_Fortran77 || cu_language == DW_LANG_Fortran90)
1567     {
1568       /* FORTRAN implies a lower bound of 1, if not given.  */
1569       low = 1;
1570     }
1571 
1572   child_die = die->next;
1573   while (child_die && child_die->tag)
1574     {
1575       if (child_die->tag == DW_TAG_subrange_type)
1576 	{
1577 	  index_type = die_type (child_die, objfile);
1578 	  attr = dwarf_attr (child_die, DW_AT_lower_bound);
1579 	  if (attr)
1580 	    {
1581 	      if (attr->form == DW_FORM_sdata)
1582 		{
1583 		  low = DW_SND (attr);
1584 		}
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)
1589 		{
1590 		  low = DW_UNSND (attr);
1591 		}
1592 	      else
1593 		{
1594 		  if (!array_bound_warning_given)
1595 		    {
1596 		      warning ("Non-constant array bounds ignored.");
1597 		      array_bound_warning_given = 1;
1598 		    }
1599 #ifdef FORTRAN_HACK
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;
1607 		  goto done;
1608 #else
1609 		  low = 0;
1610 #endif
1611 		}
1612 	    }
1613 	  attr = dwarf_attr (child_die, DW_AT_upper_bound);
1614 	  if (attr)
1615 	    {
1616 	      if (attr->form == DW_FORM_sdata)
1617 		{
1618 		  high = DW_SND (attr);
1619 		}
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)
1624 		{
1625 		  high = DW_UNSND (attr);
1626 		}
1627 	      else
1628 		{
1629 		  if (!array_bound_warning_given)
1630 		    {
1631 		      warning ("Non-constant array bounds ignored.");
1632 		      array_bound_warning_given = 1;
1633 		    }
1634 #ifdef FORTRAN_HACK
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;
1642 		  goto done;
1643 #else
1644 		  high = 1;
1645 #endif
1646 		}
1647 	    }
1648 	}
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);
1653     }
1654 done:
1655   /* Install the type in the die. */
1656   die->type = type;
1657 }
1658 
1659 /* First cut: install each common block member as a global variable.  */
1660 
1661 static void
1662 read_common_block (die, objfile)
1663      struct die_info *die;
1664      struct objfile *objfile;
1665 {
1666   struct die_info *child_die;
1667   struct attribute *attr;
1668   struct symbol *sym;
1669   CORE_ADDR base;
1670 
1671   attr = dwarf_attr (die, DW_AT_location);
1672   if (attr)
1673     {
1674       base = decode_locdesc (DW_BLOCK (attr), objfile);
1675     }
1676   if (die->has_children)
1677     {
1678       child_die = die->next;
1679       while (child_die && child_die->tag)
1680 	{
1681 	  sym = new_symbol (child_die, objfile);
1682 	  attr = dwarf_attr (child_die, DW_AT_data_member_location);
1683 	  if (attr)
1684 	    {
1685 	      SYMBOL_VALUE_ADDRESS (sym) =
1686 		base + decode_locdesc (DW_BLOCK (attr), objfile);
1687 	      add_symbol_to_list (sym, &global_symbols);
1688 	    }
1689 	  child_die = sibling_die (child_die);
1690 	}
1691     }
1692 }
1693 
1694 /* Extract all information from a DW_TAG_pointer_type DIE and add to
1695    the user defined type vector.  */
1696 
1697 static void
1698 read_tag_pointer_type (die, objfile)
1699      struct die_info *die;
1700      struct objfile *objfile;
1701 {
1702   struct type *type, *pointed_to_type;
1703   struct attribute *attr;
1704 
1705   if (die->type)
1706     {
1707       return;
1708     }
1709 
1710   pointed_to_type = die_type (die, objfile);
1711 
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);
1716   if (attr)
1717     {
1718       TYPE_LENGTH (type) = DW_UNSND (attr);
1719     }
1720   else
1721     {
1722       TYPE_LENGTH (type) = address_size;
1723     }
1724   TYPE_CODE (type) = TYPE_CODE_PTR;
1725   TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1726 
1727   TYPE_POINTER_TYPE (pointed_to_type) = type;
1728   die->type = type;
1729 }
1730 
1731 /* Extract all information from a DW_TAG_reference_type DIE and add to
1732    the user defined type vector.  */
1733 
1734 static void
1735 read_tag_reference_type (die, objfile)
1736      struct die_info *die;
1737      struct objfile *objfile;
1738 {
1739   struct type *type, *pointed_to_type;
1740   struct attribute *attr;
1741 
1742   if (die->type)
1743     {
1744       return;
1745     }
1746 
1747   pointed_to_type = die_type (die, objfile);
1748 
1749   type = dwarf_alloc_type (objfile);
1750   TYPE_TARGET_TYPE (type) = pointed_to_type;
1751   TYPE_OBJFILE (type) = objfile;
1752   attr = dwarf_attr (die, DW_AT_byte_size);
1753   if (attr)
1754     {
1755       TYPE_LENGTH (type) = DW_UNSND (attr);
1756     }
1757   else
1758     {
1759       TYPE_LENGTH (type) = address_size;
1760     }
1761   TYPE_CODE (type) = TYPE_CODE_REF;
1762   TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
1763 
1764   TYPE_REFERENCE_TYPE (pointed_to_type) = type;
1765   die->type = type;
1766 }
1767 
1768 static void
1769 read_tag_const_type (die, objfile)
1770      struct die_info *die;
1771      struct objfile *objfile;
1772 {
1773   if (die->type)
1774     {
1775       return;
1776     }
1777 
1778   if (!tag_const_warning_given)
1779     {
1780       warning ("gdb ignores `const' qualifiers.");
1781       tag_const_warning_given = 1;
1782     }
1783 
1784   die->type = die_type (die, objfile);
1785 }
1786 
1787 static void
1788 read_tag_volatile_type (die, objfile)
1789      struct die_info *die;
1790      struct objfile *objfile;
1791 {
1792   if (die->type)
1793     {
1794       return;
1795     }
1796 
1797   if (!tag_volatile_warning_given)
1798     {
1799       warning ("gdb ignores `volatile' qualifiers.");
1800       tag_volatile_warning_given = 1;
1801     }
1802 
1803   die->type = die_type (die, objfile);
1804 }
1805 
1806 /* Extract all information from a DW_TAG_string_type DIE and add to
1807    the user defined type vector.  It isn't really a user defined type,
1808    but it behaves like one, with other DIE's using an AT_user_def_type
1809    attribute to reference it.  */
1810 
1811 static void
1812 read_tag_string_type (die, objfile)
1813      struct die_info *die;
1814      struct objfile *objfile;
1815 {
1816   struct type *type, *range_type, *index_type, *char_type;
1817   struct attribute *attr;
1818   unsigned int length;
1819 
1820   if (die->type)
1821     {
1822       return;
1823     }
1824 
1825   attr = dwarf_attr (die, DW_AT_string_length);
1826   if (attr)
1827     {
1828       length = DW_UNSND (attr);
1829     }
1830   else
1831     {
1832       length = 1;
1833     }
1834   index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
1835   range_type = create_range_type (NULL, index_type, 1, length);
1836   char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
1837   type = create_string_type (char_type, range_type);
1838   die->type = type;
1839 }
1840 
1841 /* Handle DIES due to C code like:
1842 
1843    struct foo
1844      {
1845        int (*funcp)(int a, long l);
1846        int b;
1847      };
1848 
1849    ('funcp' generates a DW_TAG_subroutine_type DIE)
1850 
1851    NOTE: parameter DIES are currently ignored.  See if gdb has a way to
1852    include this info in it's type system, and decode them if so.  Is
1853    this what the type structure's "arg_types" field is for?  (FIXME) */
1854 
1855 static void
1856 read_subroutine_type (die, objfile)
1857      struct die_info *die;
1858      struct objfile *objfile;
1859 {
1860   struct type *type;		/* Type that this function returns */
1861   struct type *ftype;		/* Function that returns above type */
1862 
1863   /* Decode the type that this subroutine returns */
1864   if (die->type)
1865     {
1866       return;
1867     }
1868   type = die_type (die, objfile);
1869   ftype = lookup_function_type (type);
1870 
1871   TYPE_TARGET_TYPE (ftype) = type;
1872   TYPE_LENGTH (ftype) = 1;
1873   TYPE_CODE (ftype) = TYPE_CODE_FUNC;
1874   TYPE_OBJFILE (ftype) = objfile;
1875 
1876   die->type = type;
1877 }
1878 
1879 static void
1880 read_typedef (die, objfile)
1881      struct die_info *die;
1882      struct objfile *objfile;
1883 {
1884   struct type *type;
1885 
1886   if (!die->type)
1887     {
1888       type = die_type (die, objfile);
1889       die->type = type;
1890     }
1891 }
1892 
1893 /* Find a representation of a given base type and install
1894    it in the TYPE field of the die.  */
1895 
1896 static void
1897 read_base_type (die, objfile)
1898      struct die_info *die;
1899      struct objfile *objfile;
1900 {
1901   struct type *type;
1902   struct attribute *attr;
1903   int encoding = 0, size = 0;
1904 
1905   /* If we've already decoded this die, this is a no-op. */
1906   if (die->type)
1907     {
1908       return;
1909     }
1910 
1911   attr = dwarf_attr (die, DW_AT_encoding);
1912   if (attr)
1913     {
1914       encoding = DW_UNSND (attr);
1915     }
1916   attr = dwarf_attr (die, DW_AT_byte_size);
1917   if (attr)
1918     {
1919       size = DW_UNSND (attr);
1920     }
1921   type = dwarf_base_type (encoding, size);
1922   die->type = type;
1923 }
1924 
1925 /* Read a whole compilation unit into a linked list of dies.  */
1926 
1927 struct die_info *
1928 read_comp_unit (info_ptr, abfd)
1929     char *info_ptr;
1930     bfd *abfd;
1931 {
1932   struct die_info *first_die, *last_die, *die;
1933   char *cur_ptr;
1934   int nesting_level;
1935 
1936   cur_ptr = info_ptr;
1937   nesting_level = 0;
1938   first_die = last_die = NULL;
1939   do
1940     {
1941       cur_ptr = read_full_die (&die, abfd, cur_ptr);
1942       if (die->has_children)
1943 	{
1944 	  nesting_level++;
1945 	}
1946       if (die->tag == 0)
1947 	{
1948 	  nesting_level--;
1949 	}
1950 
1951       die->next = NULL;
1952 
1953       /* Enter die in reference hash table */
1954       store_in_ref_table (die->offset, die);
1955 
1956       if (!first_die)
1957 	{
1958 	  first_die = last_die = die;
1959 	}
1960       else
1961 	{
1962 	  last_die->next = die;
1963 	  last_die = die;
1964 	}
1965     }
1966   while (nesting_level > 0);
1967   return first_die;
1968 }
1969 
1970 /* Free a linked list of dies.  */
1971 
1972 static void
1973 free_die_list (dies)
1974      struct die_info *dies;
1975 {
1976   struct die_info *die, *next;
1977 
1978   die = dies;
1979   while (die)
1980     {
1981       next = die->next;
1982       free (die->attrs);
1983       free (die);
1984       die = next;
1985     }
1986 }
1987 
1988 /* Read the contents of the section at OFFSET and of size SIZE in the
1989    object file specified by ABFD into a buffer of bytes and return it.  */
1990 
1991 static char *
1992 dwarf2_read_section (abfd, offset, size)
1993      bfd * abfd;
1994      file_ptr offset;
1995      unsigned int size;
1996 {
1997   char *buf;
1998 
1999   buf = xmalloc (size);
2000   if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
2001       (bfd_read (buf, size, 1, abfd) != size))
2002     {
2003       free (buf);
2004       buf = NULL;
2005       error ("Dwarf Error: Can't read DWARF data from '%s'",
2006         bfd_get_filename (abfd));
2007     }
2008   return buf;
2009 }
2010 
2011 /* In DWARF version 2, the description of the debugging information is
2012    stored in a separate .debug_abbrev section.  Before we read any
2013    dies from a section we read in all abbreviations and install them
2014    in a hash table.  */
2015 
2016 static void
2017 dwarf2_read_abbrevs (abfd, offset)
2018      bfd * abfd;
2019      unsigned int offset;
2020 {
2021   char *abbrev_ptr;
2022   struct abbrev_info *cur_abbrev;
2023   unsigned int abbrev_number, bytes_read, abbrev_name;
2024   unsigned int abbrev_form, hash_number;
2025 
2026   /* empty the table */
2027   dwarf2_empty_abbrev_table ();
2028 
2029   abbrev_ptr = dwarf_abbrev_buffer + offset;
2030   abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2031   abbrev_ptr += bytes_read;
2032 
2033   /* loop until we reach an abbrev number of 0 */
2034   while (abbrev_number)
2035     {
2036       cur_abbrev = dwarf_alloc_abbrev ();
2037 
2038       /* read in abbrev header */
2039       cur_abbrev->number = abbrev_number;
2040       cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2041       abbrev_ptr += bytes_read;
2042       cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
2043       abbrev_ptr += 1;
2044 
2045       /* now read in declarations */
2046       abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2047       abbrev_ptr += bytes_read;
2048       abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2049       abbrev_ptr += bytes_read;
2050       while (abbrev_name)
2051 	{
2052 	  if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
2053 	    {
2054 	      cur_abbrev->attrs = xrealloc (cur_abbrev->attrs,
2055 			    (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
2056 				       * sizeof (struct attr_abbrev));
2057 	    }
2058 	  cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
2059 	  cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
2060 	  abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2061 	  abbrev_ptr += bytes_read;
2062 	  abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2063 	  abbrev_ptr += bytes_read;
2064 	}
2065 
2066       hash_number = abbrev_number % ABBREV_HASH_SIZE;
2067       cur_abbrev->next = dwarf2_abbrevs[hash_number];
2068       dwarf2_abbrevs[hash_number] = cur_abbrev;
2069 
2070       /* get next abbrev */
2071       abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
2072       abbrev_ptr += bytes_read;
2073     }
2074 }
2075 
2076 /* Empty the abbrev table for a new compilation unit.  */
2077 
2078 static void
2079 dwarf2_empty_abbrev_table ()
2080 {
2081   int i;
2082   struct abbrev_info *abbrev, *next;
2083 
2084   for (i = 0; i < ABBREV_HASH_SIZE; ++i)
2085     {
2086       next = NULL;
2087       abbrev = dwarf2_abbrevs[i];
2088       while (abbrev)
2089 	{
2090 	  next = abbrev->next;
2091 	  free (abbrev->attrs);
2092 	  free (abbrev);
2093 	  abbrev = next;
2094 	}
2095       dwarf2_abbrevs[i] = NULL;
2096     }
2097 }
2098 
2099 /* Lookup an abbrev_info structure in the abbrev hash table.  */
2100 
2101 static struct abbrev_info *
2102 dwarf2_lookup_abbrev (number)
2103      unsigned int number;
2104 {
2105   unsigned int hash_number;
2106   struct abbrev_info *abbrev;
2107 
2108   hash_number = number % ABBREV_HASH_SIZE;
2109   abbrev = dwarf2_abbrevs[hash_number];
2110 
2111   while (abbrev)
2112     {
2113       if (abbrev->number == number)
2114 	return abbrev;
2115       else
2116 	abbrev = abbrev->next;
2117     }
2118   return NULL;
2119 }
2120 
2121 /* Read a minimal amount of information into the minimal die structure.  */
2122 
2123 static char *
2124 read_partial_die (part_die, abfd, info_ptr, has_pc_info)
2125      struct partial_die_info *part_die;
2126      bfd * abfd;
2127      char *info_ptr;
2128      int *has_pc_info;
2129 {
2130   unsigned int abbrev_number, bytes_read, i;
2131   struct abbrev_info *abbrev;
2132   char ebuf[256];
2133   int has_low_pc_attr  = 0;
2134   int has_high_pc_attr = 0;
2135 
2136   *has_pc_info = 0;
2137   abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2138   info_ptr += bytes_read;
2139   if (!abbrev_number)
2140     {
2141       part_die->tag = 0;
2142       part_die->has_children = 0;
2143       part_die->abbrev = abbrev_number;
2144       return info_ptr;
2145     }
2146 
2147   abbrev = dwarf2_lookup_abbrev (abbrev_number);
2148   if (!abbrev)
2149     {
2150       error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number);
2151     }
2152   part_die->offset = info_ptr - dwarf_info_buffer;
2153   part_die->tag = abbrev->tag;
2154   part_die->has_children = abbrev->has_children;
2155   part_die->is_external = 0;
2156   part_die->abbrev = abbrev_number;
2157 
2158   {
2159     char *str = "";
2160     struct dwarf_block *blk = 0;
2161     CORE_ADDR addr = ((CORE_ADDR) -1);
2162     unsigned int unsnd = ((unsigned int) -1);
2163     int snd = -1;
2164 
2165     for (i = 0; i < abbrev->num_attrs; ++i)
2166       {
2167 	/* read the correct type of data */
2168 	switch (abbrev->attrs[i].form)
2169 	  {
2170 	  case DW_FORM_addr:
2171 	    addr = read_address (abfd, info_ptr);
2172 	    info_ptr += address_size;
2173 	    break;
2174 	  case DW_FORM_ref_addr:
2175 	    addr = read_address (abfd, info_ptr);
2176 	    info_ptr += address_size;
2177 	    break;
2178 	  case DW_FORM_block2:
2179 	    blk = dwarf_alloc_block ();
2180 	    blk->size = read_2_bytes (abfd, info_ptr);
2181 	    info_ptr += 2;
2182 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2183 	    info_ptr += blk->size;
2184 	    break;
2185 	  case DW_FORM_block4:
2186 	    blk = dwarf_alloc_block ();
2187 	    blk->size = read_4_bytes (abfd, info_ptr);
2188 	    info_ptr += 2;
2189 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2190 	    info_ptr += blk->size;
2191 	    break;
2192 	  case DW_FORM_data2:
2193 	    unsnd = read_2_bytes (abfd, info_ptr);
2194 	    info_ptr += 2;
2195 	    break;
2196 	  case DW_FORM_data4:
2197 	    unsnd = read_4_bytes (abfd, info_ptr);
2198 	    info_ptr += 4;
2199 	    break;
2200 	  case DW_FORM_data8:
2201 	    unsnd = read_8_bytes (abfd, info_ptr);
2202 	    info_ptr += 8;
2203 	    break;
2204 	  case DW_FORM_string:
2205 	    str = read_string (abfd, info_ptr, &bytes_read);
2206 	    info_ptr += bytes_read;
2207 	    break;
2208 	  case DW_FORM_block:
2209 	    blk = dwarf_alloc_block ();
2210 	    blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2211 	    info_ptr += bytes_read;
2212 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2213 	    info_ptr += blk->size;
2214 	    break;
2215 	  case DW_FORM_block1:
2216 	    blk = dwarf_alloc_block ();
2217 	    blk->size = read_1_byte (abfd, info_ptr);
2218 	    info_ptr += 1;
2219 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2220 	    info_ptr += blk->size;
2221 	    break;
2222 	  case DW_FORM_data1:
2223 	    unsnd = read_1_byte (abfd, info_ptr);
2224 	    info_ptr += 1;
2225 	    break;
2226 	  case DW_FORM_ref1:
2227 	    unsnd = read_1_byte (abfd, info_ptr);
2228 	    info_ptr += 1;
2229 	    break;
2230 	  case DW_FORM_ref2:
2231 	    unsnd = read_2_bytes (abfd, info_ptr);
2232 	    info_ptr += 2;
2233 	    break;
2234 	  case DW_FORM_ref4:
2235 	    unsnd = read_4_bytes (abfd, info_ptr);
2236 	    info_ptr += 4;
2237 	    break;
2238 	  case DW_FORM_ref_udata:
2239 	    unsnd = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2240 	    info_ptr += bytes_read;
2241 	    break;
2242 	  case DW_FORM_flag:
2243 	    unsnd = read_1_byte (abfd, info_ptr);
2244 	    info_ptr += 1;
2245 	    break;
2246 	  case DW_FORM_sdata:
2247 	    snd = read_signed_leb128 (abfd, info_ptr, &bytes_read);
2248 	    info_ptr += bytes_read;
2249 	    break;
2250 	  case DW_FORM_udata:
2251 	    unsnd = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2252 	    info_ptr += bytes_read;
2253 	    break;
2254 	  case DW_FORM_indirect:
2255 	  default:
2256 	    sprintf (ebuf,
2257 		     "Dwarf Error: Cannot handle %s in DWARF reader.",
2258 		     dwarf_form_name (abbrev->attrs[i].form));
2259 	    error (ebuf);
2260 	  }
2261 
2262 	/* store the data if it is of an attribute we want to keep in a
2263 	   partial symbol table */
2264 	switch (abbrev->attrs[i].name)
2265 	  {
2266 	  case DW_AT_name:
2267 	    part_die->name = str;
2268 	    break;
2269 	  case DW_AT_low_pc:
2270 	    has_low_pc_attr = 1;
2271 	    part_die->lowpc = addr;
2272 	    break;
2273 	  case DW_AT_high_pc:
2274 	    has_high_pc_attr = 1;
2275 	    part_die->highpc = addr;
2276 	    break;
2277 	  case DW_AT_location:
2278 	    part_die->locdesc = blk;
2279 	    break;
2280 	  case DW_AT_language:
2281 	    part_die->language = unsnd;
2282 	    break;
2283 	  case DW_AT_external:
2284 	    part_die->is_external = unsnd;
2285 	  }
2286       }
2287   }
2288   *has_pc_info = has_low_pc_attr && has_high_pc_attr;
2289   return info_ptr;
2290 }
2291 
2292 /* Read the die from the .debug_info section buffer.  And set diep to
2293    point to a newly allocated die with its information.  */
2294 
2295 static char *
2296 read_full_die (diep, abfd, info_ptr)
2297      struct die_info **diep;
2298      bfd *abfd;
2299      char *info_ptr;
2300 {
2301   unsigned int abbrev_number, bytes_read, i, offset;
2302   struct abbrev_info *abbrev;
2303   struct die_info *die;
2304   char ebuf[256];
2305 
2306   offset = info_ptr - dwarf_info_buffer;
2307   abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2308   info_ptr += bytes_read;
2309   if (!abbrev_number)
2310     {
2311       die = dwarf_alloc_die ();
2312       die->tag = 0;
2313       die->abbrev = abbrev_number;
2314       die->type = NULL;
2315       *diep = die;
2316       return info_ptr;
2317     }
2318 
2319   abbrev = dwarf2_lookup_abbrev (abbrev_number);
2320   if (!abbrev)
2321     {
2322       error ("Dwarf Error: could not find abbrev number %d.", abbrev_number);
2323     }
2324   die = dwarf_alloc_die ();
2325   die->offset = offset;
2326   die->tag = abbrev->tag;
2327   die->has_children = abbrev->has_children;
2328   die->abbrev = abbrev_number;
2329   die->type = NULL;
2330 
2331   die->num_attrs = abbrev->num_attrs;
2332   die->attrs = xmalloc (die->num_attrs * sizeof (struct attribute));
2333 
2334   {
2335     char *str;
2336     struct dwarf_block *blk;
2337     unsigned long addr;
2338     unsigned int unsnd;
2339     int snd;
2340 
2341     for (i = 0; i < abbrev->num_attrs; ++i)
2342       {
2343 	/* read the correct type of data */
2344 
2345 	die->attrs[i].name = abbrev->attrs[i].name;
2346 	die->attrs[i].form = abbrev->attrs[i].form;
2347 
2348 	switch (abbrev->attrs[i].form)
2349 	  {
2350 	  case DW_FORM_addr:
2351 	  case DW_FORM_ref_addr:
2352 	    die->attrs[i].u.addr = read_address (abfd, info_ptr);
2353 	    info_ptr += address_size;
2354 	    break;
2355 	  case DW_FORM_block2:
2356 	    blk = dwarf_alloc_block ();
2357 	    blk->size = read_2_bytes (abfd, info_ptr);
2358 	    info_ptr += 2;
2359 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2360 	    info_ptr += blk->size;
2361 	    die->attrs[i].u.blk = blk;
2362 	    break;
2363 	  case DW_FORM_block4:
2364 	    blk = dwarf_alloc_block ();
2365 	    blk->size = read_4_bytes (abfd, info_ptr);
2366 	    info_ptr += 2;
2367 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2368 	    info_ptr += blk->size;
2369 	    die->attrs[i].u.blk = blk;
2370 	    break;
2371 	  case DW_FORM_data2:
2372 	    die->attrs[i].u.unsnd = read_2_bytes (abfd, info_ptr);
2373 	    info_ptr += 2;
2374 	    break;
2375 	  case DW_FORM_data4:
2376 	    die->attrs[i].u.unsnd = read_4_bytes (abfd, info_ptr);
2377 	    info_ptr += 4;
2378 	    break;
2379 	  case DW_FORM_data8:
2380 	    die->attrs[i].u.unsnd = read_8_bytes (abfd, info_ptr);
2381 	    info_ptr += 8;
2382 	    break;
2383 	  case DW_FORM_string:
2384 	    die->attrs[i].u.str = read_string (abfd, info_ptr, &bytes_read);
2385 	    info_ptr += bytes_read;
2386 	    break;
2387 	  case DW_FORM_block:
2388 	    blk = dwarf_alloc_block ();
2389 	    blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2390 	    info_ptr += bytes_read;
2391 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2392 	    info_ptr += blk->size;
2393 	    die->attrs[i].u.blk = blk;
2394 	    break;
2395 	  case DW_FORM_block1:
2396 	    blk = dwarf_alloc_block ();
2397 	    blk->size = read_1_byte (abfd, info_ptr);
2398 	    info_ptr += 1;
2399 	    blk->data = read_n_bytes (abfd, info_ptr, blk->size);
2400 	    info_ptr += blk->size;
2401 	    die->attrs[i].u.blk = blk;
2402 	    break;
2403 	  case DW_FORM_data1:
2404 	    die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2405 	    info_ptr += 1;
2406 	    break;
2407 	  case DW_FORM_ref1:
2408 	    die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2409 	    info_ptr += 1;
2410 	    break;
2411 	  case DW_FORM_ref2:
2412 	    die->attrs[i].u.unsnd = read_2_bytes (abfd, info_ptr);
2413 	    info_ptr += 2;
2414 	    break;
2415 	  case DW_FORM_ref4:
2416 	    die->attrs[i].u.unsnd = read_4_bytes (abfd, info_ptr);
2417 	    info_ptr += 4;
2418 	    break;
2419 	  case DW_FORM_ref_udata:
2420 	    die->attrs[i].u.unsnd = read_unsigned_leb128 (abfd,
2421 							  info_ptr,
2422 							  &bytes_read);
2423 	    info_ptr += bytes_read;
2424 	    break;
2425 	  case DW_FORM_flag:
2426 	    die->attrs[i].u.unsnd = read_1_byte (abfd, info_ptr);
2427 	    info_ptr += 1;
2428 	    break;
2429 	  case DW_FORM_sdata:
2430 	    die->attrs[i].u.snd = read_signed_leb128 (abfd,
2431 						      info_ptr,
2432 						      &bytes_read);
2433 	    info_ptr += bytes_read;
2434 	    break;
2435 	  case DW_FORM_udata:
2436 	    die->attrs[i].u.unsnd = read_unsigned_leb128 (abfd,
2437 							  info_ptr,
2438 							  &bytes_read);
2439 	    info_ptr += bytes_read;
2440 	    break;
2441 	  case DW_FORM_indirect:
2442 	  default:
2443 	    sprintf (ebuf,
2444 		     "Dwarf Error: Cannot handle %s in DWARF reader.",
2445 		     dwarf_form_name (abbrev->attrs[i].form));
2446 	    error (ebuf);
2447 	  }
2448 
2449       }
2450   }
2451   *diep = die;
2452   return info_ptr;
2453 }
2454 
2455 /* read dwarf information from a buffer */
2456 
2457 static unsigned int
2458 read_1_byte (abfd, buf)
2459      bfd *abfd;
2460      char *buf;
2461 {
2462   return bfd_get_8 (abfd, (bfd_byte *) buf);
2463 }
2464 
2465 static unsigned int
2466 read_2_bytes (abfd, buf)
2467      bfd *abfd;
2468      char *buf;
2469 {
2470   return bfd_get_16 (abfd, (bfd_byte *) buf);
2471 }
2472 
2473 static unsigned int
2474 read_4_bytes (abfd, buf)
2475      bfd *abfd;
2476      char *buf;
2477 {
2478   return bfd_get_32 (abfd, (bfd_byte *) buf);
2479 }
2480 
2481 static unsigned int
2482 read_8_bytes (abfd, buf)
2483      bfd *abfd;
2484      char *buf;
2485 {
2486   return bfd_get_64 (abfd, (bfd_byte *) buf);
2487 }
2488 
2489 static CORE_ADDR
2490 read_address (abfd, buf)
2491      bfd *abfd;
2492      char *buf;
2493 {
2494   CORE_ADDR retval = 0;
2495 
2496   if (address_size == 4)
2497     {
2498       retval = bfd_get_32 (abfd, (bfd_byte *) buf);
2499     } else {			/* *THE* alternative is 8, right? */
2500       retval = bfd_get_64 (abfd, (bfd_byte *) buf);
2501     }
2502   return retval;
2503 }
2504 
2505 static char *
2506 read_n_bytes (abfd, buf, size)
2507      bfd * abfd;
2508      char *buf;
2509      unsigned int size;
2510 {
2511   char *ret;
2512   unsigned int i;
2513 
2514   ret = xmalloc (size);
2515   for (i = 0; i < size; ++i)
2516     {
2517       ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
2518       buf++;
2519     }
2520   return ret;
2521 }
2522 
2523 /* FIXME : hardwired string size limit */
2524 
2525 static char *
2526 read_string (abfd, buf, bytes_read_ptr)
2527      bfd *abfd;
2528      char *buf;
2529      unsigned int *bytes_read_ptr;
2530 {
2531   char ret_buf[DWARF2_MAX_STRING_SIZE], *ret, byte;
2532   unsigned int i;
2533 
2534   i = 0;
2535   do
2536     {
2537       byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2538       buf++;
2539       ret_buf[i++] = byte;
2540     }
2541   while (byte);
2542   if (i == 1)
2543     {
2544       *bytes_read_ptr = 1;
2545       return NULL;
2546     }
2547   ret = xmalloc (i);
2548   strncpy (ret, ret_buf, i);
2549   *bytes_read_ptr = i;
2550   return ret;
2551 }
2552 
2553 static unsigned int
2554 read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
2555      bfd *abfd;
2556      char *buf;
2557      unsigned int *bytes_read_ptr;
2558 {
2559   unsigned int result, num_read;
2560   int i, shift;
2561   unsigned char byte;
2562 
2563   result = 0;
2564   shift = 0;
2565   num_read = 0;
2566   i = 0;
2567   while (1)
2568     {
2569       byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2570       buf++;
2571       num_read++;
2572       result |= ((byte & 127) << shift);
2573       if ((byte & 128) == 0)
2574 	{
2575 	  break;
2576 	}
2577       shift += 7;
2578     }
2579   *bytes_read_ptr = num_read;
2580   return result;
2581 }
2582 
2583 static int
2584 read_signed_leb128 (abfd, buf, bytes_read_ptr)
2585      bfd *abfd;
2586      char *buf;
2587      unsigned int *bytes_read_ptr;
2588 {
2589   int result;
2590   int i, shift, size, num_read;
2591   unsigned char byte;
2592 
2593   result = 0;
2594   shift = 0;
2595   size = 32;
2596   num_read = 0;
2597   i = 0;
2598   while (1)
2599     {
2600       byte = bfd_get_8 (abfd, (bfd_byte *) buf);
2601       buf++;
2602       num_read++;
2603       result |= ((byte & 127) << shift);
2604       shift += 7;
2605       if ((byte & 128) == 0)
2606 	{
2607 	  break;
2608 	}
2609     }
2610   if ((shift < size) && (byte & 0x40))
2611     {
2612       result |= -(1 << shift);
2613     }
2614   *bytes_read_ptr = num_read;
2615   return result;
2616 }
2617 
2618 static void
2619 set_cu_language (lang)
2620      unsigned int lang;
2621 {
2622   switch (lang)
2623     {
2624     case DW_LANG_C89:
2625     case DW_LANG_C:
2626     case DW_LANG_Fortran77:
2627       cu_language = language_c;
2628       break;
2629     case DW_LANG_C_plus_plus:
2630       cu_language = language_cplus;
2631       break;
2632     case DW_LANG_Ada83:
2633     case DW_LANG_Cobol74:
2634     case DW_LANG_Cobol85:
2635 #if 0
2636     case DW_LANG_Fortran77:	/* moved up top for now */
2637 #endif
2638     case DW_LANG_Fortran90:
2639     case DW_LANG_Pascal83:
2640     case DW_LANG_Modula2:
2641     default:
2642       cu_language = language_unknown;
2643       break;
2644     }
2645   cu_language_defn = language_def (cu_language);
2646 }
2647 
2648 static void
2649 record_minimal_symbol (name, address, ms_type, objfile)
2650      char *name;
2651      CORE_ADDR address;
2652      enum minimal_symbol_type ms_type;
2653      struct objfile *objfile;
2654 {
2655   name = obsavestring (name, strlen (name), &objfile->symbol_obstack);
2656   prim_record_minimal_symbol (name, address, ms_type, objfile);
2657 }
2658 
2659 /* Converts a location description into gdb form.  */
2660 
2661 static int
2662 convert_locdesc (blk)
2663      struct dwarf_block *blk;
2664 {
2665   /* FIXME : this is only a stub! */
2666   return 0;
2667 }
2668 
2669 /* Return the named attribute or NULL if not there.  */
2670 
2671 static struct attribute *
2672 dwarf_attr (die, name)
2673      struct die_info *die;
2674      unsigned int name;
2675 {
2676   unsigned int i;
2677   struct attribute *spec = NULL;
2678 
2679   for (i = 0; i < die->num_attrs; ++i)
2680     {
2681       if (die->attrs[i].name == name)
2682 	{
2683 	  return &die->attrs[i];
2684 	}
2685       if (die->attrs[i].name == DW_AT_specification
2686 	  || die->attrs[i].name == DW_AT_abstract_origin)
2687 	spec = &die->attrs[i];
2688     }
2689   if (spec)
2690     return dwarf_attr (follow_die_ref (DW_UNSND (spec)), name);
2691 
2692   return NULL;
2693 }
2694 
2695 /* Decode the line number information for the compilation unit whose
2696    line number info is at OFFSET in the .debug_line section.  */
2697 
2698 struct filenames
2699 {
2700   int num_files;
2701   struct fileinfo
2702   {
2703     char *name;
2704     unsigned int dir;
2705     unsigned int time;
2706     unsigned int size;
2707   }
2708   *files;
2709 };
2710 
2711 struct directories
2712 {
2713   int num_dirs;
2714   char **dirs;
2715 };
2716 
2717 static void
2718 dwarf_decode_lines (offset, abfd)
2719      unsigned int offset;
2720      bfd *abfd;
2721 {
2722   char *line_ptr;
2723   struct line_head lh;
2724   struct cleanup *back_to;
2725   unsigned int i, bytes_read;
2726   char *cur_file, *cur_dir;
2727   unsigned char op_code, extended_op, adj_opcode;
2728 
2729 #define FILE_ALLOC_CHUNK 5
2730 #define DIR_ALLOC_CHUNK 5
2731 
2732   struct filenames files;
2733   struct directories dirs;
2734 
2735   /* state machine registers  */
2736   unsigned int address = 0;
2737   unsigned int file = 1;
2738   unsigned int line = 1;
2739   unsigned int column = 0;
2740   int is_stmt;			/* initialized below */
2741   int basic_block = 0;
2742   int beg_of_comp_unit = 0;	/* is this right? */
2743   int end_sequence = 0;
2744 
2745   files.num_files = 0;
2746   files.files = NULL;
2747 
2748   dirs.num_dirs = 0;
2749   dirs.dirs = NULL;
2750 
2751   line_ptr = dwarf_line_buffer + offset;
2752 
2753   /* read in the prologue */
2754   lh.total_length = read_4_bytes (abfd, line_ptr);
2755   line_ptr += 4;
2756   lh.version = read_2_bytes (abfd, line_ptr);
2757   line_ptr += 2;
2758   lh.prologue_length = read_4_bytes (abfd, line_ptr);
2759   line_ptr += 4;
2760   lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
2761   line_ptr += 1;
2762   lh.default_is_stmt = read_1_byte (abfd, line_ptr);
2763   is_stmt = lh.default_is_stmt;
2764   line_ptr += 1;
2765   lh.line_base = read_1_byte (abfd, line_ptr);
2766   line_ptr += 1;
2767   lh.line_range = read_1_byte (abfd, line_ptr);
2768   line_ptr += 1;
2769   lh.opcode_base = read_1_byte (abfd, line_ptr);
2770   line_ptr += 1;
2771   lh.standard_opcode_lengths = (unsigned char *)
2772     xmalloc (lh.opcode_base * sizeof (unsigned char));
2773   back_to = make_cleanup (free, lh.standard_opcode_lengths);
2774 
2775   lh.standard_opcode_lengths[0] = 1;
2776   for (i = 1; i < lh.opcode_base; ++i)
2777     {
2778       lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
2779       line_ptr += 1;
2780     }
2781 
2782   /* Read directory table  */
2783   while (cur_dir = read_string (abfd, line_ptr, &bytes_read))
2784     {
2785       line_ptr += bytes_read;
2786       if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0)
2787 	{
2788 	  dirs.dirs = xrealloc (dirs.dirs,
2789 	    (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
2790 	}
2791       dirs.dirs[dirs.num_dirs++] = cur_dir;
2792     }
2793   line_ptr += bytes_read;
2794 
2795   /* Read file name table */
2796   while (cur_file = read_string (abfd, line_ptr, &bytes_read))
2797     {
2798       line_ptr += bytes_read;
2799       if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
2800 	{
2801 	  files.files = xrealloc (files.files,
2802 	    (files.num_files + FILE_ALLOC_CHUNK) * sizeof (struct fileinfo));
2803 	}
2804       files.files[files.num_files].name = cur_file;
2805       files.files[files.num_files].dir = read_unsigned_leb128 (abfd,
2806 					   line_ptr, &bytes_read);
2807       line_ptr += bytes_read;
2808       files.files[files.num_files].time = read_unsigned_leb128 (abfd,
2809 					   line_ptr, &bytes_read);
2810       line_ptr += bytes_read;
2811       files.files[files.num_files].size = read_unsigned_leb128 (abfd,
2812 					   line_ptr, &bytes_read);
2813       line_ptr += bytes_read;
2814       files.num_files++;
2815     }
2816   line_ptr += bytes_read;
2817 
2818   /* Decode the table. */
2819   if (lh.total_length - (lh.prologue_length + 4 + 2) >= 4)
2820     do
2821       {
2822 	op_code = read_1_byte (abfd, line_ptr);
2823 	line_ptr += 1;
2824 	switch (op_code)
2825 	  {
2826 	  case DW_LNS_extended_op:
2827 	    line_ptr += 1;	/* ignore length */
2828 	    extended_op = read_1_byte (abfd, line_ptr);
2829 	    line_ptr += 1;
2830 	    switch (extended_op)
2831 	      {
2832 	      case DW_LNE_end_sequence:
2833 		end_sequence = 1;
2834 		record_line (current_subfile, line, address);
2835 		return;		/* return! */
2836 		break;
2837 	      case DW_LNE_set_address:
2838 		address = read_address (abfd, line_ptr);
2839 		line_ptr += address_size;
2840 		break;
2841 	      case DW_LNE_define_file:
2842 		cur_file = read_string (abfd, line_ptr, &bytes_read);
2843 		line_ptr += bytes_read;
2844 		if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
2845 		  {
2846 		    files.files = xrealloc (files.files,
2847 		      (files.num_files + FILE_ALLOC_CHUNK)
2848 			* sizeof (struct fileinfo));
2849 		  }
2850 		files.files[files.num_files].name = cur_file;
2851 		files.files[files.num_files].dir = read_unsigned_leb128 (
2852 		  abfd, line_ptr, &bytes_read);
2853 		line_ptr += bytes_read;
2854 		files.files[files.num_files].time = read_unsigned_leb128 (abfd,
2855 		  line_ptr, &bytes_read);
2856 		line_ptr += bytes_read;
2857 		files.files[files.num_files].size = read_unsigned_leb128 (abfd,
2858 		  line_ptr, &bytes_read);
2859 		line_ptr += bytes_read;
2860 		break;
2861 	      default:
2862 		error ("Dwarf Error: Mangled .debug_line section.");
2863 		return;
2864 	      }
2865 	    break;
2866 	  case DW_LNS_copy:
2867 	    record_line (current_subfile, line, address);
2868 	    basic_block = 0;
2869 	    break;
2870 	  case DW_LNS_advance_pc:
2871 	    address += lh.minimum_instruction_length
2872 	      * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2873 	    line_ptr += bytes_read;
2874 	    break;
2875 	  case DW_LNS_advance_line:
2876 	    line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
2877 	    line_ptr += bytes_read;
2878 	    break;
2879 	  case DW_LNS_set_file:
2880 	    /* The file table is 0 based and the references are 1
2881 	       based, thus  the subtraction of `1' at the end of the
2882 	       next line */
2883 	    file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read) - 1;
2884 	    start_subfile (files.files[file].name,
2885 			   (files.files[file].dir ?
2886 			     dirs.dirs[files.files[file].dir] : 0));
2887 	    line_ptr += bytes_read;
2888 	    break;
2889 	  case DW_LNS_set_column:
2890 	    column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
2891 	    line_ptr += bytes_read;
2892 	    break;
2893 	  case DW_LNS_negate_stmt:
2894 	    is_stmt = (!is_stmt);
2895 	    break;
2896 	  case DW_LNS_set_basic_block:
2897 	    basic_block = 1;
2898 	    break;
2899 	  case DW_LNS_const_add_pc:
2900 	    address += (255 - lh.opcode_base) / lh.line_range;
2901 	    break;
2902 	  case DW_LNS_fixed_advance_pc:
2903 	    address += read_2_bytes (abfd, line_ptr);
2904 	    line_ptr += 2;
2905 	    break;
2906 	  default:		/* special operand */
2907 	    adj_opcode = op_code - lh.opcode_base;
2908 	    address += (adj_opcode / lh.line_range)
2909 	      * lh.minimum_instruction_length;
2910 	    line += lh.line_base + (adj_opcode % lh.line_range);
2911 	    /* append row to matrix using current values */
2912 	    record_line (current_subfile, line, address);
2913 	    basic_block = 1;
2914 	  }
2915       }
2916     while (1);
2917   do_cleanups (back_to);
2918 }
2919 
2920 /* Given a pointer to a DWARF information entry, figure out if we need
2921    to make a symbol table entry for it, and if so, create a new entry
2922    and return a pointer to it.  */
2923 
2924 static struct symbol *
2925 new_symbol (die, objfile)
2926      struct die_info *die;
2927      struct objfile *objfile;
2928 {
2929   struct symbol *sym = NULL;
2930   struct attribute *attr = NULL;
2931   struct attribute *attr2 = NULL;
2932   CORE_ADDR addr;
2933 
2934   attr = dwarf_attr (die, DW_AT_name);
2935   if (attr)
2936     {
2937 #if 0
2938       sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
2939 					     sizeof (struct symbol));
2940 #endif
2941       sym = (struct symbol *) xmalloc (sizeof (struct symbol));
2942       memset (sym, 0, sizeof (struct symbol));
2943 #if 0
2944       SYMBOL_NAME (sym) = create_name (DW_STRING (attr),
2945 				       &objfile->symbol_obstack);
2946 #endif
2947       SYMBOL_NAME (sym) = strdup (DW_STRING (attr));
2948       /* default assumptions */
2949       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2950       SYMBOL_CLASS (sym) = LOC_STATIC;
2951       SYMBOL_TYPE (sym) = die_type (die, objfile);
2952 
2953       /* If this symbol is from a C++ compilation, then attempt to
2954          cache the demangled form for future reference.  This is a
2955          typical time versus space tradeoff, that was decided in favor
2956          of time because it sped up C++ symbol lookups by a factor of
2957          about 20. */
2958 
2959       SYMBOL_LANGUAGE (sym) = cu_language;
2960       SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
2961       switch (die->tag)
2962 	{
2963 	case DW_TAG_label:
2964 	  attr = dwarf_attr (die, DW_AT_low_pc);
2965 	  if (attr)
2966 	    {
2967 	      SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr);
2968 	    }
2969 	  SYMBOL_CLASS (sym) = LOC_LABEL;
2970 	  break;
2971 	case DW_TAG_subprogram:
2972 	  attr = dwarf_attr (die, DW_AT_low_pc);
2973 	  if (attr)
2974 	    {
2975 	      SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr);
2976 	    }
2977 	  SYMBOL_TYPE (sym) = make_function_type (die_type (die, objfile),
2978 						  NULL);
2979 	  SYMBOL_CLASS (sym) = LOC_BLOCK;
2980 	  attr2 = dwarf_attr (die, DW_AT_external);
2981 	  if (attr2 && (DW_UNSND (attr2) != 0))
2982 	    {
2983 	      add_symbol_to_list (sym, &global_symbols);
2984 	    }
2985 	  else
2986 	    {
2987 	      add_symbol_to_list (sym, list_in_scope);
2988 	    }
2989 	  break;
2990 	case DW_TAG_variable:
2991 	  attr = dwarf_attr (die, DW_AT_location);
2992 	  if (attr)
2993 	    {
2994 	      attr2 = dwarf_attr (die, DW_AT_external);
2995 	      if (attr2 && (DW_UNSND (attr2) != 0))
2996 		{
2997 		  SYMBOL_VALUE_ADDRESS (sym) =
2998 		    decode_locdesc (DW_BLOCK (attr), objfile);
2999 		  add_symbol_to_list (sym, &global_symbols);
3000 		  SYMBOL_CLASS (sym) = LOC_STATIC;
3001 		  SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
3002 		}
3003 	      else
3004 		{
3005 		  SYMBOL_VALUE (sym) = addr =
3006 		    decode_locdesc (DW_BLOCK (attr), objfile);
3007 		  add_symbol_to_list (sym, list_in_scope);
3008 		  if (isreg)
3009 		    {
3010 		      SYMBOL_CLASS (sym) = LOC_REGISTER;
3011 		    }
3012 		  else if (offreg)
3013 		    {
3014 		      SYMBOL_CLASS (sym) = LOC_LOCAL;
3015 		    }
3016 		  else
3017 		    {
3018 		      SYMBOL_CLASS (sym) = LOC_STATIC;
3019 		      SYMBOL_VALUE_ADDRESS (sym) = addr + baseaddr;
3020 		    }
3021 		}
3022 	    }
3023 	  break;
3024 	case DW_TAG_formal_parameter:
3025 	  attr = dwarf_attr (die, DW_AT_location);
3026 	  if (attr != NULL)
3027 	    {
3028 	      SYMBOL_VALUE (sym) = decode_locdesc (DW_BLOCK (attr), objfile);
3029 	    }
3030 	  add_symbol_to_list (sym, list_in_scope);
3031 	  if (isreg)
3032 	    {
3033 	      SYMBOL_CLASS (sym) = LOC_REGPARM;
3034 	    }
3035 	  else
3036 	    {
3037 	      SYMBOL_CLASS (sym) = LOC_ARG;
3038 	    }
3039 	  break;
3040 	case DW_TAG_unspecified_parameters:
3041 	  /* From varargs functions; gdb doesn't seem to have any
3042 	     interest in this information, so just ignore it for now.
3043 	     (FIXME?) */
3044 	  break;
3045 	case DW_TAG_class_type:
3046 	case DW_TAG_structure_type:
3047 	case DW_TAG_union_type:
3048 	case DW_TAG_enumeration_type:
3049 	  SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3050 	  SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
3051 	  add_symbol_to_list (sym, list_in_scope);
3052 	  break;
3053 	case DW_TAG_typedef:
3054 	  SYMBOL_CLASS (sym) = LOC_TYPEDEF;
3055 	  SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3056 	  add_symbol_to_list (sym, list_in_scope);
3057 	  break;
3058 	default:
3059 	  /* Not a tag we recognize.  Hopefully we aren't processing
3060 	     trash data, but since we must specifically ignore things
3061 	     we don't recognize, there is nothing else we should do at
3062 	     this point. */
3063 	  break;
3064 	}
3065     }
3066   return (sym);
3067 }
3068 
3069 /* Return the type of the die in question using its DW_AT_type attribute.  */
3070 
3071 static struct type *
3072 die_type (die, objfile)
3073      struct die_info *die;
3074      struct objfile *objfile;
3075 {
3076   struct type *type;
3077   struct attribute *attr, *type_attr;
3078   struct die_info *type_die;
3079   unsigned int size = 0, encoding = 0, ref;
3080 
3081   type_attr = dwarf_attr (die, DW_AT_type);
3082   if (!type_attr)
3083     {
3084       type = dwarf_base_type (0, 0);
3085       return type;
3086     }
3087   else
3088     {
3089       ref = DW_UNSND (type_attr);
3090       type_die = follow_die_ref (ref);
3091       if (!type_die)
3092 	{
3093 	  error ("Dwarf Error: Cannot find referent at offset %d.", ref);
3094 	  return NULL;
3095 	}
3096     }
3097   type = tag_type_to_type (type_die, objfile);
3098   if (!type)
3099     {
3100       error ("Dwarf Error: Problem turning type die at offset into gdb type:");
3101       dump_die (type_die);
3102     }
3103   return type;
3104 }
3105 
3106 static struct type *
3107 type_at_offset (offset, objfile)
3108      unsigned int offset;
3109      struct objfile *objfile;
3110 {
3111   struct die_info *die;
3112   struct type *type;
3113 
3114   die = follow_die_ref (offset);
3115   if (!die)
3116     {
3117       error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
3118       return NULL;
3119     }
3120   type = tag_type_to_type (die, objfile);
3121   return type;
3122 }
3123 
3124 static struct type *
3125 tag_type_to_type (die, objfile)
3126      struct die_info *die;
3127      struct objfile *objfile;
3128 {
3129   if (die->type)
3130     {
3131       return die->type;
3132     }
3133   else
3134     {
3135       read_type_die (die, objfile);
3136       if (!die->type)
3137 	{
3138 	  dump_die (die);
3139 	  error ("Dwarf Error: Cannot find type of die:");
3140 	}
3141       return die->type;
3142     }
3143 }
3144 
3145 static void
3146 read_type_die (die, objfile)
3147      struct die_info *die;
3148      struct objfile *objfile;
3149 {
3150   switch (die->tag)
3151     {
3152     case DW_TAG_class_type:
3153     case DW_TAG_structure_type:
3154     case DW_TAG_union_type:
3155       read_structure_scope (die, objfile);
3156       break;
3157     case DW_TAG_enumeration_type:
3158       read_enumeration (die, objfile);
3159       break;
3160     case DW_TAG_subroutine_type:
3161       read_subroutine_type (die, objfile);
3162       break;
3163     case DW_TAG_array_type:
3164       dwarf_read_array_type (die, objfile);
3165       break;
3166     case DW_TAG_pointer_type:
3167       read_tag_pointer_type (die, objfile);
3168       break;
3169     case DW_TAG_reference_type:
3170       read_tag_reference_type (die, objfile);
3171       break;
3172     case DW_TAG_const_type:
3173       read_tag_const_type (die, objfile);
3174       break;
3175     case DW_TAG_volatile_type:
3176       read_tag_volatile_type (die, objfile);
3177       break;
3178     case DW_TAG_string_type:
3179       read_tag_string_type (die, objfile);
3180       break;
3181     case DW_TAG_typedef:
3182       read_typedef (die, objfile);
3183       break;
3184     case DW_TAG_base_type:
3185       read_base_type (die, objfile);
3186       break;
3187     case DW_TAG_padding:
3188     case DW_TAG_compile_unit:
3189     case DW_TAG_subprogram:
3190     case DW_TAG_lexical_block:
3191     default:
3192       break;
3193     }
3194 }
3195 
3196 static struct type *
3197 dwarf_base_type (encoding, size)
3198      int encoding;
3199      int size;
3200 {
3201   /* FIXME - this should not produce a new (struct type *)
3202      every time.  It should cache base types.  */
3203   struct type *type;
3204   switch (encoding)
3205     {
3206     case DW_ATE_address:
3207       type = dwarf2_fundamental_type (current_objfile, FT_VOID);
3208       return type;
3209     case DW_ATE_boolean:
3210       type = dwarf2_fundamental_type (current_objfile, FT_BOOLEAN);
3211       return type;
3212     case DW_ATE_complex_float:
3213       if (size == 16)
3214 	{
3215 	  type = dwarf2_fundamental_type (current_objfile, FT_DBL_PREC_COMPLEX);
3216 	}
3217       else
3218 	{
3219 	  type = dwarf2_fundamental_type (current_objfile, FT_COMPLEX);
3220 	}
3221       return type;
3222     case DW_ATE_float:
3223       if (size == 8)
3224 	{
3225 	  type = dwarf2_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
3226 	}
3227       else
3228 	{
3229 	  type = dwarf2_fundamental_type (current_objfile, FT_FLOAT);
3230 	}
3231       return type;
3232     case DW_ATE_signed:
3233       switch (size)
3234 	{
3235 	case 1:
3236 	  type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3237 	  break;
3238 	case 2:
3239 	  type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_SHORT);
3240 	  break;
3241 	default:
3242 	case 4:
3243 	  type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3244 	  break;
3245 	}
3246       return type;
3247     case DW_ATE_signed_char:
3248       type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_CHAR);
3249       return type;
3250     case DW_ATE_unsigned:
3251       switch (size)
3252 	{
3253 	case 1:
3254 	  type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3255 	  break;
3256 	case 2:
3257 	  type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_SHORT);
3258 	  break;
3259 	default:
3260 	case 4:
3261 	  type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
3262 	  break;
3263 	}
3264       return type;
3265     case DW_ATE_unsigned_char:
3266       type = dwarf2_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
3267       return type;
3268     default:
3269       type = dwarf2_fundamental_type (current_objfile, FT_SIGNED_INTEGER);
3270       return type;
3271     }
3272 }
3273 
3274 /* Given a pointer to a string and a pointer to an obstack, allocates
3275    a fresh copy of the string on the specified obstack.  */
3276 
3277 static char *
3278 create_name (name, obstackp)
3279      char *name;
3280      struct obstack *obstackp;
3281 {
3282   int length;
3283   char *newname;
3284 
3285   length = strlen (name) + 1;
3286   newname = (char *) obstack_alloc (obstackp, length);
3287   strcpy (newname, name);
3288   return (newname);
3289 }
3290 
3291 struct die_info *
3292 copy_die (old_die)
3293      struct die_info *old_die;
3294 {
3295   struct die_info *new_die;
3296   int i, num_attrs;
3297 
3298   new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
3299   memset (new_die, 0, sizeof (struct die_info));
3300 
3301   new_die->tag = old_die->tag;
3302   new_die->has_children = old_die->has_children;
3303   new_die->abbrev = old_die->abbrev;
3304   new_die->offset = old_die->offset;
3305   new_die->type = NULL;
3306 
3307   num_attrs = old_die->num_attrs;
3308   new_die->num_attrs = num_attrs;
3309   new_die->attrs = (struct attribute *)
3310     xmalloc (num_attrs * sizeof (struct attribute));
3311 
3312   for (i = 0; i < old_die->num_attrs; ++i)
3313     {
3314       new_die->attrs[i].name = old_die->attrs[i].name;
3315       new_die->attrs[i].form = old_die->attrs[i].form;
3316       new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
3317     }
3318 
3319   new_die->next = NULL;
3320   return new_die;
3321 }
3322 
3323 /* Return sibling of die, NULL if no sibling.  */
3324 
3325 struct die_info *
3326 sibling_die (die)
3327      struct die_info *die;
3328 {
3329   struct die_info *new;
3330   int nesting_level = 0;
3331 
3332   if (!die->has_children)
3333     {
3334       if (die->next && (die->next->tag == 0))
3335 	{
3336 	  return NULL;
3337 	}
3338       else
3339 	{
3340 	  return die->next;
3341 	}
3342     }
3343   else
3344     {
3345       do
3346 	{
3347 	  if (die->has_children)
3348 	    {
3349 	      nesting_level++;
3350 	    }
3351 	  if (die->tag == 0)
3352 	    {
3353 	      nesting_level--;
3354 	    }
3355 	  die = die->next;
3356 	}
3357       while (nesting_level);
3358       if (die && (die->tag == 0))
3359 	{
3360 	  return NULL;
3361 	}
3362       else
3363 	{
3364 	  return die;
3365 	}
3366     }
3367 }
3368 
3369 /* Convert a DIE tag into its string name.  */
3370 
3371 static char *
3372 dwarf_tag_name (tag)
3373      register unsigned tag;
3374 {
3375   switch (tag)
3376     {
3377     case DW_TAG_padding:
3378       return "DW_TAG_padding";
3379     case DW_TAG_array_type:
3380       return "DW_TAG_array_type";
3381     case DW_TAG_class_type:
3382       return "DW_TAG_class_type";
3383     case DW_TAG_entry_point:
3384       return "DW_TAG_entry_point";
3385     case DW_TAG_enumeration_type:
3386       return "DW_TAG_enumeration_type";
3387     case DW_TAG_formal_parameter:
3388       return "DW_TAG_formal_parameter";
3389     case DW_TAG_imported_declaration:
3390       return "DW_TAG_imported_declaration";
3391     case DW_TAG_label:
3392       return "DW_TAG_label";
3393     case DW_TAG_lexical_block:
3394       return "DW_TAG_lexical_block";
3395     case DW_TAG_member:
3396       return "DW_TAG_member";
3397     case DW_TAG_pointer_type:
3398       return "DW_TAG_pointer_type";
3399     case DW_TAG_reference_type:
3400       return "DW_TAG_reference_type";
3401     case DW_TAG_compile_unit:
3402       return "DW_TAG_compile_unit";
3403     case DW_TAG_string_type:
3404       return "DW_TAG_string_type";
3405     case DW_TAG_structure_type:
3406       return "DW_TAG_structure_type";
3407     case DW_TAG_subroutine_type:
3408       return "DW_TAG_subroutine_type";
3409     case DW_TAG_typedef:
3410       return "DW_TAG_typedef";
3411     case DW_TAG_union_type:
3412       return "DW_TAG_union_type";
3413     case DW_TAG_unspecified_parameters:
3414       return "DW_TAG_unspecified_parameters";
3415     case DW_TAG_variant:
3416       return "DW_TAG_variant";
3417     case DW_TAG_common_block:
3418       return "DW_TAG_common_block";
3419     case DW_TAG_common_inclusion:
3420       return "DW_TAG_common_inclusion";
3421     case DW_TAG_inheritance:
3422       return "DW_TAG_inheritance";
3423     case DW_TAG_inlined_subroutine:
3424       return "DW_TAG_inlined_subroutine";
3425     case DW_TAG_module:
3426       return "DW_TAG_module";
3427     case DW_TAG_ptr_to_member_type:
3428       return "DW_TAG_ptr_to_member_type";
3429     case DW_TAG_set_type:
3430       return "DW_TAG_set_type";
3431     case DW_TAG_subrange_type:
3432       return "DW_TAG_subrange_type";
3433     case DW_TAG_with_stmt:
3434       return "DW_TAG_with_stmt";
3435     case DW_TAG_access_declaration:
3436       return "DW_TAG_access_declaration";
3437     case DW_TAG_base_type:
3438       return "DW_TAG_base_type";
3439     case DW_TAG_catch_block:
3440       return "DW_TAG_catch_block";
3441     case DW_TAG_const_type:
3442       return "DW_TAG_const_type";
3443     case DW_TAG_constant:
3444       return "DW_TAG_constant";
3445     case DW_TAG_enumerator:
3446       return "DW_TAG_enumerator";
3447     case DW_TAG_file_type:
3448       return "DW_TAG_file_type";
3449     case DW_TAG_friend:
3450       return "DW_TAG_friend";
3451     case DW_TAG_namelist:
3452       return "DW_TAG_namelist";
3453     case DW_TAG_namelist_item:
3454       return "DW_TAG_namelist_item";
3455     case DW_TAG_packed_type:
3456       return "DW_TAG_packed_type";
3457     case DW_TAG_subprogram:
3458       return "DW_TAG_subprogram";
3459     case DW_TAG_template_type_param:
3460       return "DW_TAG_template_type_param";
3461     case DW_TAG_template_value_param:
3462       return "DW_TAG_template_value_param";
3463     case DW_TAG_thrown_type:
3464       return "DW_TAG_thrown_type";
3465     case DW_TAG_try_block:
3466       return "DW_TAG_try_block";
3467     case DW_TAG_variant_part:
3468       return "DW_TAG_variant_part";
3469     case DW_TAG_variable:
3470       return "DW_TAG_variable";
3471     case DW_TAG_volatile_type:
3472       return "DW_TAG_volatile_type";
3473     case DW_TAG_MIPS_loop:
3474       return "DW_TAG_MIPS_loop";
3475     case DW_TAG_format_label:
3476       return "DW_TAG_format_label";
3477     case DW_TAG_function_template:
3478       return "DW_TAG_function_template";
3479     case DW_TAG_class_template:
3480       return "DW_TAG_class_template";
3481     default:
3482       return "DW_TAG_<unknown>";
3483     }
3484 }
3485 
3486 /* Convert a DWARF attribute code into its string name.  */
3487 
3488 static char *
3489 dwarf_attr_name (attr)
3490      register unsigned attr;
3491 {
3492   switch (attr)
3493     {
3494     case DW_AT_sibling:
3495       return "DW_AT_sibling";
3496     case DW_AT_location:
3497       return "DW_AT_location";
3498     case DW_AT_name:
3499       return "DW_AT_name";
3500     case DW_AT_ordering:
3501       return "DW_AT_ordering";
3502     case DW_AT_subscr_data:
3503       return "DW_AT_subscr_data";
3504     case DW_AT_byte_size:
3505       return "DW_AT_byte_size";
3506     case DW_AT_bit_offset:
3507       return "DW_AT_bit_offset";
3508     case DW_AT_bit_size:
3509       return "DW_AT_bit_size";
3510     case DW_AT_element_list:
3511       return "DW_AT_element_list";
3512     case DW_AT_stmt_list:
3513       return "DW_AT_stmt_list";
3514     case DW_AT_low_pc:
3515       return "DW_AT_low_pc";
3516     case DW_AT_high_pc:
3517       return "DW_AT_high_pc";
3518     case DW_AT_language:
3519       return "DW_AT_language";
3520     case DW_AT_member:
3521       return "DW_AT_member";
3522     case DW_AT_discr:
3523       return "DW_AT_discr";
3524     case DW_AT_discr_value:
3525       return "DW_AT_discr_value";
3526     case DW_AT_visibility:
3527       return "DW_AT_visibility";
3528     case DW_AT_import:
3529       return "DW_AT_import";
3530     case DW_AT_string_length:
3531       return "DW_AT_string_length";
3532     case DW_AT_common_reference:
3533       return "DW_AT_common_reference";
3534     case DW_AT_comp_dir:
3535       return "DW_AT_comp_dir";
3536     case DW_AT_const_value:
3537       return "DW_AT_const_value";
3538     case DW_AT_containing_type:
3539       return "DW_AT_containing_type";
3540     case DW_AT_default_value:
3541       return "DW_AT_default_value";
3542     case DW_AT_inline:
3543       return "DW_AT_inline";
3544     case DW_AT_is_optional:
3545       return "DW_AT_is_optional";
3546     case DW_AT_lower_bound:
3547       return "DW_AT_lower_bound";
3548     case DW_AT_producer:
3549       return "DW_AT_producer";
3550     case DW_AT_prototyped:
3551       return "DW_AT_prototyped";
3552     case DW_AT_return_addr:
3553       return "DW_AT_return_addr";
3554     case DW_AT_start_scope:
3555       return "DW_AT_start_scope";
3556     case DW_AT_stride_size:
3557       return "DW_AT_stride_size";
3558     case DW_AT_upper_bound:
3559       return "DW_AT_upper_bound";
3560     case DW_AT_abstract_origin:
3561       return "DW_AT_abstract_origin";
3562     case DW_AT_accessibility:
3563       return "DW_AT_accessibility";
3564     case DW_AT_address_class:
3565       return "DW_AT_address_class";
3566     case DW_AT_artificial:
3567       return "DW_AT_artificial";
3568     case DW_AT_base_types:
3569       return "DW_AT_base_types";
3570     case DW_AT_calling_convention:
3571       return "DW_AT_calling_convention";
3572     case DW_AT_count:
3573       return "DW_AT_count";
3574     case DW_AT_data_member_location:
3575       return "DW_AT_data_member_location";
3576     case DW_AT_decl_column:
3577       return "DW_AT_decl_column";
3578     case DW_AT_decl_file:
3579       return "DW_AT_decl_file";
3580     case DW_AT_decl_line:
3581       return "DW_AT_decl_line";
3582     case DW_AT_declaration:
3583       return "DW_AT_declaration";
3584     case DW_AT_discr_list:
3585       return "DW_AT_discr_list";
3586     case DW_AT_encoding:
3587       return "DW_AT_encoding";
3588     case DW_AT_external:
3589       return "DW_AT_external";
3590     case DW_AT_frame_base:
3591       return "DW_AT_frame_base";
3592     case DW_AT_friend:
3593       return "DW_AT_friend";
3594     case DW_AT_identifier_case:
3595       return "DW_AT_identifier_case";
3596     case DW_AT_macro_info:
3597       return "DW_AT_macro_info";
3598     case DW_AT_namelist_items:
3599       return "DW_AT_namelist_items";
3600     case DW_AT_priority:
3601       return "DW_AT_priority";
3602     case DW_AT_segment:
3603       return "DW_AT_segment";
3604     case DW_AT_specification:
3605       return "DW_AT_specification";
3606     case DW_AT_static_link:
3607       return "DW_AT_static_link";
3608     case DW_AT_type:
3609       return "DW_AT_type";
3610     case DW_AT_use_location:
3611       return "DW_AT_use_location";
3612     case DW_AT_variable_parameter:
3613       return "DW_AT_variable_parameter";
3614     case DW_AT_virtuality:
3615       return "DW_AT_virtuality";
3616     case DW_AT_vtable_elem_location:
3617       return "DW_AT_vtable_elem_location";
3618 
3619 #ifdef MIPS
3620     case DW_AT_MIPS_fde:
3621       return "DW_AT_MIPS_fde";
3622     case DW_AT_MIPS_loop_begin:
3623       return "DW_AT_MIPS_loop_begin";
3624     case DW_AT_MIPS_tail_loop_begin:
3625       return "DW_AT_MIPS_tail_loop_begin";
3626     case DW_AT_MIPS_epilog_begin:
3627       return "DW_AT_MIPS_epilog_begin";
3628     case DW_AT_MIPS_loop_unroll_factor:
3629       return "DW_AT_MIPS_loop_unroll_factor";
3630     case DW_AT_MIPS_software_pipeline_depth:
3631       return "DW_AT_MIPS_software_pipeline_depth";
3632     case DW_AT_MIPS_linkage_name:
3633       return "DW_AT_MIPS_linkage_name";
3634 #endif
3635 
3636     case DW_AT_sf_names:
3637       return "DW_AT_sf_names";
3638     case DW_AT_src_info:
3639       return "DW_AT_src_info";
3640     case DW_AT_mac_info:
3641       return "DW_AT_mac_info";
3642     case DW_AT_src_coords:
3643       return "DW_AT_src_coords";
3644     case DW_AT_body_begin:
3645       return "DW_AT_body_begin";
3646     case DW_AT_body_end:
3647       return "DW_AT_body_end";
3648     default:
3649       return "DW_AT_<unknown>";
3650     }
3651 }
3652 
3653 /* Convert a DWARF value form code into its string name.  */
3654 
3655 static char *
3656 dwarf_form_name (form)
3657      register unsigned form;
3658 {
3659   switch (form)
3660     {
3661     case DW_FORM_addr:
3662       return "DW_FORM_addr";
3663     case DW_FORM_block2:
3664       return "DW_FORM_block2";
3665     case DW_FORM_block4:
3666       return "DW_FORM_block4";
3667     case DW_FORM_data2:
3668       return "DW_FORM_data2";
3669     case DW_FORM_data4:
3670       return "DW_FORM_data4";
3671     case DW_FORM_data8:
3672       return "DW_FORM_data8";
3673     case DW_FORM_string:
3674       return "DW_FORM_string";
3675     case DW_FORM_block:
3676       return "DW_FORM_block";
3677     case DW_FORM_block1:
3678       return "DW_FORM_block1";
3679     case DW_FORM_data1:
3680       return "DW_FORM_data1";
3681     case DW_FORM_flag:
3682       return "DW_FORM_flag";
3683     case DW_FORM_sdata:
3684       return "DW_FORM_sdata";
3685     case DW_FORM_strp:
3686       return "DW_FORM_strp";
3687     case DW_FORM_udata:
3688       return "DW_FORM_udata";
3689     case DW_FORM_ref_addr:
3690       return "DW_FORM_ref_addr";
3691     case DW_FORM_ref1:
3692       return "DW_FORM_ref1";
3693     case DW_FORM_ref2:
3694       return "DW_FORM_ref2";
3695     case DW_FORM_ref4:
3696       return "DW_FORM_ref4";
3697     case DW_FORM_ref8:
3698       return "DW_FORM_ref8";
3699     case DW_FORM_ref_udata:
3700       return "DW_FORM_ref_udata";
3701     case DW_FORM_indirect:
3702       return "DW_FORM_indirect";
3703     default:
3704       return "DW_FORM_<unknown>";
3705     }
3706 }
3707 
3708 /* Convert a DWARF stack opcode into its string name.  */
3709 
3710 static char *
3711 dwarf_stack_op_name (op)
3712      register unsigned op;
3713 {
3714   switch (op)
3715     {
3716     case DW_OP_addr:
3717       return "DW_OP_addr";
3718     case DW_OP_deref:
3719       return "DW_OP_deref";
3720     case DW_OP_const1u:
3721       return "DW_OP_const1u";
3722     case DW_OP_const1s:
3723       return "DW_OP_const1s";
3724     case DW_OP_const2u:
3725       return "DW_OP_const2u";
3726     case DW_OP_const2s:
3727       return "DW_OP_const2s";
3728     case DW_OP_const4u:
3729       return "DW_OP_const4u";
3730     case DW_OP_const4s:
3731       return "DW_OP_const4s";
3732     case DW_OP_const8u:
3733       return "DW_OP_const8u";
3734     case DW_OP_const8s:
3735       return "DW_OP_const8s";
3736     case DW_OP_constu:
3737       return "DW_OP_constu";
3738     case DW_OP_consts:
3739       return "DW_OP_consts";
3740     case DW_OP_dup:
3741       return "DW_OP_dup";
3742     case DW_OP_drop:
3743       return "DW_OP_drop";
3744     case DW_OP_over:
3745       return "DW_OP_over";
3746     case DW_OP_pick:
3747       return "DW_OP_pick";
3748     case DW_OP_swap:
3749       return "DW_OP_swap";
3750     case DW_OP_rot:
3751       return "DW_OP_rot";
3752     case DW_OP_xderef:
3753       return "DW_OP_xderef";
3754     case DW_OP_abs:
3755       return "DW_OP_abs";
3756     case DW_OP_and:
3757       return "DW_OP_and";
3758     case DW_OP_div:
3759       return "DW_OP_div";
3760     case DW_OP_minus:
3761       return "DW_OP_minus";
3762     case DW_OP_mod:
3763       return "DW_OP_mod";
3764     case DW_OP_mul:
3765       return "DW_OP_mul";
3766     case DW_OP_neg:
3767       return "DW_OP_neg";
3768     case DW_OP_not:
3769       return "DW_OP_not";
3770     case DW_OP_or:
3771       return "DW_OP_or";
3772     case DW_OP_plus:
3773       return "DW_OP_plus";
3774     case DW_OP_plus_uconst:
3775       return "DW_OP_plus_uconst";
3776     case DW_OP_shl:
3777       return "DW_OP_shl";
3778     case DW_OP_shr:
3779       return "DW_OP_shr";
3780     case DW_OP_shra:
3781       return "DW_OP_shra";
3782     case DW_OP_xor:
3783       return "DW_OP_xor";
3784     case DW_OP_bra:
3785       return "DW_OP_bra";
3786     case DW_OP_eq:
3787       return "DW_OP_eq";
3788     case DW_OP_ge:
3789       return "DW_OP_ge";
3790     case DW_OP_gt:
3791       return "DW_OP_gt";
3792     case DW_OP_le:
3793       return "DW_OP_le";
3794     case DW_OP_lt:
3795       return "DW_OP_lt";
3796     case DW_OP_ne:
3797       return "DW_OP_ne";
3798     case DW_OP_skip:
3799       return "DW_OP_skip";
3800     case DW_OP_lit0:
3801       return "DW_OP_lit0";
3802     case DW_OP_lit1:
3803       return "DW_OP_lit1";
3804     case DW_OP_lit2:
3805       return "DW_OP_lit2";
3806     case DW_OP_lit3:
3807       return "DW_OP_lit3";
3808     case DW_OP_lit4:
3809       return "DW_OP_lit4";
3810     case DW_OP_lit5:
3811       return "DW_OP_lit5";
3812     case DW_OP_lit6:
3813       return "DW_OP_lit6";
3814     case DW_OP_lit7:
3815       return "DW_OP_lit7";
3816     case DW_OP_lit8:
3817       return "DW_OP_lit8";
3818     case DW_OP_lit9:
3819       return "DW_OP_lit9";
3820     case DW_OP_lit10:
3821       return "DW_OP_lit10";
3822     case DW_OP_lit11:
3823       return "DW_OP_lit11";
3824     case DW_OP_lit12:
3825       return "DW_OP_lit12";
3826     case DW_OP_lit13:
3827       return "DW_OP_lit13";
3828     case DW_OP_lit14:
3829       return "DW_OP_lit14";
3830     case DW_OP_lit15:
3831       return "DW_OP_lit15";
3832     case DW_OP_lit16:
3833       return "DW_OP_lit16";
3834     case DW_OP_lit17:
3835       return "DW_OP_lit17";
3836     case DW_OP_lit18:
3837       return "DW_OP_lit18";
3838     case DW_OP_lit19:
3839       return "DW_OP_lit19";
3840     case DW_OP_lit20:
3841       return "DW_OP_lit20";
3842     case DW_OP_lit21:
3843       return "DW_OP_lit21";
3844     case DW_OP_lit22:
3845       return "DW_OP_lit22";
3846     case DW_OP_lit23:
3847       return "DW_OP_lit23";
3848     case DW_OP_lit24:
3849       return "DW_OP_lit24";
3850     case DW_OP_lit25:
3851       return "DW_OP_lit25";
3852     case DW_OP_lit26:
3853       return "DW_OP_lit26";
3854     case DW_OP_lit27:
3855       return "DW_OP_lit27";
3856     case DW_OP_lit28:
3857       return "DW_OP_lit28";
3858     case DW_OP_lit29:
3859       return "DW_OP_lit29";
3860     case DW_OP_lit30:
3861       return "DW_OP_lit30";
3862     case DW_OP_lit31:
3863       return "DW_OP_lit31";
3864     case DW_OP_reg0:
3865       return "DW_OP_reg0";
3866     case DW_OP_reg1:
3867       return "DW_OP_reg1";
3868     case DW_OP_reg2:
3869       return "DW_OP_reg2";
3870     case DW_OP_reg3:
3871       return "DW_OP_reg3";
3872     case DW_OP_reg4:
3873       return "DW_OP_reg4";
3874     case DW_OP_reg5:
3875       return "DW_OP_reg5";
3876     case DW_OP_reg6:
3877       return "DW_OP_reg6";
3878     case DW_OP_reg7:
3879       return "DW_OP_reg7";
3880     case DW_OP_reg8:
3881       return "DW_OP_reg8";
3882     case DW_OP_reg9:
3883       return "DW_OP_reg9";
3884     case DW_OP_reg10:
3885       return "DW_OP_reg10";
3886     case DW_OP_reg11:
3887       return "DW_OP_reg11";
3888     case DW_OP_reg12:
3889       return "DW_OP_reg12";
3890     case DW_OP_reg13:
3891       return "DW_OP_reg13";
3892     case DW_OP_reg14:
3893       return "DW_OP_reg14";
3894     case DW_OP_reg15:
3895       return "DW_OP_reg15";
3896     case DW_OP_reg16:
3897       return "DW_OP_reg16";
3898     case DW_OP_reg17:
3899       return "DW_OP_reg17";
3900     case DW_OP_reg18:
3901       return "DW_OP_reg18";
3902     case DW_OP_reg19:
3903       return "DW_OP_reg19";
3904     case DW_OP_reg20:
3905       return "DW_OP_reg20";
3906     case DW_OP_reg21:
3907       return "DW_OP_reg21";
3908     case DW_OP_reg22:
3909       return "DW_OP_reg22";
3910     case DW_OP_reg23:
3911       return "DW_OP_reg23";
3912     case DW_OP_reg24:
3913       return "DW_OP_reg24";
3914     case DW_OP_reg25:
3915       return "DW_OP_reg25";
3916     case DW_OP_reg26:
3917       return "DW_OP_reg26";
3918     case DW_OP_reg27:
3919       return "DW_OP_reg27";
3920     case DW_OP_reg28:
3921       return "DW_OP_reg28";
3922     case DW_OP_reg29:
3923       return "DW_OP_reg29";
3924     case DW_OP_reg30:
3925       return "DW_OP_reg30";
3926     case DW_OP_reg31:
3927       return "DW_OP_reg31";
3928     case DW_OP_breg0:
3929       return "DW_OP_breg0";
3930     case DW_OP_breg1:
3931       return "DW_OP_breg1";
3932     case DW_OP_breg2:
3933       return "DW_OP_breg2";
3934     case DW_OP_breg3:
3935       return "DW_OP_breg3";
3936     case DW_OP_breg4:
3937       return "DW_OP_breg4";
3938     case DW_OP_breg5:
3939       return "DW_OP_breg5";
3940     case DW_OP_breg6:
3941       return "DW_OP_breg6";
3942     case DW_OP_breg7:
3943       return "DW_OP_breg7";
3944     case DW_OP_breg8:
3945       return "DW_OP_breg8";
3946     case DW_OP_breg9:
3947       return "DW_OP_breg9";
3948     case DW_OP_breg10:
3949       return "DW_OP_breg10";
3950     case DW_OP_breg11:
3951       return "DW_OP_breg11";
3952     case DW_OP_breg12:
3953       return "DW_OP_breg12";
3954     case DW_OP_breg13:
3955       return "DW_OP_breg13";
3956     case DW_OP_breg14:
3957       return "DW_OP_breg14";
3958     case DW_OP_breg15:
3959       return "DW_OP_breg15";
3960     case DW_OP_breg16:
3961       return "DW_OP_breg16";
3962     case DW_OP_breg17:
3963       return "DW_OP_breg17";
3964     case DW_OP_breg18:
3965       return "DW_OP_breg18";
3966     case DW_OP_breg19:
3967       return "DW_OP_breg19";
3968     case DW_OP_breg20:
3969       return "DW_OP_breg20";
3970     case DW_OP_breg21:
3971       return "DW_OP_breg21";
3972     case DW_OP_breg22:
3973       return "DW_OP_breg22";
3974     case DW_OP_breg23:
3975       return "DW_OP_breg23";
3976     case DW_OP_breg24:
3977       return "DW_OP_breg24";
3978     case DW_OP_breg25:
3979       return "DW_OP_breg25";
3980     case DW_OP_breg26:
3981       return "DW_OP_breg26";
3982     case DW_OP_breg27:
3983       return "DW_OP_breg27";
3984     case DW_OP_breg28:
3985       return "DW_OP_breg28";
3986     case DW_OP_breg29:
3987       return "DW_OP_breg29";
3988     case DW_OP_breg30:
3989       return "DW_OP_breg30";
3990     case DW_OP_breg31:
3991       return "DW_OP_breg31";
3992     case DW_OP_regx:
3993       return "DW_OP_regx";
3994     case DW_OP_fbreg:
3995       return "DW_OP_fbreg";
3996     case DW_OP_bregx:
3997       return "DW_OP_bregx";
3998     case DW_OP_piece:
3999       return "DW_OP_piece";
4000     case DW_OP_deref_size:
4001       return "DW_OP_deref_size";
4002     case DW_OP_xderef_size:
4003       return "DW_OP_xderef_size";
4004     case DW_OP_nop:
4005       return "DW_OP_nop";
4006     default:
4007       return "OP_<unknown>";
4008     }
4009 }
4010 
4011 static char *
4012 dwarf_bool_name (bool)
4013      unsigned bool;
4014 {
4015   if (bool)
4016     return "TRUE";
4017   else
4018     return "FALSE";
4019 }
4020 
4021 /* Convert a DWARF type code into its string name.  */
4022 
4023 static char *
4024 dwarf_type_encoding_name (enc)
4025      register unsigned enc;
4026 {
4027   switch (enc)
4028     {
4029     case DW_ATE_address:
4030       return "DW_ATE_address";
4031     case DW_ATE_boolean:
4032       return "DW_ATE_boolean";
4033     case DW_ATE_complex_float:
4034       return "DW_ATE_complex_float";
4035     case DW_ATE_float:
4036       return "DW_ATE_float";
4037     case DW_ATE_signed:
4038       return "DW_ATE_signed";
4039     case DW_ATE_signed_char:
4040       return "DW_ATE_signed_char";
4041     case DW_ATE_unsigned:
4042       return "DW_ATE_unsigned";
4043     case DW_ATE_unsigned_char:
4044       return "DW_ATE_unsigned_char";
4045     default:
4046       return "DW_ATE_<unknown>";
4047     }
4048 }
4049 
4050 /* Convert a DWARF call frame info operation to its string name. */
4051 
4052 static char *
4053 dwarf_cfi_name (cfi_opc)
4054      register unsigned cfi_opc;
4055 {
4056   switch (cfi_opc)
4057     {
4058     case DW_CFA_advance_loc:
4059       return "DW_CFA_advance_loc";
4060     case DW_CFA_offset:
4061       return "DW_CFA_offset";
4062     case DW_CFA_restore:
4063       return "DW_CFA_restore";
4064     case DW_CFA_nop:
4065       return "DW_CFA_nop";
4066     case DW_CFA_set_loc:
4067       return "DW_CFA_set_loc";
4068     case DW_CFA_advance_loc1:
4069       return "DW_CFA_advance_loc1";
4070     case DW_CFA_advance_loc2:
4071       return "DW_CFA_advance_loc2";
4072     case DW_CFA_advance_loc4:
4073       return "DW_CFA_advance_loc4";
4074     case DW_CFA_offset_extended:
4075       return "DW_CFA_offset_extended";
4076     case DW_CFA_restore_extended:
4077       return "DW_CFA_restore_extended";
4078     case DW_CFA_undefined:
4079       return "DW_CFA_undefined";
4080     case DW_CFA_same_value:
4081       return "DW_CFA_same_value";
4082     case DW_CFA_register:
4083       return "DW_CFA_register";
4084     case DW_CFA_remember_state:
4085       return "DW_CFA_remember_state";
4086     case DW_CFA_restore_state:
4087       return "DW_CFA_restore_state";
4088     case DW_CFA_def_cfa:
4089       return "DW_CFA_def_cfa";
4090     case DW_CFA_def_cfa_register:
4091       return "DW_CFA_def_cfa_register";
4092     case DW_CFA_def_cfa_offset:
4093       return "DW_CFA_def_cfa_offset";
4094       /* SGI/MIPS specific */
4095     case DW_CFA_MIPS_advance_loc8:
4096       return "DW_CFA_MIPS_advance_loc8";
4097     default:
4098       return "DW_CFA_<unknown>";
4099     }
4100 }
4101 
4102 void
4103 dump_die (die)
4104      struct die_info *die;
4105 {
4106   int i;
4107 
4108   fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n",
4109 	   dwarf_tag_name (die->tag), die->abbrev, die->offset);
4110   fprintf (stderr, "\thas children: %s\n",
4111 	   dwarf_bool_name (die->has_children));
4112 
4113   fprintf (stderr, "\tattributes:\n");
4114   for (i = 0; i < die->num_attrs; ++i)
4115     {
4116       fprintf (stderr, "\t\t%s (%s) ",
4117 	       dwarf_attr_name (die->attrs[i].name),
4118 	       dwarf_form_name (die->attrs[i].form));
4119       switch (die->attrs[i].form)
4120 	{
4121 	case DW_FORM_ref_addr:
4122 	case DW_FORM_addr:
4123 	  fprintf (stderr, sizeof (CORE_ADDR) > sizeof (long) ?
4124 		   "address: 0x%LLx" : "address: 0x%x",
4125 		   die->attrs[i].u.addr);
4126 	  break;
4127 	case DW_FORM_block2:
4128 	case DW_FORM_block4:
4129 	case DW_FORM_block:
4130 	case DW_FORM_block1:
4131 	  fprintf (stderr, "block: size %d",
4132 		   die->attrs[i].u.blk->size);
4133 	  break;
4134 	case DW_FORM_data1:
4135 	case DW_FORM_data2:
4136 	case DW_FORM_data4:
4137 	case DW_FORM_ref1:
4138 	case DW_FORM_ref2:
4139 	case DW_FORM_ref4:
4140 	case DW_FORM_udata:
4141 	case DW_FORM_sdata:
4142 	  fprintf (stderr, "constant: %d", die->attrs[i].u.unsnd);
4143 	  break;
4144 	case DW_FORM_string:
4145 	  fprintf (stderr, "string: \"%s\"", die->attrs[i].u.str);
4146 	  break;
4147 	case DW_FORM_flag:
4148 	  if (die->attrs[i].u.unsnd)
4149 	    fprintf (stderr, "flag: TRUE");
4150 	  else
4151 	    fprintf (stderr, "flag: FALSE");
4152 	  break;
4153 	case DW_FORM_strp:	/* we do not support separate string
4154 				   section yet */
4155 	case DW_FORM_indirect:	/* we do not handle indirect yet */
4156 	case DW_FORM_data8:	/* we do not have 64 bit quantities */
4157 	  error ("Dwarf Error: Unsupported attribute form: %d.",
4158 		 die->attrs[i].form);
4159 	}
4160       fprintf (stderr, "\n");
4161     }
4162 }
4163 
4164 void
4165 dump_die_list (die)
4166      struct die_info *die;
4167 {
4168   while (die)
4169     {
4170       dump_die (die);
4171       die = die->next;
4172     }
4173 }
4174 
4175 void
4176 store_in_ref_table (offset, die)
4177      unsigned int offset;
4178      struct die_info *die;
4179 {
4180   int h;
4181   struct die_info *old;
4182 
4183   h = (offset % REF_HASH_SIZE);
4184   old = die_ref_table[h];
4185   die->next_ref = old;
4186   die_ref_table[h] = die;
4187 }
4188 
4189 struct die_info *
4190 follow_die_ref (offset)
4191      unsigned int offset;
4192 {
4193   struct die_info *die;
4194   int h;
4195 
4196   h = (offset % REF_HASH_SIZE);
4197   die = die_ref_table[h];
4198   while (die)
4199     {
4200       if (die->offset == offset)
4201 	{
4202 	  return die;
4203 	}
4204       die = die->next_ref;
4205     }
4206   return NULL;
4207 }
4208 
4209 static struct type *
4210 dwarf2_fundamental_type (objfile, typeid)
4211      struct objfile *objfile;
4212      int typeid;
4213 {
4214   if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
4215     {
4216       error ("Dwarf Error: internal error - invalid fundamental type id %d.",
4217 	     typeid);
4218     }
4219 
4220   /* Look for this particular type in the fundamental type vector.  If
4221      one is not found, create and install one appropriate for the
4222      current language and the current target machine. */
4223 
4224   if (ftypes[typeid] == NULL)
4225     {
4226       ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
4227     }
4228 
4229   return (ftypes[typeid]);
4230 }
4231 
4232 /* Decode simple location descriptions.
4233    There are three cases:
4234        An address: return the address.
4235        An address relative to frame pointer: return the offset.
4236        A register: return register number and set isreg to true.
4237        A constant followed by plus: return the constant.  */
4238 
4239 static CORE_ADDR
4240 decode_locdesc (blk, objfile)
4241      struct dwarf_block *blk;
4242      struct objfile *objfile;
4243 {
4244   int i, snd;
4245   int size = blk->size;
4246   char *data = blk->data;
4247   unsigned int bytes_read, unsnd;
4248   unsigned char op;
4249   union
4250     {
4251       CORE_ADDR addr;
4252       char bytes[sizeof (CORE_ADDR)];
4253     }
4254   u;
4255 
4256   i = 0;
4257   isreg = 0;
4258   offreg = 0;
4259 
4260   /* FIXME: handle more general forms of location descriptors.  */
4261   while (i < size)
4262     {
4263       op = data[i++];
4264       switch (op)
4265 	{
4266 	case DW_OP_reg0:
4267 	  isreg = 1;
4268 	  return 0;
4269 	case DW_OP_reg1:
4270 	  isreg = 1;
4271 	  return 1;
4272 	case DW_OP_reg2:
4273 	  isreg = 1;
4274 	  return 2;
4275 	case DW_OP_reg3:
4276 	  isreg = 1;
4277 	  return 3;
4278 	case DW_OP_reg4:
4279 	  isreg = 1;
4280 	  return 4;
4281 	case DW_OP_reg5:
4282 	  isreg = 1;
4283 	  return 5;
4284 	case DW_OP_reg6:
4285 	  isreg = 1;
4286 	  return 6;
4287 	case DW_OP_reg7:
4288 	  isreg = 1;
4289 	  return 7;
4290 	case DW_OP_reg8:
4291 	  isreg = 1;
4292 	  return 8;
4293 	case DW_OP_reg9:
4294 	  isreg = 1;
4295 	  return 9;
4296 	case DW_OP_reg10:
4297 	  isreg = 1;
4298 	  return 10;
4299 	case DW_OP_reg11:
4300 	  isreg = 1;
4301 	  return 11;
4302 	case DW_OP_reg12:
4303 	  isreg = 1;
4304 	  return 12;
4305 	case DW_OP_reg13:
4306 	  isreg = 1;
4307 	  return 13;
4308 	case DW_OP_reg14:
4309 	  isreg = 1;
4310 	  return 14;
4311 	case DW_OP_reg15:
4312 	  isreg = 1;
4313 	  return 15;
4314 	case DW_OP_reg16:
4315 	  isreg = 1;
4316 	  return 16;
4317 	case DW_OP_reg17:
4318 	  isreg = 1;
4319 	  return 17;
4320 	case DW_OP_reg18:
4321 	  isreg = 1;
4322 	  return 18;
4323 	case DW_OP_reg19:
4324 	  isreg = 1;
4325 	  return 19;
4326 	case DW_OP_reg20:
4327 	  isreg = 1;
4328 	  return 20;
4329 	case DW_OP_reg21:
4330 	  isreg = 1;
4331 	  return 21;
4332 	case DW_OP_reg22:
4333 	  isreg = 1;
4334 	  return 22;
4335 	case DW_OP_reg23:
4336 	  isreg = 1;
4337 	  return 23;
4338 	case DW_OP_reg24:
4339 	  isreg = 1;
4340 	  return 24;
4341 	case DW_OP_reg25:
4342 	  isreg = 1;
4343 	  return 25;
4344 	case DW_OP_reg26:
4345 	  isreg = 1;
4346 	  return 26;
4347 	case DW_OP_reg27:
4348 	  isreg = 1;
4349 	  return 27;
4350 	case DW_OP_reg28:
4351 	  isreg = 1;
4352 	  return 28;
4353 	case DW_OP_reg29:
4354 	  isreg = 1;
4355 	  return 29;
4356 	case DW_OP_reg30:
4357 	  isreg = 1;
4358 	  return 30;
4359 	case DW_OP_reg31:
4360 	  isreg = 1;
4361 	  return 31;
4362 
4363 	case DW_OP_regx:
4364 	  isreg = 1;
4365 	  unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
4366 	  i += bytes_read;
4367 #if defined(HARRIS_TARGET) && defined(_M88K)
4368 	  /* The Harris 88110 gdb ports have long kept their special reg
4369 	     numbers between their gp-regs and their x-regs.  This is
4370 	     not how our dwarf is generated.  Punt. */
4371 	  return unsnd + 6;
4372 #else
4373 	  return unsnd;
4374 #endif
4375 
4376 	case DW_OP_fbreg:
4377 	case DW_OP_breg31:
4378 	  offreg = 1;
4379 	  snd = read_signed_leb128 (NULL, (data + i), &bytes_read);
4380 	  i += bytes_read;
4381 	  return snd;
4382 
4383 	case DW_OP_addr:
4384 	  isreg = 0;
4385 	  return read_address (objfile->obfd, &data[i]);
4386 
4387 	case DW_OP_constu:
4388 	  unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
4389 	  i += bytes_read;
4390 	  break;
4391 
4392 	case DW_OP_plus:
4393 	  return unsnd;
4394 
4395 	}
4396     }
4397   return 0;
4398 }
4399 
4400 /* memory allocation interface */
4401 
4402 static struct type *
4403 dwarf_alloc_type (objfile)
4404      struct objfile *objfile;
4405 {
4406   struct type *type;
4407 
4408   type = (struct type *) xmalloc (sizeof (struct type));
4409   memset (type, 0, sizeof (struct type));
4410 
4411 #if 0
4412   type = alloc_type (objfile);
4413 #endif
4414 
4415   return (type);
4416 }
4417 
4418 static struct abbrev_info *
4419 dwarf_alloc_abbrev ()
4420 {
4421   struct abbrev_info *abbrev;
4422 
4423   abbrev = xmalloc (sizeof (struct abbrev_info));
4424   memset (abbrev, 0, sizeof (struct abbrev_info));
4425   return (abbrev);
4426 }
4427 
4428 static struct dwarf_block *
4429 dwarf_alloc_block ()
4430 {
4431   struct dwarf_block *blk;
4432 
4433   blk = (struct dwarf_block *) xmalloc (sizeof (struct dwarf_block));
4434   return (blk);
4435 }
4436 
4437 static struct die_info *
4438 dwarf_alloc_die ()
4439 {
4440   struct die_info *die;
4441 
4442   die = (struct die_info *) xmalloc (sizeof (struct die_info));
4443   memset (die, 0, sizeof (struct die_info));
4444   return (die);
4445 }
4446