OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [dwarf2read.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* DWARF 2 debugging format support for GDB.
2
   Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3
 
4
   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5
   Inc.  with support from Florida State University (under contract
6
   with the Ada Joint Program Office), and Silicon Graphics, Inc.
7
   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8
   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
9
   support in dwarfread.c
10
 
11
   This file is part of GDB.
12
 
13
   This program is free software; you can redistribute it and/or modify
14
   it under the terms of the GNU General Public License as published by
15
   the Free Software Foundation; either version 2 of the License, or (at
16
   your option) any later version.
17
 
18
   This program is distributed in the hope that it will be useful, but
19
   WITHOUT ANY WARRANTY; without even the implied warranty of
20
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
   General Public License for more details.
22
 
23
   You should have received a copy of the GNU General Public License
24
   along with this program; if not, write to the Free Software
25
   Foundation, Inc., 59 Temple Place - Suite 330,
26
   Boston, MA 02111-1307, USA.  */
27
 
28
#include "defs.h"
29
#include "bfd.h"
30
#include "symtab.h"
31
#include "gdbtypes.h"
32
#include "symfile.h"
33
#include "objfiles.h"
34
#include "elf/dwarf2.h"
35
#include "buildsym.h"
36
#include "demangle.h"
37
#include "expression.h"
38
#include "language.h"
39
#include "complaints.h"
40
 
41
#include <fcntl.h>
42
#include "gdb_string.h"
43
#include <sys/types.h>
44
 
45
/* .debug_info header for a compilation unit
46
   Because of alignment constraints, this structure has padding and cannot
47
   be mapped directly onto the beginning of the .debug_info section.  */
48
typedef struct comp_unit_header
49
  {
50
    unsigned int length;        /* length of the .debug_info
51
                                   contribution */
52
    unsigned short version;     /* version number -- 2 for DWARF
53
                                   version 2 */
54
    unsigned int abbrev_offset; /* offset into .debug_abbrev section */
55
    unsigned char addr_size;    /* byte size of an address -- 4 */
56
  }
57
_COMP_UNIT_HEADER;
58
#define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
59
 
60
/* .debug_pubnames header
61
   Because of alignment constraints, this structure has padding and cannot
62
   be mapped directly onto the beginning of the .debug_info section.  */
63
typedef struct pubnames_header
64
  {
65
    unsigned int length;        /* length of the .debug_pubnames
66
                                   contribution  */
67
    unsigned char version;      /* version number -- 2 for DWARF
68
                                   version 2 */
69
    unsigned int info_offset;   /* offset into .debug_info section */
70
    unsigned int info_size;     /* byte size of .debug_info section
71
                                   portion */
72
  }
73
_PUBNAMES_HEADER;
74
#define _ACTUAL_PUBNAMES_HEADER_SIZE 13
75
 
76
/* .debug_pubnames header
77
   Because of alignment constraints, this structure has padding and cannot
78
   be mapped directly onto the beginning of the .debug_info section.  */
79
typedef struct aranges_header
80
  {
81
    unsigned int length;        /* byte len of the .debug_aranges
82
                                   contribution */
83
    unsigned short version;     /* version number -- 2 for DWARF
84
                                   version 2 */
85
    unsigned int info_offset;   /* offset into .debug_info section */
86
    unsigned char addr_size;    /* byte size of an address */
87
    unsigned char seg_size;     /* byte size of segment descriptor */
88
  }
89
_ARANGES_HEADER;
90
#define _ACTUAL_ARANGES_HEADER_SIZE 12
91
 
92
/* .debug_line statement program prologue
93
   Because of alignment constraints, this structure has padding and cannot
94
   be mapped directly onto the beginning of the .debug_info section.  */
95
typedef struct statement_prologue
96
  {
97
    unsigned int total_length;  /* byte length of the statement
98
                                   information */
99
    unsigned short version;     /* version number -- 2 for DWARF
100
                                   version 2 */
101
    unsigned int prologue_length;       /* # bytes between prologue &
102
                                           stmt program */
103
    unsigned char minimum_instruction_length;   /* byte size of
104
                                                   smallest instr */
105
    unsigned char default_is_stmt;      /* initial value of is_stmt
106
                                           register */
107
    char line_base;
108
    unsigned char line_range;
109
    unsigned char opcode_base;  /* number assigned to first special
110
                                   opcode */
111
    unsigned char *standard_opcode_lengths;
112
  }
113
_STATEMENT_PROLOGUE;
114
 
115
/* offsets and sizes of debugging sections */
116
 
117
static file_ptr dwarf_info_offset;
118
static file_ptr dwarf_abbrev_offset;
119
static file_ptr dwarf_line_offset;
120
static file_ptr dwarf_pubnames_offset;
121
static file_ptr dwarf_aranges_offset;
122
static file_ptr dwarf_loc_offset;
123
static file_ptr dwarf_macinfo_offset;
124
static file_ptr dwarf_str_offset;
125
 
126
static unsigned int dwarf_info_size;
127
static unsigned int dwarf_abbrev_size;
128
static unsigned int dwarf_line_size;
129
static unsigned int dwarf_pubnames_size;
130
static unsigned int dwarf_aranges_size;
131
static unsigned int dwarf_loc_size;
132
static unsigned int dwarf_macinfo_size;
133
static unsigned int dwarf_str_size;
134
 
135
/* names of the debugging sections */
136
 
137
#define INFO_SECTION     ".debug_info"
138
#define ABBREV_SECTION   ".debug_abbrev"
139
#define LINE_SECTION     ".debug_line"
140
#define PUBNAMES_SECTION ".debug_pubnames"
141
#define ARANGES_SECTION  ".debug_aranges"
142
#define LOC_SECTION      ".debug_loc"
143
#define MACINFO_SECTION  ".debug_macinfo"
144
#define STR_SECTION      ".debug_str"
145
 
146
/* local data types */
147
 
148
/* The data in a compilation unit header looks like this.  */
149
struct comp_unit_head
150
  {
151
    unsigned int length;
152
    short version;
153
    unsigned int abbrev_offset;
154
    unsigned char addr_size;
155
  };
156
 
157
/* The data in the .debug_line statement prologue looks like this.  */
158
struct line_head
159
  {
160
    unsigned int total_length;
161
    unsigned short version;
162
    unsigned int prologue_length;
163
    unsigned char minimum_instruction_length;
164
    unsigned char default_is_stmt;
165
    int line_base;
166
    unsigned char line_range;
167
    unsigned char opcode_base;
168
    unsigned char *standard_opcode_lengths;
169
  };
170
 
171
/* When we construct a partial symbol table entry we only
172
   need this much information. */
173
struct partial_die_info
174
  {
175
    enum dwarf_tag tag;
176
    unsigned char has_children;
177
    unsigned char is_external;
178
    unsigned char is_declaration;
179
    unsigned char has_type;
180
    unsigned int offset;
181
    unsigned int abbrev;
182
    char *name;
183
    CORE_ADDR lowpc;
184
    CORE_ADDR highpc;
185
    struct dwarf_block *locdesc;
186
    unsigned int language;
187
    char *sibling;
188
  };
189
 
190
/* This data structure holds the information of an abbrev. */
191
struct abbrev_info
192
  {
193
    unsigned int number;        /* number identifying abbrev */
194
    enum dwarf_tag tag;         /* dwarf tag */
195
    int has_children;           /* boolean */
196
    unsigned int num_attrs;     /* number of attributes */
197
    struct attr_abbrev *attrs;  /* an array of attribute descriptions */
198
    struct abbrev_info *next;   /* next in chain */
199
  };
200
 
201
struct attr_abbrev
202
  {
203
    enum dwarf_attribute name;
204
    enum dwarf_form form;
205
  };
206
 
207
/* This data structure holds a complete die structure. */
208
struct die_info
209
  {
210
    enum dwarf_tag tag;         /* Tag indicating type of die */
211
    unsigned short has_children;        /* Does the die have children */
212
    unsigned int abbrev;        /* Abbrev number */
213
    unsigned int offset;        /* Offset in .debug_info section */
214
    unsigned int num_attrs;     /* Number of attributes */
215
    struct attribute *attrs;    /* An array of attributes */
216
    struct die_info *next_ref;  /* Next die in ref hash table */
217
    struct die_info *next;      /* Next die in linked list */
218
    struct type *type;          /* Cached type information */
219
  };
220
 
221
/* Attributes have a name and a value */
222
struct attribute
223
  {
224
    enum dwarf_attribute name;
225
    enum dwarf_form form;
226
    union
227
      {
228
        char *str;
229
        struct dwarf_block *blk;
230
        unsigned int unsnd;
231
        int snd;
232
        CORE_ADDR addr;
233
      }
234
    u;
235
  };
236
 
237
/* Get at parts of an attribute structure */
238
 
239
#define DW_STRING(attr)    ((attr)->u.str)
240
#define DW_UNSND(attr)     ((attr)->u.unsnd)
241
#define DW_BLOCK(attr)     ((attr)->u.blk)
242
#define DW_SND(attr)       ((attr)->u.snd)
243
#define DW_ADDR(attr)      ((attr)->u.addr)
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
static struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE];
262
 
263
/* A hash table of die offsets for following references.  */
264
#ifndef REF_HASH_SIZE
265
#define REF_HASH_SIZE 1021
266
#endif
267
 
268
static struct die_info *die_ref_table[REF_HASH_SIZE];
269
 
270
/* Obstack for allocating temporary storage used during symbol reading.  */
271
static struct obstack dwarf2_tmp_obstack;
272
 
273
/* Offset to the first byte of the current compilation unit header,
274
   for resolving relative reference dies. */
275
static unsigned int cu_header_offset;
276
 
277
/* Allocate fields for structs, unions and enums in this size.  */
278
#ifndef DW_FIELD_ALLOC_CHUNK
279
#define DW_FIELD_ALLOC_CHUNK 4
280
#endif
281
 
282
/* The language we are debugging.  */
283
static enum language cu_language;
284
static const struct language_defn *cu_language_defn;
285
 
286
/* Actually data from the sections.  */
287
static char *dwarf_info_buffer;
288
static char *dwarf_abbrev_buffer;
289
static char *dwarf_line_buffer;
290
 
291
/* A zeroed version of a partial die for initialization purposes.  */
292
static struct partial_die_info zeroed_partial_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
 
305
/* FIXME: decode_locdesc sets these variables to describe the location
306
   to the caller.  These ought to be a structure or something.   If
307
   none of the flags are set, the object lives at the address returned
308
   by decode_locdesc.  */
309
 
310
static int optimized_out;       /* No ops in location in expression,
311
                                   so object was optimized out.  */
312
static int isreg;               /* Object lives in register.
313
                                   decode_locdesc's return value is
314
                                   the register number.  */
315
static int offreg;              /* Object's address is the sum of the
316
                                   register specified by basereg, plus
317
                                   the offset returned.  */
318
static int basereg;             /* See `offreg'.  */
319
static int isderef;             /* Value described by flags above is
320
                                   the address of a pointer to the object.  */
321
static int islocal;             /* Variable is at the returned offset
322
                                   from the frame start, but there's
323
                                   no identified frame pointer for
324
                                   this function, so we can't say
325
                                   which register it's relative to;
326
                                   use LOC_LOCAL.  */
327
 
328
/* DW_AT_frame_base values for the current function.
329
   frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
330
   contains the register number for the frame register.
331
   frame_base_offset is the offset from the frame register to the
332
   virtual stack frame. */
333
static int frame_base_reg;
334
static CORE_ADDR frame_base_offset;
335
 
336
/* This value is added to each symbol value.  FIXME:  Generalize to
337
   the section_offsets structure used by dbxread (once this is done,
338
   pass the appropriate section number to end_symtab).  */
339
static CORE_ADDR baseaddr;      /* Add to each symbol value */
340
 
341
/* We put a pointer to this structure in the read_symtab_private field
342
   of the psymtab.
343
   The complete dwarf information for an objfile is kept in the
344
   psymbol_obstack, so that absolute die references can be handled.
345
   Most of the information in this structure is related to an entire
346
   object file and could be passed via the sym_private field of the objfile.
347
   It is however conceivable that dwarf2 might not be the only type
348
   of symbols read from an object file.  */
349
 
350
struct dwarf2_pinfo
351
  {
352
    /* Pointer to start of dwarf info buffer for the objfile.  */
353
 
354
    char *dwarf_info_buffer;
355
 
356
    /* Offset in dwarf_info_buffer for this compilation unit. */
357
 
358
    unsigned long dwarf_info_offset;
359
 
360
    /* Pointer to start of dwarf abbreviation buffer for the objfile.  */
361
 
362
    char *dwarf_abbrev_buffer;
363
 
364
    /* Size of dwarf abbreviation section for the objfile.  */
365
 
366
    unsigned int dwarf_abbrev_size;
367
 
368
    /* Pointer to start of dwarf line buffer for the objfile.  */
369
 
370
    char *dwarf_line_buffer;
371
  };
372
 
373
#define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
374
#define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
375
#define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
376
#define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
377
#define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
378
#define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
379
 
380
/* Maintain an array of referenced fundamental types for the current
381
   compilation unit being read.  For DWARF version 1, we have to construct
382
   the fundamental types on the fly, since no information about the
383
   fundamental types is supplied.  Each such fundamental type is created by
384
   calling a language dependent routine to create the type, and then a
385
   pointer to that type is then placed in the array at the index specified
386
   by it's FT_<TYPENAME> value.  The array has a fixed size set by the
387
   FT_NUM_MEMBERS compile time constant, which is the number of predefined
388
   fundamental types gdb knows how to construct.  */
389
static struct type *ftypes[FT_NUM_MEMBERS];     /* Fundamental types */
390
 
391
/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
392
   but this would require a corresponding change in unpack_field_as_long
393
   and friends.  */
394
static int bits_per_byte = 8;
395
 
396
/* The routines that read and process dies for a C struct or C++ class
397
   pass lists of data member fields and lists of member function fields
398
   in an instance of a field_info structure, as defined below.  */
399
struct field_info
400
  {
401
    /* List of data member and baseclasses fields. */
402
    struct nextfield
403
      {
404
        struct nextfield *next;
405
        int accessibility;
406
        int virtuality;
407
        struct field field;
408
      }
409
     *fields;
410
 
411
    /* Number of fields.  */
412
    int nfields;
413
 
414
    /* Number of baseclasses.  */
415
    int nbaseclasses;
416
 
417
    /* Set if the accesibility of one of the fields is not public.  */
418
    int non_public_fields;
419
 
420
    /* Member function fields array, entries are allocated in the order they
421
       are encountered in the object file.  */
422
    struct nextfnfield
423
      {
424
        struct nextfnfield *next;
425
        struct fn_field fnfield;
426
      }
427
     *fnfields;
428
 
429
    /* Member function fieldlist array, contains name of possibly overloaded
430
       member function, number of overloaded member functions and a pointer
431
       to the head of the member function field chain.  */
432
    struct fnfieldlist
433
      {
434
        char *name;
435
        int length;
436
        struct nextfnfield *head;
437
      }
438
     *fnfieldlists;
439
 
440
    /* Number of entries in the fnfieldlists array.  */
441
    int nfnfields;
442
  };
443
 
444
/* FIXME: Kludge to mark a varargs function type for C++ member function
445
   argument processing.  */
446
#define TYPE_FLAG_VARARGS       (1 << 10)
447
 
448
/* Dwarf2 has no clean way to discern C++ static and non-static member
449
   functions. G++ helps GDB by marking the first parameter for non-static
450
   member functions (which is the this pointer) as artificial.
451
   We pass this information between dwarf2_add_member_fn and
452
   read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
453
#define TYPE_FIELD_ARTIFICIAL   TYPE_FIELD_BITPOS
454
 
455
/* Various complaints about symbol reading that don't abort the process */
456
 
457
static struct complaint dwarf2_const_ignored =
458
{
459
  "type qualifier 'const' ignored", 0, 0
460
};
461
static struct complaint dwarf2_volatile_ignored =
462
{
463
  "type qualifier 'volatile' ignored", 0, 0
464
};
465
static struct complaint dwarf2_non_const_array_bound_ignored =
466
{
467
  "non-constant array bounds form '%s' ignored", 0, 0
468
};
469
static struct complaint dwarf2_missing_line_number_section =
470
{
471
  "missing .debug_line section", 0, 0
472
};
473
static struct complaint dwarf2_mangled_line_number_section =
474
{
475
  "mangled .debug_line section", 0, 0
476
};
477
static struct complaint dwarf2_unsupported_die_ref_attr =
478
{
479
  "unsupported die ref attribute form: '%s'", 0, 0
480
};
481
static struct complaint dwarf2_unsupported_stack_op =
482
{
483
  "unsupported stack op: '%s'", 0, 0
484
};
485
static struct complaint dwarf2_complex_location_expr =
486
{
487
  "location expression too complex", 0, 0
488
};
489
static struct complaint dwarf2_unsupported_tag =
490
{
491
  "unsupported tag: '%s'", 0, 0
492
};
493
static struct complaint dwarf2_unsupported_at_encoding =
494
{
495
  "unsupported DW_AT_encoding: '%s'", 0, 0
496
};
497
static struct complaint dwarf2_unsupported_at_frame_base =
498
{
499
  "unsupported DW_AT_frame_base for function '%s'", 0, 0
500
};
501
static struct complaint dwarf2_unexpected_tag =
502
{
503
  "unexepected tag in read_type_die: '%s'", 0, 0
504
};
505
static struct complaint dwarf2_missing_at_frame_base =
506
{
507
  "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
508
};
509
static struct complaint dwarf2_bad_static_member_name =
510
{
511
  "unrecognized static data member name '%s'", 0, 0
512
};
513
static struct complaint dwarf2_unsupported_accessibility =
514
{
515
  "unsupported accessibility %d", 0, 0
516
};
517
static struct complaint dwarf2_bad_member_name_complaint =
518
{
519
  "cannot extract member name from '%s'", 0, 0
520
};
521
static struct complaint dwarf2_missing_member_fn_type_complaint =
522
{
523
  "member function type missing for '%s'", 0, 0
524
};
525
static struct complaint dwarf2_vtbl_not_found_complaint =
526
{
527
  "virtual function table pointer not found when defining class '%s'", 0, 0
528
};
529
static struct complaint dwarf2_absolute_sibling_complaint =
530
{
531
  "ignoring absolute DW_AT_sibling", 0, 0
532
};
533
static struct complaint dwarf2_const_value_length_mismatch =
534
{
535
  "const value length mismatch for '%s', got %d, expected %d", 0, 0
536
};
537
static struct complaint dwarf2_unsupported_const_value_attr =
538
{
539
  "unsupported const value attribute form: '%s'", 0, 0
540
};
541
 
542
/* Remember the addr_size read from the dwarf.
543
   If a target expects to link compilation units with differing address
544
   sizes, gdb needs to be sure that the appropriate size is here for
545
   whatever scope is currently getting read. */
546
static int address_size;
547
 
548
/* Externals references.  */
549
extern int info_verbose;        /* From main.c; nonzero => verbose */
550
 
551
/* local function prototypes */
552
 
553
static void dwarf2_locate_sections PARAMS ((bfd *, asection *, PTR));
554
 
555
#if 0
556
static void dwarf2_build_psymtabs_easy PARAMS ((struct objfile *, int));
557
#endif
558
 
559
static void dwarf2_build_psymtabs_hard PARAMS ((struct objfile *, int));
560
 
561
static char *scan_partial_symbols PARAMS ((char *, struct objfile *,
562
                                           CORE_ADDR *, CORE_ADDR *));
563
 
564
static void add_partial_symbol PARAMS ((struct partial_die_info *,
565
                                        struct objfile *));
566
 
567
static void dwarf2_psymtab_to_symtab PARAMS ((struct partial_symtab *));
568
 
569
static void psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
570
 
571
static char *dwarf2_read_section PARAMS ((struct objfile *, file_ptr,
572
                                          unsigned int));
573
 
574
static void dwarf2_read_abbrevs PARAMS ((bfd *, unsigned int));
575
 
576
static void dwarf2_empty_abbrev_table PARAMS ((PTR));
577
 
578
static struct abbrev_info *dwarf2_lookup_abbrev PARAMS ((unsigned int));
579
 
580
static char *read_partial_die PARAMS ((struct partial_die_info *,
581
                                       bfd *, char *, int *));
582
 
583
static char *read_full_die PARAMS ((struct die_info **, bfd *, char *));
584
 
585
static char *read_attribute PARAMS ((struct attribute *, struct attr_abbrev *,
586
                                     bfd *, char *));
587
 
588
static unsigned int read_1_byte PARAMS ((bfd *, char *));
589
 
590
static int read_1_signed_byte PARAMS ((bfd *, char *));
591
 
592
static unsigned int read_2_bytes PARAMS ((bfd *, char *));
593
 
594
static unsigned int read_4_bytes PARAMS ((bfd *, char *));
595
 
596
static unsigned int read_8_bytes PARAMS ((bfd *, char *));
597
 
598
static CORE_ADDR read_address PARAMS ((bfd *, char *));
599
 
600
static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int));
601
 
602
static char *read_string PARAMS ((bfd *, char *, unsigned int *));
603
 
604
static unsigned int read_unsigned_leb128 PARAMS ((bfd *, char *,
605
                                                  unsigned int *));
606
 
607
static int read_signed_leb128 PARAMS ((bfd *, char *, unsigned int *));
608
 
609
static void set_cu_language PARAMS ((unsigned int));
610
 
611
static struct attribute *dwarf_attr PARAMS ((struct die_info *,
612
                                             unsigned int));
613
 
614
static int die_is_declaration (struct die_info *);
615
 
616
static void dwarf_decode_lines PARAMS ((unsigned int, char *, bfd *));
617
 
618
static void dwarf2_start_subfile PARAMS ((char *, char *));
619
 
620
static struct symbol *new_symbol PARAMS ((struct die_info *, struct type *,
621
                                          struct objfile *));
622
 
623
static void dwarf2_const_value PARAMS ((struct attribute *, struct symbol *,
624
                                        struct objfile *));
625
 
626
static void dwarf2_const_value_data (struct attribute *attr,
627
                                     struct symbol *sym,
628
                                     int bits);
629
 
630
static struct type *die_type PARAMS ((struct die_info *, struct objfile *));
631
 
632
static struct type *die_containing_type PARAMS ((struct die_info *,
633
                                                 struct objfile *));
634
 
635
#if 0
636
static struct type *type_at_offset PARAMS ((unsigned int, struct objfile *));
637
#endif
638
 
639
static struct type *tag_type_to_type PARAMS ((struct die_info *,
640
                                              struct objfile *));
641
 
642
static void read_type_die PARAMS ((struct die_info *, struct objfile *));
643
 
644
static void read_typedef PARAMS ((struct die_info *, struct objfile *));
645
 
646
static void read_base_type PARAMS ((struct die_info *, struct objfile *));
647
 
648
static void read_file_scope PARAMS ((struct die_info *, struct objfile *));
649
 
650
static void read_func_scope PARAMS ((struct die_info *, struct objfile *));
651
 
652
static void read_lexical_block_scope PARAMS ((struct die_info *,
653
                                              struct objfile *));
654
 
655
static int dwarf2_get_pc_bounds PARAMS ((struct die_info *,
656
                                         CORE_ADDR *, CORE_ADDR *,
657
                                         struct objfile *));
658
 
659
static void dwarf2_add_field PARAMS ((struct field_info *, struct die_info *,
660
                                      struct objfile *));
661
 
662
static void dwarf2_attach_fields_to_type PARAMS ((struct field_info *,
663
                                                  struct type *,
664
                                                  struct objfile *));
665
 
666
static void dwarf2_add_member_fn PARAMS ((struct field_info *,
667
                                          struct die_info *, struct type *,
668
                                          struct objfile * objfile));
669
 
670
static void dwarf2_attach_fn_fields_to_type PARAMS ((struct field_info *,
671
                                                     struct type *,
672
                                                     struct objfile *));
673
 
674
static void read_structure_scope PARAMS ((struct die_info *, struct objfile *));
675
 
676
static void read_common_block PARAMS ((struct die_info *, struct objfile *));
677
 
678
static void read_enumeration PARAMS ((struct die_info *, struct objfile *));
679
 
680
static struct type *dwarf_base_type PARAMS ((int, int, struct objfile *));
681
 
682
static CORE_ADDR decode_locdesc PARAMS ((struct dwarf_block *,
683
                                         struct objfile *));
684
 
685
static void read_array_type PARAMS ((struct die_info *, struct objfile *));
686
 
687
static void read_tag_pointer_type PARAMS ((struct die_info *,
688
                                           struct objfile *));
689
 
690
static void read_tag_ptr_to_member_type PARAMS ((struct die_info *,
691
                                                 struct objfile *));
692
 
693
static void read_tag_reference_type PARAMS ((struct die_info *,
694
                                             struct objfile *));
695
 
696
static void read_tag_const_type PARAMS ((struct die_info *, struct objfile *));
697
 
698
static void read_tag_volatile_type PARAMS ((struct die_info *,
699
                                            struct objfile *));
700
 
701
static void read_tag_string_type PARAMS ((struct die_info *,
702
                                          struct objfile *));
703
 
704
static void read_subroutine_type PARAMS ((struct die_info *,
705
                                          struct objfile *));
706
 
707
struct die_info *read_comp_unit PARAMS ((char *, bfd *));
708
 
709
static void free_die_list PARAMS ((struct die_info *));
710
 
711
static void process_die PARAMS ((struct die_info *, struct objfile *));
712
 
713
static char *dwarf2_linkage_name PARAMS ((struct die_info *));
714
 
715
static char *dwarf_tag_name PARAMS ((unsigned int));
716
 
717
static char *dwarf_attr_name PARAMS ((unsigned int));
718
 
719
static char *dwarf_form_name PARAMS ((unsigned int));
720
 
721
static char *dwarf_stack_op_name PARAMS ((unsigned int));
722
 
723
static char *dwarf_bool_name PARAMS ((unsigned int));
724
 
