~ubuntu-branches/ubuntu/utopic/crash/utopic-proposed

« back to all changes in this revision

Viewing changes to gdb-6.1/gdb-6.1/gdb-6.1/gdb-6.1/gdb-6.1/gdb-6.1/gdb/dwarf2read.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-05 12:54:24 UTC
  • mfrom: (0.1.10 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080505125424-5q3qi10b5t8f1hc1
Tags: 4.0-6.3-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/patches/01_spu_commands.dpatch:
    + SPU extension support
  - debian/rules:
    + Build SPU on powerpc

Show diffs side-by-side

added added

removed removed

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