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