725
static char *dwarf_type_encoding_name PARAMS ((unsigned int));
726
 
727
#if 0
728
static char *dwarf_cfi_name PARAMS ((unsigned int));
729
 
730
struct die_info *copy_die PARAMS ((struct die_info *));
731
#endif
732
 
733
struct die_info *sibling_die PARAMS ((struct die_info *));
734
 
735
void dump_die PARAMS ((struct die_info *));
736
 
737
void dump_die_list PARAMS ((struct die_info *));
738
 
739
void store_in_ref_table PARAMS ((unsigned int, struct die_info *));
740
 
741
static void dwarf2_empty_die_ref_table PARAMS ((void));
742
 
743
static unsigned int dwarf2_get_ref_die_offset PARAMS ((struct attribute *));
744
 
745
struct die_info *follow_die_ref PARAMS ((unsigned int));
746
 
747
static struct type *dwarf2_fundamental_type PARAMS ((struct objfile *, int));
748
 
749
/* memory allocation interface */
750
 
751
static void dwarf2_free_tmp_obstack PARAMS ((PTR));
752
 
753
static struct dwarf_block *dwarf_alloc_block PARAMS ((void));
754
 
755
static struct abbrev_info *dwarf_alloc_abbrev PARAMS ((void));
756
 
757
static struct die_info *dwarf_alloc_die PARAMS ((void));
758
 
759
/* Try to locate the sections we need for DWARF 2 debugging
760
   information and return true if we have enough to do something.  */
761
 
762
int
763
dwarf2_has_info (abfd)
764
     bfd *abfd;
765
{
766
  dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
767
  bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
768
  if (dwarf_info_offset && dwarf_abbrev_offset)
769
    {
770
      return 1;
771
    }
772
  else
773
    {
774
      return 0;
775
    }
776
}
777
 
778
/* This function is mapped across the sections and remembers the
779
   offset and size of each of the debugging sections we are interested
780
   in.  */
781
 
782
static void
783
dwarf2_locate_sections (ignore_abfd, sectp, ignore_ptr)
784
     bfd *ignore_abfd;
785
     asection *sectp;
786
     PTR ignore_ptr;
787
{
788
  if (STREQ (sectp->name, INFO_SECTION))
789
    {
790
      dwarf_info_offset = sectp->filepos;
791
      dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
792
    }
793
  else if (STREQ (sectp->name, ABBREV_SECTION))
794
    {
795
      dwarf_abbrev_offset = sectp->filepos;
796
      dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
797
    }
798
  else if (STREQ (sectp->name, LINE_SECTION))
799
    {
800
      dwarf_line_offset = sectp->filepos;
801
      dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
802
    }
803
  else if (STREQ (sectp->name, PUBNAMES_SECTION))
804
    {
805
      dwarf_pubnames_offset = sectp->filepos;
806
      dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
807
    }
808
  else if (STREQ (sectp->name, ARANGES_SECTION))
809
    {
810
      dwarf_aranges_offset = sectp->filepos;
811
      dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
812
    }
813
  else if (STREQ (sectp->name, LOC_SECTION))
814
    {
815
      dwarf_loc_offset = sectp->filepos;
816
      dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
817
    }
818
  else if (STREQ (sectp->name, MACINFO_SECTION))
819
    {
820
      dwarf_macinfo_offset = sectp->filepos;
821
      dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
822
    }
823
  else if (STREQ (sectp->name, STR_SECTION))
824
    {
825
      dwarf_str_offset = sectp->filepos;
826
      dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
827
    }
828
}
829
 
830
/* Build a partial symbol table.  */
831
 
832
void
833
dwarf2_build_psymtabs (objfile, mainline)
834
     struct objfile *objfile;
835
     int mainline;
836
{
837
 
838
  /* We definitely need the .debug_info and .debug_abbrev sections */
839
 
840
  dwarf_info_buffer = dwarf2_read_section (objfile,
841
                                           dwarf_info_offset,
842
                                           dwarf_info_size);
843
  dwarf_abbrev_buffer = dwarf2_read_section (objfile,
844
                                             dwarf_abbrev_offset,
845
                                             dwarf_abbrev_size);
846
  dwarf_line_buffer = dwarf2_read_section (objfile,
847
                                           dwarf_line_offset,
848
                                           dwarf_line_size);
849
 
850
  if (mainline || objfile->global_psymbols.size == 0 ||
851
      objfile->static_psymbols.size == 0)
852
    {
853
      init_psymbol_list (objfile, 1024);
854
    }
855
 
856
#if 0
857
  if (dwarf_aranges_offset && dwarf_pubnames_offset)
858
    {
859
      /* Things are significantly easier if we have .debug_aranges and
860
         .debug_pubnames sections */
861
 
862
      dwarf2_build_psymtabs_easy (objfile, mainline);
863
    }
864
  else
865
#endif
866
    /* only test this case for now */
867
    {
868
      /* In this case we have to work a bit harder */
869
      dwarf2_build_psymtabs_hard (objfile, mainline);
870
    }
871
}
872
 
873
#if 0
874
/* Build the partial symbol table from the information in the
875
   .debug_pubnames and .debug_aranges sections.  */
876
 
877
static void
878
dwarf2_build_psymtabs_easy (objfile, mainline)
879
     struct objfile *objfile;
880
     int mainline;
881
{
882
  bfd *abfd = objfile->obfd;
883
  char *aranges_buffer, *pubnames_buffer;
884
  char *aranges_ptr, *pubnames_ptr;
885
  unsigned int entry_length, version, info_offset, info_size;
886
 
887
  pubnames_buffer = dwarf2_read_section (objfile,
888
                                         dwarf_pubnames_offset,
889
                                         dwarf_pubnames_size);
890
  pubnames_ptr = pubnames_buffer;
891
  while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
892
    {
893
      entry_length = read_4_bytes (abfd, pubnames_ptr);
894
      pubnames_ptr += 4;
895
      version = read_1_byte (abfd, pubnames_ptr);
896
      pubnames_ptr += 1;
897
      info_offset = read_4_bytes (abfd, pubnames_ptr);
898
      pubnames_ptr += 4;
899
      info_size = read_4_bytes (abfd, pubnames_ptr);
900
      pubnames_ptr += 4;
901
    }
902
 
903
  aranges_buffer = dwarf2_read_section (objfile,
904
                                        dwarf_aranges_offset,
905
                                        dwarf_aranges_size);
906
 
907
}
908
#endif
909
 
910
/* Build the partial symbol table by doing a quick pass through the
911
   .debug_info and .debug_abbrev sections.  */
912
 
913
static void
914
dwarf2_build_psymtabs_hard (objfile, mainline)
915
     struct objfile *objfile;
916
     int mainline;
917
{
918
  /* Instead of reading this into a big buffer, we should probably use
919
     mmap()  on architectures that support it. (FIXME) */
920
  bfd *abfd = objfile->obfd;
921
  char *info_ptr, *abbrev_ptr;
922
  char *beg_of_comp_unit;
923
  struct comp_unit_head cu_header;
924
  struct partial_die_info comp_unit_die;
925
  struct partial_symtab *pst;
926
  struct cleanup *back_to;
927
  int comp_unit_has_pc_info;
928
  CORE_ADDR lowpc, highpc;
929
 
930
  info_ptr = dwarf_info_buffer;
931
  abbrev_ptr = dwarf_abbrev_buffer;
932
 
933
  obstack_init (&dwarf2_tmp_obstack);
934
  back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
935
 
936
  while ((unsigned int) (info_ptr - dwarf_info_buffer)
937
         + ((info_ptr - dwarf_info_buffer) % 4) < dwarf_info_size)
938
    {
939
      beg_of_comp_unit = info_ptr;
940
      cu_header.length = read_4_bytes (abfd, info_ptr);
941
      info_ptr += 4;
942
      cu_header.version = read_2_bytes (abfd, info_ptr);
943
      info_ptr += 2;
944
      cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
945
      info_ptr += 4;
946
      cu_header.addr_size = read_1_byte (abfd, info_ptr);
947
      info_ptr += 1;
948
      address_size = cu_header.addr_size;
949
 
950
      if (cu_header.version != 2)
951
        {
952
          error ("Dwarf Error: wrong version in compilation unit header.");
953
          return;
954
        }
955
      if (cu_header.abbrev_offset >= dwarf_abbrev_size)
956
        {
957
          error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
958
                 (long) cu_header.abbrev_offset,
959
                 (long) (beg_of_comp_unit - dwarf_info_buffer));
960
          return;
961
        }
962
      if (beg_of_comp_unit + cu_header.length + 4
963
          > dwarf_info_buffer + dwarf_info_size)
964
        {
965
          error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
966
                 (long) cu_header.length,
967
                 (long) (beg_of_comp_unit - dwarf_info_buffer));
968
          return;
969
        }
970
      /* Read the abbrevs for this compilation unit into a table */
971
      dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
972
      make_cleanup (dwarf2_empty_abbrev_table, NULL);
973
 
974
      /* Read the compilation unit die */
975
      info_ptr = read_partial_die (&comp_unit_die, abfd,
976
                                   info_ptr, &comp_unit_has_pc_info);
977
 
978
      /* Set the language we're debugging */
979
      set_cu_language (comp_unit_die.language);
980
 
981
      /* Allocate a new partial symbol table structure */
982
      pst = start_psymtab_common (objfile, objfile->section_offsets,
983
                                  comp_unit_die.name ? comp_unit_die.name : "",
984
                                  comp_unit_die.lowpc,
985
                                  objfile->global_psymbols.next,
986
                                  objfile->static_psymbols.next);
987
 
988
      pst->read_symtab_private = (char *)
989
        obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
990
      cu_header_offset = beg_of_comp_unit - dwarf_info_buffer;
991
      DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
992
      DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
993
      DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
994
      DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
995
      DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
996
      baseaddr = ANOFFSET (objfile->section_offsets, 0);
997
 
998
      /* Store the function that reads in the rest of the symbol table */
999
      pst->read_symtab = dwarf2_psymtab_to_symtab;
1000
 
1001
      /* Check if comp unit has_children.
1002
         If so, read the rest of the partial symbols from this comp unit.
1003
         If not, there's no more debug_info for this comp unit. */
1004
      if (comp_unit_die.has_children)
1005
        {
1006
          info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc);
1007
 
1008
          /* If the compilation unit didn't have an explicit address range,
1009
             then use the information extracted from its child dies.  */
1010
          if (!comp_unit_has_pc_info)
1011
            {
1012
              comp_unit_die.lowpc = lowpc;
1013
              comp_unit_die.highpc = highpc;
1014
            }
1015
        }
1016
      pst->textlow = comp_unit_die.lowpc + baseaddr;
1017
      pst->texthigh = comp_unit_die.highpc + baseaddr;
1018
 
1019
      pst->n_global_syms = objfile->global_psymbols.next -
1020
        (objfile->global_psymbols.list + pst->globals_offset);
1021
      pst->n_static_syms = objfile->static_psymbols.next -
1022
        (objfile->static_psymbols.list + pst->statics_offset);
1023
      sort_pst_symbols (pst);
1024
 
1025
      /* If there is already a psymtab or symtab for a file of this
1026
         name, remove it. (If there is a symtab, more drastic things
1027
         also happen.) This happens in VxWorks.  */
1028
      free_named_symtabs (pst->filename);
1029
 
1030
      info_ptr = beg_of_comp_unit + cu_header.length + 4;
1031
    }
1032
  do_cleanups (back_to);
1033
}
1034
 
1035
/* Read in all interesting dies to the end of the compilation unit.  */
1036
 
1037
static char *
1038
scan_partial_symbols (info_ptr, objfile, lowpc, highpc)
1039
     char *info_ptr;
1040
     struct objfile *objfile;
1041
     CORE_ADDR *lowpc;
1042
     CORE_ADDR *highpc;
1043
{
1044
  bfd *abfd = objfile->obfd;
1045
  struct partial_die_info pdi;
1046
 
1047
  /* This function is called after we've read in the comp_unit_die in
1048
     order to read its children.  We start the nesting level at 1 since
1049
     we have pushed 1 level down in order to read the comp unit's children.
1050
     The comp unit itself is at level 0, so we stop reading when we pop
1051
     back to that level. */
1052
 
1053
  int nesting_level = 1;
1054
  int has_pc_info;
1055
 
1056
  *lowpc = ((CORE_ADDR) -1);
1057
  *highpc = ((CORE_ADDR) 0);
1058
 
1059
  while (nesting_level)
1060
    {
1061
      info_ptr = read_partial_die (&pdi, abfd, info_ptr, &has_pc_info);
1062
 
1063
      if (pdi.name)
1064
        {
1065
          switch (pdi.tag)
1066
            {
1067
            case DW_TAG_subprogram:
1068
              if (has_pc_info)
1069
                {
1070
                  if (pdi.lowpc < *lowpc)
1071
                    {
1072
                      *lowpc = pdi.lowpc;
1073
                    }
1074
                  if (pdi.highpc > *highpc)
1075
                    {
1076
                      *highpc = pdi.highpc;
1077
                    }
1078
                  if ((pdi.is_external || nesting_level == 1)
1079
                      && !pdi.is_declaration)
1080
                    {
1081
                      add_partial_symbol (&pdi, objfile);
1082
                    }
1083
                }
1084
              break;
1085
            case DW_TAG_variable:
1086
            case DW_TAG_typedef:
1087
            case DW_TAG_class_type:
1088
            case DW_TAG_structure_type:
1089
            case DW_TAG_union_type:
1090
            case DW_TAG_enumeration_type:
1091
              if ((pdi.is_external || nesting_level == 1)
1092
                  && !pdi.is_declaration)
1093
                {
1094
                  add_partial_symbol (&pdi, objfile);
1095
                }
1096
              break;
1097
            case DW_TAG_enumerator:
1098
              /* File scope enumerators are added to the partial symbol
1099
                 table.  */
1100
              if (nesting_level == 2)
1101
                add_partial_symbol (&pdi, objfile);
1102
              break;
1103
            case DW_TAG_base_type:
1104
              /* File scope base type definitions are added to the partial
1105
                 symbol table.  */
1106
              if (nesting_level == 1)
1107
                add_partial_symbol (&pdi, objfile);
1108
              break;
1109
            default:
1110
              break;
1111
            }
1112
        }
1113
 
1114
      /* If the die has a sibling, skip to the sibling.
1115
         Do not skip enumeration types, we want to record their
1116
         enumerators.  */
1117
      if (pdi.sibling && pdi.tag != DW_TAG_enumeration_type)
1118
        {
1119
          info_ptr = pdi.sibling;
1120
        }
1121
      else if (pdi.has_children)
1122
        {
1123
          /* Die has children, but the optional DW_AT_sibling attribute
1124
             is missing.  */
1125
          nesting_level++;
1126
        }
1127
 
1128
      if (pdi.tag == 0)
1129
        {
1130
          nesting_level--;
1131
        }
1132
    }
1133
 
1134
  /* If we didn't find a lowpc, set it to highpc to avoid complaints
1135
     from `maint check'.  */
1136
  if (*lowpc == ((CORE_ADDR) -1))
1137
    *lowpc = *highpc;
1138
  return info_ptr;
1139
}
1140
 
1141
static void
1142
add_partial_symbol (pdi, objfile)
1143
     struct partial_die_info *pdi;
1144
     struct objfile *objfile;
1145
{
1146
  CORE_ADDR addr = 0;
1147
 
1148
  switch (pdi->tag)
1149
    {
1150
    case DW_TAG_subprogram:
1151
      if (pdi->is_external)
1152
        {
1153
          /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1154
             mst_text, objfile); */
1155
          add_psymbol_to_list (pdi->name, strlen (pdi->name),
1156
                               VAR_NAMESPACE, LOC_BLOCK,
1157
                               &objfile->global_psymbols,
1158
                            0, pdi->lowpc + baseaddr, cu_language, objfile);
1159
        }
1160
      else
1161
        {
1162
          /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1163
             mst_file_text, objfile); */
1164
          add_psymbol_to_list (pdi->name, strlen (pdi->name),
1165
                               VAR_NAMESPACE, LOC_BLOCK,
1166
                               &objfile->static_psymbols,
1167
                            0, pdi->lowpc + baseaddr, cu_language, objfile);
1168
        }
1169
      break;
1170
    case DW_TAG_variable:
1171
      if (pdi->is_external)
1172
        {
1173
          /* Global Variable.
1174
             Don't enter into the minimal symbol tables as there is
1175
             a minimal symbol table entry from the ELF symbols already.
1176
             Enter into partial symbol table if it has a location
1177
             descriptor or a type.
1178
             If the location descriptor is missing, new_symbol will create
1179
             a LOC_UNRESOLVED symbol, the address of the variable will then
1180
             be determined from the minimal symbol table whenever the variable
1181
             is referenced.
1182
             The address for the partial symbol table entry is not
1183
             used by GDB, but it comes in handy for debugging partial symbol
1184
             table building.  */
1185
 
1186
          if (pdi->locdesc)
1187
            addr = decode_locdesc (pdi->locdesc, objfile);
1188
          if (pdi->locdesc || pdi->has_type)
1189
            add_psymbol_to_list (pdi->name, strlen (pdi->name),
1190
                                 VAR_NAMESPACE, LOC_STATIC,
1191
                                 &objfile->global_psymbols,
1192
                                 0, addr + baseaddr, cu_language, objfile);
1193
        }
1194
      else
1195
        {
1196
          /* Static Variable. Skip symbols without location descriptors.  */
1197
          if (pdi->locdesc == NULL)
1198
            return;
1199
          addr = decode_locdesc (pdi->locdesc, objfile);
1200
          /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1201
             mst_file_data, objfile); */
1202
          add_psymbol_to_list (pdi->name, strlen (pdi->name),
1203
                               VAR_NAMESPACE, LOC_STATIC,
1204
                               &objfile->static_psymbols,
1205
                               0, addr + baseaddr, cu_language, objfile);
1206
        }
1207
      break;
1208
    case DW_TAG_typedef:
1209
    case DW_TAG_base_type:
1210
      add_psymbol_to_list (pdi->name, strlen (pdi->name),
1211
                           VAR_NAMESPACE, LOC_TYPEDEF,
1212
                           &objfile->static_psymbols,
1213
                           0, (CORE_ADDR) 0, cu_language, objfile);
1214
      break;
1215
    case DW_TAG_class_type:
1216
    case DW_TAG_structure_type:
1217
    case DW_TAG_union_type:
1218
    case DW_TAG_enumeration_type:
1219
      /* Skip aggregate types without children, these are external
1220
         references.  */
1221
      if (pdi->has_children == 0)
1222
        return;
1223
      add_psymbol_to_list (pdi->name, strlen (pdi->name),
1224
                           STRUCT_NAMESPACE, LOC_TYPEDEF,
1225
                           &objfile->static_psymbols,
1226
                           0, (CORE_ADDR) 0, cu_language, objfile);
1227
 
1228
      if (cu_language == language_cplus)
1229
        {
1230
          /* For C++, these implicitly act as typedefs as well. */
1231
          add_psymbol_to_list (pdi->name, strlen (pdi->name),
1232
                               VAR_NAMESPACE, LOC_TYPEDEF,
1233
                               &objfile->static_psymbols,
1234
                               0, (CORE_ADDR) 0, cu_language, objfile);
1235
        }
1236
      break;
1237
    case DW_TAG_enumerator:
1238
      add_psymbol_to_list (pdi->name, strlen (pdi->name),
1239
                           VAR_NAMESPACE, LOC_CONST,
1240
                           &objfile->static_psymbols,
1241
                           0, (CORE_ADDR) 0, cu_language, objfile);
1242
      break;
1243
    default:
1244
      break;
1245
    }
1246
}
1247
 
1248
/* Expand this partial symbol table into a full symbol table.  */
1249
 
1250
static void
1251
dwarf2_psymtab_to_symtab (pst)
1252
     struct partial_symtab *pst;
1253
{
1254
  /* FIXME: This is barely more than a stub.  */
1255
  if (pst != NULL)
1256
    {
1257
      if (pst->readin)
1258
        {
1259
          warning ("bug: psymtab for %s is already read in.", pst->filename);
1260
        }
1261
      else
1262
        {
1263
          if (info_verbose)
1264
            {
1265
              printf_filtered ("Reading in symbols for %s...", pst->filename);
1266
              gdb_flush (gdb_stdout);
1267
            }
1268
 
1269
          psymtab_to_symtab_1 (pst);
1270
 
1271
          /* Finish up the debug error message.  */
1272
          if (info_verbose)
1273
            printf_filtered ("done.\n");
1274
        }
1275
    }
1276
}
1277
 
1278
static void
1279
psymtab_to_symtab_1 (pst)
1280
     struct partial_symtab *pst;
1281
{
1282
  struct objfile *objfile = pst->objfile;
1283
  bfd *abfd = objfile->obfd;
1284
  struct comp_unit_head cu_header;
1285
  struct die_info *dies;
1286
  unsigned long offset;
1287
  CORE_ADDR lowpc, highpc;
1288
  struct die_info *child_die;
1289
  char *info_ptr;
1290
  struct symtab *symtab;
1291
  struct cleanup *back_to;
1292
 
1293
  /* Set local variables from the partial symbol table info.  */
1294
  offset = DWARF_INFO_OFFSET (pst);
1295
  dwarf_info_buffer = DWARF_INFO_BUFFER (pst);
1296
  dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
1297
  dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
1298
  dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
1299
  baseaddr = ANOFFSET (pst->section_offsets, 0);
1300
  cu_header_offset = offset;
1301
  info_ptr = dwarf_info_buffer + offset;
1302
 
1303
  obstack_init (&dwarf2_tmp_obstack);
1304
  back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL);
1305
 
1306
  buildsym_init ();
1307
  make_cleanup (really_free_pendings, NULL);
1308
 
1309
  /* read in the comp_unit header  */
1310
  cu_header.length = read_4_bytes (abfd, info_ptr);
1311
  info_ptr += 4;
1312
  cu_header.version = read_2_bytes (abfd, info_ptr);
1313
  info_ptr += 2;
1314
  cu_header.abbrev_offset = read_4_bytes (abfd, info_ptr);
1315
  info_ptr += 4;
1316
  cu_header.addr_size = read_1_byte (abfd, info_ptr);
1317
  info_ptr += 1;
1318
 
1319
  /* Read the abbrevs for this compilation unit  */
1320
  dwarf2_read_abbrevs (abfd, cu_header.abbrev_offset);
1321
  make_cleanup (dwarf2_empty_abbrev_table, NULL);
1322
 
1323
  dies = read_comp_unit (info_ptr, abfd);
1324
 
1325
  make_cleanup ((make_cleanup_func) free_die_list, dies);
1326
 
1327
  /* Do line number decoding in read_file_scope () */
1328
  process_die (dies, objfile);
1329
 
1330
  if (!dwarf2_get_pc_bounds (dies, &lowpc, &highpc, objfile))
1331
    {
1332
      /* Some compilers don't define a DW_AT_high_pc attribute for
1333
         the compilation unit.   If the DW_AT_high_pc is missing,
1334
         synthesize it, by scanning the DIE's below the compilation unit.  */
1335
      highpc = 0;
1336
      if (dies->has_children)
1337
        {
1338
          child_die = dies->next;
1339
          while (child_die && child_die->tag)
1340
            {
1341
              if (child_die->tag == DW_TAG_subprogram)
1342
                {
1343
                  CORE_ADDR low, high;
1344
 
1345
                  if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile))
1346
                    {
1347
                      highpc = max (highpc, high);
1348
                    }
1349
                }
1350
              child_die = sibling_die (child_die);
1351
            }
1352
        }
1353
    }
1354
  symtab = end_symtab (highpc + baseaddr, objfile, 0);
1355
 
1356
  /* Set symtab language to language from DW_AT_language.
1357
     If the compilation is from a C file generated by language preprocessors,
1358
     do not set the language if it was already deduced by start_subfile.  */
1359
  if (symtab != NULL
1360
      && !(cu_language == language_c && symtab->language != language_c))
1361
    {
1362
      symtab->language = cu_language;
1363
    }
1364
  pst->symtab = symtab;
1365
  pst->readin = 1;
1366
  sort_symtab_syms (pst->symtab);
1367
 
1368
  do_cleanups (back_to);
1369
}
1370
 
1371
/* Process a die and its children.  */
1372
 
1373
static void
1374
process_die (die, objfile)
1375
     struct die_info *die;
1376
     struct objfile *objfile;
1377
{
1378
  switch (die->tag)
1379
    {
1380
    case DW_TAG_padding:
1381
      break;
1382
    case DW_TAG_compile_unit:
1383
      read_file_scope (die, objfile);
1384
      break;
1385
    case DW_TAG_subprogram:
1386
      read_subroutine_type (die, objfile);
1387
      read_func_scope (die, objfile);
1388
      break;
1389
    case DW_TAG_inlined_subroutine:
1390
      /* FIXME:  These are ignored for now.
1391
         They could be used to set breakpoints on all inlined instances
1392
         of a function and make GDB `next' properly over inlined functions.  */
1393
      break;
1394
    case DW_TAG_lexical_block:
1395
      read_lexical_block_scope (die, objfile);
1396
      break;
1397
    case DW_TAG_class_type:
1398
    case DW_TAG_structure_type:
1399
    case DW_TAG_union_type:
1400
      read_structure_scope (die, objfile);
1401
      break;
1402
    case DW_TAG_enumeration_type:
1403
      read_enumeration (die, objfile);
1404
      break;
1405
    case DW_TAG_subroutine_type:
1406
      read_subroutine_type (die, objfile);
1407
      break;
1408
    case DW_TAG_array_type:
1409
      read_array_type (die, objfile);
1410
      break;
1411
    case DW_TAG_pointer_type:
1412
      read_tag_pointer_type (die, objfile);
1413
      break;
1414
    case DW_TAG_ptr_to_member_type:
1415
      read_tag_ptr_to_member_type (die, objfile);
1416
      break;
1417
    case DW_TAG_reference_type:
1418
      read_tag_reference_type (die, objfile);
1419
      break;
1420
    case DW_TAG_string_type:
1421
      read_tag_string_type (die, objfile);
1422
      break;
1423
    case DW_TAG_base_type:
1424
      read_base_type (die, objfile);
1425
      if (dwarf_attr (die, DW_AT_name))
1426
        {
1427
          /* Add a typedef symbol for the base type definition.  */
1428
          new_symbol (die, die->type, objfile);
1429
        }
1430
      break;
1431
    case DW_TAG_common_block:
1432
      read_common_block (die, objfile);
1433
      break;
1434
    case DW_TAG_common_inclusion:
1435
      break;
1436
    default:
1437
      new_symbol (die, NULL, objfile);
1438
      break;
1439
    }
1440
}
1441
 
