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