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