1442
static void
1443
read_file_scope (die, objfile)
1444
     struct die_info *die;
1445
     struct objfile *objfile;
1446
{
1447
  unsigned int line_offset = 0;
1448
  CORE_ADDR lowpc = ((CORE_ADDR) -1);
1449
  CORE_ADDR highpc = ((CORE_ADDR) 0);
1450
  struct attribute *attr;
1451
  char *name = "<unknown>";
1452
  char *comp_dir = NULL;
1453
  struct die_info *child_die;
1454
  bfd *abfd = objfile->obfd;
1455
 
1456
  if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1457
    {
1458
      if (die->has_children)
1459
        {
1460
          child_die = die->next;
1461
          while (child_die && child_die->tag)
1462
            {
1463
              if (child_die->tag == DW_TAG_subprogram)
1464
                {
1465
                  CORE_ADDR low, high;
1466
 
1467
                  if (dwarf2_get_pc_bounds (child_die, &low, &high, objfile))
1468
                    {
1469
                      lowpc = min (lowpc, low);
1470
                      highpc = max (highpc, high);
1471
                    }
1472
                }
1473
              child_die = sibling_die (child_die);
1474
            }
1475
        }
1476
    }
1477
 
1478
  /* If we didn't find a lowpc, set it to highpc to avoid complaints
1479
     from finish_block.  */
1480
  if (lowpc == ((CORE_ADDR) -1))
1481
    lowpc = highpc;
1482
  lowpc += baseaddr;
1483
  highpc += baseaddr;
1484
 
1485
  attr = dwarf_attr (die, DW_AT_name);
1486
  if (attr)
1487
    {
1488
      name = DW_STRING (attr);
1489
    }
1490
  attr = dwarf_attr (die, DW_AT_comp_dir);
1491
  if (attr)
1492
    {
1493
      comp_dir = DW_STRING (attr);
1494
      if (comp_dir)
1495
        {
1496
          /* Irix 6.2 native cc prepends <machine>.: to the compilation
1497
             directory, get rid of it.  */
1498
          char *cp = strchr (comp_dir, ':');
1499
 
1500
          if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
1501
            comp_dir = cp + 1;
1502
        }
1503
    }
1504
 
1505
  if (objfile->ei.entry_point >= lowpc &&
1506
      objfile->ei.entry_point < highpc)
1507
    {
1508
      objfile->ei.entry_file_lowpc = lowpc;
1509
      objfile->ei.entry_file_highpc = highpc;
1510
    }
1511
 
1512
  attr = dwarf_attr (die, DW_AT_language);
1513
  if (attr)
1514
    {
1515
      set_cu_language (DW_UNSND (attr));
1516
    }
1517
 
1518
  /* We assume that we're processing GCC output. */
1519
  processing_gcc_compilation = 2;
1520
#if 0
1521
  /* FIXME:Do something here.  */
1522
  if (dip->at_producer != NULL)
1523
    {
1524
      handle_producer (dip->at_producer);
1525
    }
1526
#endif
1527
 
1528
  /* The compilation unit may be in a different language or objfile,
1529
     zero out all remembered fundamental types.  */
1530
  memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
1531
 
1532
  start_symtab (name, comp_dir, lowpc);
1533
  record_debugformat ("DWARF 2");
1534
 
1535
  /* Decode line number information if present.  */
1536
  attr = dwarf_attr (die, DW_AT_stmt_list);
1537
  if (attr)
1538
    {
1539
      line_offset = DW_UNSND (attr);
1540
      dwarf_decode_lines (line_offset, comp_dir, abfd);
1541
    }
1542
 
1543
  /* Process all dies in compilation unit.  */
1544
  if (die->has_children)
1545
    {
1546
      child_die = die->next;
1547
      while (child_die && child_die->tag)
1548
        {
1549
          process_die (child_die, objfile);
1550
          child_die = sibling_die (child_die);
1551
        }
1552
    }
1553
}
1554
 
1555
static void
1556
read_func_scope (die, objfile)
1557
     struct die_info *die;
1558
     struct objfile *objfile;
1559
{
1560
  register struct context_stack *new;
1561
  CORE_ADDR lowpc;
1562
  CORE_ADDR highpc;
1563
  struct die_info *child_die;
1564
  struct attribute *attr;
1565
  char *name;
1566
 
1567
  name = dwarf2_linkage_name (die);
1568
 
1569
  /* Ignore functions with missing or empty names and functions with
1570
     missing or invalid low and high pc attributes.  */
1571
  if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1572
    return;
1573
 
1574
  lowpc += baseaddr;
1575
  highpc += baseaddr;
1576
 
1577
  if (objfile->ei.entry_point >= lowpc &&
1578
      objfile->ei.entry_point < highpc)
1579
    {
1580
      objfile->ei.entry_func_lowpc = lowpc;
1581
      objfile->ei.entry_func_highpc = highpc;
1582
    }
1583
 
1584
  /* Decode DW_AT_frame_base location descriptor if present, keep result
1585
     for DW_OP_fbreg operands in decode_locdesc.  */
1586
  frame_base_reg = -1;
1587
  frame_base_offset = 0;
1588
  attr = dwarf_attr (die, DW_AT_frame_base);
1589
  if (attr)
1590
    {
1591
      CORE_ADDR addr = decode_locdesc (DW_BLOCK (attr), objfile);
1592
      if (isderef)
1593
        complain (&dwarf2_unsupported_at_frame_base, name);
1594
      else if (isreg)
1595
        frame_base_reg = addr;
1596
      else if (offreg)
1597
        {
1598
          frame_base_reg = basereg;
1599
          frame_base_offset = addr;
1600
        }
1601
      else
1602
        complain (&dwarf2_unsupported_at_frame_base, name);
1603
    }
1604
 
1605
  new = push_context (0, lowpc);
1606
  new->name = new_symbol (die, die->type, objfile);
1607
  list_in_scope = &local_symbols;
1608
 
1609
  if (die->has_children)
1610
    {
1611
      child_die = die->next;
1612
      while (child_die && child_die->tag)
1613
        {
1614
          process_die (child_die, objfile);
1615
          child_die = sibling_die (child_die);
1616
        }
1617
    }
1618
 
1619
  new = pop_context ();
1620
  /* Make a block for the local symbols within.  */
1621
  finish_block (new->name, &local_symbols, new->old_blocks,
1622
                lowpc, highpc, objfile);
1623
  list_in_scope = &file_symbols;
1624
}
1625
 
1626
/* Process all the DIES contained within a lexical block scope.  Start
1627
   a new scope, process the dies, and then close the scope.  */
1628
 
1629
static void
1630
read_lexical_block_scope (die, objfile)
1631
     struct die_info *die;
1632
     struct objfile *objfile;
1633
{
1634
  register struct context_stack *new;
1635
  CORE_ADDR lowpc, highpc;
1636
  struct die_info *child_die;
1637
 
1638
  /* Ignore blocks with missing or invalid low and high pc attributes.  */
1639
  if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile))
1640
    return;
1641
  lowpc += baseaddr;
1642
  highpc += baseaddr;
1643
 
1644
  push_context (0, lowpc);
1645
  if (die->has_children)
1646
    {
1647
      child_die = die->next;
1648
      while (child_die && child_die->tag)
1649
        {
1650
          process_die (child_die, objfile);
1651
          child_die = sibling_die (child_die);
1652
        }
1653
    }
1654
  new = pop_context ();
1655
 
1656
  if (local_symbols != NULL)
1657
    {
1658
      finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
1659
                    highpc, objfile);
1660
    }
1661
  local_symbols = new->locals;
1662
}
1663
 
1664
/* Get low and high pc attributes from a die.
1665
   Return 1 if the attributes are present and valid, otherwise, return 0.  */
1666
 
1667
static int
1668
dwarf2_get_pc_bounds (die, lowpc, highpc, objfile)
1669
     struct die_info *die;
1670
     CORE_ADDR *lowpc;
1671
     CORE_ADDR *highpc;
1672
     struct objfile *objfile;
1673
{
1674
  struct attribute *attr;
1675
  CORE_ADDR low;
1676
  CORE_ADDR high;
1677
 
1678
  attr = dwarf_attr (die, DW_AT_low_pc);
1679
  if (attr)
1680
    low = DW_ADDR (attr);
1681
  else
1682
    return 0;
1683
  attr = dwarf_attr (die, DW_AT_high_pc);
1684
  if (attr)
1685
    high = DW_ADDR (attr);
1686
  else
1687
    return 0;
1688
 
1689
  if (high < low)
1690
    return 0;
1691
 
1692
  /* When using the GNU linker, .gnu.linkonce. sections are used to
1693
     eliminate duplicate copies of functions and vtables and such.
1694
     The linker will arbitrarily choose one and discard the others.
1695
     The AT_*_pc values for such functions refer to local labels in
1696
     these sections.  If the section from that file was discarded, the
1697
     labels are not in the output, so the relocs get a value of 0.
1698
     If this is a discarded function, mark the pc bounds as invalid,
1699
     so that GDB will ignore it.  */
1700
  if (low == 0 && (bfd_get_file_flags (objfile->obfd) & HAS_RELOC) == 0)
1701
    return 0;
1702
 
1703
  *lowpc = low;
1704
  *highpc = high;
1705
  return 1;
1706
}
1707
 
1708
/* Add an aggregate field to the field list.  */
1709
 
1710
static void
1711
dwarf2_add_field (fip, die, objfile)
1712
     struct field_info *fip;
1713
     struct die_info *die;
1714
     struct objfile *objfile;
1715
{
1716
  struct nextfield *new_field;
1717
  struct attribute *attr;
1718
  struct field *fp;
1719
  char *fieldname = "";
1720
 
1721
  /* Allocate a new field list entry and link it in.  */
1722
  new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
1723
  make_cleanup (free, new_field);
1724
  memset (new_field, 0, sizeof (struct nextfield));
1725
  new_field->next = fip->fields;
1726
  fip->fields = new_field;
1727
  fip->nfields++;
1728
 
1729
  /* Handle accessibility and virtuality of field.
1730
     The default accessibility for members is public, the default
1731
     accessibility for inheritance is private.  */
1732
  if (die->tag != DW_TAG_inheritance)
1733
    new_field->accessibility = DW_ACCESS_public;
1734
  else
1735
    new_field->accessibility = DW_ACCESS_private;
1736
  new_field->virtuality = DW_VIRTUALITY_none;
1737
 
1738
  attr = dwarf_attr (die, DW_AT_accessibility);
1739
  if (attr)
1740
    new_field->accessibility = DW_UNSND (attr);
1741
  if (new_field->accessibility != DW_ACCESS_public)
1742
    fip->non_public_fields = 1;
1743
  attr = dwarf_attr (die, DW_AT_virtuality);
1744
  if (attr)
1745
    new_field->virtuality = DW_UNSND (attr);
1746
 
1747
  fp = &new_field->field;
1748
  if (die->tag == DW_TAG_member)
1749
    {
1750
      /* Get type of field.  */
1751
      fp->type = die_type (die, objfile);
1752
 
1753
      /* Get bit size of field (zero if none).  */
1754
      attr = dwarf_attr (die, DW_AT_bit_size);
1755
      if (attr)
1756
        {
1757
          FIELD_BITSIZE (*fp) = DW_UNSND (attr);
1758
        }
1759
      else
1760
        {
1761
          FIELD_BITSIZE (*fp) = 0;
1762
        }
1763
 
1764
      /* Get bit offset of field.  */
1765
      attr = dwarf_attr (die, DW_AT_data_member_location);
1766
      if (attr)
1767
        {
1768
          FIELD_BITPOS (*fp) =
1769
            decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1770
        }
1771
      else
1772
        FIELD_BITPOS (*fp) = 0;
1773
      attr = dwarf_attr (die, DW_AT_bit_offset);
1774
      if (attr)
1775
        {
1776
          if (BITS_BIG_ENDIAN)
1777
            {
1778
              /* For big endian bits, the DW_AT_bit_offset gives the
1779
                 additional bit offset from the MSB of the containing
1780
                 anonymous object to the MSB of the field.  We don't
1781
                 have to do anything special since we don't need to
1782
                 know the size of the anonymous object.  */
1783
              FIELD_BITPOS (*fp) += DW_UNSND (attr);
1784
            }
1785
          else
1786
            {
1787
              /* For little endian bits, compute the bit offset to the
1788
                 MSB of the anonymous object, subtract off the number of
1789
                 bits from the MSB of the field to the MSB of the
1790
                 object, and then subtract off the number of bits of
1791
                 the field itself.  The result is the bit offset of
1792
                 the LSB of the field.  */
1793
              int anonymous_size;
1794
              int bit_offset = DW_UNSND (attr);
1795
 
1796
              attr = dwarf_attr (die, DW_AT_byte_size);
1797
              if (attr)
1798
                {
1799
                  /* The size of the anonymous object containing
1800
                     the bit field is explicit, so use the
1801
                     indicated size (in bytes).  */
1802
                  anonymous_size = DW_UNSND (attr);
1803
                }
1804
              else
1805
                {
1806
                  /* The size of the anonymous object containing
1807
                     the bit field must be inferred from the type
1808
                     attribute of the data member containing the
1809
                     bit field.  */
1810
                  anonymous_size = TYPE_LENGTH (fp->type);
1811
                }
1812
              FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
1813
                - bit_offset - FIELD_BITSIZE (*fp);
1814
            }
1815
        }
1816
 
1817
      /* Get name of field.  */
1818
      attr = dwarf_attr (die, DW_AT_name);
1819
      if (attr && DW_STRING (attr))
1820
        fieldname = DW_STRING (attr);
1821
      fp->name = obsavestring (fieldname, strlen (fieldname),
1822
                               &objfile->type_obstack);
1823
 
1824
      /* Change accessibility for artificial fields (e.g. virtual table
1825
         pointer or virtual base class pointer) to private.  */
1826
      if (dwarf_attr (die, DW_AT_artificial))
1827
        {
1828
          new_field->accessibility = DW_ACCESS_private;
1829
          fip->non_public_fields = 1;
1830
        }
1831
    }
1832
  else if (die->tag == DW_TAG_variable)
1833
    {
1834
      char *physname;
1835
 
1836
      /* C++ static member.
1837
         Get name of field.  */
1838
      attr = dwarf_attr (die, DW_AT_name);
1839
      if (attr && DW_STRING (attr))
1840
        fieldname = DW_STRING (attr);
1841
      else
1842
        return;
1843
 
1844
      /* Get physical name.  */
1845
      physname = dwarf2_linkage_name (die);
1846
 
1847
      SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
1848
                                             &objfile->type_obstack));
1849
      FIELD_TYPE (*fp) = die_type (die, objfile);
1850
      FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
1851
                                       &objfile->type_obstack);
1852
    }
1853
  else if (die->tag == DW_TAG_inheritance)
1854
    {
1855
      /* C++ base class field.  */
1856
      attr = dwarf_attr (die, DW_AT_data_member_location);
1857
      if (attr)
1858
        FIELD_BITPOS (*fp) = decode_locdesc (DW_BLOCK (attr), objfile) * bits_per_byte;
1859
      FIELD_BITSIZE (*fp) = 0;
1860
      FIELD_TYPE (*fp) = die_type (die, objfile);
1861
      FIELD_NAME (*fp) = type_name_no_tag (fp->type);
1862
      fip->nbaseclasses++;
1863
    }
1864
}
1865
 
1866
/* Create the vector of fields, and attach it to the type.  */
1867
 
1868
static void
1869
dwarf2_attach_fields_to_type (fip, type, objfile)
1870
     struct field_info *fip;
1871
     struct type *type;
1872
     struct objfile *objfile;
