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