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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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