1873
{
1874
  int nfields = fip->nfields;
1875
 
1876
  /* Record the field count, allocate space for the array of fields,
1877
     and create blank accessibility bitfields if necessary.  */
1878
  TYPE_NFIELDS (type) = nfields;
1879
  TYPE_FIELDS (type) = (struct field *)
1880
    TYPE_ALLOC (type, sizeof (struct field) * nfields);
1881
  memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
1882
 
1883
  if (fip->non_public_fields)
1884
    {
1885
      ALLOCATE_CPLUS_STRUCT_TYPE (type);
1886
 
1887
      TYPE_FIELD_PRIVATE_BITS (type) =
1888
        (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1889
      B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
1890
 
1891
      TYPE_FIELD_PROTECTED_BITS (type) =
1892
        (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1893
      B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
1894
 
1895
      TYPE_FIELD_IGNORE_BITS (type) =
1896
        (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
1897
      B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
1898
    }
1899
 
1900
  /* If the type has baseclasses, allocate and clear a bit vector for
1901
     TYPE_FIELD_VIRTUAL_BITS.  */
1902
  if (fip->nbaseclasses)
1903
    {
1904
      int num_bytes = B_BYTES (fip->nbaseclasses);
1905
      char *pointer;
1906
 
1907
      ALLOCATE_CPLUS_STRUCT_TYPE (type);
1908
      pointer = (char *) TYPE_ALLOC (type, num_bytes);
1909
      TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
1910
      B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
1911
      TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
1912
    }
1913
 
1914
  /* Copy the saved-up fields into the field vector.  Start from the head
1915
     of the list, adding to the tail of the field array, so that they end
1916
     up in the same order in the array in which they were added to the list.  */
1917
  while (nfields-- > 0)
1918
    {
1919
      TYPE_FIELD (type, nfields) = fip->fields->field;
1920
      switch (fip->fields->accessibility)
1921
        {
1922
        case DW_ACCESS_private:
1923
          SET_TYPE_FIELD_PRIVATE (type, nfields);
1924
          break;
1925
 
1926
        case DW_ACCESS_protected:
1927
          SET_TYPE_FIELD_PROTECTED (type, nfields);
1928
          break;
1929
 
1930
        case DW_ACCESS_public:
1931
          break;
1932
 
1933
        default:
1934
          /* Unknown accessibility.  Complain and treat it as public.  */
1935
          {
1936
            complain (&dwarf2_unsupported_accessibility,
1937
                      fip->fields->accessibility);
1938
          }
1939
          break;
1940
        }
1941
      if (nfields < fip->nbaseclasses)
1942
        {
1943
          switch (fip->fields->virtuality)
1944
            {
1945
            case DW_VIRTUALITY_virtual:
1946
            case DW_VIRTUALITY_pure_virtual:
1947
              SET_TYPE_FIELD_VIRTUAL (type, nfields);
1948
              break;
1949
            }
1950
        }
1951
      fip->fields = fip->fields->next;
1952
    }
1953
}
1954
 
1955
/* Add a member function to the proper fieldlist.  */
1956
 
1957
static void
1958
dwarf2_add_member_fn (fip, die, type, objfile)
1959
     struct field_info *fip;
1960
     struct die_info *die;
1961
     struct type *type;
1962
     struct objfile *objfile;
1963
{
1964
  struct attribute *attr;
1965
  struct fnfieldlist *flp;
1966
  int i;
1967
  struct fn_field *fnp;
1968
  char *fieldname;
1969
  char *physname;
1970
  struct nextfnfield *new_fnfield;
1971
 
1972
  /* Get name of member function.  */
1973
  attr = dwarf_attr (die, DW_AT_name);
1974
  if (attr && DW_STRING (attr))
1975
    fieldname = DW_STRING (attr);
1976
  else
1977
    return;
1978
 
1979
  /* Get the mangled name.  */
1980
  physname = dwarf2_linkage_name (die);
1981
 
1982
  /* Look up member function name in fieldlist.  */
1983
  for (i = 0; i < fip->nfnfields; i++)
1984
    {
1985
      if (STREQ (fip->fnfieldlists[i].name, fieldname))
1986
        break;
1987
    }
1988
 
1989
  /* Create new list element if necessary.  */
1990
  if (i < fip->nfnfields)
1991
    flp = &fip->fnfieldlists[i];
1992
  else
1993
    {
1994
      if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
1995
        {
1996
          fip->fnfieldlists = (struct fnfieldlist *)
1997
            xrealloc (fip->fnfieldlists,
1998
                      (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
1999
                      * sizeof (struct fnfieldlist));
2000
          if (fip->nfnfields == 0)
2001
            make_cleanup ((make_cleanup_func) free_current_contents,
2002
                          &fip->fnfieldlists);
2003
        }
2004
      flp = &fip->fnfieldlists[fip->nfnfields];
2005
      flp->name = fieldname;
2006
      flp->length = 0;
2007
      flp->head = NULL;
2008
      fip->nfnfields++;
2009
    }
2010
 
2011
  /* Create a new member function field and chain it to the field list
2012
     entry. */
2013
  new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
2014
  make_cleanup (free, new_fnfield);
2015
  memset (new_fnfield, 0, sizeof (struct nextfnfield));
2016
  new_fnfield->next = flp->head;
2017
  flp->head = new_fnfield;
2018
  flp->length++;
2019
 
2020
  /* Fill in the member function field info.  */
2021
  fnp = &new_fnfield->fnfield;
2022
  fnp->physname = obsavestring (physname, strlen (physname),
2023
                                &objfile->type_obstack);
2024
  fnp->type = alloc_type (objfile);
2025
  if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
2026
    {
2027
      struct type *return_type = TYPE_TARGET_TYPE (die->type);
2028
      struct type **arg_types;
2029
      int nparams = TYPE_NFIELDS (die->type);
2030
      int iparams;
2031
 
2032
      /* Copy argument types from the subroutine type.  */
2033
      arg_types = (struct type **)
2034
        TYPE_ALLOC (fnp->type, (nparams + 1) * sizeof (struct type *));
2035
      for (iparams = 0; iparams < nparams; iparams++)
2036
        arg_types[iparams] = TYPE_FIELD_TYPE (die->type, iparams);
2037
 
2038
      /* Set last entry in argument type vector.  */
2039
      if (TYPE_FLAGS (die->type) & TYPE_FLAG_VARARGS)
2040
        arg_types[nparams] = NULL;
2041
      else
2042
        arg_types[nparams] = dwarf2_fundamental_type (objfile, FT_VOID);
2043
 
2044
      smash_to_method_type (fnp->type, type, return_type, arg_types);
2045
 
2046
      /* Handle static member functions.
2047
         Dwarf2 has no clean way to discern C++ static and non-static
2048
         member functions. G++ helps GDB by marking the first
2049
         parameter for non-static member functions (which is the
2050
         this pointer) as artificial. We obtain this information
2051
         from read_subroutine_type via TYPE_FIELD_ARTIFICIAL.  */
2052
      if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
2053
        fnp->voffset = VOFFSET_STATIC;
2054
    }
2055
  else
2056
    complain (&dwarf2_missing_member_fn_type_complaint, physname);
2057
 
2058
  /* Get fcontext from DW_AT_containing_type if present.  */
2059
  if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2060
    fnp->fcontext = die_containing_type (die, objfile);
2061
 
2062
  /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2063
     and is_volatile is irrelevant, as it is needed by gdb_mangle_name only.  */
2064
 
2065
  /* Get accessibility.  */
2066
  attr = dwarf_attr (die, DW_AT_accessibility);
2067
  if (attr)
2068
    {
2069
      switch (DW_UNSND (attr))
2070
        {
2071
        case DW_ACCESS_private:
2072
          fnp->is_private = 1;
2073
          break;
2074
        case DW_ACCESS_protected:
2075
          fnp->is_protected = 1;
2076
          break;
2077
        }
2078
    }
2079
 
2080
  /* Get index in virtual function table if it is a virtual member function.  */
2081
  attr = dwarf_attr (die, DW_AT_vtable_elem_location);
2082
  if (attr)
2083
    fnp->voffset = decode_locdesc (DW_BLOCK (attr), objfile) + 2;
2084
}
2085
 
2086
/* Create the vector of member function fields, and attach it to the type.  */
2087
 
2088
static void
2089
dwarf2_attach_fn_fields_to_type (fip, type, objfile)
2090
     struct field_info *fip;
2091
     struct type *type;
2092
     struct objfile *objfile;
2093
{
2094
  struct fnfieldlist *flp;
2095
  int total_length = 0;
2096
  int i;
2097
 
2098
  ALLOCATE_CPLUS_STRUCT_TYPE (type);
2099
  TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2100
    TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
2101
 
2102
  for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
2103
    {
2104
      struct nextfnfield *nfp = flp->head;
2105
      struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
2106
      int k;
2107
 
2108
      TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
2109
      TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
2110
      fn_flp->fn_fields = (struct fn_field *)
2111
        TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
2112
      for (k = flp->length; (k--, nfp); nfp = nfp->next)
2113
        fn_flp->fn_fields[k] = nfp->fnfield;
2114
 
2115
      total_length += flp->length;
2116
    }
2117
 
2118
  TYPE_NFN_FIELDS (type) = fip->nfnfields;
2119
  TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2120
}
2121
 
2122
/* Called when we find the DIE that starts a structure or union scope
2123
   (definition) to process all dies that define the members of the
2124
   structure or union.
2125
 
2126
   NOTE: we need to call struct_type regardless of whether or not the
2127
   DIE has an at_name attribute, since it might be an anonymous
2128
   structure or union.  This gets the type entered into our set of
2129
   user defined types.
2130
 
2131
   However, if the structure is incomplete (an opaque struct/union)
2132
   then suppress creating a symbol table entry for it since gdb only
2133
   wants to find the one with the complete definition.  Note that if
2134
   it is complete, we just call new_symbol, which does it's own
2135
   checking about whether the struct/union is anonymous or not (and
2136
   suppresses creating a symbol table entry itself).  */
2137
 
2138
static void
2139
read_structure_scope (die, objfile)
2140
     struct die_info *die;
2141
     struct objfile *objfile;
2142
{
2143
  struct type *type;
2144
  struct attribute *attr;
2145
 
2146
  type = alloc_type (objfile);
2147
 
2148
  INIT_CPLUS_SPECIFIC (type);
2149
  attr = dwarf_attr (die, DW_AT_name);
2150
  if (attr && DW_STRING (attr))
2151
    {
2152
      TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2153
                                           strlen (DW_STRING (attr)),
2154
                                           &objfile->type_obstack);
2155
    }
2156
 
2157
  if (die->tag == DW_TAG_structure_type)
2158
    {
2159
      TYPE_CODE (type) = TYPE_CODE_STRUCT;
2160
    }
2161
  else if (die->tag == DW_TAG_union_type)
2162
    {
2163
      TYPE_CODE (type) = TYPE_CODE_UNION;
2164
    }
2165
  else
2166
    {
2167
      /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2168
         in gdbtypes.h.  */
2169
      TYPE_CODE (type) = TYPE_CODE_CLASS;
2170
    }
2171
 
2172
  attr = dwarf_attr (die, DW_AT_byte_size);
2173
  if (attr)
2174
    {
2175
      TYPE_LENGTH (type) = DW_UNSND (attr);
2176
    }
2177
  else
2178
    {
2179
      TYPE_LENGTH (type) = 0;
2180
    }
2181
 
2182
  /* We need to add the type field to the die immediately so we don't
2183
     infinitely recurse when dealing with pointers to the structure
2184
     type within the structure itself. */
2185
  die->type = type;
2186
 
2187
  if (die->has_children && ! die_is_declaration (die))
2188
    {
2189
      struct field_info fi;
2190
      struct die_info *child_die;
2191
      struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
2192
 
2193
      memset (&fi, 0, sizeof (struct field_info));
2194
 
2195
      child_die = die->next;
2196
 
2197
      while (child_die && child_die->tag)
2198
        {
2199
          if (child_die->tag == DW_TAG_member)
2200
            {
2201
              dwarf2_add_field (&fi, child_die, objfile);
2202
            }
2203
          else if (child_die->tag == DW_TAG_variable)
2204
            {
2205
              /* C++ static member.  */
2206
              dwarf2_add_field (&fi, child_die, objfile);
2207
            }
2208
          else if (child_die->tag == DW_TAG_subprogram)
2209
            {
2210
              /* C++ member function. */
2211
              process_die (child_die, objfile);
2212
              dwarf2_add_member_fn (&fi, child_die, type, objfile);
2213
            }
2214
          else if (child_die->tag == DW_TAG_inheritance)
2215
            {
2216
              /* C++ base class field.  */
2217
              dwarf2_add_field (&fi, child_die, objfile);
2218
            }
2219
          else
2220
            {
2221
              process_die (child_die, objfile);
2222
            }
2223
          child_die = sibling_die (child_die);
2224
        }
2225
 
2226
      /* Attach fields and member functions to the type.  */
2227
      if (fi.nfields)
2228
        dwarf2_attach_fields_to_type (&fi, type, objfile);
2229
      if (fi.nfnfields)
2230
        {
2231
          dwarf2_attach_fn_fields_to_type (&fi, type, objfile);
2232
 
2233
          /* Get the type which refers to the base class (possibly this
2234
             class itself) which contains the vtable pointer for the current
2235
             class from the DW_AT_containing_type attribute.  */
2236
 
2237
          if (dwarf_attr (die, DW_AT_containing_type) != NULL)
2238
            {
2239
              struct type *t = die_containing_type (die, objfile);
2240
 
2241
              TYPE_VPTR_BASETYPE (type) = t;
2242
              if (type == t)
2243
                {
2244
                  static const char vptr_name[] =
2245
                  {'_', 'v', 'p', 't', 'r', '\0'};
2246
                  int i;
2247
 
2248
                  /* Our own class provides vtbl ptr.  */
2249
                  for (i = TYPE_NFIELDS (t) - 1;
2250
                       i >= TYPE_N_BASECLASSES (t);
2251
                       --i)
2252
                    {
2253
                      char *fieldname = TYPE_FIELD_NAME (t, i);
2254
 
2255
                      if (STREQN (fieldname, vptr_name, strlen (vptr_name) - 1)
2256
                          && is_cplus_marker (fieldname[strlen (vptr_name)]))
2257
                        {
2258
                          TYPE_VPTR_FIELDNO (type) = i;
2259
                          break;
2260
                        }
2261
                    }
2262
 
2263
                  /* Complain if virtual function table field not found.  */
2264
                  if (i < TYPE_N_BASECLASSES (t))
2265
                    complain (&dwarf2_vtbl_not_found_complaint,
2266
                          TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "");
2267
                }
2268
              else
2269
                {
2270
                  TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2271
                }
2272
            }
2273
        }
2274
 
2275
      new_symbol (die, type, objfile);
2276
 
2277
      do_cleanups (back_to);
2278
    }
2279
  else
2280
    {
2281
      /* No children, must be stub. */
2282
      TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2283
    }
2284
 
2285
  die->type = type;
2286
}
2287
 
2288
/* Given a pointer to a die which begins an enumeration, process all
2289
   the dies that define the members of the enumeration.
2290
 
2291
   This will be much nicer in draft 6 of the DWARF spec when our
2292
   members will be dies instead squished into the DW_AT_element_list
2293
   attribute.
2294
 
2295
   NOTE: We reverse the order of the element list.  */
2296
 
2297
static void
2298
read_enumeration (die, objfile)
2299
     struct die_info *die;
2300
     struct objfile *objfile;
2301
{
2302
  struct die_info *child_die;
2303
  struct type *type;
2304
  struct field *fields;
2305
  struct attribute *attr;
2306
  struct symbol *sym;
2307
  int num_fields;
2308
  int unsigned_enum = 1;
2309
 
2310
  type = alloc_type (objfile);
2311
 
2312
  TYPE_CODE (type) = TYPE_CODE_ENUM;
2313
  attr = dwarf_attr (die, DW_AT_name);
2314
  if (attr && DW_STRING (attr))
2315
    {
2316
      TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr),
2317
                                           strlen (DW_STRING (attr)),
2318
                                           &objfile->type_obstack);
2319
    }
2320
 
2321
  attr = dwarf_attr (die, DW_AT_byte_size);
2322
  if (attr)
2323
    {
2324
      TYPE_LENGTH (type) = DW_UNSND (attr);
2325
    }
2326
  else
2327
    {
2328
      TYPE_LENGTH (type) = 0;
2329
    }
2330
 
2331
  num_fields = 0;
2332
  fields = NULL;
2333
  if (die->has_children)
2334
    {
2335
      child_die = die->next;
2336
      while (child_die && child_die->tag)
2337
        {
2338
          if (child_die->tag != DW_TAG_enumerator)
2339
            {
2340
              process_die (child_die, objfile);
2341
            }
2342
          else
2343
            {
2344
              attr = dwarf_attr (child_die, DW_AT_name);
2345
              if (attr)
2346
                {
2347
                  sym = new_symbol (child_die, type, objfile);
2348
                  if (SYMBOL_VALUE (sym) < 0)
2349
                    unsigned_enum = 0;
2350
 
2351
                  if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
2352
                    {
2353
                      fields = (struct field *)
2354
                        xrealloc (fields,
2355
                                  (num_fields + DW_FIELD_ALLOC_CHUNK)
2356
                                  * sizeof (struct field));
2357
                    }
2358
 
2359
                  FIELD_NAME (fields[num_fields]) = SYMBOL_NAME (sym);
2360
                  FIELD_TYPE (fields[num_fields]) = NULL;
2361
                  FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
2362
                  FIELD_BITSIZE (fields[num_fields]) = 0;
2363
 
2364
                  num_fields++;
2365
                }
2366
            }
2367
 
2368
          child_die = sibling_die (child_die);
2369
        }
2370
 
2371
      if (num_fields)
2372
        {
2373
          TYPE_NFIELDS (type) = num_fields;
2374
          TYPE_FIELDS (type) = (struct field *)
2375
            TYPE_ALLOC (type, sizeof (struct field) * num_fields);
2376
          memcpy (TYPE_FIELDS (type), fields,
2377
                  sizeof (struct field) * num_fields);
2378
          free (fields);
2379
        }
2380
      if (unsigned_enum)
2381
        TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
2382
    }
2383
  die->type = type;
2384
  new_symbol (die, type, objfile);
2385
}
2386
 
2387
/* Extract all information from a DW_TAG_array_type DIE and put it in
2388
   the DIE's type field.  For now, this only handles one dimensional
2389
   arrays.  */
2390
 
2391
static void
2392
read_array_type (die, objfile)
2393
     struct die_info *die;
2394
     struct objfile *objfile;
2395
{
2396
  struct die_info *child_die;
2397
  struct type *type = NULL;
2398
  struct type *element_type, *range_type, *index_type;
2399
  struct type **range_types = NULL;
2400
  struct attribute *attr;
2401
  int ndim = 0;
2402
  struct cleanup *back_to;
2403
 
2404
  /* Return if we've already decoded this type. */
2405
  if (die->type)
2406
    {
2407
      return;
2408
    }
2409
 
2410
  element_type = die_type (die, objfile);
2411
 
2412
  /* Irix 6.2 native cc creates array types without children for
2413
     arrays with unspecified length.  */
2414
  if (die->has_children == 0)
2415
    {
2416
      index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2417
      range_type = create_range_type (NULL, index_type, 0, -1);
2418
      die->type = create_array_type (NULL, element_type, range_type);
2419
      return;
2420
    }
2421
 
2422
  back_to = make_cleanup (null_cleanup, NULL);
2423
  child_die = die->next;
2424
  while (child_die && child_die->tag)
2425
    {
2426
      if (child_die->tag == DW_TAG_subrange_type)
2427
        {
2428
          unsigned int low, high;
2429
 
2430
          /* Default bounds to an array with unspecified length.  */
2431
          low = 0;
2432
          high = -1;
2433
          if (cu_language == language_fortran)
2434
            {
2435
              /* FORTRAN implies a lower bound of 1, if not given.  */
2436
              low = 1;
2437
            }
2438
 
2439
          index_type = die_type (child_die, objfile);
2440
          attr = dwarf_attr (child_die, DW_AT_lower_bound);
2441
          if (attr)
2442
            {
2443
              if (attr->form == DW_FORM_sdata)
2444
                {
2445
                  low = DW_SND (attr);
2446
                }
2447
              else if (attr->form == DW_FORM_udata
2448
                       || attr->form == DW_FORM_data1
2449
                       || attr->form == DW_FORM_data2
2450
                       || attr->form == DW_FORM_data4)
2451
                {
2452
                  low = DW_UNSND (attr);
2453
                }
2454
              else
2455
                {
2456
                  complain (&dwarf2_non_const_array_bound_ignored,
2457
                            dwarf_form_name (attr->form));
2458
#ifdef FORTRAN_HACK
2459
                  die->type = lookup_pointer_type (element_type);
2460
                  return;
2461
#else
2462
                  low = 0;
2463
#endif
2464
                }
2465
            }
2466
          attr = dwarf_attr (child_die, DW_AT_upper_bound);
2467
          if (attr)
2468
            {
2469
              if (attr->form == DW_FORM_sdata)
2470
                {
2471
                  high = DW_SND (attr);
2472
                }
2473
              else if (attr->form == DW_FORM_udata
2474
                       || attr->form == DW_FORM_data1
2475
                       || attr->form == DW_FORM_data2
2476
                       || attr->form == DW_FORM_data4)
2477
                {
2478
                  high = DW_UNSND (attr);
2479
                }
2480
              else if (attr->form == DW_FORM_block1)
2481
                {
2482
                  /* GCC encodes arrays with unspecified or dynamic length
2483
                     with a DW_FORM_block1 attribute.
2484
                     FIXME: GDB does not yet know how to handle dynamic
2485
                     arrays properly, treat them as arrays with unspecified
2486
                     length for now.  */
2487
                  high = -1;
2488
                }
2489
              else
2490
                {
2491
                  complain (&dwarf2_non_const_array_bound_ignored,
2492
                            dwarf_form_name (attr->form));
2493
#ifdef FORTRAN_HACK
2494
                  die->type = lookup_pointer_type (element_type);
2495
                  return;
2496
#else
2497
                  high = 1;
2498
#endif
2499
                }
2500
            }
2501
 
2502
          /* Create a range type and save it for array type creation.  */
2503
          if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
2504
            {
2505
              range_types = (struct type **)
2506
                xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
2507
                          * sizeof (struct type *));
2508
              if (ndim == 0)
2509
                make_cleanup ((make_cleanup_func) free_current_contents,
2510
                              &range_types);
2511
            }
2512
          range_types[ndim++] = create_range_type (NULL, index_type, low, high);
2513
        }
2514
      child_die = sibling_die (child_die);
2515
    }
2516
 
2517
  /* Dwarf2 dimensions are output from left to right, create the
2518
     necessary array types in backwards order.  */
2519
  type = element_type;
2520
  while (ndim-- > 0)
2521
    type = create_array_type (NULL, type, range_types[ndim]);
2522
 
2523
  do_cleanups (back_to);
2524
 
2525
  /* Install the type in the die. */
2526
  die->type = type;
2527
}
2528
 
2529
/* First cut: install each common block member as a global variable.  */
2530
 
2531
static void
2532
read_common_block (die, objfile)
2533
     struct die_info *die;
2534
     struct objfile *objfile;
2535
{
2536
  struct die_info *child_die;
2537
  struct attribute *attr;
2538
  struct symbol *sym;
2539
  CORE_ADDR base = (CORE_ADDR) 0;
2540
 
2541
  attr = dwarf_attr (die, DW_AT_location);
2542
  if (attr)
2543
    {
2544
      base = decode_locdesc (DW_BLOCK (attr), objfile);
2545
    }
2546
  if (die->has_children)
2547
    {
2548
      child_die = die->next;
2549
      while (child_die && child_die->tag)
2550
        {
2551
          sym = new_symbol (child_die, NULL, objfile);
2552
          attr = dwarf_attr (child_die, DW_AT_data_member_location);
2553
          if (attr)
2554
            {
2555
              SYMBOL_VALUE_ADDRESS (sym) =
2556
                base + decode_locdesc (DW_BLOCK (attr), objfile);
2557
              add_symbol_to_list (sym, &global_symbols);
2558
            }
2559
          child_die = sibling_die (child_die);
2560
        }
2561
    }
2562
}
2563
 
2564
/* Extract all information from a DW_TAG_pointer_type DIE and add to
2565
   the user defined type vector.  */
2566
 
2567
static void
2568
read_tag_pointer_type (die, objfile)
2569
     struct die_info *die;
2570
     struct objfile *objfile;
2571
{
2572
  struct type *type;
2573
  struct attribute *attr;
2574
 
2575
  if (die->type)
2576
    {
2577
      return;
2578
    }
2579
 
2580
  type = lookup_pointer_type (die_type (die, objfile));
2581
  attr = dwarf_attr (die, DW_AT_byte_size);
2582
  if (attr)
2583
    {
2584
      TYPE_LENGTH (type) = DW_UNSND (attr);
2585
    }
2586
  else
2587
    {
2588
      TYPE_LENGTH (type) = address_size;
2589
    }
2590
  die->type = type;
2591
}
2592
 
2593
/* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2594
   the user defined type vector.  */
2595
 
2596
static void
2597
read_tag_ptr_to_member_type (die, objfile)
2598
     struct die_info *die;
2599
     struct objfile *objfile;
2600
{
2601
  struct type *type;
2602
  struct type *to_type;
2603
  struct type *domain;
2604
 
2605
  if (die->type)
2606
    {
2607
      return;
2608
    }
2609
 
2610
  type = alloc_type (objfile);
2611
  to_type = die_type (die, objfile);
2612
  domain = die_containing_type (die, objfile);
2613
  smash_to_member_type (type, domain, to_type);
2614
 
2615
  die->type = type;
2616
}
2617
 
2618
/* Extract all information from a DW_TAG_reference_type DIE and add to
2619
   the user defined type vector.  */
2620
 
2621
static void
2622
read_tag_reference_type (die, objfile)
2623
     struct die_info *die;
2624
     struct objfile *objfile;
2625
{
2626
  struct type *type;
2627
  struct attribute *attr;
2628
 
2629
  if (die->type)
2630
    {
2631
      return;
2632
    }
2633
 
2634
  type = lookup_reference_type (die_type (die, objfile));
2635
  attr = dwarf_attr (die, DW_AT_byte_size);
2636
  if (attr)
2637
    {
2638
      TYPE_LENGTH (type) = DW_UNSND (attr);
2639
    }
2640
  else
2641
    {
2642
      TYPE_LENGTH (type) = address_size;
2643
    }
2644
  die->type = type;
2645
}
2646
 
2647
static void
2648
read_tag_const_type (die, objfile)
2649
     struct die_info *die;
2650
     struct objfile *objfile;
2651
{
2652
  if (die->type)
2653
    {
2654
      return;
2655
    }
2656
 
2657
  complain (&dwarf2_const_ignored);
2658
  die->type = die_type (die, objfile);
2659
}
2660
 
2661
static void
2662
read_tag_volatile_type (die, objfile)
2663
     struct die_info *die;
2664
     struct objfile *objfile;
2665
{
2666
  if (die->type)
2667
    {
2668
      return;
2669
    }
2670
 
2671
  complain (&dwarf2_volatile_ignored);
2672
  die->type = die_type (die, objfile);
2673
}
2674
 
2675
/* Extract all information from a DW_TAG_string_type DIE and add to
2676
   the user defined type vector.  It isn't really a user defined type,
2677
   but it behaves like one, with other DIE's using an AT_user_def_type
2678
   attribute to reference it.  */
2679
 
2680
static void
2681
read_tag_string_type (die, objfile)
2682
     struct die_info *die;
2683
     struct objfile *objfile;
2684
{
2685
  struct type *type, *range_type, *index_type, *char_type;
2686
  struct attribute *attr;
2687
  unsigned int length;
2688
 
2689
  if (die->type)
2690
    {
2691
      return;
2692
    }
2693
 
2694
  attr = dwarf_attr (die, DW_AT_string_length);
2695
  if (attr)
2696
    {
2697
      length = DW_UNSND (attr);
2698
    }
2699
  else
2700
    {
2701
      length = 1;
2702
    }
2703
  index_type = dwarf2_fundamental_type (objfile, FT_INTEGER);
2704
  range_type = create_range_type (NULL, index_type, 1, length);
2705
  char_type = dwarf2_fundamental_type (objfile, FT_CHAR);
2706
  type = create_string_type (char_type, range_type);
2707
  die->type = type;
2708
}
2709
 
2710
/* Handle DIES due to C code like:
2711
 
2712
   struct foo
2713
   {
2714
   int (*funcp)(int a, long l);
2715
   int b;
2716
   };
2717
 
2718
   ('funcp' generates a DW_TAG_subroutine_type DIE)
2719
 */
2720
 
2721
static void
2722
read_subroutine_type (die, objfile)
2723
     struct die_info *die;
2724
     struct objfile *objfile;
2725
{
2726
  struct type *type;            /* Type that this function returns */
2727
  struct type *ftype;           /* Function that returns above type */
2728
  struct attribute *attr;
2729
 
2730
  /* Decode the type that this subroutine returns */
2731
  if (die->type)
2732
    {
2733
      return;
2734
    }
2735
  type = die_type (die, objfile);
2736
  ftype = lookup_function_type (type);
2737
 
2738
  /* All functions in C++ have prototypes.  */
2739
  attr = dwarf_attr (die, DW_AT_prototyped);
2740
  if ((attr && (DW_UNSND (attr) != 0))
2741
      || cu_language == language_cplus)
2742
    TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
2743
 
2744
  if (die->has_children)
2745
    {
2746
      struct die_info *child_die;
2747
      int nparams = 0;
2748
      int iparams = 0;
2749
 
2750
      /* Count the number of parameters.
2751
         FIXME: GDB currently ignores vararg functions, but knows about
2752
         vararg member functions.  */
2753
      child_die = die->next;
2754
      while (child_die && child_die->tag)
2755
        {
2756
          if (child_die->tag == DW_TAG_formal_parameter)
2757
            nparams++;
2758
          else if (child_die->tag == DW_TAG_unspecified_parameters)
2759
            TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
2760
          child_die = sibling_die (child_die);
2761
        }
2762
 
2763
      /* Allocate storage for parameters and fill them in.  */
2764
      TYPE_NFIELDS (ftype) = nparams;
2765
      TYPE_FIELDS (ftype) = (struct field *)
2766
        TYPE_ALLOC (ftype, nparams * sizeof (struct field));
2767
 
2768
      child_die = die->next;
2769
      while (child_die && child_die->tag)
2770
        {
2771
          if (child_die->tag == DW_TAG_formal_parameter)
2772
            {
2773
              /* Dwarf2 has no clean way to discern C++ static and non-static
2774
                 member functions. G++ helps GDB by marking the first
2775
                 parameter for non-static member functions (which is the
2776
                 this pointer) as artificial. We pass this information
2777
                 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.  */
2778
              attr = dwarf_attr (child_die, DW_AT_artificial);
2779
              if (attr)
2780
                TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
2781
              else
2782
                TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
2783
              TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, objfile);
2784
              iparams++;
2785
            }
2786
          child_die = sibling_die (child_die);
2787
        }
2788
    }
2789
 
2790
  die->type = ftype;
2791
}
2792
 
2793
static void
2794
read_typedef (die, objfile)
2795
     struct die_info *die;
2796
     struct objfile *objfile;
2797
{
2798
  struct type *type;
2799
 
2800
  if (!die->type)
2801
    {
2802
      struct attribute *attr;
2803
      struct type *xtype;
2804
 
2805
      xtype = die_type (die, objfile);
2806
 
2807
      type = alloc_type (objfile);
2808
      TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2809
      TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2810
      TYPE_TARGET_TYPE (type) = xtype;
2811
      attr = dwarf_attr (die, DW_AT_name);
2812
      if (attr && DW_STRING (attr))
2813
        TYPE_NAME (type) = obsavestring (DW_STRING (attr),
2814
                                         strlen (DW_STRING (attr)),
2815
                                         &objfile->type_obstack);
2816
 
2817
      die->type = type;
2818
    }
2819
}
2820
 
2821
/* Find a representation of a given base type and install
2822
   it in the TYPE field of the die.  */
2823
 
2824
static void
2825
read_base_type (die, objfile)
2826
     struct die_info *die;
2827
     struct objfile *objfile;
2828
{
2829
  struct type *type;
2830
  struct attribute *attr;
2831
  int encoding = 0, size = 0;
2832
 
2833
  /* If we've already decoded this die, this is a no-op. */
2834
  if (die->type)
2835
    {
2836
      return;
2837
    }
2838
 
2839
  attr = dwarf_attr (die, DW_AT_encoding);
2840
  if (attr)
2841
    {
2842
      encoding = DW_UNSND (attr);
2843
    }
2844
  attr = dwarf_attr (die, DW_AT_byte_size);
2845
  if (attr)
2846
    {
2847
      size = DW_UNSND (attr);
2848
    }
2849
  attr = dwarf_attr (die, DW_AT_name);
2850
  if (attr && DW_STRING (attr))
2851
    {
2852
      enum type_code code = TYPE_CODE_INT;
2853
      int is_unsigned = 0;
2854
 
2855
      switch (encoding)
2856
        {
2857
        case DW_ATE_address:
2858
          /* Turn DW_ATE_address into a void * pointer.  */
2859
          code = TYPE_CODE_PTR;
2860
          is_unsigned = 1;
2861
          break;
2862
        case DW_ATE_boolean:
2863
          code = TYPE_CODE_BOOL;
2864
          is_unsigned = 1;
2865
          break;
2866
        case DW_ATE_complex_float:
2867
          code = TYPE_CODE_COMPLEX;
2868
          break;
2869
        case DW_ATE_float:
2870
          code = TYPE_CODE_FLT;
2871
          break;
2872
        case DW_ATE_signed:
2873
        case DW_ATE_signed_char:
2874
          break;
2875
        case DW_ATE_unsigned:
2876
        case DW_ATE_unsigned_char:
2877
          is_unsigned = 1;
2878
          break;
2879
        default:
2880
          complain (&dwarf2_unsupported_at_encoding,
2881
                    dwarf_type_encoding_name (encoding));
2882
          break;
2883
        }
2884
      type = init_type (code, size, is_unsigned, DW_STRING (attr), objfile);
2885
      if (encoding == DW_ATE_address)
2886
        TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID);
2887
    }
2888
  else
2889
    {
2890
      type = dwarf_base_type (encoding, size, objfile);
2891
    }
2892
  die->type = type;
2893
}
2894
 
2895
/* Read a whole compilation unit into a linked list of dies.  */
2896
 
2897
struct die_info *
2898
read_comp_unit (info_ptr, abfd)
2899
     char *info_ptr;
2900
     bfd *abfd;
2901
{
2902
  struct die_info *first_die, *last_die, *die;
2903
  char *cur_ptr;
2904
  int nesting_level;
2905
 
2906
  /* Reset die reference table, we are building a new one now. */
2907
  dwarf2_empty_die_ref_table ();
2908
 
2909
  cur_ptr = info_ptr;
2910
  nesting_level = 0;
2911
  first_die = last_die = NULL;
2912
  do
2913
    {
2914
      cur_ptr = read_full_die (&die, abfd, cur_ptr);
2915
      if (die->has_children)
2916
        {
2917
          nesting_level++;
2918
        }
2919
      if (die->tag == 0)
2920
        {
2921
          nesting_level--;
2922
        }
2923
 
2924
      die->next = NULL;
2925
 
2926
      /* Enter die in reference hash table */
2927
      store_in_ref_table (die->offset, die);
2928
 
2929
      if (!first_die)
2930
        {
2931
          first_die = last_die = die;
2932
        }
2933
      else
2934
        {
2935
          last_die->next = die;
2936
          last_die = die;
2937
        }
2938
    }
2939
  while (nesting_level > 0);
2940
  return first_die;
2941
}
2942
 
