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