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