2943
/* Free a linked list of dies.  */
2944
 
2945
static void
2946
free_die_list (dies)
2947
     struct die_info *dies;
2948
{
2949
  struct die_info *die, *next;
2950
 
2951
  die = dies;
2952
  while (die)
2953
    {
2954
      next = die->next;
2955
      free (die->attrs);
2956
      free (die);
2957
      die = next;
2958
    }
2959
}
2960
 
2961
/* Read the contents of the section at OFFSET and of size SIZE from the
2962
   object file specified by OBJFILE into the psymbol_obstack and return it.  */
2963
 
2964
static char *
2965
dwarf2_read_section (objfile, offset, size)
2966
     struct objfile *objfile;
2967
     file_ptr offset;
2968
     unsigned int size;
2969
{
2970
  bfd *abfd = objfile->obfd;
2971
  char *buf;
2972
 
2973
  if (size == 0)
2974
    return NULL;
2975
 
2976
  buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
2977
  if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
2978
      (bfd_read (buf, size, 1, abfd) != size))
2979
    {
2980
      buf = NULL;
2981
      error ("Dwarf Error: Can't read DWARF data from '%s'",
2982
             bfd_get_filename (abfd));
2983
    }
2984
  return buf;
2985
}
2986
 
2987
/* In DWARF version 2, the description of the debugging information is
2988
   stored in a separate .debug_abbrev section.  Before we read any
2989
   dies from a section we read in all abbreviations and install them
2990
   in a hash table.  */
2991
 
2992
static void
2993
dwarf2_read_abbrevs (abfd, offset)
2994
     bfd *abfd;
2995
     unsigned int offset;
2996
{
2997
  char *abbrev_ptr;
2998
  struct abbrev_info *cur_abbrev;
2999
  unsigned int abbrev_number, bytes_read, abbrev_name;
3000
  unsigned int abbrev_form, hash_number;
3001
 
3002
  /* empty the table */
3003
  dwarf2_empty_abbrev_table (NULL);
3004
 
3005
  abbrev_ptr = dwarf_abbrev_buffer + offset;
3006
  abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3007
  abbrev_ptr += bytes_read;
3008
 
3009
  /* loop until we reach an abbrev number of 0 */
3010
  while (abbrev_number)
3011
    {
3012
      cur_abbrev = dwarf_alloc_abbrev ();
3013
 
3014
      /* read in abbrev header */
3015
      cur_abbrev->number = abbrev_number;
3016
      cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3017
      abbrev_ptr += bytes_read;
3018
      cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
3019
      abbrev_ptr += 1;
3020
 
3021
      /* now read in declarations */
3022
      abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3023
      abbrev_ptr += bytes_read;
3024
      abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3025
      abbrev_ptr += bytes_read;
3026
      while (abbrev_name)
3027
        {
3028
          if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
3029
            {
3030
              cur_abbrev->attrs = (struct attr_abbrev *)
3031
                xrealloc (cur_abbrev->attrs,
3032
                          (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)
3033
                          * sizeof (struct attr_abbrev));
3034
            }
3035
          cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name;
3036
          cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form;
3037
          abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3038
          abbrev_ptr += bytes_read;
3039
          abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3040
          abbrev_ptr += bytes_read;
3041
        }
3042
 
3043
      hash_number = abbrev_number % ABBREV_HASH_SIZE;
3044
      cur_abbrev->next = dwarf2_abbrevs[hash_number];
3045
      dwarf2_abbrevs[hash_number] = cur_abbrev;
3046
 
3047
      /* Get next abbreviation.
3048
         Under Irix6 the abbreviations for a compilation unit are not
3049
         always properly terminated with an abbrev number of 0.
3050
         Exit loop if we encounter an abbreviation which we have
3051
         already read (which means we are about to read the abbreviations
3052
         for the next compile unit) or if the end of the abbreviation
3053
         table is reached.  */
3054
      if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer)
3055
          >= dwarf_abbrev_size)
3056
        break;
3057
      abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
3058
      abbrev_ptr += bytes_read;
3059
      if (dwarf2_lookup_abbrev (abbrev_number) != NULL)
3060
        break;
3061
    }
3062
}
3063
 
3064
/* Empty the abbrev table for a new compilation unit.  */
3065
 
3066
/* ARGSUSED */
3067
static void
3068
dwarf2_empty_abbrev_table (ignore)
3069
     PTR ignore;
3070
{
3071
  int i;
3072
  struct abbrev_info *abbrev, *next;
3073
 
3074
  for (i = 0; i < ABBREV_HASH_SIZE; ++i)
3075
    {
3076
      next = NULL;
3077
      abbrev = dwarf2_abbrevs[i];
3078
      while (abbrev)
3079
        {
3080
          next = abbrev->next;
3081
          free (abbrev->attrs);
3082
          free (abbrev);
3083
          abbrev = next;
3084
        }
3085
      dwarf2_abbrevs[i] = NULL;
3086
    }
3087
}
3088
 
3089
/* Lookup an abbrev_info structure in the abbrev hash table.  */
3090
 
3091
static struct abbrev_info *
3092
dwarf2_lookup_abbrev (number)
3093
     unsigned int number;
3094
{
3095
  unsigned int hash_number;
3096
  struct abbrev_info *abbrev;
3097
 
3098
  hash_number = number % ABBREV_HASH_SIZE;
3099
  abbrev = dwarf2_abbrevs[hash_number];
3100
 
3101
  while (abbrev)
3102
    {
3103
      if (abbrev->number == number)
3104
        return abbrev;
3105
      else
3106
        abbrev = abbrev->next;
3107
    }
3108
  return NULL;
3109
}
3110
 
3111
/* Read a minimal amount of information into the minimal die structure.  */
3112
 
3113
static char *
3114
read_partial_die (part_die, abfd, info_ptr, has_pc_info)
3115
     struct partial_die_info *part_die;
3116
     bfd *abfd;
3117
     char *info_ptr;
3118
     int *has_pc_info;
3119
{
3120
  unsigned int abbrev_number, bytes_read, i;
3121
  struct abbrev_info *abbrev;
3122
  struct attribute attr;
3123
  struct attribute spec_attr;
3124
  int found_spec_attr = 0;
3125
  int has_low_pc_attr = 0;
3126
  int has_high_pc_attr = 0;
3127
 
3128
  *part_die = zeroed_partial_die;
3129
  *has_pc_info = 0;
3130
  abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3131
  info_ptr += bytes_read;
3132
  if (!abbrev_number)
3133
    return info_ptr;
3134
 
3135
  abbrev = dwarf2_lookup_abbrev (abbrev_number);
3136
  if (!abbrev)
3137
    {
3138
      error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number);
3139
    }
3140
  part_die->offset = info_ptr - dwarf_info_buffer;
3141
  part_die->tag = abbrev->tag;
3142
  part_die->has_children = abbrev->has_children;
3143
  part_die->abbrev = abbrev_number;
3144
 
3145
  for (i = 0; i < abbrev->num_attrs; ++i)
3146
    {
3147
      info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr);
3148
 
3149
      /* Store the data if it is of an attribute we want to keep in a
3150
         partial symbol table.  */
3151
      switch (attr.name)
3152
        {
3153
        case DW_AT_name:
3154
 
3155
          /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name.  */
3156
          if (part_die->name == NULL)
3157
            part_die->name = DW_STRING (&attr);
3158
          break;
3159
        case DW_AT_MIPS_linkage_name:
3160
          part_die->name = DW_STRING (&attr);
3161
          break;
3162
        case DW_AT_low_pc:
3163
          has_low_pc_attr = 1;
3164
          part_die->lowpc = DW_ADDR (&attr);
3165
          break;
3166
        case DW_AT_high_pc:
3167
          has_high_pc_attr = 1;
3168
          part_die->highpc = DW_ADDR (&attr);
3169
          break;
3170
        case DW_AT_location:
3171
          part_die->locdesc = DW_BLOCK (&attr);
3172
          break;
3173
        case DW_AT_language:
3174
          part_die->language = DW_UNSND (&attr);
3175
          break;
3176
        case DW_AT_external:
3177
          part_die->is_external = DW_UNSND (&attr);
3178
          break;
3179
        case DW_AT_declaration:
3180
          part_die->is_declaration = DW_UNSND (&attr);
3181
          break;
3182
        case DW_AT_type:
3183
          part_die->has_type = 1;
3184
          break;
3185
        case DW_AT_abstract_origin:
3186
        case DW_AT_specification:
3187
          found_spec_attr = 1;
3188
          spec_attr = attr;
3189
          break;
3190
        case DW_AT_sibling:
3191
          /* Ignore absolute siblings, they might point outside of
3192
             the current compile unit.  */
3193
          if (attr.form == DW_FORM_ref_addr)
3194
            complain (&dwarf2_absolute_sibling_complaint);
3195
          else
3196
            part_die->sibling =
3197
              dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr);
3198
          break;
3199
        default:
3200
          break;
3201
        }
3202
    }
3203
 
3204
  /* If we found a reference attribute and the die has no name, try
3205
     to find a name in the referred to die.  */
3206
 
3207
  if (found_spec_attr && part_die->name == NULL)
3208
    {
3209
      struct partial_die_info spec_die;
3210
      char *spec_ptr;
3211
      int dummy;
3212
 
3213
      spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr);
3214
      read_partial_die (&spec_die, abfd, spec_ptr, &dummy);
3215
      if (spec_die.name)
3216
        {
3217
          part_die->name = spec_die.name;
3218
 
3219
          /* Copy DW_AT_external attribute if it is set.  */
3220
          if (spec_die.is_external)
3221
            part_die->is_external = spec_die.is_external;
3222
        }
3223
    }
3224
 
3225
  /* When using the GNU linker, .gnu.linkonce. sections are used to
3226
     eliminate duplicate copies of functions and vtables and such.
3227
     The linker will arbitrarily choose one and discard the others.
3228
     The AT_*_pc values for such functions refer to local labels in
3229
     these sections.  If the section from that file was discarded, the
3230
     labels are not in the output, so the relocs get a value of 0.
3231
     If this is a discarded function, mark the pc bounds as invalid,
3232
     so that GDB will ignore it.  */
3233
  if (has_low_pc_attr && has_high_pc_attr
3234
      && part_die->lowpc < part_die->highpc
3235
      && (part_die->lowpc != 0
3236
          || (bfd_get_file_flags (abfd) & HAS_RELOC)))
3237
    *has_pc_info = 1;
3238
  return info_ptr;
3239
}
3240
 
3241
/* Read the die from the .debug_info section buffer.  And set diep to
3242
   point to a newly allocated die with its information.  */
3243
 
3244
static char *
3245
read_full_die (diep, abfd, info_ptr)
3246
     struct die_info **diep;
3247
     bfd *abfd;
3248
     char *info_ptr;
3249
{
3250
  unsigned int abbrev_number, bytes_read, i, offset;
3251
  struct abbrev_info *abbrev;
3252
  struct die_info *die;
3253
 
3254
  offset = info_ptr - dwarf_info_buffer;
3255
  abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3256
  info_ptr += bytes_read;
3257
  if (!abbrev_number)
3258
    {
3259
      die = dwarf_alloc_die ();
3260
      die->tag = 0;
3261
      die->abbrev = abbrev_number;
3262
      die->type = NULL;
3263
      *diep = die;
3264
      return info_ptr;
3265
    }
3266
 
3267
  abbrev = dwarf2_lookup_abbrev (abbrev_number);
3268
  if (!abbrev)
3269
    {
3270
      error ("Dwarf Error: could not find abbrev number %d.", abbrev_number);
3271
    }
3272
  die = dwarf_alloc_die ();
3273
  die->offset = offset;
3274
  die->tag = abbrev->tag;
3275
  die->has_children = abbrev->has_children;
3276
  die->abbrev = abbrev_number;
3277
  die->type = NULL;
3278
 
3279
  die->num_attrs = abbrev->num_attrs;
3280
  die->attrs = (struct attribute *)
3281
    xmalloc (die->num_attrs * sizeof (struct attribute));
3282
 
3283
  for (i = 0; i < abbrev->num_attrs; ++i)
3284
    {
3285
      info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
3286
                                 abfd, info_ptr);
3287
    }
3288
 
3289
  *diep = die;
3290
  return info_ptr;
3291
}
3292
 
3293
/* Read an attribute described by an abbreviated attribute.  */
3294
 
3295
static char *
3296
read_attribute (attr, abbrev, abfd, info_ptr)
3297
     struct attribute *attr;
3298
     struct attr_abbrev *abbrev;
3299
     bfd *abfd;
3300
     char *info_ptr;
3301
{
3302
  unsigned int bytes_read;
3303
  struct dwarf_block *blk;
3304
 
3305
  attr->name = abbrev->name;
3306
  attr->form = abbrev->form;
3307
  switch (abbrev->form)
3308
    {
3309
    case DW_FORM_addr:
3310
    case DW_FORM_ref_addr:
3311
      DW_ADDR (attr) = read_address (abfd, info_ptr);
3312
      info_ptr += address_size;
3313
      break;
3314
    case DW_FORM_block2:
3315
      blk = dwarf_alloc_block ();
3316
      blk->size = read_2_bytes (abfd, info_ptr);
3317
      info_ptr += 2;
3318
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3319
      info_ptr += blk->size;
3320
      DW_BLOCK (attr) = blk;
3321
      break;
3322
    case DW_FORM_block4:
3323
      blk = dwarf_alloc_block ();
3324
      blk->size = read_4_bytes (abfd, info_ptr);
3325
      info_ptr += 4;
3326
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3327
      info_ptr += blk->size;
3328
      DW_BLOCK (attr) = blk;
3329
      break;
3330
    case DW_FORM_data2:
3331
      DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
3332
      info_ptr += 2;
3333
      break;
3334
    case DW_FORM_data4:
3335
      DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
3336
      info_ptr += 4;
3337
      break;
3338
    case DW_FORM_data8:
3339
      DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
3340
      info_ptr += 8;
3341
      break;
3342
    case DW_FORM_string:
3343
      DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
3344
      info_ptr += bytes_read;
3345
      break;
3346
    case DW_FORM_block:
3347
      blk = dwarf_alloc_block ();
3348
      blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3349
      info_ptr += bytes_read;
3350
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3351
      info_ptr += blk->size;
3352
      DW_BLOCK (attr) = blk;
3353
      break;
3354
    case DW_FORM_block1:
3355
      blk = dwarf_alloc_block ();
3356
      blk->size = read_1_byte (abfd, info_ptr);
3357
      info_ptr += 1;
3358
      blk->data = read_n_bytes (abfd, info_ptr, blk->size);
3359
      info_ptr += blk->size;
3360
      DW_BLOCK (attr) = blk;
3361
      break;
3362
    case DW_FORM_data1:
3363
      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3364
      info_ptr += 1;
3365
      break;
3366
    case DW_FORM_flag:
3367
      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3368
      info_ptr += 1;
3369
      break;
3370
    case DW_FORM_sdata:
3371
      DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
3372
      info_ptr += bytes_read;
3373
      break;
3374
    case DW_FORM_udata:
3375
      DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3376
      info_ptr += bytes_read;
3377
      break;
3378
    case DW_FORM_ref1:
3379
      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
3380
      info_ptr += 1;
3381
      break;
3382
    case DW_FORM_ref2:
3383
      DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
3384
      info_ptr += 2;
3385
      break;
3386
    case DW_FORM_ref4:
3387
      DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
3388
      info_ptr += 4;
3389
      break;
3390
    case DW_FORM_ref_udata:
3391
      DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
3392
      info_ptr += bytes_read;
3393
      break;
3394
    case DW_FORM_strp:
3395
    case DW_FORM_indirect:
3396
    default:
3397
      error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3398
             dwarf_form_name (abbrev->form));
3399
    }
3400
  return info_ptr;
3401
}
3402
 
3403
/* read dwarf information from a buffer */
3404
 
3405
static unsigned int
3406
read_1_byte (abfd, buf)
3407
     bfd *abfd;
3408
     char *buf;
3409
{
3410
  return bfd_get_8 (abfd, (bfd_byte *) buf);
3411
}
3412
 
3413
static int
3414
read_1_signed_byte (abfd, buf)
3415
     bfd *abfd;
3416
     char *buf;
3417
{
3418
  return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
3419
}
3420
 
3421
static unsigned int
3422
read_2_bytes (abfd, buf)
3423
     bfd *abfd;
3424
     char *buf;
3425
{
3426
  return bfd_get_16 (abfd, (bfd_byte *) buf);
3427
}
3428
 
3429
static int
3430
read_2_signed_bytes (abfd, buf)
3431
     bfd *abfd;
3432
     char *buf;
3433
{
3434
  return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
3435
}
3436
 
3437
static unsigned int
3438
read_4_bytes (abfd, buf)
3439
     bfd *abfd;
3440
     char *buf;
3441
{
3442
  return bfd_get_32 (abfd, (bfd_byte *) buf);
3443
}
3444
 
3445
static int
3446
read_4_signed_bytes (abfd, buf)
3447
     bfd *abfd;
3448
     char *buf;
3449
{
3450
  return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
3451
}
3452
 
3453
static unsigned int
3454
read_8_bytes (abfd, buf)
3455
     bfd *abfd;
3456
     char *buf;
3457
{
3458
  return bfd_get_64 (abfd, (bfd_byte *) buf);
3459
}
3460
 
3461
static CORE_ADDR
3462
read_address (abfd, buf)
3463
     bfd *abfd;
3464
     char *buf;
3465
{
3466
  CORE_ADDR retval = 0;
3467
 
3468
  switch (address_size)
3469
    {
3470
    case 2:
3471
      retval = bfd_get_16 (abfd, (bfd_byte *) buf);
3472
      break;
3473
    case 4:
3474
      retval = bfd_get_32 (abfd, (bfd_byte *) buf);
3475
      break;
3476
    case 8:
3477
      retval = bfd_get_64 (abfd, (bfd_byte *) buf);
3478
      break;
3479
    default:
3480
      /* *THE* alternative is 8, right? */
3481
      abort ();
3482
    }
3483
 
3484
 return retval;
3485
}
3486
 
3487
static char *
3488
read_n_bytes (abfd, buf, size)
3489
     bfd *abfd;
3490
     char *buf;
3491
     unsigned int size;
3492
{
3493
  /* If the size of a host char is 8 bits, we can return a pointer
3494
     to the buffer, otherwise we have to copy the data to a buffer
3495
     allocated on the temporary obstack.  */
3496
#if HOST_CHAR_BIT == 8
3497
  return buf;
3498
#else
3499
  char *ret;
3500
  unsigned int i;
3501
 
3502
  ret = obstack_alloc (&dwarf2_tmp_obstack, size);
3503
  for (i = 0; i < size; ++i)
3504
    {
3505
      ret[i] = bfd_get_8 (abfd, (bfd_byte *) buf);
3506
      buf++;
3507
    }
3508
  return ret;
3509
#endif
3510
}
3511
 
3512
static char *
3513
read_string (abfd, buf, bytes_read_ptr)
3514
     bfd *abfd;
3515
     char *buf;
3516
     unsigned int *bytes_read_ptr;
3517
{
3518
  /* If the size of a host char is 8 bits, we can return a pointer
3519
     to the string, otherwise we have to copy the string to a buffer
3520
     allocated on the temporary obstack.  */
3521
#if HOST_CHAR_BIT == 8
3522
  if (*buf == '\0')
3523
    {
3524
      *bytes_read_ptr = 1;
3525
      return NULL;
3526
    }
3527
  *bytes_read_ptr = strlen (buf) + 1;
3528
  return buf;
3529
#else
3530
  int byte;
3531
  unsigned int i = 0;
3532
 
3533
  while ((byte = bfd_get_8 (abfd, (bfd_byte *) buf)) != 0)
3534
    {
3535
      obstack_1grow (&dwarf2_tmp_obstack, byte);
3536
      i++;
3537
      buf++;
3538
    }
3539
  if (i == 0)
3540
    {
3541
      *bytes_read_ptr = 1;
3542
      return NULL;
3543
    }
3544
  obstack_1grow (&dwarf2_tmp_obstack, '\0');
3545
  *bytes_read_ptr = i + 1;
3546
  return obstack_finish (&dwarf2_tmp_obstack);
3547
#endif
3548
}
3549
 
3550
static unsigned int
3551
read_unsigned_leb128 (abfd, buf, bytes_read_ptr)
3552
     bfd *abfd;
3553
     char *buf;
3554
     unsigned int *bytes_read_ptr;
3555
{
3556
  unsigned int result, num_read;
3557
  int i, shift;
3558
  unsigned char byte;
3559
 
3560
  result = 0;
3561
  shift = 0;
3562
  num_read = 0;
3563
  i = 0;
3564
  while (1)
3565
    {
3566
      byte = bfd_get_8 (abfd, (bfd_byte *) buf);
3567
      buf++;
3568
      num_read++;
3569
      result |= ((byte & 127) << shift);
3570
      if ((byte & 128) == 0)
3571
        {
3572
          break;
3573
        }
3574
      shift += 7;
3575
    }
3576
  *bytes_read_ptr = num_read;
3577
  return result;
3578
}
3579
 
3580
static int
3581
read_signed_leb128 (abfd, buf, bytes_read_ptr)
3582
     bfd *abfd;
3583
     char *buf;
3584
     unsigned int *bytes_read_ptr;
3585
{
3586
  int result;
3587
  int i, shift, size, num_read;
3588
  unsigned char byte;
3589
 
3590
  result = 0;
3591
  shift = 0;
3592
  size = 32;
3593
  num_read = 0;
3594
  i = 0;
3595
  while (1)
3596
    {
3597
      byte = bfd_get_8 (abfd, (bfd_byte *) buf);
3598
      buf++;
3599
      num_read++;
3600
      result |= ((byte & 127) << shift);
3601
      shift += 7;
3602
      if ((byte & 128) == 0)
3603
        {
3604
          break;
3605
        }
3606
    }
3607
  if ((shift < size) && (byte & 0x40))
3608
    {
3609
      result |= -(1 << shift);
3610
    }
3611
  *bytes_read_ptr = num_read;
3612
  return result;
3613
}
3614
 
3615
static void
3616
set_cu_language (lang)
3617
     unsigned int lang;
3618
{
3619
  switch (lang)
3620
    {
3621
    case DW_LANG_C89:
3622
    case DW_LANG_C:
3623
      cu_language = language_c;
3624
      break;
3625
    case DW_LANG_C_plus_plus:
3626
      cu_language = language_cplus;
3627
      break;
3628
    case DW_LANG_Fortran77:
3629
    case DW_LANG_Fortran90:
3630
      cu_language = language_fortran;
3631
      break;
3632
    case DW_LANG_Mips_Assembler:
3633
      cu_language = language_asm;
3634
      break;
3635
    case DW_LANG_Ada83:
3636
    case DW_LANG_Cobol74:
3637
    case DW_LANG_Cobol85:
3638
    case DW_LANG_Pascal83:
3639
    case DW_LANG_Modula2:
3640
    default:
3641
      cu_language = language_unknown;
3642
      break;
3643
    }
3644
  cu_language_defn = language_def (cu_language);
3645
}
3646
 
3647
/* Return the named attribute or NULL if not there.  */
3648
 
3649
static struct attribute *
3650
dwarf_attr (die, name)
3651
     struct die_info *die;
3652
     unsigned int name;
3653
{
3654
  unsigned int i;
3655
  struct attribute *spec = NULL;
3656
 
3657
  for (i = 0; i < die->num_attrs; ++i)
3658
    {
3659
      if (die->attrs[i].name == name)
3660
        {
3661
          return &die->attrs[i];
3662
        }
3663
      if (die->attrs[i].name == DW_AT_specification
3664
          || die->attrs[i].name == DW_AT_abstract_origin)
3665
        spec = &die->attrs[i];
3666
    }
3667
  if (spec)
3668
    {
3669
      struct die_info *ref_die =
3670
      follow_die_ref (dwarf2_get_ref_die_offset (spec));
3671
 
3672
      if (ref_die)
3673
        return dwarf_attr (ref_die, name);
3674
    }
3675
 
3676
  return NULL;
3677
}
3678
 
3679
static int
3680
die_is_declaration (struct die_info *die)
3681
{
3682
  return (dwarf_attr (die, DW_AT_declaration)
3683
          && ! dwarf_attr (die, DW_AT_specification));
3684
}
3685
 
3686
/* Decode the line number information for the compilation unit whose
3687
   line number info is at OFFSET in the .debug_line section.
3688
   The compilation directory of the file is passed in COMP_DIR.  */
3689
 
3690
struct filenames
3691
{
3692
  unsigned int num_files;
3693
  struct fileinfo
3694
    {
3695
      char *name;
3696
      unsigned int dir;
3697
      unsigned int time;
3698
      unsigned int size;
3699
    }
3700
   *files;
3701
};
3702
 
3703
struct directories
3704
  {
3705
    unsigned int num_dirs;
3706
    char **dirs;
3707
  };
3708
 
3709
static void
3710
dwarf_decode_lines (offset, comp_dir, abfd)
3711
     unsigned int offset;
3712
     char *comp_dir;
3713
     bfd *abfd;
3714
{
3715
  char *line_ptr;
3716
  char *line_end;
3717
  struct line_head lh;
3718
  struct cleanup *back_to;
3719
  unsigned int i, bytes_read;
3720
  char *cur_file, *cur_dir;
3721
  unsigned char op_code, extended_op, adj_opcode;
3722
 
3723
#define FILE_ALLOC_CHUNK 5
3724
#define DIR_ALLOC_CHUNK 5
3725
 
3726
  struct filenames files;
3727
  struct directories dirs;
3728
 
3729
  if (dwarf_line_buffer == NULL)
3730
    {
3731
      complain (&dwarf2_missing_line_number_section);
3732
      return;
3733
    }
3734
 
3735
  files.num_files = 0;
3736
  files.files = NULL;
3737
 
3738
  dirs.num_dirs = 0;
3739
  dirs.dirs = NULL;
3740
 
3741
  line_ptr = dwarf_line_buffer + offset;
3742
 
3743
  /* read in the prologue */
3744
  lh.total_length = read_4_bytes (abfd, line_ptr);
3745
  line_ptr += 4;
3746
  line_end = line_ptr + lh.total_length;
3747
  lh.version = read_2_bytes (abfd, line_ptr);
3748
  line_ptr += 2;
3749
  lh.prologue_length = read_4_bytes (abfd, line_ptr);
3750
  line_ptr += 4;
3751
  lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
3752
  line_ptr += 1;
3753
  lh.default_is_stmt = read_1_byte (abfd, line_ptr);
3754
  line_ptr += 1;
3755
  lh.line_base = read_1_signed_byte (abfd, line_ptr);
3756
  line_ptr += 1;
3757
  lh.line_range = read_1_byte (abfd, line_ptr);
3758
  line_ptr += 1;
3759
  lh.opcode_base = read_1_byte (abfd, line_ptr);
3760
  line_ptr += 1;
3761
  lh.standard_opcode_lengths = (unsigned char *)
3762
    xmalloc (lh.opcode_base * sizeof (unsigned char));
3763
  back_to = make_cleanup ((make_cleanup_func) free_current_contents,
3764
                          &lh.standard_opcode_lengths);
3765
 
3766
  lh.standard_opcode_lengths[0] = 1;
3767
  for (i = 1; i < lh.opcode_base; ++i)
3768
    {
3769
      lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
3770
      line_ptr += 1;
3771
    }
3772
 
3773
  /* Read directory table  */
3774
  while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3775
    {
3776
      line_ptr += bytes_read;
3777
      if ((dirs.num_dirs % DIR_ALLOC_CHUNK) == 0)
3778
        {
3779
          dirs.dirs = (char **)
3780
            xrealloc (dirs.dirs,
3781
                      (dirs.num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));
3782
          if (dirs.num_dirs == 0)
3783
            make_cleanup ((make_cleanup_func) free_current_contents, &dirs.dirs);
3784
        }
3785
      dirs.dirs[dirs.num_dirs++] = cur_dir;
3786
    }
3787
  line_ptr += bytes_read;
3788
 
3789
  /* Read file name table */
3790
  while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
3791
    {
3792
      line_ptr += bytes_read;
3793
      if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3794
        {
3795
          files.files = (struct fileinfo *)
3796
            xrealloc (files.files,
3797
                      (files.num_files + FILE_ALLOC_CHUNK)
3798
                      * sizeof (struct fileinfo));
3799
          if (files.num_files == 0)
3800
            make_cleanup ((make_cleanup_func) free_current_contents,
3801
                          &files.files);
3802
        }
3803
      files.files[files.num_files].name = cur_file;
3804
      files.files[files.num_files].dir =
3805
        read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3806
      line_ptr += bytes_read;
3807
      files.files[files.num_files].time =
3808
        read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3809
      line_ptr += bytes_read;
3810
      files.files[files.num_files].size =
3811
        read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3812
      line_ptr += bytes_read;
3813
      files.num_files++;
3814
    }
3815
  line_ptr += bytes_read;
3816
 
3817
  /* Read the statement sequences until there's nothing left.  */
3818
  while (line_ptr < line_end)
3819
    {
3820
      /* state machine registers  */
3821
      CORE_ADDR address = 0;
3822
      unsigned int file = 1;
3823
      unsigned int line = 1;
3824
      unsigned int column = 0;
3825
      int is_stmt = lh.default_is_stmt;
3826
      int basic_block = 0;
3827
      int end_sequence = 0;
3828
 
3829
      /* Start a subfile for the current file of the state machine.  */
3830
      if (files.num_files >= file)
3831
        {
3832
          /* The file and directory tables are 0 based, the references
3833
             are 1 based.  */
3834
          dwarf2_start_subfile (files.files[file - 1].name,
3835
                                (files.files[file - 1].dir
3836
                                 ? dirs.dirs[files.files[file - 1].dir - 1]
3837
                                 : comp_dir));
3838
        }
3839
 
3840
      /* Decode the table. */
3841
      while (!end_sequence)
3842
        {
3843
          op_code = read_1_byte (abfd, line_ptr);
3844
          line_ptr += 1;
3845
          switch (op_code)
3846
            {
3847
            case DW_LNS_extended_op:
3848
              line_ptr += 1;    /* ignore length */
3849
              extended_op = read_1_byte (abfd, line_ptr);
3850
              line_ptr += 1;
3851
              switch (extended_op)
3852
                {
3853
                case DW_LNE_end_sequence:
3854
                  end_sequence = 1;
3855
                  /* Don't call record_line here.  The end_sequence
3856
                     instruction provides the address of the first byte
3857
                     *after* the last line in the sequence; it's not the
3858
                     address of any real source line.  However, the GDB
3859
                     linetable structure only records the starts of lines,
3860
                     not the ends.  This is a weakness of GDB.  */
3861
                  break;
3862
                case DW_LNE_set_address:
3863
                  address = read_address (abfd, line_ptr) + baseaddr;
3864
                  line_ptr += address_size;
3865
                  break;
3866
                case DW_LNE_define_file:
3867
                  cur_file = read_string (abfd, line_ptr, &bytes_read);
3868
                  line_ptr += bytes_read;
3869
                  if ((files.num_files % FILE_ALLOC_CHUNK) == 0)
3870
                    {
3871
                      files.files = (struct fileinfo *)
3872
                        xrealloc (files.files,
3873
                                  (files.num_files + FILE_ALLOC_CHUNK)
3874
                                  * sizeof (struct fileinfo));
3875
                      if (files.num_files == 0)
3876
                        make_cleanup ((make_cleanup_func) free_current_contents,
3877
                                      &files.files);
3878
                    }
3879
                  files.files[files.num_files].name = cur_file;
3880
                  files.files[files.num_files].dir =
3881
                    read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3882
                  line_ptr += bytes_read;
3883
                  files.files[files.num_files].time =
3884
                    read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3885
                  line_ptr += bytes_read;
3886
                  files.files[files.num_files].size =
3887
                    read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3888
                  line_ptr += bytes_read;
3889
                  files.num_files++;
3890
                  break;
3891
                default:
3892
                  complain (&dwarf2_mangled_line_number_section);
3893
                  goto done;
3894
                }
3895
              break;
3896
            case DW_LNS_copy:
3897
              record_line (current_subfile, line, address);
3898
              basic_block = 0;
3899
              break;
3900
            case DW_LNS_advance_pc:
3901
              address += lh.minimum_instruction_length
3902
                * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3903
              line_ptr += bytes_read;
3904
              break;
3905
            case DW_LNS_advance_line:
3906
              line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
3907
              line_ptr += bytes_read;
3908
              break;
3909
            case DW_LNS_set_file:
3910
              /* The file and directory tables are 0 based, the references
3911
                 are 1 based.  */
3912
              file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3913
              line_ptr += bytes_read;
3914
              dwarf2_start_subfile
3915
                (files.files[file - 1].name,
3916
                 (files.files[file - 1].dir
3917
                  ? dirs.dirs[files.files[file - 1].dir - 1]
3918
                  : comp_dir));
3919
              break;
3920
            case DW_LNS_set_column:
3921
              column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
3922
              line_ptr += bytes_read;
3923
              break;
3924
            case DW_LNS_negate_stmt:
3925
              is_stmt = (!is_stmt);
3926
              break;
3927
            case DW_LNS_set_basic_block:
3928
              basic_block = 1;
3929
              break;
3930
            /* Add to the address register of the state machine the
3931
               address increment value corresponding to special opcode
3932
               255.  Ie, this value is scaled by the minimum instruction
3933
               length since special opcode 255 would have scaled the
3934
               the increment.  */
3935
            case DW_LNS_const_add_pc:
3936
              address += (lh.minimum_instruction_length
3937
                          * ((255 - lh.opcode_base) / lh.line_range));
3938
              break;
3939
            case DW_LNS_fixed_advance_pc:
3940
              address += read_2_bytes (abfd, line_ptr);
3941
              line_ptr += 2;
3942
              break;
3943
            default:            /* special operand */
3944
              adj_opcode = op_code - lh.opcode_base;
3945
              address += (adj_opcode / lh.line_range)
3946
                * lh.minimum_instruction_length;
3947
              line += lh.line_base + (adj_opcode % lh.line_range);
3948
              /* append row to matrix using current values */
3949
              record_line (current_subfile, line, address);
3950
              basic_block = 1;
3951
            }
3952
        }
3953
    }
3954
done:
3955
  do_cleanups (back_to);
3956
}
3957
 
3958
/* Start a subfile for DWARF.  FILENAME is the name of the file and
3959
   DIRNAME the name of the source directory which contains FILENAME
3960
   or NULL if not known.
3961
   This routine tries to keep line numbers from identical absolute and
3962
   relative file names in a common subfile.
3963
 
3964
   Using the `list' example from the GDB testsuite, which resides in
3965
   /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3966
   of /srcdir/list0.c yields the following debugging information for list0.c:
3967
 
3968
   DW_AT_name:          /srcdir/list0.c
3969
   DW_AT_comp_dir:              /compdir
3970
   files.files[0].name: list0.h
3971
   files.files[0].dir:  /srcdir
3972
   files.files[1].name: list0.c
3973
   files.files[1].dir:  /srcdir
3974
 
3975
   The line number information for list0.c has to end up in a single
3976
   subfile, so that `break /srcdir/list0.c:1' works as expected.  */
3977
 
3978
static void
3979
dwarf2_start_subfile (filename, dirname)
3980
     char *filename;
3981
     char *dirname;
3982
{
3983
  /* If the filename isn't absolute, try to match an existing subfile
3984
     with the full pathname.  */
3985
 
3986
  if (*filename != '/' && dirname != NULL)
3987
    {
3988
      struct subfile *subfile;
3989
      char *fullname = concat (dirname, "/", filename, NULL);
3990
 
3991
      for (subfile = subfiles; subfile; subfile = subfile->next)
3992
        {
3993
          if (STREQ (subfile->name, fullname))
3994
            {
3995
              current_subfile = subfile;
3996
              free (fullname);
3997
              return;
3998
            }
3999
        }
4000
      free (fullname);
4001
    }
4002
  start_subfile (filename, dirname);
4003
}
4004
 
4005
/* Given a pointer to a DWARF information entry, figure out if we need
4006
   to make a symbol table entry for it, and if so, create a new entry
4007
   and return a pointer to it.
4008
   If TYPE is NULL, determine symbol type from the die, otherwise
4009
   used the passed type.  */
4010
 
4011
static struct symbol *
4012
new_symbol (die, type, objfile)
4013
     struct die_info *die;
4014
     struct type *type;
4015
     struct objfile *objfile;
4016
{
4017
  struct symbol *sym = NULL;
4018
  char *name;
4019
  struct attribute *attr = NULL;
4020
  struct attribute *attr2 = NULL;
4021
  CORE_ADDR addr;
4022
 
4023
  name = dwarf2_linkage_name (die);
4024
  if (name)
4025
    {
4026
      sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
4027
                                             sizeof (struct symbol));
4028
      OBJSTAT (objfile, n_syms++);
4029
      memset (sym, 0, sizeof (struct symbol));
4030
      SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
4031
                                        &objfile->symbol_obstack);
4032
 
4033
      /* Default assumptions.
4034
         Use the passed type or decode it from the die.  */
4035
      SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4036
      SYMBOL_CLASS (sym) = LOC_STATIC;
4037
      if (type != NULL)
4038
        SYMBOL_TYPE (sym) = type;
4039
      else
4040
        SYMBOL_TYPE (sym) = die_type (die, objfile);
4041
      attr = dwarf_attr (die, DW_AT_decl_line);
4042
      if (attr)
4043
        {
4044
          SYMBOL_LINE (sym) = DW_UNSND (attr);
4045
        }
4046
 
4047
      /* If this symbol is from a C++ compilation, then attempt to
4048
         cache the demangled form for future reference.  This is a
4049
         typical time versus space tradeoff, that was decided in favor
4050
         of time because it sped up C++ symbol lookups by a factor of
4051
         about 20. */
4052
 
4053
      SYMBOL_LANGUAGE (sym) = cu_language;
4054
      SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
4055
      switch (die->tag)
4056
        {
4057
        case DW_TAG_label:
4058
          attr = dwarf_attr (die, DW_AT_low_pc);
4059
          if (attr)
4060
            {
4061
              SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
4062
            }
4063
          SYMBOL_CLASS (sym) = LOC_LABEL;
4064
          break;
4065
        case DW_TAG_subprogram:
4066
          /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4067
             finish_block.  */
4068
          SYMBOL_CLASS (sym) = LOC_BLOCK;
4069
          attr2 = dwarf_attr (die, DW_AT_external);
4070
          if (attr2 && (DW_UNSND (attr2) != 0))
4071
            {
4072
              add_symbol_to_list (sym, &global_symbols);
4073
            }
4074
          else
4075
            {
4076
              add_symbol_to_list (sym, list_in_scope);
4077
            }
4078
          break;
4079
        case DW_TAG_variable:
4080
          /* Compilation with minimal debug info may result in variables
4081
             with missing type entries. Change the misleading `void' type
4082
             to something sensible.  */
4083
          if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
4084
            SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
4085
                                           TARGET_INT_BIT / HOST_CHAR_BIT, 0,
4086
                                           "<variable, no debug info>",
4087
                                           objfile);
4088
          attr = dwarf_attr (die, DW_AT_const_value);
4089
          if (attr)
4090
            {
4091
              dwarf2_const_value (attr, sym, objfile);
4092
              attr2 = dwarf_attr (die, DW_AT_external);
4093
              if (attr2 && (DW_UNSND (attr2) != 0))
4094
                add_symbol_to_list (sym, &global_symbols);
4095
              else
4096
                add_symbol_to_list (sym, list_in_scope);
4097
              break;
4098
            }
4099
          attr = dwarf_attr (die, DW_AT_location);
4100
          if (attr)
4101
            {
4102
              attr2 = dwarf_attr (die, DW_AT_external);
4103
              if (attr2 && (DW_UNSND (attr2) != 0))
4104
                {
4105
                  SYMBOL_VALUE_ADDRESS (sym) =
4106
                    decode_locdesc (DW_BLOCK (attr), objfile);
4107
                  add_symbol_to_list (sym, &global_symbols);
4108
 
4109
                  /* In shared libraries the address of the variable
4110
                     in the location descriptor might still be relocatable,
4111
                     so its value could be zero.
4112
                     Enter the symbol as a LOC_UNRESOLVED symbol, if its
4113
                     value is zero, the address of the variable will then
4114
                     be determined from the minimal symbol table whenever
4115
                     the variable is referenced.  */
4116
                  if (SYMBOL_VALUE_ADDRESS (sym))
4117
                    {
4118
                      SYMBOL_VALUE_ADDRESS (sym) += baseaddr;
4119
                      SYMBOL_CLASS (sym) = LOC_STATIC;
4120
                    }
4121
                  else
4122
                    SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
4123
                }
4124
              else
4125
                {
4126
                  SYMBOL_VALUE (sym) = addr =
4127
                    decode_locdesc (DW_BLOCK (attr), objfile);
4128
                  add_symbol_to_list (sym, list_in_scope);
4129
                  if (optimized_out)
4130
                    {
4131
                      SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
4132
                    }
4133
                  else if (isreg)
4134
                    {
4135
                      SYMBOL_CLASS (sym) = LOC_REGISTER;
4136
                    }
4137
                  else if (offreg)
4138
                    {
4139
                      SYMBOL_CLASS (sym) = LOC_BASEREG;
4140
                      SYMBOL_BASEREG (sym) = basereg;
4141
                    }
4142
                  else if (islocal)
4143
                    {
4144
                      SYMBOL_CLASS (sym) = LOC_LOCAL;
4145
                    }
4146
                  else
4147
                    {
4148
                      SYMBOL_CLASS (sym) = LOC_STATIC;
4149
                      SYMBOL_VALUE_ADDRESS (sym) = addr + baseaddr;
4150
                    }
4151
                }
4152
            }
4153
          else
4154
            {
4155
              /* We do not know the address of this symbol.
4156
                 If it is an external symbol and we have type information
4157
                 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4158
                 The address of the variable will then be determined from
4159
                 the minimal symbol table whenever the variable is
4160
                 referenced.  */
4161
              attr2 = dwarf_attr (die, DW_AT_external);
4162
              if (attr2 && (DW_UNSND (attr2) != 0)
4163
                  && dwarf_attr (die, DW_AT_type) != NULL)
4164
                {
4165
                  SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
4166
                  add_symbol_to_list (sym, &global_symbols);
4167
                }
4168
            }
4169
          break;
4170
        case DW_TAG_formal_parameter:
4171
          attr = dwarf_attr (die, DW_AT_location);
4172
          if (attr)
4173
            {
4174
              SYMBOL_VALUE (sym) = decode_locdesc (DW_BLOCK (attr), objfile);
4175
              if (isreg)
4176
                {
4177
                  SYMBOL_CLASS (sym) = LOC_REGPARM;
4178
                }
4179
              else if (offreg)
4180
                {
4181
                  if (isderef)
4182
                    {
4183
                      if (basereg != frame_base_reg)
4184
                        complain (&dwarf2_complex_location_expr);
4185
                      SYMBOL_CLASS (sym) = LOC_REF_ARG;
4186
                    }
4187
                  else
4188
                    {
4189
                      SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
4190
                      SYMBOL_BASEREG (sym) = basereg;
4191
                    }
4192
                }
4193
              else
4194
                {
4195
                  SYMBOL_CLASS (sym) = LOC_ARG;
4196
                }
4197
            }
4198
          attr = dwarf_attr (die, DW_AT_const_value);
4199
          if (attr)
4200
            {
4201
              dwarf2_const_value (attr, sym, objfile);
4202
            }
4203
          add_symbol_to_list (sym, list_in_scope);
4204
          break;
4205
        case DW_TAG_unspecified_parameters:
4206
          /* From varargs functions; gdb doesn't seem to have any
4207
             interest in this information, so just ignore it for now.
4208
             (FIXME?) */
4209
          break;
4210
        case DW_TAG_class_type:
4211
        case DW_TAG_structure_type:
4212
        case DW_TAG_union_type:
4213
        case DW_TAG_enumeration_type:
4214
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4215
          SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
4216
          add_symbol_to_list (sym, list_in_scope);
4217
 
4218
          /* The semantics of C++ state that "struct foo { ... }" also
4219
             defines a typedef for "foo". Synthesize a typedef symbol so
4220
             that "ptype foo" works as expected.  */
4221
          if (cu_language == language_cplus)
4222
            {
4223
              struct symbol *typedef_sym = (struct symbol *)
4224
              obstack_alloc (&objfile->symbol_obstack,
4225
                             sizeof (struct symbol));
4226
              *typedef_sym = *sym;
4227
              SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
4228
              if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
4229
                TYPE_NAME (SYMBOL_TYPE (sym)) =
4230
                  obsavestring (SYMBOL_NAME (sym),
4231
                                strlen (SYMBOL_NAME (sym)),
4232
                                &objfile->type_obstack);
4233
              add_symbol_to_list (typedef_sym, list_in_scope);
4234
            }
4235
          break;
4236
        case DW_TAG_typedef:
4237
        case DW_TAG_base_type:
4238
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
4239
          SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4240
          add_symbol_to_list (sym, list_in_scope);
4241
          break;
4242
        case DW_TAG_enumerator:
4243
          attr = dwarf_attr (die, DW_AT_const_value);
4244
          if (attr)
4245
            {
4246
              dwarf2_const_value (attr, sym, objfile);
4247
            }
4248
          add_symbol_to_list (sym, list_in_scope);
4249
          break;
4250
        default:
4251
          /* Not a tag we recognize.  Hopefully we aren't processing
4252
             trash data, but since we must specifically ignore things
4253
             we don't recognize, there is nothing else we should do at
4254
             this point. */
4255
          complain (&dwarf2_unsupported_tag, dwarf_tag_name (die->tag));
4256
          break;
4257
        }
4258
    }
4259
  return (sym);
4260
}
4261
 
4262
/* Copy constant value from an attribute to a symbol.  */
4263
 
4264
static void
4265
dwarf2_const_value (attr, sym, objfile)
4266
     struct attribute *attr;
4267
     struct symbol *sym;
4268
     struct objfile *objfile;
4269
{
4270
  struct dwarf_block *blk;
4271
 
4272
  switch (attr->form)
4273
    {
4274
    case DW_FORM_addr:
4275
      if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != (unsigned int) address_size)
4276
        complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym),
4277
                  address_size, TYPE_LENGTH (SYMBOL_TYPE (sym)));
4278
      SYMBOL_VALUE_BYTES (sym) = (char *)
4279
        obstack_alloc (&objfile->symbol_obstack, address_size);
4280
      store_address (SYMBOL_VALUE_BYTES (sym), address_size, DW_ADDR (attr));
4281
      SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
4282
      break;
4283
    case DW_FORM_block1:
4284
    case DW_FORM_block2:
4285
    case DW_FORM_block4:
4286
    case DW_FORM_block:
4287
      blk = DW_BLOCK (attr);
4288
      if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
4289
        complain (&dwarf2_const_value_length_mismatch, SYMBOL_NAME (sym),
4290
                  blk->size, TYPE_LENGTH (SYMBOL_TYPE (sym)));
4291
      SYMBOL_VALUE_BYTES (sym) = (char *)
4292
        obstack_alloc (&objfile->symbol_obstack, blk->size);
4293
      memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
4294
      SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
4295
      break;
4296
 
4297
      /* The DW_AT_const_value attributes are supposed to carry the
4298
         symbol's value "represented as it would be on the target
4299
         architecture."  By the time we get here, it's already been
4300
         converted to host endianness, so we just need to sign- or
4301
         zero-extend it as appropriate.  */
4302
    case DW_FORM_data1:
4303
      dwarf2_const_value_data (attr, sym, 8);
4304
      break;
4305
    case DW_FORM_data2:
4306
      dwarf2_const_value_data (attr, sym, 16);
4307
      break;
4308
    case DW_FORM_data4:
4309
      dwarf2_const_value_data (attr, sym, 32);
4310
      break;
4311
    case DW_FORM_data8:
4312
      dwarf2_const_value_data (attr, sym, 64);
4313
      break;
4314
 
4315
    case DW_FORM_sdata:
4316
      SYMBOL_VALUE (sym) = DW_SND (attr);
4317
      SYMBOL_CLASS (sym) = LOC_CONST;
4318
      break;
4319
 
4320
    case DW_FORM_udata:
4321
      SYMBOL_VALUE (sym) = DW_UNSND (attr);
4322
      SYMBOL_CLASS (sym) = LOC_CONST;
4323
      break;
4324
 
4325
    default:
4326
      complain (&dwarf2_unsupported_const_value_attr,
4327
                dwarf_form_name (attr->form));
4328
      SYMBOL_VALUE (sym) = 0;
4329
      SYMBOL_CLASS (sym) = LOC_CONST;
4330
      break;
4331
    }
4332
}
4333
 
4334
 
4335
/* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4336
   or zero-extend it as appropriate for the symbol's type.  */
4337
static void
4338
dwarf2_const_value_data (struct attribute *attr,
4339
                         struct symbol *sym,
4340
                         int bits)
4341
{
4342
  LONGEST l = DW_UNSND (attr);
4343
 
4344
  if (bits < sizeof (l) * 8)
4345
    {
4346
      if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
4347
        l &= ((LONGEST) 1 << bits) - 1;
4348
      else
4349
        l = (l << (sizeof (l) - bits)) >> (sizeof (l) - bits);
4350
    }
4351
 
4352
  SYMBOL_VALUE (sym) = l;
4353
  SYMBOL_CLASS (sym) = LOC_CONST;
4354
}
4355
 
4356
 
4357
/* Return the type of the die in question using its DW_AT_type attribute.  */
4358
 
4359
static struct type *
4360
die_type (die, objfile)
4361
     struct die_info *die;
4362
     struct objfile *objfile;
4363
{
4364
  struct type *type;
4365
  struct attribute *type_attr;
4366
  struct die_info *type_die;
4367
  unsigned int ref;
4368
 
4369
  type_attr = dwarf_attr (die, DW_AT_type);
4370
  if (!type_attr)
4371
    {
4372
      /* A missing DW_AT_type represents a void type.  */
4373
      return dwarf2_fundamental_type (objfile, FT_VOID);
4374
    }
4375
  else
4376
    {
4377
      ref = dwarf2_get_ref_die_offset (type_attr);
4378
      type_die = follow_die_ref (ref);
4379
      if (!type_die)
4380
        {
4381
          error ("Dwarf Error: Cannot find referent at offset %d.", ref);
4382
          return NULL;
4383
        }
4384
    }
4385
  type = tag_type_to_type (type_die, objfile);
4386
  if (!type)
4387
    {
4388
      dump_die (type_die);
4389
      error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4390
    }
4391
  return type;
4392
}
4393
 
4394
/* Return the containing type of the die in question using its
4395
   DW_AT_containing_type attribute.  */
4396
 
4397
static struct type *
4398
die_containing_type (die, objfile)
4399
     struct die_info *die;
4400
     struct objfile *objfile;
4401
{
4402
  struct type *type = NULL;
4403
  struct attribute *type_attr;
4404
  struct die_info *type_die = NULL;
4405
  unsigned int ref;
4406
 
4407
  type_attr = dwarf_attr (die, DW_AT_containing_type);
4408
  if (type_attr)
4409
    {
4410
      ref = dwarf2_get_ref_die_offset (type_attr);
4411
      type_die = follow_die_ref (ref);
4412
      if (!type_die)
4413
        {
4414
          error ("Dwarf Error: Cannot find referent at offset %d.", ref);
4415
          return NULL;
4416
        }
4417
      type = tag_type_to_type (type_die, objfile);
4418
    }
4419
  if (!type)
4420
    {
4421
      if (type_die)
4422
        dump_die (type_die);
4423
      error ("Dwarf Error: Problem turning containing type into gdb type.");
4424
    }
4425
  return type;
4426
}
4427
 
4428
#if 0
4429
static struct type *
4430
type_at_offset (offset, objfile)
4431
     unsigned int offset;
4432
     struct objfile *objfile;
4433
{
4434
  struct die_info *die;
4435
  struct type *type;
4436
 
4437
  die = follow_die_ref (offset);
4438
  if (!die)
4439
    {
4440
      error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
4441
      return NULL;
4442
    }
4443
  type = tag_type_to_type (die, objfile);
4444
  return type;
4445
}
4446
#endif
4447
 
4448
static struct type *
4449
tag_type_to_type (die, objfile)
4450
     struct die_info *die;
4451
     struct objfile *objfile;
4452
{
4453
  if (die->type)
4454
    {
4455
      return die->type;
4456
    }
4457
  else
4458
    {
4459
      read_type_die (die, objfile);
4460
      if (!die->type)
4461
        {
4462
          dump_die (die);
4463
          error ("Dwarf Error: Cannot find type of die.");
4464
        }
4465
      return die->type;
4466
    }
4467
}
4468
 
4469
static void
4470
read_type_die (die, objfile)
4471
     struct die_info *die;
4472
     struct objfile *objfile;
4473
{
4474
  switch (die->tag)
4475
    {
4476
    case DW_TAG_class_type:
4477
    case DW_TAG_structure_type:
4478
    case DW_TAG_union_type:
4479
      read_structure_scope (die, objfile);
4480
      break;
4481
    case DW_TAG_enumeration_type:
4482
      read_enumeration (die, objfile);
4483
      break;
4484
    case DW_TAG_subprogram:
4485
    case DW_TAG_subroutine_type:
4486
      read_subroutine_type (die, objfile);
4487
      break;
4488
    case DW_TAG_array_type:
4489
      read_array_type (die, objfile);
4490
      break;
4491
    case DW_TAG_pointer_type:
4492
      read_tag_pointer_type (die, objfile);
4493
      break;
4494
    case DW_TAG_ptr_to_member_type:
4495
      read_tag_ptr_to_member_type (die, objfile);
4496
      break;
4497
    case DW_TAG_reference_type:
4498
      read_tag_reference_type (die, objfile);
4499
      break;
4500
    case DW_TAG_const_type:
4501
      read_tag_const_type (die, objfile);
4502
      break;
4503
    case DW_TAG_volatile_type:
4504
      read_tag_volatile_type (die, objfile);
4505
      break;
4506
    case DW_TAG_string_type:
4507
      read_tag_string_type (die, objfile);
4508
      break;
4509
    case DW_TAG_typedef:
4510
      read_typedef (die, objfile);
4511
      break;
4512
    case DW_TAG_base_type:
4513
      read_base_type (die, objfile);
4514
      break;
4515
    default:
4516
      complain (&dwarf2_unexpected_tag, dwarf_tag_name (die->tag));
4517
      break;
4518
    }
4519
}
4520
 
4521
static struct type *
4522
dwarf_base_type (encoding, size, objfile)
4523
     int encoding;
4524
     int size;
4525
     struct objfile *objfile;
4526
{
4527
  /* FIXME - this should not produce a new (struct type *)
4528
     every time.  It should cache base types.  */
4529
  struct type *type;
4530
  switch (encoding)
4531
    {
4532
    case DW_ATE_address:
4533
      type = dwarf2_fundamental_type (objfile, FT_VOID);
4534
      return type;
4535
    case DW_ATE_boolean:
4536
      type = dwarf2_fundamental_type (objfile, FT_BOOLEAN);
4537
      return type;
4538
    case DW_ATE_complex_float:
4539
      if (size == 16)
4540
        {
4541
          type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX);
4542
        }
4543
      else
4544
        {
4545
          type = dwarf2_fundamental_type (objfile, FT_COMPLEX);
4546
        }
4547
      return type;
4548
    case DW_ATE_float:
4549
      if (size == 8)
4550
        {
4551
          type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
4552
        }
4553
      else
4554
        {
4555
          type = dwarf2_fundamental_type (objfile, FT_FLOAT);
4556
        }
4557
      return type;
4558
    case DW_ATE_signed:
4559
      switch (size)
4560
        {
4561
        case 1:
4562
          type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
4563
          break;
4564
        case 2:
4565
          type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT);
4566
          break;
4567
        default:
4568
        case 4:
4569
          type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
4570
          break;
4571
        }
4572
      return type;
4573
    case DW_ATE_signed_char:
4574
      type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR);
4575
      return type;
4576
    case DW_ATE_unsigned:
4577
      switch (size)
4578
        {
4579
        case 1:
4580
          type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
4581
          break;
4582
        case 2:
4583
          type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT);
4584
          break;
4585
        default:
4586
        case 4:
4587
          type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
4588
          break;
4589
        }
4590
      return type;
4591
    case DW_ATE_unsigned_char:
4592
      type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR);
4593
      return type;
4594
    default:
4595
      type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER);
4596
      return type;
4597
    }
4598
}
4599
 
4600
#if 0
4601
struct die_info *
4602
copy_die (old_die)
4603
     struct die_info *old_die;
4604
{
4605
  struct die_info *new_die;
4606
  int i, num_attrs;
4607
 
4608
  new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
4609
  memset (new_die, 0, sizeof (struct die_info));
4610
 
4611
  new_die->tag = old_die->tag;
4612
  new_die->has_children = old_die->has_children;
4613
  new_die->abbrev = old_die->abbrev;
4614
  new_die->offset = old_die->offset;
4615
  new_die->type = NULL;
4616
 
4617
  num_attrs = old_die->num_attrs;
4618
  new_die->num_attrs = num_attrs;
4619
  new_die->attrs = (struct attribute *)
4620
    xmalloc (num_attrs * sizeof (struct attribute));
4621
 
4622
  for (i = 0; i < old_die->num_attrs; ++i)
4623
    {
4624
      new_die->attrs[i].name = old_die->attrs[i].name;
4625
      new_die->attrs[i].form = old_die->attrs[i].form;
4626
      new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
4627
    }
4628
 
4629
  new_die->next = NULL;
4630
  return new_die;
4631
}
4632
#endif
4633
 
4634
/* Return sibling of die, NULL if no sibling.  */
4635
 
4636
struct die_info *
4637
sibling_die (die)
4638
     struct die_info *die;
4639
{
4640
  int nesting_level = 0;
4641
 
4642
  if (!die->has_children)
4643
    {
4644
      if (die->next && (die->next->tag == 0))
4645
        {
4646
          return NULL;
4647
        }
4648
      else
4649
        {
4650
          return die->next;
4651
        }
4652
    }
4653
  else
4654
    {
4655
      do
4656
        {
4657
          if (die->has_children)
4658
            {
4659
              nesting_level++;
4660
            }
4661
          if (die->tag == 0)
4662
            {
4663
              nesting_level--;
4664
            }
4665
          die = die->next;
4666
        }
4667
      while (nesting_level);
4668
      if (die && (die->tag == 0))
4669
        {
4670
          return NULL;
4671
        }
4672
      else
4673
        {
4674
          return die;
4675
        }
4676
    }
4677
}
4678
 
4679
/* Get linkage name of a die, return NULL if not found.  */
4680
 
4681
static char *
4682
dwarf2_linkage_name (die)
4683
     struct die_info *die;
4684
{
4685
  struct attribute *attr;
4686
 
4687
  attr = dwarf_attr (die, DW_AT_MIPS_linkage_name);
4688
  if (attr && DW_STRING (attr))
4689
    return DW_STRING (attr);
4690
  attr = dwarf_attr (die, DW_AT_name);
4691
  if (attr && DW_STRING (attr))
4692
    return DW_STRING (attr);
4693
  return NULL;
4694
}
4695
 
4696
/* Convert a DIE tag into its string name.  */
4697
 
4698
static char *
4699
dwarf_tag_name (tag)
4700
     register unsigned tag;
4701
{
4702
  switch (tag)
4703
    {
4704
    case DW_TAG_padding:
4705
      return "DW_TAG_padding";
4706
    case DW_TAG_array_type:
4707
      return "DW_TAG_array_type";
4708
    case DW_TAG_class_type:
4709
      return "DW_TAG_class_type";
4710
    case DW_TAG_entry_point:
4711
      return "DW_TAG_entry_point";
4712
    case DW_TAG_enumeration_type:
4713
      return "DW_TAG_enumeration_type";
4714
    case DW_TAG_formal_parameter:
4715
      return "DW_TAG_formal_parameter";
4716
    case DW_TAG_imported_declaration:
4717
      return "DW_TAG_imported_declaration";
4718
    case DW_TAG_label:
4719
      return "DW_TAG_label";
4720
    case DW_TAG_lexical_block:
4721
      return "DW_TAG_lexical_block";
4722
    case DW_TAG_member:
4723
      return "DW_TAG_member";
4724
    case DW_TAG_pointer_type:
4725
      return "DW_TAG_pointer_type";
4726
    case DW_TAG_reference_type:
4727
      return "DW_TAG_reference_type";
4728
    case DW_TAG_compile_unit:
4729
      return "DW_TAG_compile_unit";
4730
    case DW_TAG_string_type:
4731
      return "DW_TAG_string_type";
4732
    case DW_TAG_structure_type:
4733
      return "DW_TAG_structure_type";
4734
    case DW_TAG_subroutine_type:
4735
      return "DW_TAG_subroutine_type";
4736
    case DW_TAG_typedef:
4737
      return "DW_TAG_typedef";
4738
    case DW_TAG_union_type:
4739
      return "DW_TAG_union_type";
4740
    case DW_TAG_unspecified_parameters:
4741
      return "DW_TAG_unspecified_parameters";
4742
    case DW_TAG_variant:
4743
      return "DW_TAG_variant";
4744
    case DW_TAG_common_block:
4745
      return "DW_TAG_common_block";
4746
    case DW_TAG_common_inclusion:
4747
      return "DW_TAG_common_inclusion";
4748
    case DW_TAG_inheritance:
4749
      return "DW_TAG_inheritance";
4750
    case DW_TAG_inlined_subroutine:
4751
      return "DW_TAG_inlined_subroutine";
4752
    case DW_TAG_module:
4753
      return "DW_TAG_module";
4754
    case DW_TAG_ptr_to_member_type:
4755
      return "DW_TAG_ptr_to_member_type";
4756
    case DW_TAG_set_type:
4757
      return "DW_TAG_set_type";
4758
    case DW_TAG_subrange_type:
4759
      return "DW_TAG_subrange_type";
4760
    case DW_TAG_with_stmt:
4761
      return "DW_TAG_with_stmt";
4762
    case DW_TAG_access_declaration:
4763
      return "DW_TAG_access_declaration";
4764
    case DW_TAG_base_type:
4765
      return "DW_TAG_base_type";
4766
    case DW_TAG_catch_block:
4767
      return "DW_TAG_catch_block";
4768
    case DW_TAG_const_type:
4769
      return "DW_TAG_const_type";
4770
    case DW_TAG_constant:
4771
      return "DW_TAG_constant";
4772
    case DW_TAG_enumerator:
4773
      return "DW_TAG_enumerator";
4774
    case DW_TAG_file_type:
4775
      return "DW_TAG_file_type";
4776
    case DW_TAG_friend:
4777
      return "DW_TAG_friend";
4778
    case DW_TAG_namelist:
4779
      return "DW_TAG_namelist";
4780
    case DW_TAG_namelist_item:
4781
      return "DW_TAG_namelist_item";
4782
    case DW_TAG_packed_type:
4783
      return "DW_TAG_packed_type";
4784
    case DW_TAG_subprogram:
4785
      return "DW_TAG_subprogram";
4786
    case DW_TAG_template_type_param:
4787
      return "DW_TAG_template_type_param";
4788
    case DW_TAG_template_value_param:
4789
      return "DW_TAG_template_value_param";
4790
    case DW_TAG_thrown_type:
4791
      return "DW_TAG_thrown_type";
4792
    case DW_TAG_try_block:
4793
      return "DW_TAG_try_block";
4794
    case DW_TAG_variant_part:
4795
      return "DW_TAG_variant_part";
4796
    case DW_TAG_variable:
4797
      return "DW_TAG_variable";
4798
    case DW_TAG_volatile_type:
4799
      return "DW_TAG_volatile_type";
4800
    case DW_TAG_MIPS_loop:
4801
      return "DW_TAG_MIPS_loop";
4802
    case DW_TAG_format_label:
4803
      return "DW_TAG_format_label";
4804
    case DW_TAG_function_template:
4805
      return "DW_TAG_function_template";
4806
    case DW_TAG_class_template:
4807
      return "DW_TAG_class_template";
4808
    default:
4809
      return "DW_TAG_<unknown>";
4810
    }
4811
}
4812
 
4813
/* Convert a DWARF attribute code into its string name.  */
4814
 
4815
static char *
4816
dwarf_attr_name (attr)
4817
     register unsigned attr;
4818
{
4819
  switch (attr)
4820
    {
4821
    case DW_AT_sibling:
4822
      return "DW_AT_sibling";
4823
    case DW_AT_location:
4824
      return "DW_AT_location";
4825
    case DW_AT_name:
4826
      return "DW_AT_name";
4827
    case DW_AT_ordering:
4828
      return "DW_AT_ordering";
4829
    case DW_AT_subscr_data:
4830
      return "DW_AT_subscr_data";
4831
    case DW_AT_byte_size:
4832
      return "DW_AT_byte_size";
4833
    case DW_AT_bit_offset:
4834
      return "DW_AT_bit_offset";
4835
    case DW_AT_bit_size:
4836
      return "DW_AT_bit_size";
4837
    case DW_AT_element_list:
4838
      return "DW_AT_element_list";
4839
    case DW_AT_stmt_list:
4840
      return "DW_AT_stmt_list";
4841
    case DW_AT_low_pc:
4842
      return "DW_AT_low_pc";
4843
    case DW_AT_high_pc:
4844
      return "DW_AT_high_pc";
4845
    case DW_AT_language:
4846
      return "DW_AT_language";
4847
    case DW_AT_member:
4848
      return "DW_AT_member";
4849
    case DW_AT_discr:
4850
      return "DW_AT_discr";
4851
    case DW_AT_discr_value:
4852
      return "DW_AT_discr_value";
4853
    case DW_AT_visibility:
4854
      return "DW_AT_visibility";
4855
    case DW_AT_import:
4856
      return "DW_AT_import";
4857
    case DW_AT_string_length:
4858
      return "DW_AT_string_length";
4859
    case DW_AT_common_reference:
4860
      return "DW_AT_common_reference";
4861
    case DW_AT_comp_dir:
4862
      return "DW_AT_comp_dir";
4863
    case DW_AT_const_value:
4864
      return "DW_AT_const_value";
4865
    case DW_AT_containing_type:
4866
      return "DW_AT_containing_type";
4867
    case DW_AT_default_value:
4868
      return "DW_AT_default_value";
4869
    case DW_AT_inline:
4870
      return "DW_AT_inline";
4871
    case DW_AT_is_optional:
4872
      return "DW_AT_is_optional";
4873
    case DW_AT_lower_bound:
4874
      return "DW_AT_lower_bound";
4875
    case DW_AT_producer:
4876
      return "DW_AT_producer";
4877
    case DW_AT_prototyped:
4878
      return "DW_AT_prototyped";
4879
    case DW_AT_return_addr:
4880
      return "DW_AT_return_addr";
4881
    case DW_AT_start_scope:
4882
      return "DW_AT_start_scope";
4883
    case DW_AT_stride_size:
4884
      return "DW_AT_stride_size";
4885
    case DW_AT_upper_bound:
4886
      return "DW_AT_upper_bound";
4887
    case DW_AT_abstract_origin:
4888
      return "DW_AT_abstract_origin";
4889
    case DW_AT_accessibility:
4890
      return "DW_AT_accessibility";
4891
    case DW_AT_address_class:
4892
      return "DW_AT_address_class";
4893
    case DW_AT_artificial:
4894
      return "DW_AT_artificial";
4895
    case DW_AT_base_types:
4896
      return "DW_AT_base_types";
4897
    case DW_AT_calling_convention:
4898
      return "DW_AT_calling_convention";
4899
    case DW_AT_count:
4900
      return "DW_AT_count";
4901
    case DW_AT_data_member_location:
4902
      return "DW_AT_data_member_location";
4903
    case DW_AT_decl_column:
4904
      return "DW_AT_decl_column";
4905
    case DW_AT_decl_file:
4906
      return "DW_AT_decl_file";
4907
    case DW_AT_decl_line:
4908
      return "DW_AT_decl_line";
4909
    case DW_AT_declaration:
4910
      return "DW_AT_declaration";
4911
    case DW_AT_discr_list:
4912
      return "DW_AT_discr_list";
4913
    case DW_AT_encoding:
4914
      return "DW_AT_encoding";
4915
    case DW_AT_external:
4916
      return "DW_AT_external";
4917
    case DW_AT_frame_base:
4918
      return "DW_AT_frame_base";
4919
    case DW_AT_friend:
4920
      return "DW_AT_friend";
4921
    case DW_AT_identifier_case:
4922
      return "DW_AT_identifier_case";
4923
    case DW_AT_macro_info:
4924
      return "DW_AT_macro_info";
4925
    case DW_AT_namelist_items:
4926
      return "DW_AT_namelist_items";
4927
    case DW_AT_priority:
4928
      return "DW_AT_priority";
4929
    case DW_AT_segment:
4930
      return "DW_AT_segment";
4931
    case DW_AT_specification:
4932
      return "DW_AT_specification";
4933
    case DW_AT_static_link:
4934
      return "DW_AT_static_link";
4935
    case DW_AT_type:
4936
      return "DW_AT_type";
4937
    case DW_AT_use_location:
4938
      return "DW_AT_use_location";
4939
    case DW_AT_variable_parameter:
4940
      return "DW_AT_variable_parameter";
4941
    case DW_AT_virtuality:
4942
      return "DW_AT_virtuality";
4943
    case DW_AT_vtable_elem_location:
4944
      return "DW_AT_vtable_elem_location";
4945
 
4946
#ifdef MIPS
4947
    case DW_AT_MIPS_fde:
4948
      return "DW_AT_MIPS_fde";
4949
    case DW_AT_MIPS_loop_begin:
4950
      return "DW_AT_MIPS_loop_begin";
4951
    case DW_AT_MIPS_tail_loop_begin:
4952
      return "DW_AT_MIPS_tail_loop_begin";
4953
    case DW_AT_MIPS_epilog_begin:
4954
      return "DW_AT_MIPS_epilog_begin";
4955
    case DW_AT_MIPS_loop_unroll_factor:
4956
      return "DW_AT_MIPS_loop_unroll_factor";
4957
    case DW_AT_MIPS_software_pipeline_depth:
4958
      return "DW_AT_MIPS_software_pipeline_depth";
4959
    case DW_AT_MIPS_linkage_name:
4960
      return "DW_AT_MIPS_linkage_name";
4961
#endif
4962
 
4963
    case DW_AT_sf_names:
4964
      return "DW_AT_sf_names";
4965
    case DW_AT_src_info:
4966
      return "DW_AT_src_info";
4967
    case DW_AT_mac_info:
4968
      return "DW_AT_mac_info";
4969
    case DW_AT_src_coords:
4970
      return "DW_AT_src_coords";
4971
    case DW_AT_body_begin:
4972
      return "DW_AT_body_begin";
4973
    case DW_AT_body_end:
4974
      return "DW_AT_body_end";
4975
    default:
4976
      return "DW_AT_<unknown>";
4977
    }
4978
}
4979
 
4980
/* Convert a DWARF value form code into its string name.  */
4981
 
4982
static char *
4983
dwarf_form_name (form)
4984
     register unsigned form;
4985
{
4986
  switch (form)
4987
    {
4988
    case DW_FORM_addr:
4989
      return "DW_FORM_addr";
4990
    case DW_FORM_block2:
4991
      return "DW_FORM_block2";
4992
    case DW_FORM_block4:
4993
      return "DW_FORM_block4";
4994
    case DW_FORM_data2:
4995
      return "DW_FORM_data2";
4996
    case DW_FORM_data4:
4997
      return "DW_FORM_data4";
4998
    case DW_FORM_data8:
4999
      return "DW_FORM_data8";
5000
    case DW_FORM_string:
5001
      return "DW_FORM_string";
5002
    case DW_FORM_block:
5003
      return "DW_FORM_block";
5004
    case DW_FORM_block1:
5005
      return "DW_FORM_block1";
5006
    case DW_FORM_data1:
5007
      return "DW_FORM_data1";
5008
    case DW_FORM_flag:
5009
      return "DW_FORM_flag";
5010
    case DW_FORM_sdata:
5011
      return "DW_FORM_sdata";
5012
    case DW_FORM_strp:
5013
      return "DW_FORM_strp";
5014
    case DW_FORM_udata:
5015
      return "DW_FORM_udata";
5016
    case DW_FORM_ref_addr:
5017
      return "DW_FORM_ref_addr";
5018
    case DW_FORM_ref1:
5019
      return "DW_FORM_ref1";
5020
    case DW_FORM_ref2:
5021
      return "DW_FORM_ref2";
5022
    case DW_FORM_ref4:
5023
      return "DW_FORM_ref4";
5024
    case DW_FORM_ref8:
5025
      return "DW_FORM_ref8";
5026
    case DW_FORM_ref_udata:
5027
      return "DW_FORM_ref_udata";
5028
    case DW_FORM_indirect:
5029
      return "DW_FORM_indirect";
5030
    default:
5031
      return "DW_FORM_<unknown>";
5032
    }
5033
}
5034
 
5035
/* Convert a DWARF stack opcode into its string name.  */
5036
 
5037
static char *
5038
dwarf_stack_op_name (op)
5039
     register unsigned op;
5040
{
5041
  switch (op)
5042
    {
5043
    case DW_OP_addr:
5044
      return "DW_OP_addr";
5045
    case DW_OP_deref:
5046
      return "DW_OP_deref";
5047
    case DW_OP_const1u:
5048
      return "DW_OP_const1u";
5049
    case DW_OP_const1s:
5050
      return "DW_OP_const1s";
5051
    case DW_OP_const2u:
5052
      return "DW_OP_const2u";
5053
    case DW_OP_const2s:
5054
      return "DW_OP_const2s";
5055
    case DW_OP_const4u:
5056
      return "DW_OP_const4u";
5057
    case DW_OP_const4s:
5058
      return "DW_OP_const4s";
5059
    case DW_OP_const8u:
5060
      return "DW_OP_const8u";
5061
    case DW_OP_const8s:
5062
      return "DW_OP_const8s";
5063
    case DW_OP_constu:
5064
      return "DW_OP_constu";
5065
    case DW_OP_consts:
5066
      return "DW_OP_consts";
5067
    case DW_OP_dup:
5068
      return "DW_OP_dup";
5069
    case DW_OP_drop:
5070
      return "DW_OP_drop";
5071
    case DW_OP_over:
5072
      return "DW_OP_over";
5073
    case DW_OP_pick:
5074
      return "DW_OP_pick";
5075
    case DW_OP_swap:
5076
      return "DW_OP_swap";
5077
    case DW_OP_rot:
5078
      return "DW_OP_rot";
5079
    case DW_OP_xderef:
5080
      return "DW_OP_xderef";
5081
    case DW_OP_abs:
5082
      return "DW_OP_abs";
5083
    case DW_OP_and:
5084
      return "DW_OP_and";
5085
    case DW_OP_div:
5086
      return "DW_OP_div";
5087
    case DW_OP_minus:
5088
      return "DW_OP_minus";
5089
    case DW_OP_mod:
5090
      return "DW_OP_mod";
5091
    case DW_OP_mul:
5092
      return "DW_OP_mul";
5093
    case DW_OP_neg:
5094
      return "DW_OP_neg";
5095
    case DW_OP_not:
5096
      return "DW_OP_not";
5097
    case DW_OP_or:
5098
      return "DW_OP_or";
5099
    case DW_OP_plus:
5100
      return "DW_OP_plus";
5101
    case DW_OP_plus_uconst:
5102
      return "DW_OP_plus_uconst";
5103
    case DW_OP_shl:
5104
      return "DW_OP_shl";
5105
    case DW_OP_shr:
5106
      return "DW_OP_shr";
5107
    case DW_OP_shra:
5108
      return "DW_OP_shra";
5109
    case DW_OP_xor:
5110
      return "DW_OP_xor";
5111
    case DW_OP_bra:
5112
      return "DW_OP_bra";
5113
    case DW_OP_eq:
5114
      return "DW_OP_eq";
5115
    case DW_OP_ge:
5116
      return "DW_OP_ge";
5117
    case DW_OP_gt:
5118
      return "DW_OP_gt";
5119
    case DW_OP_le:
5120
      return "DW_OP_le";
5121
    case DW_OP_lt:
5122
      return "DW_OP_lt";
5123
    case DW_OP_ne:
5124
      return "DW_OP_ne";
5125
    case DW_OP_skip:
5126
      return "DW_OP_skip";
5127
    case DW_OP_lit0:
5128
      return "DW_OP_lit0";
5129
    case DW_OP_lit1:
5130
      return "DW_OP_lit1";
5131
    case DW_OP_lit2:
5132
      return "DW_OP_lit2";
5133
    case DW_OP_lit3:
5134
      return "DW_OP_lit3";
5135
    case DW_OP_lit4:
5136
      return "DW_OP_lit4";
5137
    case DW_OP_lit5:
5138
      return "DW_OP_lit5";
5139
    case DW_OP_lit6:
5140
      return "DW_OP_lit6";
5141
    case DW_OP_lit7:
5142
      return "DW_OP_lit7";
5143
    case DW_OP_lit8:
5144
      return "DW_OP_lit8";
5145
    case DW_OP_lit9:
5146
      return "DW_OP_lit9";
5147
    case DW_OP_lit10:
5148
      return "DW_OP_lit10";
5149
    case DW_OP_lit11:
5150
      return "DW_OP_lit11";
5151
    case DW_OP_lit12:
5152
      return "DW_OP_lit12";
5153
    case DW_OP_lit13:
5154
      return "DW_OP_lit13";
5155
    case DW_OP_lit14:
5156
      return "DW_OP_lit14";
5157
    case DW_OP_lit15:
5158
      return "DW_OP_lit15";
5159
    case DW_OP_lit16:
5160
      return "DW_OP_lit16";
5161
    case DW_OP_lit17:
5162
      return "DW_OP_lit17";
5163
    case DW_OP_lit18:
5164
      return "DW_OP_lit18";
5165
    case DW_OP_lit19:
5166
      return "DW_OP_lit19";
5167
    case DW_OP_lit20:
5168
      return "DW_OP_lit20";
5169
    case DW_OP_lit21:
5170
      return "DW_OP_lit21";
5171
    case DW_OP_lit22:
5172
      return "DW_OP_lit22";
5173
    case DW_OP_lit23:
5174
      return "DW_OP_lit23";
5175
    case DW_OP_lit24:
5176
      return "DW_OP_lit24";
5177
    case DW_OP_lit25:
5178
      return "DW_OP_lit25";
5179
    case DW_OP_lit26:
5180
      return "DW_OP_lit26";
5181
    case DW_OP_lit27:
5182
      return "DW_OP_lit27";
5183
    case DW_OP_lit28:
5184
      return "DW_OP_lit28";
5185
    case DW_OP_lit29:
5186
      return "DW_OP_lit29";
5187
    case DW_OP_lit30:
5188
      return "DW_OP_lit30";
5189
    case DW_OP_lit31:
5190
      return "DW_OP_lit31";
5191
    case DW_OP_reg0:
5192
      return "DW_OP_reg0";
5193
    case DW_OP_reg1:
5194
      return "DW_OP_reg1";
5195
    case DW_OP_reg2:
5196
      return "DW_OP_reg2";
5197
    case DW_OP_reg3:
5198
      return "DW_OP_reg3";
5199
    case DW_OP_reg4:
5200
      return "DW_OP_reg4";
5201
    case DW_OP_reg5:
5202
      return "DW_OP_reg5";
5203
    case DW_OP_reg6:
5204
      return "DW_OP_reg6";
5205
    case DW_OP_reg7:
5206
      return "DW_OP_reg7";
5207
    case DW_OP_reg8:
5208
      return "DW_OP_reg8";
5209
    case DW_OP_reg9:
5210
      return "DW_OP_reg9";
5211
    case DW_OP_reg10:
5212
      return "DW_OP_reg10";
5213
    case DW_OP_reg11:
5214
      return "DW_OP_reg11";
5215
    case DW_OP_reg12:
5216
      return "DW_OP_reg12";
5217
    case DW_OP_reg13:
5218
      return "DW_OP_reg13";
5219
    case DW_OP_reg14:
5220
      return "DW_OP_reg14";
5221
    case DW_OP_reg15:
5222
      return "DW_OP_reg15";
5223
    case DW_OP_reg16:
5224
      return "DW_OP_reg16";
5225
    case DW_OP_reg17:
5226
      return "DW_OP_reg17";
5227
    case DW_OP_reg18:
5228
      return "DW_OP_reg18";
5229
    case DW_OP_reg19:
5230
      return "DW_OP_reg19";
5231
    case DW_OP_reg20:
5232
      return "DW_OP_reg20";
5233
    case DW_OP_reg21:
5234
      return "DW_OP_reg21";
5235
    case DW_OP_reg22:
5236
      return "DW_OP_reg22";
5237
    case DW_OP_reg23:
5238
      return "DW_OP_reg23";
5239
    case DW_OP_reg24:
5240
      return "DW_OP_reg24";
5241
    case DW_OP_reg25:
5242
      return "DW_OP_reg25";
5243
    case DW_OP_reg26:
5244
      return "DW_OP_reg26";
5245
    case DW_OP_reg27:
5246
      return "DW_OP_reg27";
5247
    case DW_OP_reg28:
5248
      return "DW_OP_reg28";
5249
    case DW_OP_reg29:
5250
      return "DW_OP_reg29";
5251
    case DW_OP_reg30:
5252
      return "DW_OP_reg30";
5253
    case DW_OP_reg31:
5254
      return "DW_OP_reg31";
5255
    case DW_OP_breg0:
5256
      return "DW_OP_breg0";
5257
    case DW_OP_breg1:
5258
      return "DW_OP_breg1";
5259
    case DW_OP_breg2:
5260
      return "DW_OP_breg2";
5261
    case DW_OP_breg3:
5262
      return "DW_OP_breg3";
5263
    case DW_OP_breg4:
5264
      return "DW_OP_breg4";
5265
    case DW_OP_breg5:
5266
      return "DW_OP_breg5";
5267
    case DW_OP_breg6:
5268
      return "DW_OP_breg6";
5269
    case DW_OP_breg7:
5270
      return "DW_OP_breg7";
5271
    case DW_OP_breg8:
5272
      return "DW_OP_breg8";
5273
    case DW_OP_breg9:
5274
      return "DW_OP_breg9";
5275
    case DW_OP_breg10:
5276
      return "DW_OP_breg10";
5277
    case DW_OP_breg11:
5278
      return "DW_OP_breg11";
5279
    case DW_OP_breg12:
5280
      return "DW_OP_breg12";
5281
    case DW_OP_breg13:
5282
      return "DW_OP_breg13";
5283
    case DW_OP_breg14:
5284
      return "DW_OP_breg14";
5285
    case DW_OP_breg15:
5286
      return "DW_OP_breg15";
5287
    case DW_OP_breg16:
5288
      return "DW_OP_breg16";
5289
    case DW_OP_breg17:
5290
      return "DW_OP_breg17";
5291
    case DW_OP_breg18:
5292
      return "DW_OP_breg18";
5293
    case DW_OP_breg19:
5294
      return "DW_OP_breg19";
5295
    case DW_OP_breg20:
5296
      return "DW_OP_breg20";
5297
    case DW_OP_breg21:
5298
      return "DW_OP_breg21";
5299
    case DW_OP_breg22:
5300
      return "DW_OP_breg22";
5301
    case DW_OP_breg23:
5302
      return "DW_OP_breg23";
5303
    case DW_OP_breg24:
5304
      return "DW_OP_breg24";
5305
    case DW_OP_breg25:
5306
      return "DW_OP_breg25";
5307
    case DW_OP_breg26:
5308
      return "DW_OP_breg26";
5309
    case DW_OP_breg27:
5310
      return "DW_OP_breg27";
5311
    case DW_OP_breg28:
5312
      return "DW_OP_breg28";
5313
    case DW_OP_breg29:
5314
      return "DW_OP_breg29";
5315
    case DW_OP_breg30:
5316
      return "DW_OP_breg30";
5317
    case DW_OP_breg31:
5318
      return "DW_OP_breg31";
5319
    case DW_OP_regx:
5320
      return "DW_OP_regx";
5321
    case DW_OP_fbreg:
5322
      return "DW_OP_fbreg";
5323
    case DW_OP_bregx:
5324
      return "DW_OP_bregx";
5325
    case DW_OP_piece:
5326
      return "DW_OP_piece";
5327
    case DW_OP_deref_size:
5328
      return "DW_OP_deref_size";
5329
    case DW_OP_xderef_size:
5330
      return "DW_OP_xderef_size";
5331
    case DW_OP_nop:
5332
      return "DW_OP_nop";
5333
    default:
5334
      return "OP_<unknown>";
5335
    }
5336
}
5337
 
5338
static char *
5339
dwarf_bool_name (mybool)
5340
     unsigned mybool;
5341
{
5342
  if (mybool)
5343
    return "TRUE";
5344
  else
5345
    return "FALSE";
5346
}
5347
 
5348
/* Convert a DWARF type code into its string name.  */
5349
 
5350
static char *
5351
dwarf_type_encoding_name (enc)
5352
     register unsigned enc;
5353
{
5354
  switch (enc)
5355
    {
5356
    case DW_ATE_address:
5357
      return "DW_ATE_address";
5358
    case DW_ATE_boolean:
5359
      return "DW_ATE_boolean";
5360
    case DW_ATE_complex_float:
5361
      return "DW_ATE_complex_float";
5362
    case DW_ATE_float:
5363
      return "DW_ATE_float";
5364
    case DW_ATE_signed:
5365
      return "DW_ATE_signed";
5366
    case DW_ATE_signed_char:
5367
      return "DW_ATE_signed_char";
5368
    case DW_ATE_unsigned:
5369
      return "DW_ATE_unsigned";
5370
    case DW_ATE_unsigned_char:
5371
      return "DW_ATE_unsigned_char";
5372
    default:
5373
      return "DW_ATE_<unknown>";
5374
    }
5375
}
5376
 
5377
/* Convert a DWARF call frame info operation to its string name. */
5378
 
5379
#if 0
5380
static char *
5381
dwarf_cfi_name (cfi_opc)
5382
     register unsigned cfi_opc;
5383
{
5384
  switch (cfi_opc)
5385
    {
5386
    case DW_CFA_advance_loc:
5387
      return "DW_CFA_advance_loc";
5388
    case DW_CFA_offset:
5389
      return "DW_CFA_offset";
5390
    case DW_CFA_restore:
5391
      return "DW_CFA_restore";
5392
    case DW_CFA_nop:
5393
      return "DW_CFA_nop";
5394
    case DW_CFA_set_loc:
5395
      return "DW_CFA_set_loc";
5396
    case DW_CFA_advance_loc1:
5397
      return "DW_CFA_advance_loc1";
5398
    case DW_CFA_advance_loc2:
5399
      return "DW_CFA_advance_loc2";
5400
    case DW_CFA_advance_loc4:
5401
      return "DW_CFA_advance_loc4";
5402
    case DW_CFA_offset_extended:
5403
      return "DW_CFA_offset_extended";
5404
    case DW_CFA_restore_extended:
5405
      return "DW_CFA_restore_extended";
5406
    case DW_CFA_undefined:
5407
      return "DW_CFA_undefined";
5408
    case DW_CFA_same_value:
5409
      return "DW_CFA_same_value";
5410
    case DW_CFA_register:
5411
      return "DW_CFA_register";
5412
    case DW_CFA_remember_state:
5413
      return "DW_CFA_remember_state";
5414
    case DW_CFA_restore_state:
5415
      return "DW_CFA_restore_state";
5416
    case DW_CFA_def_cfa:
5417
      return "DW_CFA_def_cfa";
5418
    case DW_CFA_def_cfa_register:
5419
      return "DW_CFA_def_cfa_register";
5420
    case DW_CFA_def_cfa_offset:
5421
      return "DW_CFA_def_cfa_offset";
5422
      /* SGI/MIPS specific */
5423
    case DW_CFA_MIPS_advance_loc8:
5424
      return "DW_CFA_MIPS_advance_loc8";
5425
    default:
5426
      return "DW_CFA_<unknown>";
5427
    }
5428
}
5429
#endif
5430
 
5431
void
5432
dump_die (die)
5433
     struct die_info *die;
5434
{
5435
  unsigned int i;
5436
 
5437
  fprintf (stderr, "Die: %s (abbrev = %d, offset = %d)\n",
5438
           dwarf_tag_name (die->tag), die->abbrev, die->offset);
5439
  fprintf (stderr, "\thas children: %s\n",
5440
           dwarf_bool_name (die->has_children));
5441
 
5442
  fprintf (stderr, "\tattributes:\n");
5443
  for (i = 0; i < die->num_attrs; ++i)
5444
    {
5445
      fprintf (stderr, "\t\t%s (%s) ",
5446
               dwarf_attr_name (die->attrs[i].name),
5447
               dwarf_form_name (die->attrs[i].form));
5448
      switch (die->attrs[i].form)
5449
        {
5450
        case DW_FORM_ref_addr:
5451
        case DW_FORM_addr:
5452
          fprintf (stderr, "address: ");
5453
          print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
5454
          break;
5455
        case DW_FORM_block2:
5456
        case DW_FORM_block4:
5457
        case DW_FORM_block:
5458
        case DW_FORM_block1:
5459
          fprintf (stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
5460
          break;
5461
        case DW_FORM_data1:
5462
        case DW_FORM_data2:
5463
        case DW_FORM_data4:
5464
        case DW_FORM_ref1:
5465
        case DW_FORM_ref2:
5466
        case DW_FORM_ref4:
5467
        case DW_FORM_udata:
5468
        case DW_FORM_sdata:
5469
          fprintf (stderr, "constant: %d", DW_UNSND (&die->attrs[i]));
5470
          break;
5471
        case DW_FORM_string:
5472
          fprintf (stderr, "string: \"%s\"",
5473
                   DW_STRING (&die->attrs[i])
5474
                   ? DW_STRING (&die->attrs[i]) : "");
5475
          break;
5476
        case DW_FORM_flag:
5477
          if (DW_UNSND (&die->attrs[i]))
5478
            fprintf (stderr, "flag: TRUE");
5479
          else
5480
            fprintf (stderr, "flag: FALSE");
5481
          break;
5482
        case DW_FORM_strp:      /* we do not support separate string
5483
                                   section yet */
5484
        case DW_FORM_indirect:  /* we do not handle indirect yet */
5485
        case DW_FORM_data8:     /* we do not have 64 bit quantities */
5486
        default:
5487
          fprintf (stderr, "unsupported attribute form: %d.",
5488
                   die->attrs[i].form);
5489
        }
5490
      fprintf (stderr, "\n");
5491
    }
5492
}
5493
 
5494
void
5495
dump_die_list (die)
5496
     struct die_info *die;
5497
{
5498
  while (die)
5499
    {
5500
      dump_die (die);
5501
      die = die->next;
5502
    }
5503
}
5504
 
5505
void
5506
store_in_ref_table (offset, die)
5507
     unsigned int offset;
5508
     struct die_info *die;
5509
{
5510
  int h;
5511
  struct die_info *old;
5512
 
5513
  h = (offset % REF_HASH_SIZE);
5514
  old = die_ref_table[h];
5515
  die->next_ref = old;
5516
  die_ref_table[h] = die;
5517
}
5518
 
5519
 
5520
static void
5521
dwarf2_empty_die_ref_table ()
5522
{
5523
  memset (die_ref_table, 0, sizeof (die_ref_table));
5524
}
5525
 
5526
static unsigned int
5527
dwarf2_get_ref_die_offset (attr)
5528
     struct attribute *attr;
5529
{
5530
  unsigned int result = 0;
5531
 
5532
  switch (attr->form)
5533
    {
5534
    case DW_FORM_ref_addr:
5535
      result = DW_ADDR (attr);
5536
      break;
5537
    case DW_FORM_ref1:
5538
    case DW_FORM_ref2:
5539
    case DW_FORM_ref4:
5540
    case DW_FORM_ref_udata:
5541
      result = cu_header_offset + DW_UNSND (attr);
5542
      break;
5543
    default:
5544
      complain (&dwarf2_unsupported_die_ref_attr, dwarf_form_name (attr->form));
5545
    }
5546
  return result;
5547
}
5548
 
5549
struct die_info *
5550
follow_die_ref (offset)
5551
     unsigned int offset;
5552
{
5553
  struct die_info *die;
5554
  int h;
5555
 
5556
  h = (offset % REF_HASH_SIZE);
5557
  die = die_ref_table[h];
5558
  while (die)
5559
    {
5560
      if (die->offset == offset)
5561
        {
5562
          return die;
5563
        }
5564
      die = die->next_ref;
5565
    }
5566
  return NULL;
5567
}
5568
 
5569
static struct type *
5570
dwarf2_fundamental_type (objfile, typeid)
5571
     struct objfile *objfile;
5572
     int typeid;
5573
{
5574
  if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
5575
    {
5576
      error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5577
             typeid);
5578
    }
5579
 
5580
  /* Look for this particular type in the fundamental type vector.  If
5581
     one is not found, create and install one appropriate for the
5582
     current language and the current target machine. */
5583
 
5584
  if (ftypes[typeid] == NULL)
5585
    {
5586
      ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid);
5587
    }
5588
 
5589
  return (ftypes[typeid]);
5590
}
5591
 
5592
/* Decode simple location descriptions.
5593
   Given a pointer to a dwarf block that defines a location, compute
5594
   the location and return the value.
5595
 
5596
   FIXME: This is a kludge until we figure out a better
5597
   way to handle the location descriptions.
5598
   Gdb's design does not mesh well with the DWARF2 notion of a location
5599
   computing interpreter, which is a shame because the flexibility goes unused.
5600
   FIXME: Implement more operations as necessary.
5601
 
5602
   A location description containing no operations indicates that the
5603
   object is optimized out. The global optimized_out flag is set for
5604
   those, the return value is meaningless.
5605
 
5606
   When the result is a register number, the global isreg flag is set,
5607
   otherwise it is cleared.
5608
 
5609
   When the result is a base register offset, the global offreg flag is set
5610
   and the register number is returned in basereg, otherwise it is cleared.
5611
 
5612
   When the DW_OP_fbreg operation is encountered without a corresponding
5613
   DW_AT_frame_base attribute, the global islocal flag is set.
5614
   Hopefully the machine dependent code knows how to set up a virtual
5615
   frame pointer for the local references.
5616
 
5617
   Note that stack[0] is unused except as a default error return.
5618
   Note that stack overflow is not yet handled.  */
5619
 
5620
static CORE_ADDR
5621
decode_locdesc (blk, objfile)
5622
     struct dwarf_block *blk;
5623
     struct objfile *objfile;
5624
{
5625
  int i;
5626
  int size = blk->size;
5627
  char *data = blk->data;
5628
  CORE_ADDR stack[64];
5629
  int stacki;
5630
  unsigned int bytes_read, unsnd;
5631
  unsigned char op;
5632
 
5633
  i = 0;
5634
  stacki = 0;
5635
  stack[stacki] = 0;
5636
  isreg = 0;
5637
  offreg = 0;
5638
  isderef = 0;
5639
  islocal = 0;
5640
  optimized_out = 1;
5641
 
5642
  while (i < size)
5643
    {
5644
      optimized_out = 0;
5645
      op = data[i++];
5646
      switch (op)
5647
        {
5648
        case DW_OP_reg0:
5649
        case DW_OP_reg1:
5650
        case DW_OP_reg2:
5651
        case DW_OP_reg3:
5652
        case DW_OP_reg4:
5653
        case DW_OP_reg5:
5654
        case DW_OP_reg6:
5655
        case DW_OP_reg7:
5656
        case DW_OP_reg8:
5657
        case DW_OP_reg9:
5658
        case DW_OP_reg10:
5659
        case DW_OP_reg11:
5660
        case DW_OP_reg12:
5661
        case DW_OP_reg13:
5662
        case DW_OP_reg14:
5663
        case DW_OP_reg15:
5664
        case DW_OP_reg16:
5665
        case DW_OP_reg17:
5666
        case DW_OP_reg18:
5667
        case DW_OP_reg19:
5668
        case DW_OP_reg20:
5669
        case DW_OP_reg21:
5670
        case DW_OP_reg22:
5671
        case DW_OP_reg23:
5672
        case DW_OP_reg24:
5673
        case DW_OP_reg25:
5674
        case DW_OP_reg26:
5675
        case DW_OP_reg27:
5676
        case DW_OP_reg28:
5677
        case DW_OP_reg29:
5678
        case DW_OP_reg30:
5679
        case DW_OP_reg31:
5680
          isreg = 1;
5681
          stack[++stacki] = op - DW_OP_reg0;
5682
          break;
5683
 
5684
        case DW_OP_regx:
5685
          isreg = 1;
5686
          unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5687
          i += bytes_read;
5688
#if defined(HARRIS_TARGET) && defined(_M88K)
5689
          /* The Harris 88110 gdb ports have long kept their special reg
5690
             numbers between their gp-regs and their x-regs.  This is
5691
             not how our dwarf is generated.  Punt. */
5692
          unsnd += 6;
5693
#endif
5694
          stack[++stacki] = unsnd;
5695
          break;
5696
 
5697
        case DW_OP_breg0:
5698
        case DW_OP_breg1:
5699
        case DW_OP_breg2:
5700
        case DW_OP_breg3:
5701
        case DW_OP_breg4:
5702
        case DW_OP_breg5:
5703
        case DW_OP_breg6:
5704
        case DW_OP_breg7:
5705
        case DW_OP_breg8:
5706
        case DW_OP_breg9:
5707
        case DW_OP_breg10:
5708
        case DW_OP_breg11:
5709
        case DW_OP_breg12:
5710
        case DW_OP_breg13:
5711
        case DW_OP_breg14:
5712
        case DW_OP_breg15:
5713
        case DW_OP_breg16:
5714
        case DW_OP_breg17:
5715
        case DW_OP_breg18:
5716
        case DW_OP_breg19:
5717
        case DW_OP_breg20:
5718
        case DW_OP_breg21:
5719
        case DW_OP_breg22:
5720
        case DW_OP_breg23:
5721
        case DW_OP_breg24:
5722
        case DW_OP_breg25:
5723
        case DW_OP_breg26:
5724
        case DW_OP_breg27:
5725
        case DW_OP_breg28:
5726
        case DW_OP_breg29:
5727
        case DW_OP_breg30:
5728
        case DW_OP_breg31:
5729
          offreg = 1;
5730
          basereg = op - DW_OP_breg0;
5731
          stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5732
          i += bytes_read;
5733
          break;
5734
 
5735
        case DW_OP_bregx:
5736
          offreg = 1;
5737
          basereg = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5738
          i += bytes_read;
5739
          stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5740
          i += bytes_read;
5741
          break;
5742
 
5743
        case DW_OP_fbreg:
5744
          stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5745
          i += bytes_read;
5746
          if (frame_base_reg >= 0)
5747
            {
5748
              offreg = 1;
5749
              basereg = frame_base_reg;
5750
              stack[stacki] += frame_base_offset;
5751
            }
5752
          else
5753
            {
5754
              complain (&dwarf2_missing_at_frame_base);
5755
              islocal = 1;
5756
            }
5757
          break;
5758
 
5759
        case DW_OP_addr:
5760
          stack[++stacki] = read_address (objfile->obfd, &data[i]);
5761
          i += address_size;
5762
          break;
5763
 
5764
        case DW_OP_const1u:
5765
          stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
5766
          i += 1;
5767
          break;
5768
 
5769
        case DW_OP_const1s:
5770
          stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
5771
          i += 1;
5772
          break;
5773
 
5774
        case DW_OP_const2u:
5775
          stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
5776
          i += 2;
5777
          break;
5778
 
5779
        case DW_OP_const2s:
5780
          stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
5781
          i += 2;
5782
          break;
5783
 
5784
        case DW_OP_const4u:
5785
          stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
5786
          i += 4;
5787
          break;
5788
 
5789
        case DW_OP_const4s:
5790
          stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
5791
          i += 4;
5792
          break;
5793
 
5794
        case DW_OP_constu:
5795
          stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
5796
                                                  &bytes_read);
5797
          i += bytes_read;
5798
          break;
5799
 
5800
        case DW_OP_consts:
5801
          stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
5802
          i += bytes_read;
5803
          break;
5804
 
5805
        case DW_OP_plus:
5806
          stack[stacki - 1] += stack[stacki];
5807
          stacki--;
5808
          break;
5809
 
5810
        case DW_OP_plus_uconst:
5811
          stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
5812
          i += bytes_read;
5813
          break;
5814
 
5815
        case DW_OP_minus:
5816
          stack[stacki - 1] = stack[stacki] - stack[stacki - 1];
5817
          stacki--;
5818
          break;
5819
 
5820
        case DW_OP_deref:
5821
          isderef = 1;
5822
          /* If we're not the last op, then we definitely can't encode
5823
             this using GDB's address_class enum.  */
5824
          if (i < size)
5825
            complain (&dwarf2_complex_location_expr);
5826
          break;
5827
 
5828
        default:
5829
          complain (&dwarf2_unsupported_stack_op, dwarf_stack_op_name (op));
5830
          return (stack[stacki]);
5831
        }
5832
    }
5833
  return (stack[stacki]);
5834
}
5835
 
5836
/* memory allocation interface */
5837
 
5838
/* ARGSUSED */
5839
static void
5840
dwarf2_free_tmp_obstack (ignore)
5841
     PTR ignore;
5842
{
5843
  obstack_free (&dwarf2_tmp_obstack, NULL);
5844
}
5845
 
5846
static struct dwarf_block *
5847
dwarf_alloc_block ()
5848
{
5849
  struct dwarf_block *blk;
5850
 
5851
  blk = (struct dwarf_block *)
5852
    obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block));
5853
  return (blk);
5854
}
5855
 
5856
static struct abbrev_info *
5857
dwarf_alloc_abbrev ()
5858
{
5859
  struct abbrev_info *abbrev;
5860
 
5861
  abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info));
5862
  memset (abbrev, 0, sizeof (struct abbrev_info));
5863
  return (abbrev);
5864
}
5865
 
5866
static struct die_info *
5867
dwarf_alloc_die ()
5868
{
5869
  struct die_info *die;
5870
 
5871
  die = (struct die_info *) xmalloc (sizeof (struct die_info));
5872
  memset (die, 0, sizeof (struct die_info));
5873
  return (die);
5874
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.