2004-09-20 Jeff Johnston <jjohnstn@redhat.com>
[deliverable/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, 2003,
3 2004
4 Free Software Foundation, Inc.
5
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
12
13 This file is part of GDB.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
19
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
29
30 #include "defs.h"
31 #include "bfd.h"
32 #include "symtab.h"
33 #include "gdbtypes.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 #include "macrotab.h"
41 #include "language.h"
42 #include "complaints.h"
43 #include "bcache.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
47 #include "hashtab.h"
48
49 #include <fcntl.h>
50 #include "gdb_string.h"
51 #include "gdb_assert.h"
52 #include <sys/types.h>
53
54 /* A note on memory usage for this file.
55
56 At the present time, this code reads the debug info sections into
57 the objfile's objfile_obstack. A definite improvement for startup
58 time, on platforms which do not emit relocations for debug
59 sections, would be to use mmap instead. The object's complete
60 debug information is loaded into memory, partly to simplify
61 absolute DIE references.
62
63 Whether using obstacks or mmap, the sections should remain loaded
64 until the objfile is released, and pointers into the section data
65 can be used for any other data associated to the objfile (symbol
66 names, type names, location expressions to name a few). */
67
68 #ifndef DWARF2_REG_TO_REGNUM
69 #define DWARF2_REG_TO_REGNUM(REG) (REG)
70 #endif
71
72 #if 0
73 /* .debug_info header for a compilation unit
74 Because of alignment constraints, this structure has padding and cannot
75 be mapped directly onto the beginning of the .debug_info section. */
76 typedef struct comp_unit_header
77 {
78 unsigned int length; /* length of the .debug_info
79 contribution */
80 unsigned short version; /* version number -- 2 for DWARF
81 version 2 */
82 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
83 unsigned char addr_size; /* byte size of an address -- 4 */
84 }
85 _COMP_UNIT_HEADER;
86 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
87 #endif
88
89 /* .debug_pubnames header
90 Because of alignment constraints, this structure has padding and cannot
91 be mapped directly onto the beginning of the .debug_info section. */
92 typedef struct pubnames_header
93 {
94 unsigned int length; /* length of the .debug_pubnames
95 contribution */
96 unsigned char version; /* version number -- 2 for DWARF
97 version 2 */
98 unsigned int info_offset; /* offset into .debug_info section */
99 unsigned int info_size; /* byte size of .debug_info section
100 portion */
101 }
102 _PUBNAMES_HEADER;
103 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
104
105 /* .debug_pubnames header
106 Because of alignment constraints, this structure has padding and cannot
107 be mapped directly onto the beginning of the .debug_info section. */
108 typedef struct aranges_header
109 {
110 unsigned int length; /* byte len of the .debug_aranges
111 contribution */
112 unsigned short version; /* version number -- 2 for DWARF
113 version 2 */
114 unsigned int info_offset; /* offset into .debug_info section */
115 unsigned char addr_size; /* byte size of an address */
116 unsigned char seg_size; /* byte size of segment descriptor */
117 }
118 _ARANGES_HEADER;
119 #define _ACTUAL_ARANGES_HEADER_SIZE 12
120
121 /* .debug_line statement program prologue
122 Because of alignment constraints, this structure has padding and cannot
123 be mapped directly onto the beginning of the .debug_info section. */
124 typedef struct statement_prologue
125 {
126 unsigned int total_length; /* byte length of the statement
127 information */
128 unsigned short version; /* version number -- 2 for DWARF
129 version 2 */
130 unsigned int prologue_length; /* # bytes between prologue &
131 stmt program */
132 unsigned char minimum_instruction_length; /* byte size of
133 smallest instr */
134 unsigned char default_is_stmt; /* initial value of is_stmt
135 register */
136 char line_base;
137 unsigned char line_range;
138 unsigned char opcode_base; /* number assigned to first special
139 opcode */
140 unsigned char *standard_opcode_lengths;
141 }
142 _STATEMENT_PROLOGUE;
143
144 static const struct objfile_data *dwarf2_objfile_data_key;
145
146 struct dwarf2_per_objfile
147 {
148 /* Sizes of debugging sections. */
149 unsigned int info_size;
150 unsigned int abbrev_size;
151 unsigned int line_size;
152 unsigned int pubnames_size;
153 unsigned int aranges_size;
154 unsigned int loc_size;
155 unsigned int macinfo_size;
156 unsigned int str_size;
157 unsigned int ranges_size;
158 unsigned int frame_size;
159 unsigned int eh_frame_size;
160
161 /* Loaded data from the sections. */
162 char *info_buffer;
163 char *abbrev_buffer;
164 char *line_buffer;
165 char *str_buffer;
166 char *macinfo_buffer;
167 char *ranges_buffer;
168 char *loc_buffer;
169 };
170
171 static struct dwarf2_per_objfile *dwarf2_per_objfile;
172
173 static asection *dwarf_info_section;
174 static asection *dwarf_abbrev_section;
175 static asection *dwarf_line_section;
176 static asection *dwarf_pubnames_section;
177 static asection *dwarf_aranges_section;
178 static asection *dwarf_loc_section;
179 static asection *dwarf_macinfo_section;
180 static asection *dwarf_str_section;
181 static asection *dwarf_ranges_section;
182 asection *dwarf_frame_section;
183 asection *dwarf_eh_frame_section;
184
185 /* names of the debugging sections */
186
187 #define INFO_SECTION ".debug_info"
188 #define ABBREV_SECTION ".debug_abbrev"
189 #define LINE_SECTION ".debug_line"
190 #define PUBNAMES_SECTION ".debug_pubnames"
191 #define ARANGES_SECTION ".debug_aranges"
192 #define LOC_SECTION ".debug_loc"
193 #define MACINFO_SECTION ".debug_macinfo"
194 #define STR_SECTION ".debug_str"
195 #define RANGES_SECTION ".debug_ranges"
196 #define FRAME_SECTION ".debug_frame"
197 #define EH_FRAME_SECTION ".eh_frame"
198
199 /* local data types */
200
201 /* We hold several abbreviation tables in memory at the same time. */
202 #ifndef ABBREV_HASH_SIZE
203 #define ABBREV_HASH_SIZE 121
204 #endif
205
206 /* The data in a compilation unit header, after target2host
207 translation, looks like this. */
208 struct comp_unit_head
209 {
210 unsigned long length;
211 short version;
212 unsigned int abbrev_offset;
213 unsigned char addr_size;
214 unsigned char signed_addr_p;
215 unsigned int offset_size; /* size of file offsets; either 4 or 8 */
216 unsigned int initial_length_size; /* size of the length field; either
217 4 or 12 */
218
219 /* Offset to the first byte of this compilation unit header in the
220 * .debug_info section, for resolving relative reference dies. */
221
222 unsigned int offset;
223
224 /* Pointer to this compilation unit header in the .debug_info
225 * section */
226
227 char *cu_head_ptr;
228
229 /* Pointer to the first die of this compilatio unit. This will
230 * be the first byte following the compilation unit header. */
231
232 char *first_die_ptr;
233
234 /* Pointer to the next compilation unit header in the program. */
235
236 struct comp_unit_head *next;
237
238 /* Base address of this compilation unit. */
239
240 CORE_ADDR base_address;
241
242 /* Non-zero if base_address has been set. */
243
244 int base_known;
245 };
246
247 /* Internal state when decoding a particular compilation unit. */
248 struct dwarf2_cu
249 {
250 /* The objfile containing this compilation unit. */
251 struct objfile *objfile;
252
253 /* The header of the compilation unit.
254
255 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
256 should logically be moved to the dwarf2_cu structure. */
257 struct comp_unit_head header;
258
259 struct function_range *first_fn, *last_fn, *cached_fn;
260
261 /* The language we are debugging. */
262 enum language language;
263 const struct language_defn *language_defn;
264
265 const char *producer;
266
267 /* The generic symbol table building routines have separate lists for
268 file scope symbols and all all other scopes (local scopes). So
269 we need to select the right one to pass to add_symbol_to_list().
270 We do it by keeping a pointer to the correct list in list_in_scope.
271
272 FIXME: The original dwarf code just treated the file scope as the
273 first local scope, and all other local scopes as nested local
274 scopes, and worked fine. Check to see if we really need to
275 distinguish these in buildsym.c. */
276 struct pending **list_in_scope;
277
278 /* Maintain an array of referenced fundamental types for the current
279 compilation unit being read. For DWARF version 1, we have to construct
280 the fundamental types on the fly, since no information about the
281 fundamental types is supplied. Each such fundamental type is created by
282 calling a language dependent routine to create the type, and then a
283 pointer to that type is then placed in the array at the index specified
284 by it's FT_<TYPENAME> value. The array has a fixed size set by the
285 FT_NUM_MEMBERS compile time constant, which is the number of predefined
286 fundamental types gdb knows how to construct. */
287 struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */
288
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info **dwarf2_abbrevs;
291
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack;
294
295 /* Hash table holding all the loaded partial DIEs. */
296 htab_t partial_dies;
297
298 /* Storage for things with the same lifetime as this read-in compilation
299 unit, including partial DIEs. */
300 struct obstack comp_unit_obstack;
301
302 /* This flag will be set if this compilation unit includes any
303 DW_TAG_namespace DIEs. If we know that there are explicit
304 DIEs for namespaces, we don't need to try to infer them
305 from mangled names. */
306 unsigned int has_namespace_info : 1;
307 };
308
309 /* The line number information for a compilation unit (found in the
310 .debug_line section) begins with a "statement program header",
311 which contains the following information. */
312 struct line_header
313 {
314 unsigned int total_length;
315 unsigned short version;
316 unsigned int header_length;
317 unsigned char minimum_instruction_length;
318 unsigned char default_is_stmt;
319 int line_base;
320 unsigned char line_range;
321 unsigned char opcode_base;
322
323 /* standard_opcode_lengths[i] is the number of operands for the
324 standard opcode whose value is i. This means that
325 standard_opcode_lengths[0] is unused, and the last meaningful
326 element is standard_opcode_lengths[opcode_base - 1]. */
327 unsigned char *standard_opcode_lengths;
328
329 /* The include_directories table. NOTE! These strings are not
330 allocated with xmalloc; instead, they are pointers into
331 debug_line_buffer. If you try to free them, `free' will get
332 indigestion. */
333 unsigned int num_include_dirs, include_dirs_size;
334 char **include_dirs;
335
336 /* The file_names table. NOTE! These strings are not allocated
337 with xmalloc; instead, they are pointers into debug_line_buffer.
338 Don't try to free them directly. */
339 unsigned int num_file_names, file_names_size;
340 struct file_entry
341 {
342 char *name;
343 unsigned int dir_index;
344 unsigned int mod_time;
345 unsigned int length;
346 int included_p; /* Non-zero if referenced by the Line Number Program. */
347 } *file_names;
348
349 /* The start and end of the statement program following this
350 header. These point into dwarf2_per_objfile->line_buffer. */
351 char *statement_program_start, *statement_program_end;
352 };
353
354 /* When we construct a partial symbol table entry we only
355 need this much information. */
356 struct partial_die_info
357 {
358 /* Offset of this DIE. */
359 unsigned int offset;
360
361 /* DWARF-2 tag for this DIE. */
362 ENUM_BITFIELD(dwarf_tag) tag : 16;
363
364 /* Language code associated with this DIE. This is only used
365 for the compilation unit DIE. */
366 unsigned int language : 8;
367
368 /* Assorted flags describing the data found in this DIE. */
369 unsigned int has_children : 1;
370 unsigned int is_external : 1;
371 unsigned int is_declaration : 1;
372 unsigned int has_type : 1;
373 unsigned int has_specification : 1;
374 unsigned int has_stmt_list : 1;
375 unsigned int has_pc_info : 1;
376
377 /* Flag set if the SCOPE field of this structure has been
378 computed. */
379 unsigned int scope_set : 1;
380
381 /* The name of this DIE. Normally the value of DW_AT_name, but
382 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
383 other fashion. */
384 char *name;
385 char *dirname;
386
387 /* The scope to prepend to our children. This is generally
388 allocated on the comp_unit_obstack, so will disappear
389 when this compilation unit leaves the cache. */
390 char *scope;
391
392 /* The location description associated with this DIE, if any. */
393 struct dwarf_block *locdesc;
394
395 /* If HAS_PC_INFO, the PC range associated with this DIE. */
396 CORE_ADDR lowpc;
397 CORE_ADDR highpc;
398
399 /* Pointer into the info_buffer pointing at the target of
400 DW_AT_sibling, if any. */
401 char *sibling;
402
403 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
404 DW_AT_specification (or DW_AT_abstract_origin or
405 DW_AT_extension). */
406 unsigned int spec_offset;
407
408 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
409 unsigned int line_offset;
410
411 /* Pointers to this DIE's parent, first child, and next sibling,
412 if any. */
413 struct partial_die_info *die_parent, *die_child, *die_sibling;
414 };
415
416 /* This data structure holds the information of an abbrev. */
417 struct abbrev_info
418 {
419 unsigned int number; /* number identifying abbrev */
420 enum dwarf_tag tag; /* dwarf tag */
421 unsigned short has_children; /* boolean */
422 unsigned short num_attrs; /* number of attributes */
423 struct attr_abbrev *attrs; /* an array of attribute descriptions */
424 struct abbrev_info *next; /* next in chain */
425 };
426
427 struct attr_abbrev
428 {
429 enum dwarf_attribute name;
430 enum dwarf_form form;
431 };
432
433 /* This data structure holds a complete die structure. */
434 struct die_info
435 {
436 enum dwarf_tag tag; /* Tag indicating type of die */
437 unsigned int abbrev; /* Abbrev number */
438 unsigned int offset; /* Offset in .debug_info section */
439 unsigned int num_attrs; /* Number of attributes */
440 struct attribute *attrs; /* An array of attributes */
441 struct die_info *next_ref; /* Next die in ref hash table */
442
443 /* The dies in a compilation unit form an n-ary tree. PARENT
444 points to this die's parent; CHILD points to the first child of
445 this node; and all the children of a given node are chained
446 together via their SIBLING fields, terminated by a die whose
447 tag is zero. */
448 struct die_info *child; /* Its first child, if any. */
449 struct die_info *sibling; /* Its next sibling, if any. */
450 struct die_info *parent; /* Its parent, if any. */
451
452 struct type *type; /* Cached type information */
453 };
454
455 /* Attributes have a name and a value */
456 struct attribute
457 {
458 enum dwarf_attribute name;
459 enum dwarf_form form;
460 union
461 {
462 char *str;
463 struct dwarf_block *blk;
464 unsigned long unsnd;
465 long int snd;
466 CORE_ADDR addr;
467 }
468 u;
469 };
470
471 struct function_range
472 {
473 const char *name;
474 CORE_ADDR lowpc, highpc;
475 int seen_line;
476 struct function_range *next;
477 };
478
479 /* Get at parts of an attribute structure */
480
481 #define DW_STRING(attr) ((attr)->u.str)
482 #define DW_UNSND(attr) ((attr)->u.unsnd)
483 #define DW_BLOCK(attr) ((attr)->u.blk)
484 #define DW_SND(attr) ((attr)->u.snd)
485 #define DW_ADDR(attr) ((attr)->u.addr)
486
487 /* Blocks are a bunch of untyped bytes. */
488 struct dwarf_block
489 {
490 unsigned int size;
491 char *data;
492 };
493
494 #ifndef ATTR_ALLOC_CHUNK
495 #define ATTR_ALLOC_CHUNK 4
496 #endif
497
498 /* A hash table of die offsets for following references. */
499 #ifndef REF_HASH_SIZE
500 #define REF_HASH_SIZE 1021
501 #endif
502
503 static struct die_info *die_ref_table[REF_HASH_SIZE];
504
505 /* Allocate fields for structs, unions and enums in this size. */
506 #ifndef DW_FIELD_ALLOC_CHUNK
507 #define DW_FIELD_ALLOC_CHUNK 4
508 #endif
509
510 /* A zeroed version of a partial die for initialization purposes. */
511 static struct partial_die_info zeroed_partial_die;
512
513 /* FIXME: decode_locdesc sets these variables to describe the location
514 to the caller. These ought to be a structure or something. If
515 none of the flags are set, the object lives at the address returned
516 by decode_locdesc. */
517
518 static int isreg; /* Object lives in register.
519 decode_locdesc's return value is
520 the register number. */
521
522 /* We put a pointer to this structure in the read_symtab_private field
523 of the psymtab. */
524
525 struct dwarf2_pinfo
526 {
527 /* Offset in .debug_info for this compilation unit. */
528
529 unsigned long dwarf_info_offset;
530 };
531
532 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
533 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
534
535 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
536 but this would require a corresponding change in unpack_field_as_long
537 and friends. */
538 static int bits_per_byte = 8;
539
540 /* The routines that read and process dies for a C struct or C++ class
541 pass lists of data member fields and lists of member function fields
542 in an instance of a field_info structure, as defined below. */
543 struct field_info
544 {
545 /* List of data member and baseclasses fields. */
546 struct nextfield
547 {
548 struct nextfield *next;
549 int accessibility;
550 int virtuality;
551 struct field field;
552 }
553 *fields;
554
555 /* Number of fields. */
556 int nfields;
557
558 /* Number of baseclasses. */
559 int nbaseclasses;
560
561 /* Set if the accesibility of one of the fields is not public. */
562 int non_public_fields;
563
564 /* Member function fields array, entries are allocated in the order they
565 are encountered in the object file. */
566 struct nextfnfield
567 {
568 struct nextfnfield *next;
569 struct fn_field fnfield;
570 }
571 *fnfields;
572
573 /* Member function fieldlist array, contains name of possibly overloaded
574 member function, number of overloaded member functions and a pointer
575 to the head of the member function field chain. */
576 struct fnfieldlist
577 {
578 char *name;
579 int length;
580 struct nextfnfield *head;
581 }
582 *fnfieldlists;
583
584 /* Number of entries in the fnfieldlists array. */
585 int nfnfields;
586 };
587
588 /* Various complaints about symbol reading that don't abort the process */
589
590 static void
591 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
592 {
593 complaint (&symfile_complaints,
594 "statement list doesn't fit in .debug_line section");
595 }
596
597 static void
598 dwarf2_complex_location_expr_complaint (void)
599 {
600 complaint (&symfile_complaints, "location expression too complex");
601 }
602
603 static void
604 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
605 int arg3)
606 {
607 complaint (&symfile_complaints,
608 "const value length mismatch for '%s', got %d, expected %d", arg1,
609 arg2, arg3);
610 }
611
612 static void
613 dwarf2_macros_too_long_complaint (void)
614 {
615 complaint (&symfile_complaints,
616 "macro info runs off end of `.debug_macinfo' section");
617 }
618
619 static void
620 dwarf2_macro_malformed_definition_complaint (const char *arg1)
621 {
622 complaint (&symfile_complaints,
623 "macro debug info contains a malformed macro definition:\n`%s'",
624 arg1);
625 }
626
627 static void
628 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
629 {
630 complaint (&symfile_complaints,
631 "invalid attribute class or form for '%s' in '%s'", arg1, arg2);
632 }
633
634 /* local function prototypes */
635
636 static void dwarf2_locate_sections (bfd *, asection *, void *);
637
638 #if 0
639 static void dwarf2_build_psymtabs_easy (struct objfile *, int);
640 #endif
641
642 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
643 struct objfile *);
644
645 static void dwarf2_build_include_psymtabs (struct dwarf2_cu *,
646 struct partial_die_info *,
647 struct partial_symtab *);
648
649 static void dwarf2_build_psymtabs_hard (struct objfile *, int);
650
651 static void scan_partial_symbols (struct partial_die_info *,
652 CORE_ADDR *, CORE_ADDR *,
653 struct dwarf2_cu *);
654
655 static void add_partial_symbol (struct partial_die_info *,
656 struct dwarf2_cu *);
657
658 static int pdi_needs_namespace (enum dwarf_tag tag);
659
660 static void add_partial_namespace (struct partial_die_info *pdi,
661 CORE_ADDR *lowpc, CORE_ADDR *highpc,
662 struct dwarf2_cu *cu);
663
664 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
665 struct dwarf2_cu *cu);
666
667 static char *locate_pdi_sibling (struct partial_die_info *orig_pdi,
668 char *info_ptr,
669 bfd *abfd,
670 struct dwarf2_cu *cu);
671
672 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
673
674 static void psymtab_to_symtab_1 (struct partial_symtab *);
675
676 char *dwarf2_read_section (struct objfile *, asection *);
677
678 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
679
680 static void dwarf2_free_abbrev_table (void *);
681
682 static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *);
683
684 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
685 struct dwarf2_cu *);
686
687 static struct partial_die_info *load_partial_dies (bfd *, char *, int,
688 struct dwarf2_cu *);
689
690 static char *read_partial_die (struct partial_die_info *,
691 struct abbrev_info *abbrev, unsigned int,
692 bfd *, char *, struct dwarf2_cu *);
693
694 static struct partial_die_info *find_partial_die (unsigned long,
695 struct dwarf2_cu *,
696 struct dwarf2_cu **);
697
698 static void fixup_partial_die (struct partial_die_info *,
699 struct dwarf2_cu *);
700
701 static char *read_full_die (struct die_info **, bfd *, char *,
702 struct dwarf2_cu *, int *);
703
704 static char *read_attribute (struct attribute *, struct attr_abbrev *,
705 bfd *, char *, struct dwarf2_cu *);
706
707 static char *read_attribute_value (struct attribute *, unsigned,
708 bfd *, char *, struct dwarf2_cu *);
709
710 static unsigned int read_1_byte (bfd *, char *);
711
712 static int read_1_signed_byte (bfd *, char *);
713
714 static unsigned int read_2_bytes (bfd *, char *);
715
716 static unsigned int read_4_bytes (bfd *, char *);
717
718 static unsigned long read_8_bytes (bfd *, char *);
719
720 static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *,
721 int *bytes_read);
722
723 static LONGEST read_initial_length (bfd *, char *,
724 struct comp_unit_head *, int *bytes_read);
725
726 static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *,
727 int *bytes_read);
728
729 static char *read_n_bytes (bfd *, char *, unsigned int);
730
731 static char *read_string (bfd *, char *, unsigned int *);
732
733 static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
734 unsigned int *);
735
736 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
737
738 static long read_signed_leb128 (bfd *, char *, unsigned int *);
739
740 static char *skip_leb128 (bfd *, char *);
741
742 static void set_cu_language (unsigned int, struct dwarf2_cu *);
743
744 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
745 struct dwarf2_cu *);
746
747 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
748 struct dwarf2_cu *cu);
749
750 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
751
752 static struct die_info *die_specification (struct die_info *die,
753 struct dwarf2_cu *);
754
755 static void free_line_header (struct line_header *lh);
756
757 static void add_file_name (struct line_header *, char *, unsigned int,
758 unsigned int, unsigned int);
759
760 static struct line_header *(dwarf_decode_line_header
761 (unsigned int offset,
762 bfd *abfd, struct dwarf2_cu *cu));
763
764 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
765 struct dwarf2_cu *, struct partial_symtab *);
766
767 static void dwarf2_start_subfile (char *, char *);
768
769 static struct symbol *new_symbol (struct die_info *, struct type *,
770 struct dwarf2_cu *);
771
772 static void dwarf2_const_value (struct attribute *, struct symbol *,
773 struct dwarf2_cu *);
774
775 static void dwarf2_const_value_data (struct attribute *attr,
776 struct symbol *sym,
777 int bits);
778
779 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
780
781 static struct type *die_containing_type (struct die_info *,
782 struct dwarf2_cu *);
783
784 #if 0
785 static struct type *type_at_offset (unsigned int, struct objfile *);
786 #endif
787
788 static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *);
789
790 static void read_type_die (struct die_info *, struct dwarf2_cu *);
791
792 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
793
794 static char *typename_concat (struct obstack *, const char *prefix, const char *suffix,
795 struct dwarf2_cu *);
796
797 static void read_typedef (struct die_info *, struct dwarf2_cu *);
798
799 static void read_base_type (struct die_info *, struct dwarf2_cu *);
800
801 static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu);
802
803 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
804
805 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
806
807 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
808
809 static int dwarf2_get_pc_bounds (struct die_info *,
810 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *);
811
812 static void get_scope_pc_bounds (struct die_info *,
813 CORE_ADDR *, CORE_ADDR *,
814 struct dwarf2_cu *);
815
816 static void dwarf2_add_field (struct field_info *, struct die_info *,
817 struct dwarf2_cu *);
818
819 static void dwarf2_attach_fields_to_type (struct field_info *,
820 struct type *, struct dwarf2_cu *);
821
822 static void dwarf2_add_member_fn (struct field_info *,
823 struct die_info *, struct type *,
824 struct dwarf2_cu *);
825
826 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
827 struct type *, struct dwarf2_cu *);
828
829 static void read_structure_type (struct die_info *, struct dwarf2_cu *);
830
831 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
832
833 static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu);
834
835 static void read_common_block (struct die_info *, struct dwarf2_cu *);
836
837 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
838
839 static const char *namespace_name (struct die_info *die,
840 int *is_anonymous, struct dwarf2_cu *);
841
842 static void read_enumeration_type (struct die_info *, struct dwarf2_cu *);
843
844 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
845
846 static struct type *dwarf_base_type (int, int, struct dwarf2_cu *);
847
848 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
849
850 static void read_array_type (struct die_info *, struct dwarf2_cu *);
851
852 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
853 struct dwarf2_cu *);
854
855 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
856
857 static void read_tag_ptr_to_member_type (struct die_info *,
858 struct dwarf2_cu *);
859
860 static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *);
861
862 static void read_tag_const_type (struct die_info *, struct dwarf2_cu *);
863
864 static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *);
865
866 static void read_tag_string_type (struct die_info *, struct dwarf2_cu *);
867
868 static void read_subroutine_type (struct die_info *, struct dwarf2_cu *);
869
870 static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *);
871
872 static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd,
873 struct dwarf2_cu *,
874 char **new_info_ptr,
875 struct die_info *parent);
876
877 static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd,
878 struct dwarf2_cu *,
879 char **new_info_ptr,
880 struct die_info *parent);
881
882 static void free_die_list (struct die_info *);
883
884 static struct cleanup *make_cleanup_free_die_list (struct die_info *);
885
886 static void process_die (struct die_info *, struct dwarf2_cu *);
887
888 static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *);
889
890 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
891
892 static struct die_info *dwarf2_extension (struct die_info *die,
893 struct dwarf2_cu *);
894
895 static char *dwarf_tag_name (unsigned int);
896
897 static char *dwarf_attr_name (unsigned int);
898
899 static char *dwarf_form_name (unsigned int);
900
901 static char *dwarf_stack_op_name (unsigned int);
902
903 static char *dwarf_bool_name (unsigned int);
904
905 static char *dwarf_type_encoding_name (unsigned int);
906
907 #if 0
908 static char *dwarf_cfi_name (unsigned int);
909
910 struct die_info *copy_die (struct die_info *);
911 #endif
912
913 static struct die_info *sibling_die (struct die_info *);
914
915 static void dump_die (struct die_info *);
916
917 static void dump_die_list (struct die_info *);
918
919 static void store_in_ref_table (unsigned int, struct die_info *);
920
921 static void dwarf2_empty_hash_tables (void);
922
923 static unsigned int dwarf2_get_ref_die_offset (struct attribute *,
924 struct dwarf2_cu *);
925
926 static int dwarf2_get_attr_constant_value (struct attribute *, int);
927
928 static struct die_info *follow_die_ref (unsigned int);
929
930 static struct type *dwarf2_fundamental_type (struct objfile *, int,
931 struct dwarf2_cu *);
932
933 /* memory allocation interface */
934
935 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
936
937 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
938
939 static struct die_info *dwarf_alloc_die (void);
940
941 static void initialize_cu_func_list (struct dwarf2_cu *);
942
943 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
944 struct dwarf2_cu *);
945
946 static void dwarf_decode_macros (struct line_header *, unsigned int,
947 char *, bfd *, struct dwarf2_cu *);
948
949 static int attr_form_is_block (struct attribute *);
950
951 static void
952 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
953 struct dwarf2_cu *cu);
954
955 static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
956 struct dwarf2_cu *cu);
957
958 static void free_stack_comp_unit (void *);
959
960 static void *hashtab_obstack_allocate (void *data, size_t size, size_t count);
961
962 static void dummy_obstack_deallocate (void *object, void *data);
963
964 static hashval_t partial_die_hash (const void *item);
965
966 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
967
968 /* Try to locate the sections we need for DWARF 2 debugging
969 information and return true if we have enough to do something. */
970
971 int
972 dwarf2_has_info (struct objfile *objfile)
973 {
974 struct dwarf2_per_objfile *data;
975
976 /* Initialize per-objfile state. */
977 data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
978 memset (data, 0, sizeof (*data));
979 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
980 dwarf2_per_objfile = data;
981
982 dwarf_info_section = 0;
983 dwarf_abbrev_section = 0;
984 dwarf_line_section = 0;
985 dwarf_str_section = 0;
986 dwarf_macinfo_section = 0;
987 dwarf_frame_section = 0;
988 dwarf_eh_frame_section = 0;
989 dwarf_ranges_section = 0;
990 dwarf_loc_section = 0;
991
992 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
993 return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
994 }
995
996 /* This function is mapped across the sections and remembers the
997 offset and size of each of the debugging sections we are interested
998 in. */
999
1000 static void
1001 dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
1002 {
1003 if (strcmp (sectp->name, INFO_SECTION) == 0)
1004 {
1005 dwarf2_per_objfile->info_size = bfd_get_section_size (sectp);
1006 dwarf_info_section = sectp;
1007 }
1008 else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
1009 {
1010 dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp);
1011 dwarf_abbrev_section = sectp;
1012 }
1013 else if (strcmp (sectp->name, LINE_SECTION) == 0)
1014 {
1015 dwarf2_per_objfile->line_size = bfd_get_section_size (sectp);
1016 dwarf_line_section = sectp;
1017 }
1018 else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
1019 {
1020 dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp);
1021 dwarf_pubnames_section = sectp;
1022 }
1023 else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
1024 {
1025 dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp);
1026 dwarf_aranges_section = sectp;
1027 }
1028 else if (strcmp (sectp->name, LOC_SECTION) == 0)
1029 {
1030 dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp);
1031 dwarf_loc_section = sectp;
1032 }
1033 else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
1034 {
1035 dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp);
1036 dwarf_macinfo_section = sectp;
1037 }
1038 else if (strcmp (sectp->name, STR_SECTION) == 0)
1039 {
1040 dwarf2_per_objfile->str_size = bfd_get_section_size (sectp);
1041 dwarf_str_section = sectp;
1042 }
1043 else if (strcmp (sectp->name, FRAME_SECTION) == 0)
1044 {
1045 dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp);
1046 dwarf_frame_section = sectp;
1047 }
1048 else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0)
1049 {
1050 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1051 if (aflag & SEC_HAS_CONTENTS)
1052 {
1053 dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp);
1054 dwarf_eh_frame_section = sectp;
1055 }
1056 }
1057 else if (strcmp (sectp->name, RANGES_SECTION) == 0)
1058 {
1059 dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp);
1060 dwarf_ranges_section = sectp;
1061 }
1062 }
1063
1064 /* Build a partial symbol table. */
1065
1066 void
1067 dwarf2_build_psymtabs (struct objfile *objfile, int mainline)
1068 {
1069 /* We definitely need the .debug_info and .debug_abbrev sections */
1070
1071 dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
1072 dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
1073
1074 if (dwarf_line_section)
1075 dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
1076 else
1077 dwarf2_per_objfile->line_buffer = NULL;
1078
1079 if (dwarf_str_section)
1080 dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
1081 else
1082 dwarf2_per_objfile->str_buffer = NULL;
1083
1084 if (dwarf_macinfo_section)
1085 dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile,
1086 dwarf_macinfo_section);
1087 else
1088 dwarf2_per_objfile->macinfo_buffer = NULL;
1089
1090 if (dwarf_ranges_section)
1091 dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
1092 else
1093 dwarf2_per_objfile->ranges_buffer = NULL;
1094
1095 if (dwarf_loc_section)
1096 dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
1097 else
1098 dwarf2_per_objfile->loc_buffer = NULL;
1099
1100 if (mainline
1101 || (objfile->global_psymbols.size == 0
1102 && objfile->static_psymbols.size == 0))
1103 {
1104 init_psymbol_list (objfile, 1024);
1105 }
1106
1107 #if 0
1108 if (dwarf_aranges_offset && dwarf_pubnames_offset)
1109 {
1110 /* Things are significantly easier if we have .debug_aranges and
1111 .debug_pubnames sections */
1112
1113 dwarf2_build_psymtabs_easy (objfile, mainline);
1114 }
1115 else
1116 #endif
1117 /* only test this case for now */
1118 {
1119 /* In this case we have to work a bit harder */
1120 dwarf2_build_psymtabs_hard (objfile, mainline);
1121 }
1122 }
1123
1124 #if 0
1125 /* Build the partial symbol table from the information in the
1126 .debug_pubnames and .debug_aranges sections. */
1127
1128 static void
1129 dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline)
1130 {
1131 bfd *abfd = objfile->obfd;
1132 char *aranges_buffer, *pubnames_buffer;
1133 char *aranges_ptr, *pubnames_ptr;
1134 unsigned int entry_length, version, info_offset, info_size;
1135
1136 pubnames_buffer = dwarf2_read_section (objfile,
1137 dwarf_pubnames_section);
1138 pubnames_ptr = pubnames_buffer;
1139 while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size)
1140 {
1141 struct comp_unit_head cu_header;
1142 int bytes_read;
1143
1144 entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header,
1145 &bytes_read);
1146 pubnames_ptr += bytes_read;
1147 version = read_1_byte (abfd, pubnames_ptr);
1148 pubnames_ptr += 1;
1149 info_offset = read_4_bytes (abfd, pubnames_ptr);
1150 pubnames_ptr += 4;
1151 info_size = read_4_bytes (abfd, pubnames_ptr);
1152 pubnames_ptr += 4;
1153 }
1154
1155 aranges_buffer = dwarf2_read_section (objfile,
1156 dwarf_aranges_section);
1157
1158 }
1159 #endif
1160
1161 /* Read in the comp unit header information from the debug_info at
1162 info_ptr. */
1163
1164 static char *
1165 read_comp_unit_head (struct comp_unit_head *cu_header,
1166 char *info_ptr, bfd *abfd)
1167 {
1168 int signed_addr;
1169 int bytes_read;
1170 cu_header->length = read_initial_length (abfd, info_ptr, cu_header,
1171 &bytes_read);
1172 info_ptr += bytes_read;
1173 cu_header->version = read_2_bytes (abfd, info_ptr);
1174 info_ptr += 2;
1175 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
1176 &bytes_read);
1177 info_ptr += bytes_read;
1178 cu_header->addr_size = read_1_byte (abfd, info_ptr);
1179 info_ptr += 1;
1180 signed_addr = bfd_get_sign_extend_vma (abfd);
1181 if (signed_addr < 0)
1182 internal_error (__FILE__, __LINE__,
1183 "read_comp_unit_head: dwarf from non elf file");
1184 cu_header->signed_addr_p = signed_addr;
1185 return info_ptr;
1186 }
1187
1188 static char *
1189 partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr,
1190 bfd *abfd)
1191 {
1192 char *beg_of_comp_unit = info_ptr;
1193
1194 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
1195
1196 if (header->version != 2)
1197 error ("Dwarf Error: wrong version in compilation unit header "
1198 "(is %d, should be %d) [in module %s]", header->version,
1199 2, bfd_get_filename (abfd));
1200
1201 if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size)
1202 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1203 "(offset 0x%lx + 6) [in module %s]",
1204 (long) header->abbrev_offset,
1205 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1206 bfd_get_filename (abfd));
1207
1208 if (beg_of_comp_unit + header->length + header->initial_length_size
1209 > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size)
1210 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1211 "(offset 0x%lx + 0) [in module %s]",
1212 (long) header->length,
1213 (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer),
1214 bfd_get_filename (abfd));
1215
1216 return info_ptr;
1217 }
1218
1219 /* Allocate a new partial symtab for file named NAME and mark this new
1220 partial symtab as being an include of PST. */
1221
1222 static void
1223 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
1224 struct objfile *objfile)
1225 {
1226 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
1227
1228 subpst->section_offsets = pst->section_offsets;
1229 subpst->textlow = 0;
1230 subpst->texthigh = 0;
1231
1232 subpst->dependencies = (struct partial_symtab **)
1233 obstack_alloc (&objfile->objfile_obstack,
1234 sizeof (struct partial_symtab *));
1235 subpst->dependencies[0] = pst;
1236 subpst->number_of_dependencies = 1;
1237
1238 subpst->globals_offset = 0;
1239 subpst->n_global_syms = 0;
1240 subpst->statics_offset = 0;
1241 subpst->n_static_syms = 0;
1242 subpst->symtab = NULL;
1243 subpst->read_symtab = pst->read_symtab;
1244 subpst->readin = 0;
1245
1246 /* No private part is necessary for include psymtabs. This property
1247 can be used to differentiate between such include psymtabs and
1248 the regular ones. If it ever happens that a regular psymtab can
1249 legitimally have a NULL private part, then we'll have to add a
1250 dedicated field for that in the dwarf2_pinfo structure. */
1251 subpst->read_symtab_private = NULL;
1252 }
1253
1254 /* Read the Line Number Program data and extract the list of files
1255 included by the source file represented by PST. Build an include
1256 partial symtab for each of these included files.
1257
1258 This procedure assumes that there *is* a Line Number Program in
1259 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1260 before calling this procedure. */
1261
1262 static void
1263 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
1264 struct partial_die_info *pdi,
1265 struct partial_symtab *pst)
1266 {
1267 struct objfile *objfile = cu->objfile;
1268 bfd *abfd = objfile->obfd;
1269 struct line_header *lh;
1270
1271 lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu);
1272 if (lh == NULL)
1273 return; /* No linetable, so no includes. */
1274
1275 dwarf_decode_lines (lh, NULL, abfd, cu, pst);
1276
1277 free_line_header (lh);
1278 }
1279
1280
1281 /* Build the partial symbol table by doing a quick pass through the
1282 .debug_info and .debug_abbrev sections. */
1283
1284 static void
1285 dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
1286 {
1287 /* Instead of reading this into a big buffer, we should probably use
1288 mmap() on architectures that support it. (FIXME) */
1289 bfd *abfd = objfile->obfd;
1290 char *info_ptr;
1291 char *beg_of_comp_unit;
1292 struct partial_die_info comp_unit_die;
1293 struct partial_symtab *pst;
1294 CORE_ADDR lowpc, highpc, baseaddr;
1295
1296 info_ptr = dwarf2_per_objfile->info_buffer;
1297
1298 /* Since the objects we're extracting from .debug_info vary in
1299 length, only the individual functions to extract them (like
1300 read_comp_unit_head and load_partial_die) can really know whether
1301 the buffer is large enough to hold another complete object.
1302
1303 At the moment, they don't actually check that. If .debug_info
1304 holds just one extra byte after the last compilation unit's dies,
1305 then read_comp_unit_head will happily read off the end of the
1306 buffer. read_partial_die is similarly casual. Those functions
1307 should be fixed.
1308
1309 For this loop condition, simply checking whether there's any data
1310 left at all should be sufficient. */
1311 while (info_ptr < (dwarf2_per_objfile->info_buffer
1312 + dwarf2_per_objfile->info_size))
1313 {
1314 struct cleanup *back_to_inner;
1315 struct dwarf2_cu cu;
1316 struct abbrev_info *abbrev;
1317 unsigned int bytes_read;
1318 struct dwarf2_per_cu_data *this_cu;
1319
1320 beg_of_comp_unit = info_ptr;
1321
1322 memset (&cu, 0, sizeof (cu));
1323
1324 obstack_init (&cu.comp_unit_obstack);
1325
1326 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
1327
1328 cu.objfile = objfile;
1329 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd);
1330
1331 /* Complete the cu_header */
1332 cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1333 cu.header.first_die_ptr = info_ptr;
1334 cu.header.cu_head_ptr = beg_of_comp_unit;
1335
1336 cu.list_in_scope = &file_symbols;
1337
1338 cu.partial_dies = NULL;
1339
1340 /* Read the abbrevs for this compilation unit into a table */
1341 dwarf2_read_abbrevs (abfd, &cu);
1342 make_cleanup (dwarf2_free_abbrev_table, &cu);
1343
1344 /* Read the compilation unit die */
1345 abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu);
1346 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
1347 abfd, info_ptr, &cu);
1348
1349 /* Set the language we're debugging */
1350 set_cu_language (comp_unit_die.language, &cu);
1351
1352 /* Allocate a new partial symbol table structure */
1353 pst = start_psymtab_common (objfile, objfile->section_offsets,
1354 comp_unit_die.name ? comp_unit_die.name : "",
1355 comp_unit_die.lowpc,
1356 objfile->global_psymbols.next,
1357 objfile->static_psymbols.next);
1358
1359 if (comp_unit_die.dirname)
1360 pst->dirname = xstrdup (comp_unit_die.dirname);
1361
1362 pst->read_symtab_private = (char *)
1363 obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
1364 DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf2_per_objfile->info_buffer;
1365 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1366
1367 /* Store the function that reads in the rest of the symbol table */
1368 pst->read_symtab = dwarf2_psymtab_to_symtab;
1369
1370 /* Check if comp unit has_children.
1371 If so, read the rest of the partial symbols from this comp unit.
1372 If not, there's no more debug_info for this comp unit. */
1373 if (comp_unit_die.has_children)
1374 {
1375 struct partial_die_info *first_die;
1376
1377 lowpc = ((CORE_ADDR) -1);
1378 highpc = ((CORE_ADDR) 0);
1379
1380 first_die = load_partial_dies (abfd, info_ptr, 1, &cu);
1381
1382 scan_partial_symbols (first_die, &lowpc, &highpc, &cu);
1383
1384 /* If we didn't find a lowpc, set it to highpc to avoid
1385 complaints from `maint check'. */
1386 if (lowpc == ((CORE_ADDR) -1))
1387 lowpc = highpc;
1388
1389 /* If the compilation unit didn't have an explicit address range,
1390 then use the information extracted from its child dies. */
1391 if (! comp_unit_die.has_pc_info)
1392 {
1393 comp_unit_die.lowpc = lowpc;
1394 comp_unit_die.highpc = highpc;
1395 }
1396 }
1397 pst->textlow = comp_unit_die.lowpc + baseaddr;
1398 pst->texthigh = comp_unit_die.highpc + baseaddr;
1399
1400 pst->n_global_syms = objfile->global_psymbols.next -
1401 (objfile->global_psymbols.list + pst->globals_offset);
1402 pst->n_static_syms = objfile->static_psymbols.next -
1403 (objfile->static_psymbols.list + pst->statics_offset);
1404 sort_pst_symbols (pst);
1405
1406 /* If there is already a psymtab or symtab for a file of this
1407 name, remove it. (If there is a symtab, more drastic things
1408 also happen.) This happens in VxWorks. */
1409 free_named_symtabs (pst->filename);
1410
1411 if (comp_unit_die.has_stmt_list)
1412 {
1413 /* Get the list of files included in the current compilation unit,
1414 and build a psymtab for each of them. */
1415 dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst);
1416 }
1417
1418 info_ptr = beg_of_comp_unit + cu.header.length
1419 + cu.header.initial_length_size;
1420
1421 do_cleanups (back_to_inner);
1422 }
1423 }
1424
1425 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1426 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1427 in CU. */
1428
1429 static void
1430 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
1431 CORE_ADDR *highpc, struct dwarf2_cu *cu)
1432 {
1433 struct objfile *objfile = cu->objfile;
1434 bfd *abfd = objfile->obfd;
1435 struct partial_die_info *pdi;
1436
1437 /* Now, march along the PDI's, descending into ones which have
1438 interesting children but skipping the children of the other ones,
1439 until we reach the end of the compilation unit. */
1440
1441 pdi = first_die;
1442
1443 while (pdi != NULL)
1444 {
1445 fixup_partial_die (pdi, cu);
1446
1447 /* Anonymous namespaces have no name but have interesting
1448 children, so we need to look at them. Ditto for anonymous
1449 enums. */
1450
1451 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
1452 || pdi->tag == DW_TAG_enumeration_type)
1453 {
1454 switch (pdi->tag)
1455 {
1456 case DW_TAG_subprogram:
1457 if (pdi->has_pc_info)
1458 {
1459 if (pdi->lowpc < *lowpc)
1460 {
1461 *lowpc = pdi->lowpc;
1462 }
1463 if (pdi->highpc > *highpc)
1464 {
1465 *highpc = pdi->highpc;
1466 }
1467 if (!pdi->is_declaration)
1468 {
1469 add_partial_symbol (pdi, cu);
1470 }
1471 }
1472 break;
1473 case DW_TAG_variable:
1474 case DW_TAG_typedef:
1475 case DW_TAG_union_type:
1476 if (!pdi->is_declaration)
1477 {
1478 add_partial_symbol (pdi, cu);
1479 }
1480 break;
1481 case DW_TAG_class_type:
1482 case DW_TAG_structure_type:
1483 if (!pdi->is_declaration)
1484 {
1485 add_partial_symbol (pdi, cu);
1486 }
1487 break;
1488 case DW_TAG_enumeration_type:
1489 if (!pdi->is_declaration)
1490 add_partial_enumeration (pdi, cu);
1491 break;
1492 case DW_TAG_base_type:
1493 case DW_TAG_subrange_type:
1494 /* File scope base type definitions are added to the partial
1495 symbol table. */
1496 add_partial_symbol (pdi, cu);
1497 break;
1498 case DW_TAG_namespace:
1499 add_partial_namespace (pdi, lowpc, highpc, cu);
1500 break;
1501 default:
1502 break;
1503 }
1504 }
1505
1506 /* If the die has a sibling, skip to the sibling. */
1507
1508 pdi = pdi->die_sibling;
1509 }
1510 }
1511
1512 /* Functions used to compute the fully scoped name of a partial DIE.
1513
1514 Normally, this is simple. For C++, the parent DIE's fully scoped
1515 name is concatenated with "::" and the partial DIE's name. For
1516 Java, the same thing occurs except that "." is used instead of "::".
1517 Enumerators are an exception; they use the scope of their parent
1518 enumeration type, i.e. the name of the enumeration type is not
1519 prepended to the enumerator.
1520
1521 There are two complexities. One is DW_AT_specification; in this
1522 case "parent" means the parent of the target of the specification,
1523 instead of the direct parent of the DIE. The other is compilers
1524 which do not emit DW_TAG_namespace; in this case we try to guess
1525 the fully qualified name of structure types from their members'
1526 linkage names. This must be done using the DIE's children rather
1527 than the children of any DW_AT_specification target. We only need
1528 to do this for structures at the top level, i.e. if the target of
1529 any DW_AT_specification (if any; otherwise the DIE itself) does not
1530 have a parent. */
1531
1532 /* Compute the scope prefix associated with PDI's parent, in
1533 compilation unit CU. The result will be allocated on CU's
1534 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1535 field. NULL is returned if no prefix is necessary. */
1536 static char *
1537 partial_die_parent_scope (struct partial_die_info *pdi,
1538 struct dwarf2_cu *cu)
1539 {
1540 char *grandparent_scope;
1541 struct partial_die_info *parent, *real_pdi;
1542 struct dwarf2_cu *spec_cu;
1543
1544 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1545 then this means the parent of the specification DIE. */
1546
1547 real_pdi = pdi;
1548 spec_cu = cu;
1549 while (real_pdi->has_specification)
1550 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1551
1552 parent = real_pdi->die_parent;
1553 if (parent == NULL)
1554 return NULL;
1555
1556 if (parent->scope_set)
1557 return parent->scope;
1558
1559 fixup_partial_die (parent, cu);
1560
1561 grandparent_scope = partial_die_parent_scope (parent, spec_cu);
1562
1563 if (parent->tag == DW_TAG_namespace
1564 || parent->tag == DW_TAG_structure_type
1565 || parent->tag == DW_TAG_class_type
1566 || parent->tag == DW_TAG_union_type)
1567 {
1568 if (grandparent_scope == NULL)
1569 parent->scope = parent->name;
1570 else
1571 parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope,
1572 parent->name, cu);
1573 }
1574 else if (parent->tag == DW_TAG_enumeration_type)
1575 /* Enumerators should not get the name of the enumeration as a prefix. */
1576 parent->scope = grandparent_scope;
1577 else
1578 {
1579 /* FIXME drow/2004-04-01: What should we be doing with
1580 function-local names? For partial symbols, we should probably be
1581 ignoring them. */
1582 complaint (&symfile_complaints,
1583 "unhandled containing DIE tag %d for DIE at %d",
1584 parent->tag, pdi->offset);
1585 parent->scope = grandparent_scope;
1586 }
1587
1588 parent->scope_set = 1;
1589 return parent->scope;
1590 }
1591
1592 /* Return the fully scoped name associated with PDI, from compilation unit
1593 CU. The result will be allocated with malloc. */
1594 static char *
1595 partial_die_full_name (struct partial_die_info *pdi,
1596 struct dwarf2_cu *cu)
1597 {
1598 char *parent_scope;
1599
1600 parent_scope = partial_die_parent_scope (pdi, cu);
1601 if (parent_scope == NULL)
1602 return NULL;
1603 else
1604 return typename_concat (NULL, parent_scope, pdi->name, cu);
1605 }
1606
1607 static void
1608 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
1609 {
1610 struct objfile *objfile = cu->objfile;
1611 CORE_ADDR addr = 0;
1612 char *actual_name;
1613 const char *my_prefix;
1614 const struct partial_symbol *psym = NULL;
1615 CORE_ADDR baseaddr;
1616 int built_actual_name = 0;
1617
1618 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1619
1620 actual_name = NULL;
1621
1622 if (pdi_needs_namespace (pdi->tag))
1623 {
1624 actual_name = partial_die_full_name (pdi, cu);
1625 if (actual_name)
1626 built_actual_name = 1;
1627 }
1628
1629 if (actual_name == NULL)
1630 actual_name = pdi->name;
1631
1632 switch (pdi->tag)
1633 {
1634 case DW_TAG_subprogram:
1635 if (pdi->is_external)
1636 {
1637 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1638 mst_text, objfile); */
1639 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1640 VAR_DOMAIN, LOC_BLOCK,
1641 &objfile->global_psymbols,
1642 0, pdi->lowpc + baseaddr,
1643 cu->language, objfile);
1644 }
1645 else
1646 {
1647 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1648 mst_file_text, objfile); */
1649 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1650 VAR_DOMAIN, LOC_BLOCK,
1651 &objfile->static_psymbols,
1652 0, pdi->lowpc + baseaddr,
1653 cu->language, objfile);
1654 }
1655 break;
1656 case DW_TAG_variable:
1657 if (pdi->is_external)
1658 {
1659 /* Global Variable.
1660 Don't enter into the minimal symbol tables as there is
1661 a minimal symbol table entry from the ELF symbols already.
1662 Enter into partial symbol table if it has a location
1663 descriptor or a type.
1664 If the location descriptor is missing, new_symbol will create
1665 a LOC_UNRESOLVED symbol, the address of the variable will then
1666 be determined from the minimal symbol table whenever the variable
1667 is referenced.
1668 The address for the partial symbol table entry is not
1669 used by GDB, but it comes in handy for debugging partial symbol
1670 table building. */
1671
1672 if (pdi->locdesc)
1673 addr = decode_locdesc (pdi->locdesc, cu);
1674 if (pdi->locdesc || pdi->has_type)
1675 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1676 VAR_DOMAIN, LOC_STATIC,
1677 &objfile->global_psymbols,
1678 0, addr + baseaddr,
1679 cu->language, objfile);
1680 }
1681 else
1682 {
1683 /* Static Variable. Skip symbols without location descriptors. */
1684 if (pdi->locdesc == NULL)
1685 return;
1686 addr = decode_locdesc (pdi->locdesc, cu);
1687 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1688 mst_file_data, objfile); */
1689 psym = add_psymbol_to_list (actual_name, strlen (actual_name),
1690 VAR_DOMAIN, LOC_STATIC,
1691 &objfile->static_psymbols,
1692 0, addr + baseaddr,
1693 cu->language, objfile);
1694 }
1695 break;
1696 case DW_TAG_typedef:
1697 case DW_TAG_base_type:
1698 case DW_TAG_subrange_type:
1699 add_psymbol_to_list (actual_name, strlen (actual_name),
1700 VAR_DOMAIN, LOC_TYPEDEF,
1701 &objfile->static_psymbols,
1702 0, (CORE_ADDR) 0, cu->language, objfile);
1703 break;
1704 case DW_TAG_namespace:
1705 add_psymbol_to_list (actual_name, strlen (actual_name),
1706 VAR_DOMAIN, LOC_TYPEDEF,
1707 &objfile->global_psymbols,
1708 0, (CORE_ADDR) 0, cu->language, objfile);
1709 break;
1710 case DW_TAG_class_type:
1711 case DW_TAG_structure_type:
1712 case DW_TAG_union_type:
1713 case DW_TAG_enumeration_type:
1714 /* Skip aggregate types without children, these are external
1715 references. */
1716 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1717 static vs. global. */
1718 if (pdi->has_children == 0)
1719 return;
1720 add_psymbol_to_list (actual_name, strlen (actual_name),
1721 STRUCT_DOMAIN, LOC_TYPEDEF,
1722 (cu->language == language_cplus
1723 || cu->language == language_java)
1724 ? &objfile->global_psymbols
1725 : &objfile->static_psymbols,
1726 0, (CORE_ADDR) 0, cu->language, objfile);
1727
1728 if (cu->language == language_cplus
1729 || cu->language == language_java)
1730 {
1731 /* For C++ and Java, these implicitly act as typedefs as well. */
1732 add_psymbol_to_list (actual_name, strlen (actual_name),
1733 VAR_DOMAIN, LOC_TYPEDEF,
1734 &objfile->global_psymbols,
1735 0, (CORE_ADDR) 0, cu->language, objfile);
1736 }
1737 break;
1738 case DW_TAG_enumerator:
1739 add_psymbol_to_list (actual_name, strlen (actual_name),
1740 VAR_DOMAIN, LOC_CONST,
1741 (cu->language == language_cplus
1742 || cu->language == language_java)
1743 ? &objfile->global_psymbols
1744 : &objfile->static_psymbols,
1745 0, (CORE_ADDR) 0, cu->language, objfile);
1746 break;
1747 default:
1748 break;
1749 }
1750
1751 /* Check to see if we should scan the name for possible namespace
1752 info. Only do this if this is C++, if we don't have namespace
1753 debugging info in the file, if the psym is of an appropriate type
1754 (otherwise we'll have psym == NULL), and if we actually had a
1755 mangled name to begin with. */
1756
1757 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1758 cases which do not set PSYM above? */
1759
1760 if (cu->language == language_cplus
1761 && cu->has_namespace_info == 0
1762 && psym != NULL
1763 && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL)
1764 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym),
1765 objfile);
1766
1767 if (built_actual_name)
1768 xfree (actual_name);
1769 }
1770
1771 /* Determine whether a die of type TAG living in a C++ class or
1772 namespace needs to have the name of the scope prepended to the
1773 name listed in the die. */
1774
1775 static int
1776 pdi_needs_namespace (enum dwarf_tag tag)
1777 {
1778 switch (tag)
1779 {
1780 case DW_TAG_namespace:
1781 case DW_TAG_typedef:
1782 case DW_TAG_class_type:
1783 case DW_TAG_structure_type:
1784 case DW_TAG_union_type:
1785 case DW_TAG_enumeration_type:
1786 case DW_TAG_enumerator:
1787 return 1;
1788 default:
1789 return 0;
1790 }
1791 }
1792
1793 /* Read a partial die corresponding to a namespace; also, add a symbol
1794 corresponding to that namespace to the symbol table. NAMESPACE is
1795 the name of the enclosing namespace. */
1796
1797 static void
1798 add_partial_namespace (struct partial_die_info *pdi,
1799 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1800 struct dwarf2_cu *cu)
1801 {
1802 struct objfile *objfile = cu->objfile;
1803
1804 /* Add a symbol for the namespace. */
1805
1806 add_partial_symbol (pdi, cu);
1807
1808 /* Now scan partial symbols in that namespace. */
1809
1810 if (pdi->has_children)
1811 scan_partial_symbols (pdi->die_child, lowpc, highpc, cu);
1812 }
1813
1814 /* See if we can figure out if the class lives in a namespace. We do
1815 this by looking for a member function; its demangled name will
1816 contain namespace info, if there is any. */
1817
1818 static void
1819 guess_structure_name (struct partial_die_info *struct_pdi,
1820 struct dwarf2_cu *cu)
1821 {
1822 if ((cu->language == language_cplus
1823 || cu->language == language_java)
1824 && cu->has_namespace_info == 0
1825 && struct_pdi->has_children)
1826 {
1827 /* NOTE: carlton/2003-10-07: Getting the info this way changes
1828 what template types look like, because the demangler
1829 frequently doesn't give the same name as the debug info. We
1830 could fix this by only using the demangled name to get the
1831 prefix (but see comment in read_structure_type). */
1832
1833 struct partial_die_info *child_pdi = struct_pdi->die_child;
1834 struct partial_die_info *real_pdi;
1835 struct dwarf2_cu *spec_cu;
1836
1837 /* If this DIE (this DIE's specification, if any) has a parent, then
1838 we should not do this. We'll prepend the parent's fully qualified
1839 name when we create the partial symbol. */
1840
1841 real_pdi = struct_pdi;
1842 spec_cu = cu;
1843 while (real_pdi->has_specification)
1844 real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu);
1845
1846 if (real_pdi->die_parent != NULL)
1847 return;
1848
1849 while (child_pdi != NULL)
1850 {
1851 if (child_pdi->tag == DW_TAG_subprogram)
1852 {
1853 char *actual_class_name
1854 = language_class_name_from_physname (cu->language_defn,
1855 child_pdi->name);
1856 if (actual_class_name != NULL)
1857 {
1858 struct_pdi->name
1859 = obsavestring (actual_class_name,
1860 strlen (actual_class_name),
1861 &cu->comp_unit_obstack);
1862 xfree (actual_class_name);
1863 }
1864 break;
1865 }
1866
1867 child_pdi = child_pdi->die_sibling;
1868 }
1869 }
1870 }
1871
1872 /* Read a partial die corresponding to an enumeration type. */
1873
1874 static void
1875 add_partial_enumeration (struct partial_die_info *enum_pdi,
1876 struct dwarf2_cu *cu)
1877 {
1878 struct objfile *objfile = cu->objfile;
1879 bfd *abfd = objfile->obfd;
1880 struct partial_die_info *pdi;
1881
1882 if (enum_pdi->name != NULL)
1883 add_partial_symbol (enum_pdi, cu);
1884
1885 pdi = enum_pdi->die_child;
1886 while (pdi)
1887 {
1888 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
1889 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
1890 else
1891 add_partial_symbol (pdi, cu);
1892 pdi = pdi->die_sibling;
1893 }
1894 }
1895
1896 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
1897 Return the corresponding abbrev, or NULL if the number is zero (indicating
1898 an empty DIE). In either case *BYTES_READ will be set to the length of
1899 the initial number. */
1900
1901 static struct abbrev_info *
1902 peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu)
1903 {
1904 bfd *abfd = cu->objfile->obfd;
1905 unsigned int abbrev_number;
1906 struct abbrev_info *abbrev;
1907
1908 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
1909
1910 if (abbrev_number == 0)
1911 return NULL;
1912
1913 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
1914 if (!abbrev)
1915 {
1916 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number,
1917 bfd_get_filename (abfd));
1918 }
1919
1920 return abbrev;
1921 }
1922
1923 /* Scan the debug information for CU starting at INFO_PTR. Returns a
1924 pointer to the end of a series of DIEs, terminated by an empty
1925 DIE. Any children of the skipped DIEs will also be skipped. */
1926
1927 static char *
1928 skip_children (char *info_ptr, struct dwarf2_cu *cu)
1929 {
1930 struct abbrev_info *abbrev;
1931 unsigned int bytes_read;
1932
1933 while (1)
1934 {
1935 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
1936 if (abbrev == NULL)
1937 return info_ptr + bytes_read;
1938 else
1939 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
1940 }
1941 }
1942
1943 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
1944 should point just after the initial uleb128 of a DIE, and the
1945 abbrev corresponding to that skipped uleb128 should be passed in
1946 ABBREV. Returns a pointer to this DIE's sibling, skipping any
1947 children. */
1948
1949 static char *
1950 skip_one_die (char *info_ptr, struct abbrev_info *abbrev,
1951 struct dwarf2_cu *cu)
1952 {
1953 unsigned int bytes_read;
1954 struct attribute attr;
1955 bfd *abfd = cu->objfile->obfd;
1956 unsigned int form, i;
1957
1958 for (i = 0; i < abbrev->num_attrs; i++)
1959 {
1960 /* The only abbrev we care about is DW_AT_sibling. */
1961 if (abbrev->attrs[i].name == DW_AT_sibling)
1962 {
1963 read_attribute (&attr, &abbrev->attrs[i],
1964 abfd, info_ptr, cu);
1965 if (attr.form == DW_FORM_ref_addr)
1966 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
1967 else
1968 return dwarf2_per_objfile->info_buffer
1969 + dwarf2_get_ref_die_offset (&attr, cu);
1970 }
1971
1972 /* If it isn't DW_AT_sibling, skip this attribute. */
1973 form = abbrev->attrs[i].form;
1974 skip_attribute:
1975 switch (form)
1976 {
1977 case DW_FORM_addr:
1978 case DW_FORM_ref_addr:
1979 info_ptr += cu->header.addr_size;
1980 break;
1981 case DW_FORM_data1:
1982 case DW_FORM_ref1:
1983 case DW_FORM_flag:
1984 info_ptr += 1;
1985 break;
1986 case DW_FORM_data2:
1987 case DW_FORM_ref2:
1988 info_ptr += 2;
1989 break;
1990 case DW_FORM_data4:
1991 case DW_FORM_ref4:
1992 info_ptr += 4;
1993 break;
1994 case DW_FORM_data8:
1995 case DW_FORM_ref8:
1996 info_ptr += 8;
1997 break;
1998 case DW_FORM_string:
1999 read_string (abfd, info_ptr, &bytes_read);
2000 info_ptr += bytes_read;
2001 break;
2002 case DW_FORM_strp:
2003 info_ptr += cu->header.offset_size;
2004 break;
2005 case DW_FORM_block:
2006 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2007 info_ptr += bytes_read;
2008 break;
2009 case DW_FORM_block1:
2010 info_ptr += 1 + read_1_byte (abfd, info_ptr);
2011 break;
2012 case DW_FORM_block2:
2013 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
2014 break;
2015 case DW_FORM_block4:
2016 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
2017 break;
2018 case DW_FORM_sdata:
2019 case DW_FORM_udata:
2020 case DW_FORM_ref_udata:
2021 info_ptr = skip_leb128 (abfd, info_ptr);
2022 break;
2023 case DW_FORM_indirect:
2024 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
2025 info_ptr += bytes_read;
2026 /* We need to continue parsing from here, so just go back to
2027 the top. */
2028 goto skip_attribute;
2029
2030 default:
2031 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2032 dwarf_form_name (form),
2033 bfd_get_filename (abfd));
2034 }
2035 }
2036
2037 if (abbrev->has_children)
2038 return skip_children (info_ptr, cu);
2039 else
2040 return info_ptr;
2041 }
2042
2043 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2044 the next DIE after ORIG_PDI. */
2045
2046 static char *
2047 locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr,
2048 bfd *abfd, struct dwarf2_cu *cu)
2049 {
2050 /* Do we know the sibling already? */
2051
2052 if (orig_pdi->sibling)
2053 return orig_pdi->sibling;
2054
2055 /* Are there any children to deal with? */
2056
2057 if (!orig_pdi->has_children)
2058 return info_ptr;
2059
2060 /* Skip the children the long way. */
2061
2062 return skip_children (info_ptr, cu);
2063 }
2064
2065 /* Expand this partial symbol table into a full symbol table. */
2066
2067 static void
2068 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
2069 {
2070 /* FIXME: This is barely more than a stub. */
2071 if (pst != NULL)
2072 {
2073 if (pst->readin)
2074 {
2075 warning ("bug: psymtab for %s is already read in.", pst->filename);
2076 }
2077 else
2078 {
2079 if (info_verbose)
2080 {
2081 printf_filtered ("Reading in symbols for %s...", pst->filename);
2082 gdb_flush (gdb_stdout);
2083 }
2084
2085 psymtab_to_symtab_1 (pst);
2086
2087 /* Finish up the debug error message. */
2088 if (info_verbose)
2089 printf_filtered ("done.\n");
2090 }
2091 }
2092 }
2093
2094 static void
2095 psymtab_to_symtab_1 (struct partial_symtab *pst)
2096 {
2097 struct objfile *objfile = pst->objfile;
2098 bfd *abfd = objfile->obfd;
2099 struct dwarf2_cu cu;
2100 struct die_info *dies;
2101 unsigned long offset;
2102 CORE_ADDR lowpc, highpc;
2103 struct die_info *child_die;
2104 char *info_ptr;
2105 struct symtab *symtab;
2106 struct cleanup *back_to;
2107 struct attribute *attr;
2108 CORE_ADDR baseaddr;
2109 int i;
2110
2111 for (i = 0; i < pst->number_of_dependencies; i++)
2112 if (!pst->dependencies[i]->readin)
2113 {
2114 /* Inform about additional files that need to be read in. */
2115 if (info_verbose)
2116 {
2117 fputs_filtered (" ", gdb_stdout);
2118 wrap_here ("");
2119 fputs_filtered ("and ", gdb_stdout);
2120 wrap_here ("");
2121 printf_filtered ("%s...", pst->dependencies[i]->filename);
2122 wrap_here (""); /* Flush output */
2123 gdb_flush (gdb_stdout);
2124 }
2125 psymtab_to_symtab_1 (pst->dependencies[i]);
2126 }
2127
2128 if (pst->read_symtab_private == NULL)
2129 {
2130 /* It's an include file, no symbols to read for it.
2131 Everything is in the parent symtab. */
2132 pst->readin = 1;
2133 return;
2134 }
2135
2136 dwarf2_per_objfile = objfile_data (pst->objfile, dwarf2_objfile_data_key);
2137
2138 /* Set local variables from the partial symbol table info. */
2139 offset = DWARF_INFO_OFFSET (pst);
2140
2141 info_ptr = dwarf2_per_objfile->info_buffer + offset;
2142 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2143
2144 /* We're in the global namespace. */
2145 processing_current_prefix = "";
2146
2147 obstack_init (&cu.comp_unit_obstack);
2148 back_to = make_cleanup (free_stack_comp_unit, &cu);
2149
2150 buildsym_init ();
2151 make_cleanup (really_free_pendings, NULL);
2152
2153 cu.objfile = objfile;
2154
2155 /* read in the comp_unit header */
2156 info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd);
2157
2158 /* Read the abbrevs for this compilation unit */
2159 dwarf2_read_abbrevs (abfd, &cu);
2160 make_cleanup (dwarf2_free_abbrev_table, &cu);
2161
2162 cu.header.offset = offset;
2163
2164 cu.list_in_scope = &file_symbols;
2165
2166 dies = read_comp_unit (info_ptr, abfd, &cu);
2167
2168 make_cleanup_free_die_list (dies);
2169
2170 /* Find the base address of the compilation unit for range lists and
2171 location lists. It will normally be specified by DW_AT_low_pc.
2172 In DWARF-3 draft 4, the base address could be overridden by
2173 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2174 compilation units with discontinuous ranges. */
2175
2176 cu.header.base_known = 0;
2177 cu.header.base_address = 0;
2178
2179 attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu);
2180 if (attr)
2181 {
2182 cu.header.base_address = DW_ADDR (attr);
2183 cu.header.base_known = 1;
2184 }
2185 else
2186 {
2187 attr = dwarf2_attr (dies, DW_AT_low_pc, &cu);
2188 if (attr)
2189 {
2190 cu.header.base_address = DW_ADDR (attr);
2191 cu.header.base_known = 1;
2192 }
2193 }
2194
2195 /* Do line number decoding in read_file_scope () */
2196 process_die (dies, &cu);
2197
2198 /* Some compilers don't define a DW_AT_high_pc attribute for the
2199 compilation unit. If the DW_AT_high_pc is missing, synthesize
2200 it, by scanning the DIE's below the compilation unit. */
2201 get_scope_pc_bounds (dies, &lowpc, &highpc, &cu);
2202
2203 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
2204
2205 /* Set symtab language to language from DW_AT_language.
2206 If the compilation is from a C file generated by language preprocessors,
2207 do not set the language if it was already deduced by start_subfile. */
2208 if (symtab != NULL
2209 && !(cu.language == language_c && symtab->language != language_c))
2210 {
2211 symtab->language = cu.language;
2212 }
2213 pst->symtab = symtab;
2214 pst->readin = 1;
2215
2216 do_cleanups (back_to);
2217 }
2218
2219 /* Process a die and its children. */
2220
2221 static void
2222 process_die (struct die_info *die, struct dwarf2_cu *cu)
2223 {
2224 switch (die->tag)
2225 {
2226 case DW_TAG_padding:
2227 break;
2228 case DW_TAG_compile_unit:
2229 read_file_scope (die, cu);
2230 break;
2231 case DW_TAG_subprogram:
2232 read_subroutine_type (die, cu);
2233 read_func_scope (die, cu);
2234 break;
2235 case DW_TAG_inlined_subroutine:
2236 /* FIXME: These are ignored for now.
2237 They could be used to set breakpoints on all inlined instances
2238 of a function and make GDB `next' properly over inlined functions. */
2239 break;
2240 case DW_TAG_lexical_block:
2241 case DW_TAG_try_block:
2242 case DW_TAG_catch_block:
2243 read_lexical_block_scope (die, cu);
2244 break;
2245 case DW_TAG_class_type:
2246 case DW_TAG_structure_type:
2247 case DW_TAG_union_type:
2248 read_structure_type (die, cu);
2249 process_structure_scope (die, cu);
2250 break;
2251 case DW_TAG_enumeration_type:
2252 read_enumeration_type (die, cu);
2253 process_enumeration_scope (die, cu);
2254 break;
2255
2256 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2257 a symbol or process any children. Therefore it doesn't do anything
2258 that won't be done on-demand by read_type_die. */
2259 case DW_TAG_subroutine_type:
2260 read_subroutine_type (die, cu);
2261 break;
2262 case DW_TAG_array_type:
2263 read_array_type (die, cu);
2264 break;
2265 case DW_TAG_pointer_type:
2266 read_tag_pointer_type (die, cu);
2267 break;
2268 case DW_TAG_ptr_to_member_type:
2269 read_tag_ptr_to_member_type (die, cu);
2270 break;
2271 case DW_TAG_reference_type:
2272 read_tag_reference_type (die, cu);
2273 break;
2274 case DW_TAG_string_type:
2275 read_tag_string_type (die, cu);
2276 break;
2277 /* END FIXME */
2278
2279 case DW_TAG_base_type:
2280 read_base_type (die, cu);
2281 /* Add a typedef symbol for the type definition, if it has a
2282 DW_AT_name. */
2283 new_symbol (die, die->type, cu);
2284 break;
2285 case DW_TAG_subrange_type:
2286 read_subrange_type (die, cu);
2287 /* Add a typedef symbol for the type definition, if it has a
2288 DW_AT_name. */
2289 new_symbol (die, die->type, cu);
2290 break;
2291 case DW_TAG_common_block:
2292 read_common_block (die, cu);
2293 break;
2294 case DW_TAG_common_inclusion:
2295 break;
2296 case DW_TAG_namespace:
2297 processing_has_namespace_info = 1;
2298 read_namespace (die, cu);
2299 break;
2300 case DW_TAG_imported_declaration:
2301 case DW_TAG_imported_module:
2302 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2303 information contained in these. DW_TAG_imported_declaration
2304 dies shouldn't have children; DW_TAG_imported_module dies
2305 shouldn't in the C++ case, but conceivably could in the
2306 Fortran case, so we'll have to replace this gdb_assert if
2307 Fortran compilers start generating that info. */
2308 processing_has_namespace_info = 1;
2309 gdb_assert (die->child == NULL);
2310 break;
2311 default:
2312 new_symbol (die, NULL, cu);
2313 break;
2314 }
2315 }
2316
2317 static void
2318 initialize_cu_func_list (struct dwarf2_cu *cu)
2319 {
2320 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
2321 }
2322
2323 static void
2324 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
2325 {
2326 struct objfile *objfile = cu->objfile;
2327 struct comp_unit_head *cu_header = &cu->header;
2328 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2329 CORE_ADDR lowpc = ((CORE_ADDR) -1);
2330 CORE_ADDR highpc = ((CORE_ADDR) 0);
2331 struct attribute *attr;
2332 char *name = "<unknown>";
2333 char *comp_dir = NULL;
2334 struct die_info *child_die;
2335 bfd *abfd = objfile->obfd;
2336 struct line_header *line_header = 0;
2337 CORE_ADDR baseaddr;
2338
2339 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2340
2341 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
2342
2343 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2344 from finish_block. */
2345 if (lowpc == ((CORE_ADDR) -1))
2346 lowpc = highpc;
2347 lowpc += baseaddr;
2348 highpc += baseaddr;
2349
2350 attr = dwarf2_attr (die, DW_AT_name, cu);
2351 if (attr)
2352 {
2353 name = DW_STRING (attr);
2354 }
2355 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
2356 if (attr)
2357 {
2358 comp_dir = DW_STRING (attr);
2359 if (comp_dir)
2360 {
2361 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2362 directory, get rid of it. */
2363 char *cp = strchr (comp_dir, ':');
2364
2365 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
2366 comp_dir = cp + 1;
2367 }
2368 }
2369
2370 attr = dwarf2_attr (die, DW_AT_language, cu);
2371 if (attr)
2372 {
2373 set_cu_language (DW_UNSND (attr), cu);
2374 }
2375
2376 attr = dwarf2_attr (die, DW_AT_producer, cu);
2377 if (attr)
2378 cu->producer = DW_STRING (attr);
2379
2380 /* We assume that we're processing GCC output. */
2381 processing_gcc_compilation = 2;
2382 #if 0
2383 /* FIXME:Do something here. */
2384 if (dip->at_producer != NULL)
2385 {
2386 handle_producer (dip->at_producer);
2387 }
2388 #endif
2389
2390 /* The compilation unit may be in a different language or objfile,
2391 zero out all remembered fundamental types. */
2392 memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
2393
2394 start_symtab (name, comp_dir, lowpc);
2395 record_debugformat ("DWARF 2");
2396
2397 initialize_cu_func_list (cu);
2398
2399 /* Process all dies in compilation unit. */
2400 if (die->child != NULL)
2401 {
2402 child_die = die->child;
2403 while (child_die && child_die->tag)
2404 {
2405 process_die (child_die, cu);
2406 child_die = sibling_die (child_die);
2407 }
2408 }
2409
2410 /* Decode line number information if present. */
2411 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
2412 if (attr)
2413 {
2414 unsigned int line_offset = DW_UNSND (attr);
2415 line_header = dwarf_decode_line_header (line_offset, abfd, cu);
2416 if (line_header)
2417 {
2418 make_cleanup ((make_cleanup_ftype *) free_line_header,
2419 (void *) line_header);
2420 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
2421 }
2422 }
2423
2424 /* Decode macro information, if present. Dwarf 2 macro information
2425 refers to information in the line number info statement program
2426 header, so we can only read it if we've read the header
2427 successfully. */
2428 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
2429 if (attr && line_header)
2430 {
2431 unsigned int macro_offset = DW_UNSND (attr);
2432 dwarf_decode_macros (line_header, macro_offset,
2433 comp_dir, abfd, cu);
2434 }
2435 do_cleanups (back_to);
2436 }
2437
2438 static void
2439 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
2440 struct dwarf2_cu *cu)
2441 {
2442 struct function_range *thisfn;
2443
2444 thisfn = (struct function_range *)
2445 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
2446 thisfn->name = name;
2447 thisfn->lowpc = lowpc;
2448 thisfn->highpc = highpc;
2449 thisfn->seen_line = 0;
2450 thisfn->next = NULL;
2451
2452 if (cu->last_fn == NULL)
2453 cu->first_fn = thisfn;
2454 else
2455 cu->last_fn->next = thisfn;
2456
2457 cu->last_fn = thisfn;
2458 }
2459
2460 static void
2461 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
2462 {
2463 struct objfile *objfile = cu->objfile;
2464 struct context_stack *new;
2465 CORE_ADDR lowpc;
2466 CORE_ADDR highpc;
2467 struct die_info *child_die;
2468 struct attribute *attr;
2469 char *name;
2470 const char *previous_prefix = processing_current_prefix;
2471 struct cleanup *back_to = NULL;
2472 CORE_ADDR baseaddr;
2473
2474 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2475
2476 name = dwarf2_linkage_name (die, cu);
2477
2478 /* Ignore functions with missing or empty names and functions with
2479 missing or invalid low and high pc attributes. */
2480 if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2481 return;
2482
2483 if (cu->language == language_cplus
2484 || cu->language == language_java)
2485 {
2486 struct die_info *spec_die = die_specification (die, cu);
2487
2488 /* NOTE: carlton/2004-01-23: We have to be careful in the
2489 presence of DW_AT_specification. For example, with GCC 3.4,
2490 given the code
2491
2492 namespace N {
2493 void foo() {
2494 // Definition of N::foo.
2495 }
2496 }
2497
2498 then we'll have a tree of DIEs like this:
2499
2500 1: DW_TAG_compile_unit
2501 2: DW_TAG_namespace // N
2502 3: DW_TAG_subprogram // declaration of N::foo
2503 4: DW_TAG_subprogram // definition of N::foo
2504 DW_AT_specification // refers to die #3
2505
2506 Thus, when processing die #4, we have to pretend that we're
2507 in the context of its DW_AT_specification, namely the contex
2508 of die #3. */
2509
2510 if (spec_die != NULL)
2511 {
2512 char *specification_prefix = determine_prefix (spec_die, cu);
2513 processing_current_prefix = specification_prefix;
2514 back_to = make_cleanup (xfree, specification_prefix);
2515 }
2516 }
2517
2518 lowpc += baseaddr;
2519 highpc += baseaddr;
2520
2521 /* Record the function range for dwarf_decode_lines. */
2522 add_to_cu_func_list (name, lowpc, highpc, cu);
2523
2524 new = push_context (0, lowpc);
2525 new->name = new_symbol (die, die->type, cu);
2526
2527 /* If there is a location expression for DW_AT_frame_base, record
2528 it. */
2529 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
2530 if (attr)
2531 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2532 expression is being recorded directly in the function's symbol
2533 and not in a separate frame-base object. I guess this hack is
2534 to avoid adding some sort of frame-base adjunct/annex to the
2535 function's symbol :-(. The problem with doing this is that it
2536 results in a function symbol with a location expression that
2537 has nothing to do with the location of the function, ouch! The
2538 relationship should be: a function's symbol has-a frame base; a
2539 frame-base has-a location expression. */
2540 dwarf2_symbol_mark_computed (attr, new->name, cu);
2541
2542 cu->list_in_scope = &local_symbols;
2543
2544 if (die->child != NULL)
2545 {
2546 child_die = die->child;
2547 while (child_die && child_die->tag)
2548 {
2549 process_die (child_die, cu);
2550 child_die = sibling_die (child_die);
2551 }
2552 }
2553
2554 new = pop_context ();
2555 /* Make a block for the local symbols within. */
2556 finish_block (new->name, &local_symbols, new->old_blocks,
2557 lowpc, highpc, objfile);
2558
2559 /* In C++, we can have functions nested inside functions (e.g., when
2560 a function declares a class that has methods). This means that
2561 when we finish processing a function scope, we may need to go
2562 back to building a containing block's symbol lists. */
2563 local_symbols = new->locals;
2564 param_symbols = new->params;
2565
2566 /* If we've finished processing a top-level function, subsequent
2567 symbols go in the file symbol list. */
2568 if (outermost_context_p ())
2569 cu->list_in_scope = &file_symbols;
2570
2571 processing_current_prefix = previous_prefix;
2572 if (back_to != NULL)
2573 do_cleanups (back_to);
2574 }
2575
2576 /* Process all the DIES contained within a lexical block scope. Start
2577 a new scope, process the dies, and then close the scope. */
2578
2579 static void
2580 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
2581 {
2582 struct objfile *objfile = cu->objfile;
2583 struct context_stack *new;
2584 CORE_ADDR lowpc, highpc;
2585 struct die_info *child_die;
2586 CORE_ADDR baseaddr;
2587
2588 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2589
2590 /* Ignore blocks with missing or invalid low and high pc attributes. */
2591 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2592 as multiple lexical blocks? Handling children in a sane way would
2593 be nasty. Might be easier to properly extend generic blocks to
2594 describe ranges. */
2595 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu))
2596 return;
2597 lowpc += baseaddr;
2598 highpc += baseaddr;
2599
2600 push_context (0, lowpc);
2601 if (die->child != NULL)
2602 {
2603 child_die = die->child;
2604 while (child_die && child_die->tag)
2605 {
2606 process_die (child_die, cu);
2607 child_die = sibling_die (child_die);
2608 }
2609 }
2610 new = pop_context ();
2611
2612 if (local_symbols != NULL)
2613 {
2614 finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
2615 highpc, objfile);
2616 }
2617 local_symbols = new->locals;
2618 }
2619
2620 /* Get low and high pc attributes from a die. Return 1 if the attributes
2621 are present and valid, otherwise, return 0. Return -1 if the range is
2622 discontinuous, i.e. derived from DW_AT_ranges information. */
2623 static int
2624 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
2625 CORE_ADDR *highpc, struct dwarf2_cu *cu)
2626 {
2627 struct objfile *objfile = cu->objfile;
2628 struct comp_unit_head *cu_header = &cu->header;
2629 struct attribute *attr;
2630 bfd *obfd = objfile->obfd;
2631 CORE_ADDR low = 0;
2632 CORE_ADDR high = 0;
2633 int ret = 0;
2634
2635 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
2636 if (attr)
2637 {
2638 high = DW_ADDR (attr);
2639 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
2640 if (attr)
2641 low = DW_ADDR (attr);
2642 else
2643 /* Found high w/o low attribute. */
2644 return 0;
2645
2646 /* Found consecutive range of addresses. */
2647 ret = 1;
2648 }
2649 else
2650 {
2651 attr = dwarf2_attr (die, DW_AT_ranges, cu);
2652 if (attr != NULL)
2653 {
2654 unsigned int addr_size = cu_header->addr_size;
2655 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2656 /* Value of the DW_AT_ranges attribute is the offset in the
2657 .debug_ranges section. */
2658 unsigned int offset = DW_UNSND (attr);
2659 /* Base address selection entry. */
2660 CORE_ADDR base;
2661 int found_base;
2662 int dummy;
2663 char *buffer;
2664 CORE_ADDR marker;
2665 int low_set;
2666
2667 found_base = cu_header->base_known;
2668 base = cu_header->base_address;
2669
2670 if (offset >= dwarf2_per_objfile->ranges_size)
2671 {
2672 complaint (&symfile_complaints,
2673 "Offset %d out of bounds for DW_AT_ranges attribute",
2674 offset);
2675 return 0;
2676 }
2677 buffer = dwarf2_per_objfile->ranges_buffer + offset;
2678
2679 /* Read in the largest possible address. */
2680 marker = read_address (obfd, buffer, cu, &dummy);
2681 if ((marker & mask) == mask)
2682 {
2683 /* If we found the largest possible address, then
2684 read the base address. */
2685 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2686 buffer += 2 * addr_size;
2687 offset += 2 * addr_size;
2688 found_base = 1;
2689 }
2690
2691 low_set = 0;
2692
2693 while (1)
2694 {
2695 CORE_ADDR range_beginning, range_end;
2696
2697 range_beginning = read_address (obfd, buffer, cu, &dummy);
2698 buffer += addr_size;
2699 range_end = read_address (obfd, buffer, cu, &dummy);
2700 buffer += addr_size;
2701 offset += 2 * addr_size;
2702
2703 /* An end of list marker is a pair of zero addresses. */
2704 if (range_beginning == 0 && range_end == 0)
2705 /* Found the end of list entry. */
2706 break;
2707
2708 /* Each base address selection entry is a pair of 2 values.
2709 The first is the largest possible address, the second is
2710 the base address. Check for a base address here. */
2711 if ((range_beginning & mask) == mask)
2712 {
2713 /* If we found the largest possible address, then
2714 read the base address. */
2715 base = read_address (obfd, buffer + addr_size, cu, &dummy);
2716 found_base = 1;
2717 continue;
2718 }
2719
2720 if (!found_base)
2721 {
2722 /* We have no valid base address for the ranges
2723 data. */
2724 complaint (&symfile_complaints,
2725 "Invalid .debug_ranges data (no base address)");
2726 return 0;
2727 }
2728
2729 range_beginning += base;
2730 range_end += base;
2731
2732 /* FIXME: This is recording everything as a low-high
2733 segment of consecutive addresses. We should have a
2734 data structure for discontiguous block ranges
2735 instead. */
2736 if (! low_set)
2737 {
2738 low = range_beginning;
2739 high = range_end;
2740 low_set = 1;
2741 }
2742 else
2743 {
2744 if (range_beginning < low)
2745 low = range_beginning;
2746 if (range_end > high)
2747 high = range_end;
2748 }
2749 }
2750
2751 if (! low_set)
2752 /* If the first entry is an end-of-list marker, the range
2753 describes an empty scope, i.e. no instructions. */
2754 return 0;
2755
2756 ret = -1;
2757 }
2758 }
2759
2760 if (high < low)
2761 return 0;
2762
2763 /* When using the GNU linker, .gnu.linkonce. sections are used to
2764 eliminate duplicate copies of functions and vtables and such.
2765 The linker will arbitrarily choose one and discard the others.
2766 The AT_*_pc values for such functions refer to local labels in
2767 these sections. If the section from that file was discarded, the
2768 labels are not in the output, so the relocs get a value of 0.
2769 If this is a discarded function, mark the pc bounds as invalid,
2770 so that GDB will ignore it. */
2771 if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
2772 return 0;
2773
2774 *lowpc = low;
2775 *highpc = high;
2776 return ret;
2777 }
2778
2779 /* Get the low and high pc's represented by the scope DIE, and store
2780 them in *LOWPC and *HIGHPC. If the correct values can't be
2781 determined, set *LOWPC to -1 and *HIGHPC to 0. */
2782
2783 static void
2784 get_scope_pc_bounds (struct die_info *die,
2785 CORE_ADDR *lowpc, CORE_ADDR *highpc,
2786 struct dwarf2_cu *cu)
2787 {
2788 CORE_ADDR best_low = (CORE_ADDR) -1;
2789 CORE_ADDR best_high = (CORE_ADDR) 0;
2790 CORE_ADDR current_low, current_high;
2791
2792 if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu))
2793 {
2794 best_low = current_low;
2795 best_high = current_high;
2796 }
2797 else
2798 {
2799 struct die_info *child = die->child;
2800
2801 while (child && child->tag)
2802 {
2803 switch (child->tag) {
2804 case DW_TAG_subprogram:
2805 if (dwarf2_get_pc_bounds (child, &current_low, &current_high, cu))
2806 {
2807 best_low = min (best_low, current_low);
2808 best_high = max (best_high, current_high);
2809 }
2810 break;
2811 case DW_TAG_namespace:
2812 /* FIXME: carlton/2004-01-16: Should we do this for
2813 DW_TAG_class_type/DW_TAG_structure_type, too? I think
2814 that current GCC's always emit the DIEs corresponding
2815 to definitions of methods of classes as children of a
2816 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
2817 the DIEs giving the declarations, which could be
2818 anywhere). But I don't see any reason why the
2819 standards says that they have to be there. */
2820 get_scope_pc_bounds (child, &current_low, &current_high, cu);
2821
2822 if (current_low != ((CORE_ADDR) -1))
2823 {
2824 best_low = min (best_low, current_low);
2825 best_high = max (best_high, current_high);
2826 }
2827 break;
2828 default:
2829 /* Ignore. */
2830 break;
2831 }
2832
2833 child = sibling_die (child);
2834 }
2835 }
2836
2837 *lowpc = best_low;
2838 *highpc = best_high;
2839 }
2840
2841 /* Add an aggregate field to the field list. */
2842
2843 static void
2844 dwarf2_add_field (struct field_info *fip, struct die_info *die,
2845 struct dwarf2_cu *cu)
2846 {
2847 struct objfile *objfile = cu->objfile;
2848 struct nextfield *new_field;
2849 struct attribute *attr;
2850 struct field *fp;
2851 char *fieldname = "";
2852
2853 /* Allocate a new field list entry and link it in. */
2854 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2855 make_cleanup (xfree, new_field);
2856 memset (new_field, 0, sizeof (struct nextfield));
2857 new_field->next = fip->fields;
2858 fip->fields = new_field;
2859 fip->nfields++;
2860
2861 /* Handle accessibility and virtuality of field.
2862 The default accessibility for members is public, the default
2863 accessibility for inheritance is private. */
2864 if (die->tag != DW_TAG_inheritance)
2865 new_field->accessibility = DW_ACCESS_public;
2866 else
2867 new_field->accessibility = DW_ACCESS_private;
2868 new_field->virtuality = DW_VIRTUALITY_none;
2869
2870 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
2871 if (attr)
2872 new_field->accessibility = DW_UNSND (attr);
2873 if (new_field->accessibility != DW_ACCESS_public)
2874 fip->non_public_fields = 1;
2875 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
2876 if (attr)
2877 new_field->virtuality = DW_UNSND (attr);
2878
2879 fp = &new_field->field;
2880
2881 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
2882 {
2883 /* Data member other than a C++ static data member. */
2884
2885 /* Get type of field. */
2886 fp->type = die_type (die, cu);
2887
2888 FIELD_STATIC_KIND (*fp) = 0;
2889
2890 /* Get bit size of field (zero if none). */
2891 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
2892 if (attr)
2893 {
2894 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
2895 }
2896 else
2897 {
2898 FIELD_BITSIZE (*fp) = 0;
2899 }
2900
2901 /* Get bit offset of field. */
2902 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
2903 if (attr)
2904 {
2905 FIELD_BITPOS (*fp) =
2906 decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte;
2907 }
2908 else
2909 FIELD_BITPOS (*fp) = 0;
2910 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
2911 if (attr)
2912 {
2913 if (BITS_BIG_ENDIAN)
2914 {
2915 /* For big endian bits, the DW_AT_bit_offset gives the
2916 additional bit offset from the MSB of the containing
2917 anonymous object to the MSB of the field. We don't
2918 have to do anything special since we don't need to
2919 know the size of the anonymous object. */
2920 FIELD_BITPOS (*fp) += DW_UNSND (attr);
2921 }
2922 else
2923 {
2924 /* For little endian bits, compute the bit offset to the
2925 MSB of the anonymous object, subtract off the number of
2926 bits from the MSB of the field to the MSB of the
2927 object, and then subtract off the number of bits of
2928 the field itself. The result is the bit offset of
2929 the LSB of the field. */
2930 int anonymous_size;
2931 int bit_offset = DW_UNSND (attr);
2932
2933 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
2934 if (attr)
2935 {
2936 /* The size of the anonymous object containing
2937 the bit field is explicit, so use the
2938 indicated size (in bytes). */
2939 anonymous_size = DW_UNSND (attr);
2940 }
2941 else
2942 {
2943 /* The size of the anonymous object containing
2944 the bit field must be inferred from the type
2945 attribute of the data member containing the
2946 bit field. */
2947 anonymous_size = TYPE_LENGTH (fp->type);
2948 }
2949 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
2950 - bit_offset - FIELD_BITSIZE (*fp);
2951 }
2952 }
2953
2954 /* Get name of field. */
2955 attr = dwarf2_attr (die, DW_AT_name, cu);
2956 if (attr && DW_STRING (attr))
2957 fieldname = DW_STRING (attr);
2958
2959 /* The name is already allocated along with this objfile, so we don't
2960 need to duplicate it for the type. */
2961 fp->name = fieldname;
2962
2963 /* Change accessibility for artificial fields (e.g. virtual table
2964 pointer or virtual base class pointer) to private. */
2965 if (dwarf2_attr (die, DW_AT_artificial, cu))
2966 {
2967 new_field->accessibility = DW_ACCESS_private;
2968 fip->non_public_fields = 1;
2969 }
2970 }
2971 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
2972 {
2973 /* C++ static member. */
2974
2975 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2976 is a declaration, but all versions of G++ as of this writing
2977 (so through at least 3.2.1) incorrectly generate
2978 DW_TAG_variable tags. */
2979
2980 char *physname;
2981
2982 /* Get name of field. */
2983 attr = dwarf2_attr (die, DW_AT_name, cu);
2984 if (attr && DW_STRING (attr))
2985 fieldname = DW_STRING (attr);
2986 else
2987 return;
2988
2989 /* Get physical name. */
2990 physname = dwarf2_linkage_name (die, cu);
2991
2992 /* The name is already allocated along with this objfile, so we don't
2993 need to duplicate it for the type. */
2994 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
2995 FIELD_TYPE (*fp) = die_type (die, cu);
2996 FIELD_NAME (*fp) = fieldname;
2997 }
2998 else if (die->tag == DW_TAG_inheritance)
2999 {
3000 /* C++ base class field. */
3001 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
3002 if (attr)
3003 FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu)
3004 * bits_per_byte);
3005 FIELD_BITSIZE (*fp) = 0;
3006 FIELD_STATIC_KIND (*fp) = 0;
3007 FIELD_TYPE (*fp) = die_type (die, cu);
3008 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
3009 fip->nbaseclasses++;
3010 }
3011 }
3012
3013 /* Create the vector of fields, and attach it to the type. */
3014
3015 static void
3016 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
3017 struct dwarf2_cu *cu)
3018 {
3019 int nfields = fip->nfields;
3020
3021 /* Record the field count, allocate space for the array of fields,
3022 and create blank accessibility bitfields if necessary. */
3023 TYPE_NFIELDS (type) = nfields;
3024 TYPE_FIELDS (type) = (struct field *)
3025 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3026 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3027
3028 if (fip->non_public_fields)
3029 {
3030 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3031
3032 TYPE_FIELD_PRIVATE_BITS (type) =
3033 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3034 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3035
3036 TYPE_FIELD_PROTECTED_BITS (type) =
3037 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3038 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3039
3040 TYPE_FIELD_IGNORE_BITS (type) =
3041 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3042 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3043 }
3044
3045 /* If the type has baseclasses, allocate and clear a bit vector for
3046 TYPE_FIELD_VIRTUAL_BITS. */
3047 if (fip->nbaseclasses)
3048 {
3049 int num_bytes = B_BYTES (fip->nbaseclasses);
3050 char *pointer;
3051
3052 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3053 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3054 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3055 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
3056 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
3057 }
3058
3059 /* Copy the saved-up fields into the field vector. Start from the head
3060 of the list, adding to the tail of the field array, so that they end
3061 up in the same order in the array in which they were added to the list. */
3062 while (nfields-- > 0)
3063 {
3064 TYPE_FIELD (type, nfields) = fip->fields->field;
3065 switch (fip->fields->accessibility)
3066 {
3067 case DW_ACCESS_private:
3068 SET_TYPE_FIELD_PRIVATE (type, nfields);
3069 break;
3070
3071 case DW_ACCESS_protected:
3072 SET_TYPE_FIELD_PROTECTED (type, nfields);
3073 break;
3074
3075 case DW_ACCESS_public:
3076 break;
3077
3078 default:
3079 /* Unknown accessibility. Complain and treat it as public. */
3080 {
3081 complaint (&symfile_complaints, "unsupported accessibility %d",
3082 fip->fields->accessibility);
3083 }
3084 break;
3085 }
3086 if (nfields < fip->nbaseclasses)
3087 {
3088 switch (fip->fields->virtuality)
3089 {
3090 case DW_VIRTUALITY_virtual:
3091 case DW_VIRTUALITY_pure_virtual:
3092 SET_TYPE_FIELD_VIRTUAL (type, nfields);
3093 break;
3094 }
3095 }
3096 fip->fields = fip->fields->next;
3097 }
3098 }
3099
3100 /* Add a member function to the proper fieldlist. */
3101
3102 static void
3103 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
3104 struct type *type, struct dwarf2_cu *cu)
3105 {
3106 struct objfile *objfile = cu->objfile;
3107 struct attribute *attr;
3108 struct fnfieldlist *flp;
3109 int i;
3110 struct fn_field *fnp;
3111 char *fieldname;
3112 char *physname;
3113 struct nextfnfield *new_fnfield;
3114
3115 /* Get name of member function. */
3116 attr = dwarf2_attr (die, DW_AT_name, cu);
3117 if (attr && DW_STRING (attr))
3118 fieldname = DW_STRING (attr);
3119 else
3120 return;
3121
3122 /* Get the mangled name. */
3123 physname = dwarf2_linkage_name (die, cu);
3124
3125 /* Look up member function name in fieldlist. */
3126 for (i = 0; i < fip->nfnfields; i++)
3127 {
3128 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
3129 break;
3130 }
3131
3132 /* Create new list element if necessary. */
3133 if (i < fip->nfnfields)
3134 flp = &fip->fnfieldlists[i];
3135 else
3136 {
3137 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
3138 {
3139 fip->fnfieldlists = (struct fnfieldlist *)
3140 xrealloc (fip->fnfieldlists,
3141 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
3142 * sizeof (struct fnfieldlist));
3143 if (fip->nfnfields == 0)
3144 make_cleanup (free_current_contents, &fip->fnfieldlists);
3145 }
3146 flp = &fip->fnfieldlists[fip->nfnfields];
3147 flp->name = fieldname;
3148 flp->length = 0;
3149 flp->head = NULL;
3150 fip->nfnfields++;
3151 }
3152
3153 /* Create a new member function field and chain it to the field list
3154 entry. */
3155 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
3156 make_cleanup (xfree, new_fnfield);
3157 memset (new_fnfield, 0, sizeof (struct nextfnfield));
3158 new_fnfield->next = flp->head;
3159 flp->head = new_fnfield;
3160 flp->length++;
3161
3162 /* Fill in the member function field info. */
3163 fnp = &new_fnfield->fnfield;
3164 /* The name is already allocated along with this objfile, so we don't
3165 need to duplicate it for the type. */
3166 fnp->physname = physname ? physname : "";
3167 fnp->type = alloc_type (objfile);
3168 if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
3169 {
3170 int nparams = TYPE_NFIELDS (die->type);
3171
3172 /* TYPE is the domain of this method, and DIE->TYPE is the type
3173 of the method itself (TYPE_CODE_METHOD). */
3174 smash_to_method_type (fnp->type, type,
3175 TYPE_TARGET_TYPE (die->type),
3176 TYPE_FIELDS (die->type),
3177 TYPE_NFIELDS (die->type),
3178 TYPE_VARARGS (die->type));
3179
3180 /* Handle static member functions.
3181 Dwarf2 has no clean way to discern C++ static and non-static
3182 member functions. G++ helps GDB by marking the first
3183 parameter for non-static member functions (which is the
3184 this pointer) as artificial. We obtain this information
3185 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3186 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0)
3187 fnp->voffset = VOFFSET_STATIC;
3188 }
3189 else
3190 complaint (&symfile_complaints, "member function type missing for '%s'",
3191 physname);
3192
3193 /* Get fcontext from DW_AT_containing_type if present. */
3194 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3195 fnp->fcontext = die_containing_type (die, cu);
3196
3197 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3198 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3199
3200 /* Get accessibility. */
3201 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
3202 if (attr)
3203 {
3204 switch (DW_UNSND (attr))
3205 {
3206 case DW_ACCESS_private:
3207 fnp->is_private = 1;
3208 break;
3209 case DW_ACCESS_protected:
3210 fnp->is_protected = 1;
3211 break;
3212 }
3213 }
3214
3215 /* Check for artificial methods. */
3216 attr = dwarf2_attr (die, DW_AT_artificial, cu);
3217 if (attr && DW_UNSND (attr) != 0)
3218 fnp->is_artificial = 1;
3219
3220 /* Get index in virtual function table if it is a virtual member function. */
3221 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
3222 if (attr)
3223 {
3224 /* Support the .debug_loc offsets */
3225 if (attr_form_is_block (attr))
3226 {
3227 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
3228 }
3229 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3230 {
3231 dwarf2_complex_location_expr_complaint ();
3232 }
3233 else
3234 {
3235 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3236 fieldname);
3237 }
3238 }
3239 }
3240
3241 /* Create the vector of member function fields, and attach it to the type. */
3242
3243 static void
3244 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
3245 struct dwarf2_cu *cu)
3246 {
3247 struct fnfieldlist *flp;
3248 int total_length = 0;
3249 int i;
3250
3251 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3252 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3253 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
3254
3255 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
3256 {
3257 struct nextfnfield *nfp = flp->head;
3258 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
3259 int k;
3260
3261 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
3262 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
3263 fn_flp->fn_fields = (struct fn_field *)
3264 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
3265 for (k = flp->length; (k--, nfp); nfp = nfp->next)
3266 fn_flp->fn_fields[k] = nfp->fnfield;
3267
3268 total_length += flp->length;
3269 }
3270
3271 TYPE_NFN_FIELDS (type) = fip->nfnfields;
3272 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3273 }
3274
3275
3276 /* Returns non-zero if NAME is the name of a vtable member in CU's
3277 language, zero otherwise. */
3278 static int
3279 is_vtable_name (const char *name, struct dwarf2_cu *cu)
3280 {
3281 static const char vptr[] = "_vptr";
3282 static const char vtable[] = "vtable";
3283
3284 /* Look for the C++ and Java forms of the vtable. */
3285 if ((cu->language == language_java
3286 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
3287 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
3288 && is_cplus_marker (name[sizeof (vptr) - 1])))
3289 return 1;
3290
3291 return 0;
3292 }
3293
3294
3295 /* Called when we find the DIE that starts a structure or union scope
3296 (definition) to process all dies that define the members of the
3297 structure or union.
3298
3299 NOTE: we need to call struct_type regardless of whether or not the
3300 DIE has an at_name attribute, since it might be an anonymous
3301 structure or union. This gets the type entered into our set of
3302 user defined types.
3303
3304 However, if the structure is incomplete (an opaque struct/union)
3305 then suppress creating a symbol table entry for it since gdb only
3306 wants to find the one with the complete definition. Note that if
3307 it is complete, we just call new_symbol, which does it's own
3308 checking about whether the struct/union is anonymous or not (and
3309 suppresses creating a symbol table entry itself). */
3310
3311 static void
3312 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
3313 {
3314 struct objfile *objfile = cu->objfile;
3315 struct type *type;
3316 struct attribute *attr;
3317 const char *previous_prefix = processing_current_prefix;
3318 struct cleanup *back_to = NULL;
3319
3320 if (die->type)
3321 return;
3322
3323 type = alloc_type (objfile);
3324
3325 INIT_CPLUS_SPECIFIC (type);
3326 attr = dwarf2_attr (die, DW_AT_name, cu);
3327 if (attr && DW_STRING (attr))
3328 {
3329 if (cu->language == language_cplus
3330 || cu->language == language_java)
3331 {
3332 char *new_prefix = determine_class_name (die, cu);
3333 TYPE_TAG_NAME (type) = obsavestring (new_prefix,
3334 strlen (new_prefix),
3335 &objfile->objfile_obstack);
3336 back_to = make_cleanup (xfree, new_prefix);
3337 processing_current_prefix = new_prefix;
3338 }
3339 else
3340 {
3341 /* The name is already allocated along with this objfile, so
3342 we don't need to duplicate it for the type. */
3343 TYPE_TAG_NAME (type) = DW_STRING (attr);
3344 }
3345 }
3346
3347 if (die->tag == DW_TAG_structure_type)
3348 {
3349 TYPE_CODE (type) = TYPE_CODE_STRUCT;
3350 }
3351 else if (die->tag == DW_TAG_union_type)
3352 {
3353 TYPE_CODE (type) = TYPE_CODE_UNION;
3354 }
3355 else
3356 {
3357 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3358 in gdbtypes.h. */
3359 TYPE_CODE (type) = TYPE_CODE_CLASS;
3360 }
3361
3362 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3363 if (attr)
3364 {
3365 TYPE_LENGTH (type) = DW_UNSND (attr);
3366 }
3367 else
3368 {
3369 TYPE_LENGTH (type) = 0;
3370 }
3371
3372 if (die_is_declaration (die, cu))
3373 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
3374
3375 /* We need to add the type field to the die immediately so we don't
3376 infinitely recurse when dealing with pointers to the structure
3377 type within the structure itself. */
3378 die->type = type;
3379
3380 if (die->child != NULL && ! die_is_declaration (die, cu))
3381 {
3382 struct field_info fi;
3383 struct die_info *child_die;
3384 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
3385
3386 memset (&fi, 0, sizeof (struct field_info));
3387
3388 child_die = die->child;
3389
3390 while (child_die && child_die->tag)
3391 {
3392 if (child_die->tag == DW_TAG_member
3393 || child_die->tag == DW_TAG_variable)
3394 {
3395 /* NOTE: carlton/2002-11-05: A C++ static data member
3396 should be a DW_TAG_member that is a declaration, but
3397 all versions of G++ as of this writing (so through at
3398 least 3.2.1) incorrectly generate DW_TAG_variable
3399 tags for them instead. */
3400 dwarf2_add_field (&fi, child_die, cu);
3401 }
3402 else if (child_die->tag == DW_TAG_subprogram)
3403 {
3404 /* C++ member function. */
3405 read_type_die (child_die, cu);
3406 dwarf2_add_member_fn (&fi, child_die, type, cu);
3407 }
3408 else if (child_die->tag == DW_TAG_inheritance)
3409 {
3410 /* C++ base class field. */
3411 dwarf2_add_field (&fi, child_die, cu);
3412 }
3413 child_die = sibling_die (child_die);
3414 }
3415
3416 /* Attach fields and member functions to the type. */
3417 if (fi.nfields)
3418 dwarf2_attach_fields_to_type (&fi, type, cu);
3419 if (fi.nfnfields)
3420 {
3421 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
3422
3423 /* Get the type which refers to the base class (possibly this
3424 class itself) which contains the vtable pointer for the current
3425 class from the DW_AT_containing_type attribute. */
3426
3427 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
3428 {
3429 struct type *t = die_containing_type (die, cu);
3430
3431 TYPE_VPTR_BASETYPE (type) = t;
3432 if (type == t)
3433 {
3434 int i;
3435
3436 /* Our own class provides vtbl ptr. */
3437 for (i = TYPE_NFIELDS (t) - 1;
3438 i >= TYPE_N_BASECLASSES (t);
3439 --i)
3440 {
3441 char *fieldname = TYPE_FIELD_NAME (t, i);
3442
3443 if (is_vtable_name (fieldname, cu))
3444 {
3445 TYPE_VPTR_FIELDNO (type) = i;
3446 break;
3447 }
3448 }
3449
3450 /* Complain if virtual function table field not found. */
3451 if (i < TYPE_N_BASECLASSES (t))
3452 complaint (&symfile_complaints,
3453 "virtual function table pointer not found when defining class '%s'",
3454 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
3455 "");
3456 }
3457 else
3458 {
3459 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3460 }
3461 }
3462 }
3463
3464 do_cleanups (back_to);
3465 }
3466
3467 processing_current_prefix = previous_prefix;
3468 if (back_to != NULL)
3469 do_cleanups (back_to);
3470 }
3471
3472 static void
3473 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
3474 {
3475 struct objfile *objfile = cu->objfile;
3476 const char *previous_prefix = processing_current_prefix;
3477 struct die_info *child_die = die->child;
3478
3479 if (TYPE_TAG_NAME (die->type) != NULL)
3480 processing_current_prefix = TYPE_TAG_NAME (die->type);
3481
3482 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3483 snapshots) has been known to create a die giving a declaration
3484 for a class that has, as a child, a die giving a definition for a
3485 nested class. So we have to process our children even if the
3486 current die is a declaration. Normally, of course, a declaration
3487 won't have any children at all. */
3488
3489 while (child_die != NULL && child_die->tag)
3490 {
3491 if (child_die->tag == DW_TAG_member
3492 || child_die->tag == DW_TAG_variable
3493 || child_die->tag == DW_TAG_inheritance)
3494 {
3495 /* Do nothing. */
3496 }
3497 else
3498 process_die (child_die, cu);
3499
3500 child_die = sibling_die (child_die);
3501 }
3502
3503 if (die->child != NULL && ! die_is_declaration (die, cu))
3504 new_symbol (die, die->type, cu);
3505
3506 processing_current_prefix = previous_prefix;
3507 }
3508
3509 /* Given a DW_AT_enumeration_type die, set its type. We do not
3510 complete the type's fields yet, or create any symbols. */
3511
3512 static void
3513 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
3514 {
3515 struct objfile *objfile = cu->objfile;
3516 struct type *type;
3517 struct attribute *attr;
3518
3519 if (die->type)
3520 return;
3521
3522 type = alloc_type (objfile);
3523
3524 TYPE_CODE (type) = TYPE_CODE_ENUM;
3525 attr = dwarf2_attr (die, DW_AT_name, cu);
3526 if (attr && DW_STRING (attr))
3527 {
3528 char *name = DW_STRING (attr);
3529
3530 if (processing_has_namespace_info)
3531 {
3532 TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack,
3533 processing_current_prefix,
3534 name, cu);
3535 }
3536 else
3537 {
3538 /* The name is already allocated along with this objfile, so
3539 we don't need to duplicate it for the type. */
3540 TYPE_TAG_NAME (type) = name;
3541 }
3542 }
3543
3544 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
3545 if (attr)
3546 {
3547 TYPE_LENGTH (type) = DW_UNSND (attr);
3548 }
3549 else
3550 {
3551 TYPE_LENGTH (type) = 0;
3552 }
3553
3554 die->type = type;
3555 }
3556
3557 /* Determine the name of the type represented by DIE, which should be
3558 a named C++ or Java compound type. Return the name in question; the caller
3559 is responsible for xfree()'ing it. */
3560
3561 static char *
3562 determine_class_name (struct die_info *die, struct dwarf2_cu *cu)
3563 {
3564 struct cleanup *back_to = NULL;
3565 struct die_info *spec_die = die_specification (die, cu);
3566 char *new_prefix = NULL;
3567
3568 /* If this is the definition of a class that is declared by another
3569 die, then processing_current_prefix may not be accurate; see
3570 read_func_scope for a similar example. */
3571 if (spec_die != NULL)
3572 {
3573 char *specification_prefix = determine_prefix (spec_die, cu);
3574 processing_current_prefix = specification_prefix;
3575 back_to = make_cleanup (xfree, specification_prefix);
3576 }
3577
3578 /* If we don't have namespace debug info, guess the name by trying
3579 to demangle the names of members, just like we did in
3580 guess_structure_name. */
3581 if (!processing_has_namespace_info)
3582 {
3583 struct die_info *child;
3584
3585 for (child = die->child;
3586 child != NULL && child->tag != 0;
3587 child = sibling_die (child))
3588 {
3589 if (child->tag == DW_TAG_subprogram)
3590 {
3591 new_prefix
3592 = language_class_name_from_physname (cu->language_defn,
3593 dwarf2_linkage_name
3594 (child, cu));
3595
3596 if (new_prefix != NULL)
3597 break;
3598 }
3599 }
3600 }
3601
3602 if (new_prefix == NULL)
3603 {
3604 const char *name = dwarf2_name (die, cu);
3605 new_prefix = typename_concat (NULL, processing_current_prefix,
3606 name ? name : "<<anonymous>>",
3607 cu);
3608 }
3609
3610 if (back_to != NULL)
3611 do_cleanups (back_to);
3612
3613 return new_prefix;
3614 }
3615
3616 /* Given a pointer to a die which begins an enumeration, process all
3617 the dies that define the members of the enumeration, and create the
3618 symbol for the enumeration type.
3619
3620 NOTE: We reverse the order of the element list. */
3621
3622 static void
3623 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
3624 {
3625 struct objfile *objfile = cu->objfile;
3626 struct die_info *child_die;
3627 struct field *fields;
3628 struct attribute *attr;
3629 struct symbol *sym;
3630 int num_fields;
3631 int unsigned_enum = 1;
3632
3633 num_fields = 0;
3634 fields = NULL;
3635 if (die->child != NULL)
3636 {
3637 child_die = die->child;
3638 while (child_die && child_die->tag)
3639 {
3640 if (child_die->tag != DW_TAG_enumerator)
3641 {
3642 process_die (child_die, cu);
3643 }
3644 else
3645 {
3646 attr = dwarf2_attr (child_die, DW_AT_name, cu);
3647 if (attr)
3648 {
3649 sym = new_symbol (child_die, die->type, cu);
3650 if (SYMBOL_VALUE (sym) < 0)
3651 unsigned_enum = 0;
3652
3653 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
3654 {
3655 fields = (struct field *)
3656 xrealloc (fields,
3657 (num_fields + DW_FIELD_ALLOC_CHUNK)
3658 * sizeof (struct field));
3659 }
3660
3661 FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym);
3662 FIELD_TYPE (fields[num_fields]) = NULL;
3663 FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym);
3664 FIELD_BITSIZE (fields[num_fields]) = 0;
3665 FIELD_STATIC_KIND (fields[num_fields]) = 0;
3666
3667 num_fields++;
3668 }
3669 }
3670
3671 child_die = sibling_die (child_die);
3672 }
3673
3674 if (num_fields)
3675 {
3676 TYPE_NFIELDS (die->type) = num_fields;
3677 TYPE_FIELDS (die->type) = (struct field *)
3678 TYPE_ALLOC (die->type, sizeof (struct field) * num_fields);
3679 memcpy (TYPE_FIELDS (die->type), fields,
3680 sizeof (struct field) * num_fields);
3681 xfree (fields);
3682 }
3683 if (unsigned_enum)
3684 TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED;
3685 }
3686
3687 new_symbol (die, die->type, cu);
3688 }
3689
3690 /* Extract all information from a DW_TAG_array_type DIE and put it in
3691 the DIE's type field. For now, this only handles one dimensional
3692 arrays. */
3693
3694 static void
3695 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
3696 {
3697 struct objfile *objfile = cu->objfile;
3698 struct die_info *child_die;
3699 struct type *type = NULL;
3700 struct type *element_type, *range_type, *index_type;
3701 struct type **range_types = NULL;
3702 struct attribute *attr;
3703 int ndim = 0;
3704 struct cleanup *back_to;
3705
3706 /* Return if we've already decoded this type. */
3707 if (die->type)
3708 {
3709 return;
3710 }
3711
3712 element_type = die_type (die, cu);
3713
3714 /* Irix 6.2 native cc creates array types without children for
3715 arrays with unspecified length. */
3716 if (die->child == NULL)
3717 {
3718 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
3719 range_type = create_range_type (NULL, index_type, 0, -1);
3720 die->type = create_array_type (NULL, element_type, range_type);
3721 return;
3722 }
3723
3724 back_to = make_cleanup (null_cleanup, NULL);
3725 child_die = die->child;
3726 while (child_die && child_die->tag)
3727 {
3728 if (child_die->tag == DW_TAG_subrange_type)
3729 {
3730 read_subrange_type (child_die, cu);
3731
3732 if (child_die->type != NULL)
3733 {
3734 /* The range type was succesfully read. Save it for
3735 the array type creation. */
3736 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
3737 {
3738 range_types = (struct type **)
3739 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
3740 * sizeof (struct type *));
3741 if (ndim == 0)
3742 make_cleanup (free_current_contents, &range_types);
3743 }
3744 range_types[ndim++] = child_die->type;
3745 }
3746 }
3747 child_die = sibling_die (child_die);
3748 }
3749
3750 /* Dwarf2 dimensions are output from left to right, create the
3751 necessary array types in backwards order. */
3752
3753 type = element_type;
3754
3755 if (read_array_order (die, cu) == DW_ORD_col_major)
3756 {
3757 int i = 0;
3758 while (i < ndim)
3759 type = create_array_type (NULL, type, range_types[i++]);
3760 }
3761 else
3762 {
3763 while (ndim-- > 0)
3764 type = create_array_type (NULL, type, range_types[ndim]);
3765 }
3766
3767 /* Understand Dwarf2 support for vector types (like they occur on
3768 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3769 array type. This is not part of the Dwarf2/3 standard yet, but a
3770 custom vendor extension. The main difference between a regular
3771 array and the vector variant is that vectors are passed by value
3772 to functions. */
3773 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
3774 if (attr)
3775 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
3776
3777 do_cleanups (back_to);
3778
3779 /* Install the type in the die. */
3780 die->type = type;
3781 }
3782
3783 static enum dwarf_array_dim_ordering
3784 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
3785 {
3786 struct attribute *attr;
3787
3788 attr = dwarf2_attr (die, DW_AT_ordering, cu);
3789
3790 if (attr) return DW_SND (attr);
3791
3792 /*
3793 GNU F77 is a special case, as at 08/2004 array type info is the
3794 opposite order to the dwarf2 specification, but data is still
3795 laid out as per normal fortran.
3796
3797 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
3798 version checking.
3799 */
3800
3801 if (cu->language == language_fortran &&
3802 cu->producer && strstr (cu->producer, "GNU F77"))
3803 {
3804 return DW_ORD_row_major;
3805 }
3806
3807 switch (cu->language_defn->la_array_ordering)
3808 {
3809 case array_column_major:
3810 return DW_ORD_col_major;
3811 case array_row_major:
3812 default:
3813 return DW_ORD_row_major;
3814 };
3815 }
3816
3817
3818 /* First cut: install each common block member as a global variable. */
3819
3820 static void
3821 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
3822 {
3823 struct die_info *child_die;
3824 struct attribute *attr;
3825 struct symbol *sym;
3826 CORE_ADDR base = (CORE_ADDR) 0;
3827
3828 attr = dwarf2_attr (die, DW_AT_location, cu);
3829 if (attr)
3830 {
3831 /* Support the .debug_loc offsets */
3832 if (attr_form_is_block (attr))
3833 {
3834 base = decode_locdesc (DW_BLOCK (attr), cu);
3835 }
3836 else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
3837 {
3838 dwarf2_complex_location_expr_complaint ();
3839 }
3840 else
3841 {
3842 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3843 "common block member");
3844 }
3845 }
3846 if (die->child != NULL)
3847 {
3848 child_die = die->child;
3849 while (child_die && child_die->tag)
3850 {
3851 sym = new_symbol (child_die, NULL, cu);
3852 attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu);
3853 if (attr)
3854 {
3855 SYMBOL_VALUE_ADDRESS (sym) =
3856 base + decode_locdesc (DW_BLOCK (attr), cu);
3857 add_symbol_to_list (sym, &global_symbols);
3858 }
3859 child_die = sibling_die (child_die);
3860 }
3861 }
3862 }
3863
3864 /* Read a C++ namespace. */
3865
3866 static void
3867 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
3868 {
3869 struct objfile *objfile = cu->objfile;
3870 const char *previous_prefix = processing_current_prefix;
3871 const char *name;
3872 int is_anonymous;
3873 struct die_info *current_die;
3874 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
3875
3876 name = namespace_name (die, &is_anonymous, cu);
3877
3878 /* Now build the name of the current namespace. */
3879
3880 if (previous_prefix[0] == '\0')
3881 {
3882 processing_current_prefix = name;
3883 }
3884 else
3885 {
3886 char *temp_name = typename_concat (NULL, previous_prefix, name, cu);
3887 make_cleanup (xfree, temp_name);
3888 processing_current_prefix = temp_name;
3889 }
3890
3891 /* Add a symbol associated to this if we haven't seen the namespace
3892 before. Also, add a using directive if it's an anonymous
3893 namespace. */
3894
3895 if (dwarf2_extension (die, cu) == NULL)
3896 {
3897 struct type *type;
3898
3899 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
3900 this cast will hopefully become unnecessary. */
3901 type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
3902 (char *) processing_current_prefix,
3903 objfile);
3904 TYPE_TAG_NAME (type) = TYPE_NAME (type);
3905
3906 new_symbol (die, type, cu);
3907 die->type = type;
3908
3909 if (is_anonymous)
3910 cp_add_using_directive (processing_current_prefix,
3911 strlen (previous_prefix),
3912 strlen (processing_current_prefix));
3913 }
3914
3915 if (die->child != NULL)
3916 {
3917 struct die_info *child_die = die->child;
3918
3919 while (child_die && child_die->tag)
3920 {
3921 process_die (child_die, cu);
3922 child_die = sibling_die (child_die);
3923 }
3924 }
3925
3926 processing_current_prefix = previous_prefix;
3927 do_cleanups (back_to);
3928 }
3929
3930 /* Return the name of the namespace represented by DIE. Set
3931 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
3932 namespace. */
3933
3934 static const char *
3935 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
3936 {
3937 struct die_info *current_die;
3938 const char *name = NULL;
3939
3940 /* Loop through the extensions until we find a name. */
3941
3942 for (current_die = die;
3943 current_die != NULL;
3944 current_die = dwarf2_extension (die, cu))
3945 {
3946 name = dwarf2_name (current_die, cu);
3947 if (name != NULL)
3948 break;
3949 }
3950
3951 /* Is it an anonymous namespace? */
3952
3953 *is_anonymous = (name == NULL);
3954 if (*is_anonymous)
3955 name = "(anonymous namespace)";
3956
3957 return name;
3958 }
3959
3960 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3961 the user defined type vector. */
3962
3963 static void
3964 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
3965 {
3966 struct comp_unit_head *cu_header = &cu->header;
3967 struct type *type;
3968 struct attribute *attr_byte_size;
3969 struct attribute *attr_address_class;
3970 int byte_size, addr_class;
3971
3972 if (die->type)
3973 {
3974 return;
3975 }
3976
3977 type = lookup_pointer_type (die_type (die, cu));
3978
3979 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
3980 if (attr_byte_size)
3981 byte_size = DW_UNSND (attr_byte_size);
3982 else
3983 byte_size = cu_header->addr_size;
3984
3985 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
3986 if (attr_address_class)
3987 addr_class = DW_UNSND (attr_address_class);
3988 else
3989 addr_class = DW_ADDR_none;
3990
3991 /* If the pointer size or address class is different than the
3992 default, create a type variant marked as such and set the
3993 length accordingly. */
3994 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
3995 {
3996 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3997 {
3998 int type_flags;
3999
4000 type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class);
4001 gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
4002 type = make_type_with_address_space (type, type_flags);
4003 }
4004 else if (TYPE_LENGTH (type) != byte_size)
4005 {
4006 complaint (&symfile_complaints, "invalid pointer size %d", byte_size);
4007 }
4008 else {
4009 /* Should we also complain about unhandled address classes? */
4010 }
4011 }
4012
4013 TYPE_LENGTH (type) = byte_size;
4014 die->type = type;
4015 }
4016
4017 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4018 the user defined type vector. */
4019
4020 static void
4021 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
4022 {
4023 struct objfile *objfile = cu->objfile;
4024 struct type *type;
4025 struct type *to_type;
4026 struct type *domain;
4027
4028 if (die->type)
4029 {
4030 return;
4031 }
4032
4033 type = alloc_type (objfile);
4034 to_type = die_type (die, cu);
4035 domain = die_containing_type (die, cu);
4036 smash_to_member_type (type, domain, to_type);
4037
4038 die->type = type;
4039 }
4040
4041 /* Extract all information from a DW_TAG_reference_type DIE and add to
4042 the user defined type vector. */
4043
4044 static void
4045 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
4046 {
4047 struct comp_unit_head *cu_header = &cu->header;
4048 struct type *type;
4049 struct attribute *attr;
4050
4051 if (die->type)
4052 {
4053 return;
4054 }
4055
4056 type = lookup_reference_type (die_type (die, cu));
4057 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4058 if (attr)
4059 {
4060 TYPE_LENGTH (type) = DW_UNSND (attr);
4061 }
4062 else
4063 {
4064 TYPE_LENGTH (type) = cu_header->addr_size;
4065 }
4066 die->type = type;
4067 }
4068
4069 static void
4070 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
4071 {
4072 struct type *base_type;
4073
4074 if (die->type)
4075 {
4076 return;
4077 }
4078
4079 base_type = die_type (die, cu);
4080 die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
4081 }
4082
4083 static void
4084 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
4085 {
4086 struct type *base_type;
4087
4088 if (die->type)
4089 {
4090 return;
4091 }
4092
4093 base_type = die_type (die, cu);
4094 die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
4095 }
4096
4097 /* Extract all information from a DW_TAG_string_type DIE and add to
4098 the user defined type vector. It isn't really a user defined type,
4099 but it behaves like one, with other DIE's using an AT_user_def_type
4100 attribute to reference it. */
4101
4102 static void
4103 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
4104 {
4105 struct objfile *objfile = cu->objfile;
4106 struct type *type, *range_type, *index_type, *char_type;
4107 struct attribute *attr;
4108 unsigned int length;
4109
4110 if (die->type)
4111 {
4112 return;
4113 }
4114
4115 attr = dwarf2_attr (die, DW_AT_string_length, cu);
4116 if (attr)
4117 {
4118 length = DW_UNSND (attr);
4119 }
4120 else
4121 {
4122 /* check for the DW_AT_byte_size attribute */
4123 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4124 if (attr)
4125 {
4126 length = DW_UNSND (attr);
4127 }
4128 else
4129 {
4130 length = 1;
4131 }
4132 }
4133 index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu);
4134 range_type = create_range_type (NULL, index_type, 1, length);
4135 if (cu->language == language_fortran)
4136 {
4137 /* Need to create a unique string type for bounds
4138 information */
4139 type = create_string_type (0, range_type);
4140 }
4141 else
4142 {
4143 char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu);
4144 type = create_string_type (char_type, range_type);
4145 }
4146 die->type = type;
4147 }
4148
4149 /* Handle DIES due to C code like:
4150
4151 struct foo
4152 {
4153 int (*funcp)(int a, long l);
4154 int b;
4155 };
4156
4157 ('funcp' generates a DW_TAG_subroutine_type DIE)
4158 */
4159
4160 static void
4161 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
4162 {
4163 struct type *type; /* Type that this function returns */
4164 struct type *ftype; /* Function that returns above type */
4165 struct attribute *attr;
4166
4167 /* Decode the type that this subroutine returns */
4168 if (die->type)
4169 {
4170 return;
4171 }
4172 type = die_type (die, cu);
4173 ftype = lookup_function_type (type);
4174
4175 /* All functions in C++ and Java have prototypes. */
4176 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
4177 if ((attr && (DW_UNSND (attr) != 0))
4178 || cu->language == language_cplus
4179 || cu->language == language_java)
4180 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
4181
4182 if (die->child != NULL)
4183 {
4184 struct die_info *child_die;
4185 int nparams = 0;
4186 int iparams = 0;
4187
4188 /* Count the number of parameters.
4189 FIXME: GDB currently ignores vararg functions, but knows about
4190 vararg member functions. */
4191 child_die = die->child;
4192 while (child_die && child_die->tag)
4193 {
4194 if (child_die->tag == DW_TAG_formal_parameter)
4195 nparams++;
4196 else if (child_die->tag == DW_TAG_unspecified_parameters)
4197 TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS;
4198 child_die = sibling_die (child_die);
4199 }
4200
4201 /* Allocate storage for parameters and fill them in. */
4202 TYPE_NFIELDS (ftype) = nparams;
4203 TYPE_FIELDS (ftype) = (struct field *)
4204 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
4205
4206 child_die = die->child;
4207 while (child_die && child_die->tag)
4208 {
4209 if (child_die->tag == DW_TAG_formal_parameter)
4210 {
4211 /* Dwarf2 has no clean way to discern C++ static and non-static
4212 member functions. G++ helps GDB by marking the first
4213 parameter for non-static member functions (which is the
4214 this pointer) as artificial. We pass this information
4215 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4216 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
4217 if (attr)
4218 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
4219 else
4220 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
4221 TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu);
4222 iparams++;
4223 }
4224 child_die = sibling_die (child_die);
4225 }
4226 }
4227
4228 die->type = ftype;
4229 }
4230
4231 static void
4232 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
4233 {
4234 struct objfile *objfile = cu->objfile;
4235 struct attribute *attr;
4236 char *name = NULL;
4237
4238 if (!die->type)
4239 {
4240 attr = dwarf2_attr (die, DW_AT_name, cu);
4241 if (attr && DW_STRING (attr))
4242 {
4243 name = DW_STRING (attr);
4244 }
4245 die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile);
4246 TYPE_TARGET_TYPE (die->type) = die_type (die, cu);
4247 }
4248 }
4249
4250 /* Find a representation of a given base type and install
4251 it in the TYPE field of the die. */
4252
4253 static void
4254 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
4255 {
4256 struct objfile *objfile = cu->objfile;
4257 struct type *type;
4258 struct attribute *attr;
4259 int encoding = 0, size = 0;
4260
4261 /* If we've already decoded this die, this is a no-op. */
4262 if (die->type)
4263 {
4264 return;
4265 }
4266
4267 attr = dwarf2_attr (die, DW_AT_encoding, cu);
4268 if (attr)
4269 {
4270 encoding = DW_UNSND (attr);
4271 }
4272 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4273 if (attr)
4274 {
4275 size = DW_UNSND (attr);
4276 }
4277 attr = dwarf2_attr (die, DW_AT_name, cu);
4278 if (attr && DW_STRING (attr))
4279 {
4280 enum type_code code = TYPE_CODE_INT;
4281 int type_flags = 0;
4282
4283 switch (encoding)
4284 {
4285 case DW_ATE_address:
4286 /* Turn DW_ATE_address into a void * pointer. */
4287 code = TYPE_CODE_PTR;
4288 type_flags |= TYPE_FLAG_UNSIGNED;
4289 break;
4290 case DW_ATE_boolean:
4291 code = TYPE_CODE_BOOL;
4292 type_flags |= TYPE_FLAG_UNSIGNED;
4293 break;
4294 case DW_ATE_complex_float:
4295 code = TYPE_CODE_COMPLEX;
4296 break;
4297 case DW_ATE_float:
4298 code = TYPE_CODE_FLT;
4299 break;
4300 case DW_ATE_signed:
4301 case DW_ATE_signed_char:
4302 break;
4303 case DW_ATE_unsigned:
4304 case DW_ATE_unsigned_char:
4305 type_flags |= TYPE_FLAG_UNSIGNED;
4306 break;
4307 default:
4308 complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'",
4309 dwarf_type_encoding_name (encoding));
4310 break;
4311 }
4312 type = init_type (code, size, type_flags, DW_STRING (attr), objfile);
4313 if (encoding == DW_ATE_address)
4314 TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID,
4315 cu);
4316 else if (encoding == DW_ATE_complex_float)
4317 {
4318 if (size == 32)
4319 TYPE_TARGET_TYPE (type)
4320 = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu);
4321 else if (size == 16)
4322 TYPE_TARGET_TYPE (type)
4323 = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
4324 else if (size == 8)
4325 TYPE_TARGET_TYPE (type)
4326 = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
4327 }
4328 }
4329 else
4330 {
4331 type = dwarf_base_type (encoding, size, cu);
4332 }
4333 die->type = type;
4334 }
4335
4336 /* Read the given DW_AT_subrange DIE. */
4337
4338 static void
4339 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
4340 {
4341 struct type *base_type;
4342 struct type *range_type;
4343 struct attribute *attr;
4344 int low = 0;
4345 int high = -1;
4346
4347 /* If we have already decoded this die, then nothing more to do. */
4348 if (die->type)
4349 return;
4350
4351 base_type = die_type (die, cu);
4352 if (base_type == NULL)
4353 {
4354 complaint (&symfile_complaints,
4355 "DW_AT_type missing from DW_TAG_subrange_type");
4356 return;
4357 }
4358
4359 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
4360 base_type = alloc_type (NULL);
4361
4362 if (cu->language == language_fortran)
4363 {
4364 /* FORTRAN implies a lower bound of 1, if not given. */
4365 low = 1;
4366 }
4367
4368 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
4369 if (attr)
4370 low = dwarf2_get_attr_constant_value (attr, 0);
4371
4372 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
4373 if (attr)
4374 {
4375 if (attr->form == DW_FORM_block1)
4376 {
4377 /* GCC encodes arrays with unspecified or dynamic length
4378 with a DW_FORM_block1 attribute.
4379 FIXME: GDB does not yet know how to handle dynamic
4380 arrays properly, treat them as arrays with unspecified
4381 length for now.
4382
4383 FIXME: jimb/2003-09-22: GDB does not really know
4384 how to handle arrays of unspecified length
4385 either; we just represent them as zero-length
4386 arrays. Choose an appropriate upper bound given
4387 the lower bound we've computed above. */
4388 high = low - 1;
4389 }
4390 else
4391 high = dwarf2_get_attr_constant_value (attr, 1);
4392 }
4393
4394 range_type = create_range_type (NULL, base_type, low, high);
4395
4396 attr = dwarf2_attr (die, DW_AT_name, cu);
4397 if (attr && DW_STRING (attr))
4398 TYPE_NAME (range_type) = DW_STRING (attr);
4399
4400 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
4401 if (attr)
4402 TYPE_LENGTH (range_type) = DW_UNSND (attr);
4403
4404 die->type = range_type;
4405 }
4406
4407
4408 /* Read a whole compilation unit into a linked list of dies. */
4409
4410 static struct die_info *
4411 read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu)
4412 {
4413 /* Reset die reference table; we are
4414 building new ones now. */
4415 dwarf2_empty_hash_tables ();
4416
4417 return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL);
4418 }
4419
4420 /* Read a single die and all its descendents. Set the die's sibling
4421 field to NULL; set other fields in the die correctly, and set all
4422 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4423 location of the info_ptr after reading all of those dies. PARENT
4424 is the parent of the die in question. */
4425
4426 static struct die_info *
4427 read_die_and_children (char *info_ptr, bfd *abfd,
4428 struct dwarf2_cu *cu,
4429 char **new_info_ptr,
4430 struct die_info *parent)
4431 {
4432 struct die_info *die;
4433 char *cur_ptr;
4434 int has_children;
4435
4436 cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children);
4437 store_in_ref_table (die->offset, die);
4438
4439 if (has_children)
4440 {
4441 die->child = read_die_and_siblings (cur_ptr, abfd, cu,
4442 new_info_ptr, die);
4443 }
4444 else
4445 {
4446 die->child = NULL;
4447 *new_info_ptr = cur_ptr;
4448 }
4449
4450 die->sibling = NULL;
4451 die->parent = parent;
4452 return die;
4453 }
4454
4455 /* Read a die, all of its descendents, and all of its siblings; set
4456 all of the fields of all of the dies correctly. Arguments are as
4457 in read_die_and_children. */
4458
4459 static struct die_info *
4460 read_die_and_siblings (char *info_ptr, bfd *abfd,
4461 struct dwarf2_cu *cu,
4462 char **new_info_ptr,
4463 struct die_info *parent)
4464 {
4465 struct die_info *first_die, *last_sibling;
4466 char *cur_ptr;
4467
4468 cur_ptr = info_ptr;
4469 first_die = last_sibling = NULL;
4470
4471 while (1)
4472 {
4473 struct die_info *die
4474 = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent);
4475
4476 if (!first_die)
4477 {
4478 first_die = die;
4479 }
4480 else
4481 {
4482 last_sibling->sibling = die;
4483 }
4484
4485 if (die->tag == 0)
4486 {
4487 *new_info_ptr = cur_ptr;
4488 return first_die;
4489 }
4490 else
4491 {
4492 last_sibling = die;
4493 }
4494 }
4495 }
4496
4497 /* Free a linked list of dies. */
4498
4499 static void
4500 free_die_list (struct die_info *dies)
4501 {
4502 struct die_info *die, *next;
4503
4504 die = dies;
4505 while (die)
4506 {
4507 if (die->child != NULL)
4508 free_die_list (die->child);
4509 next = die->sibling;
4510 xfree (die->attrs);
4511 xfree (die);
4512 die = next;
4513 }
4514 }
4515
4516 static void
4517 do_free_die_list_cleanup (void *dies)
4518 {
4519 free_die_list (dies);
4520 }
4521
4522 static struct cleanup *
4523 make_cleanup_free_die_list (struct die_info *dies)
4524 {
4525 return make_cleanup (do_free_die_list_cleanup, dies);
4526 }
4527
4528
4529 /* Read the contents of the section at OFFSET and of size SIZE from the
4530 object file specified by OBJFILE into the objfile_obstack and return it. */
4531
4532 char *
4533 dwarf2_read_section (struct objfile *objfile, asection *sectp)
4534 {
4535 bfd *abfd = objfile->obfd;
4536 char *buf, *retbuf;
4537 bfd_size_type size = bfd_get_section_size (sectp);
4538
4539 if (size == 0)
4540 return NULL;
4541
4542 buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
4543 retbuf
4544 = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
4545 if (retbuf != NULL)
4546 return retbuf;
4547
4548 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
4549 || bfd_bread (buf, size, abfd) != size)
4550 error ("Dwarf Error: Can't read DWARF data from '%s'",
4551 bfd_get_filename (abfd));
4552
4553 return buf;
4554 }
4555
4556 /* In DWARF version 2, the description of the debugging information is
4557 stored in a separate .debug_abbrev section. Before we read any
4558 dies from a section we read in all abbreviations and install them
4559 in a hash table. This function also sets flags in CU describing
4560 the data found in the abbrev table. */
4561
4562 static void
4563 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
4564 {
4565 struct comp_unit_head *cu_header = &cu->header;
4566 char *abbrev_ptr;
4567 struct abbrev_info *cur_abbrev;
4568 unsigned int abbrev_number, bytes_read, abbrev_name;
4569 unsigned int abbrev_form, hash_number;
4570 struct attr_abbrev *cur_attrs;
4571 unsigned int allocated_attrs;
4572
4573 /* Initialize dwarf2 abbrevs */
4574 obstack_init (&cu->abbrev_obstack);
4575 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
4576 (ABBREV_HASH_SIZE
4577 * sizeof (struct abbrev_info *)));
4578 memset (cu->dwarf2_abbrevs, 0,
4579 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
4580
4581 abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset;
4582 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4583 abbrev_ptr += bytes_read;
4584
4585 allocated_attrs = ATTR_ALLOC_CHUNK;
4586 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
4587
4588 /* loop until we reach an abbrev number of 0 */
4589 while (abbrev_number)
4590 {
4591 cur_abbrev = dwarf_alloc_abbrev (cu);
4592
4593 /* read in abbrev header */
4594 cur_abbrev->number = abbrev_number;
4595 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4596 abbrev_ptr += bytes_read;
4597 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
4598 abbrev_ptr += 1;
4599
4600 if (cur_abbrev->tag == DW_TAG_namespace)
4601 cu->has_namespace_info = 1;
4602
4603 /* now read in declarations */
4604 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4605 abbrev_ptr += bytes_read;
4606 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4607 abbrev_ptr += bytes_read;
4608 while (abbrev_name)
4609 {
4610 if (cur_abbrev->num_attrs == allocated_attrs)
4611 {
4612 allocated_attrs += ATTR_ALLOC_CHUNK;
4613 cur_attrs
4614 = xrealloc (cur_attrs, (allocated_attrs
4615 * sizeof (struct attr_abbrev)));
4616 }
4617 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
4618 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
4619 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4620 abbrev_ptr += bytes_read;
4621 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4622 abbrev_ptr += bytes_read;
4623 }
4624
4625 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
4626 (cur_abbrev->num_attrs
4627 * sizeof (struct attr_abbrev)));
4628 memcpy (cur_abbrev->attrs, cur_attrs,
4629 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
4630
4631 hash_number = abbrev_number % ABBREV_HASH_SIZE;
4632 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
4633 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
4634
4635 /* Get next abbreviation.
4636 Under Irix6 the abbreviations for a compilation unit are not
4637 always properly terminated with an abbrev number of 0.
4638 Exit loop if we encounter an abbreviation which we have
4639 already read (which means we are about to read the abbreviations
4640 for the next compile unit) or if the end of the abbreviation
4641 table is reached. */
4642 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer)
4643 >= dwarf2_per_objfile->abbrev_size)
4644 break;
4645 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
4646 abbrev_ptr += bytes_read;
4647 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
4648 break;
4649 }
4650
4651 xfree (cur_attrs);
4652 }
4653
4654 /* Release the memory used by the abbrev table for a compilation unit. */
4655
4656 static void
4657 dwarf2_free_abbrev_table (void *ptr_to_cu)
4658 {
4659 struct dwarf2_cu *cu = ptr_to_cu;
4660
4661 obstack_free (&cu->abbrev_obstack, NULL);
4662 cu->dwarf2_abbrevs = NULL;
4663 }
4664
4665 /* Lookup an abbrev_info structure in the abbrev hash table. */
4666
4667 static struct abbrev_info *
4668 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
4669 {
4670 unsigned int hash_number;
4671 struct abbrev_info *abbrev;
4672
4673 hash_number = number % ABBREV_HASH_SIZE;
4674 abbrev = cu->dwarf2_abbrevs[hash_number];
4675
4676 while (abbrev)
4677 {
4678 if (abbrev->number == number)
4679 return abbrev;
4680 else
4681 abbrev = abbrev->next;
4682 }
4683 return NULL;
4684 }
4685
4686 /* Returns nonzero if TAG represents a type that we might generate a partial
4687 symbol for. */
4688
4689 static int
4690 is_type_tag_for_partial (int tag)
4691 {
4692 switch (tag)
4693 {
4694 #if 0
4695 /* Some types that would be reasonable to generate partial symbols for,
4696 that we don't at present. */
4697 case DW_TAG_array_type:
4698 case DW_TAG_file_type:
4699 case DW_TAG_ptr_to_member_type:
4700 case DW_TAG_set_type:
4701 case DW_TAG_string_type:
4702 case DW_TAG_subroutine_type:
4703 #endif
4704 case DW_TAG_base_type:
4705 case DW_TAG_class_type:
4706 case DW_TAG_enumeration_type:
4707 case DW_TAG_structure_type:
4708 case DW_TAG_subrange_type:
4709 case DW_TAG_typedef:
4710 case DW_TAG_union_type:
4711 return 1;
4712 default:
4713 return 0;
4714 }
4715 }
4716
4717 /* Load all DIEs that are interesting for partial symbols into memory. */
4718
4719 static struct partial_die_info *
4720 load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab,
4721 struct dwarf2_cu *cu)
4722 {
4723 struct partial_die_info *part_die;
4724 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
4725 struct abbrev_info *abbrev;
4726 unsigned int bytes_read;
4727
4728 int nesting_level = 1;
4729
4730 parent_die = NULL;
4731 last_die = NULL;
4732
4733 cu->partial_dies
4734 = htab_create_alloc_ex (cu->header.length / 12,
4735 partial_die_hash,
4736 partial_die_eq,
4737 NULL,
4738 &cu->comp_unit_obstack,
4739 hashtab_obstack_allocate,
4740 dummy_obstack_deallocate);
4741
4742 part_die = obstack_alloc (&cu->comp_unit_obstack,
4743 sizeof (struct partial_die_info));
4744
4745 while (1)
4746 {
4747 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4748
4749 /* A NULL abbrev means the end of a series of children. */
4750 if (abbrev == NULL)
4751 {
4752 if (--nesting_level == 0)
4753 {
4754 /* PART_DIE was probably the last thing allocated on the
4755 comp_unit_obstack, so we could call obstack_free
4756 here. We don't do that because the waste is small,
4757 and will be cleaned up when we're done with this
4758 compilation unit. This way, we're also more robust
4759 against other users of the comp_unit_obstack. */
4760 return first_die;
4761 }
4762 info_ptr += bytes_read;
4763 last_die = parent_die;
4764 parent_die = parent_die->die_parent;
4765 continue;
4766 }
4767
4768 /* Check whether this DIE is interesting enough to save. */
4769 if (!is_type_tag_for_partial (abbrev->tag)
4770 && abbrev->tag != DW_TAG_enumerator
4771 && abbrev->tag != DW_TAG_subprogram
4772 && abbrev->tag != DW_TAG_variable
4773 && abbrev->tag != DW_TAG_namespace)
4774 {
4775 /* Otherwise we skip to the next sibling, if any. */
4776 info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu);
4777 continue;
4778 }
4779
4780 info_ptr = read_partial_die (part_die, abbrev, bytes_read,
4781 abfd, info_ptr, cu);
4782
4783 /* This two-pass algorithm for processing partial symbols has a
4784 high cost in cache pressure. Thus, handle some simple cases
4785 here which cover the majority of C partial symbols. DIEs
4786 which neither have specification tags in them, nor could have
4787 specification tags elsewhere pointing at them, can simply be
4788 processed and discarded.
4789
4790 This segment is also optional; scan_partial_symbols and
4791 add_partial_symbol will handle these DIEs if we chain
4792 them in normally. When compilers which do not emit large
4793 quantities of duplicate debug information are more common,
4794 this code can probably be removed. */
4795
4796 /* Any complete simple types at the top level (pretty much all
4797 of them, for a language without namespaces), can be processed
4798 directly. */
4799 if (parent_die == NULL
4800 && part_die->has_specification == 0
4801 && part_die->is_declaration == 0
4802 && (part_die->tag == DW_TAG_typedef
4803 || part_die->tag == DW_TAG_base_type
4804 || part_die->tag == DW_TAG_subrange_type))
4805 {
4806 if (building_psymtab && part_die->name != NULL)
4807 add_psymbol_to_list (part_die->name, strlen (part_die->name),
4808 VAR_DOMAIN, LOC_TYPEDEF,
4809 &cu->objfile->static_psymbols,
4810 0, (CORE_ADDR) 0, cu->language, cu->objfile);
4811 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
4812 continue;
4813 }
4814
4815 /* If we're at the second level, and we're an enumerator, and
4816 our parent has no specification (meaning possibly lives in a
4817 namespace elsewhere), then we can add the partial symbol now
4818 instead of queueing it. */
4819 if (part_die->tag == DW_TAG_enumerator
4820 && parent_die != NULL
4821 && parent_die->die_parent == NULL
4822 && parent_die->tag == DW_TAG_enumeration_type
4823 && parent_die->has_specification == 0)
4824 {
4825 if (part_die->name == NULL)
4826 complaint (&symfile_complaints, "malformed enumerator DIE ignored");
4827 else if (building_psymtab)
4828 add_psymbol_to_list (part_die->name, strlen (part_die->name),
4829 VAR_DOMAIN, LOC_CONST,
4830 (cu->language == language_cplus
4831 || cu->language == language_java)
4832 ? &cu->objfile->global_psymbols
4833 : &cu->objfile->static_psymbols,
4834 0, (CORE_ADDR) 0, cu->language, cu->objfile);
4835
4836 info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu);
4837 continue;
4838 }
4839
4840 /* We'll save this DIE so link it in. */
4841 part_die->die_parent = parent_die;
4842 part_die->die_sibling = NULL;
4843 part_die->die_child = NULL;
4844
4845 if (last_die && last_die == parent_die)
4846 last_die->die_child = part_die;
4847 else if (last_die)
4848 last_die->die_sibling = part_die;
4849
4850 last_die = part_die;
4851
4852 if (first_die == NULL)
4853 first_die = part_die;
4854
4855 /* Maybe add the DIE to the hash table. Not all DIEs that we
4856 find interesting need to be in the hash table, because we
4857 also have the parent/sibling/child chains; only those that we
4858 might refer to by offset later during partial symbol reading.
4859
4860 For now this means things that might have be the target of a
4861 DW_AT_specification, DW_AT_abstract_origin, or
4862 DW_AT_extension. DW_AT_extension will refer only to
4863 namespaces; DW_AT_abstract_origin refers to functions (and
4864 many things under the function DIE, but we do not recurse
4865 into function DIEs during partial symbol reading) and
4866 possibly variables as well; DW_AT_specification refers to
4867 declarations. Declarations ought to have the DW_AT_declaration
4868 flag. It happens that GCC forgets to put it in sometimes, but
4869 only for functions, not for types.
4870
4871 Adding more things than necessary to the hash table is harmless
4872 except for the performance cost. Adding too few will result in
4873 internal errors in find_partial_die. */
4874
4875 if (abbrev->tag == DW_TAG_subprogram
4876 || abbrev->tag == DW_TAG_variable
4877 || abbrev->tag == DW_TAG_namespace
4878 || part_die->is_declaration)
4879 {
4880 void **slot;
4881
4882 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
4883 part_die->offset, INSERT);
4884 *slot = part_die;
4885 }
4886
4887 part_die = obstack_alloc (&cu->comp_unit_obstack,
4888 sizeof (struct partial_die_info));
4889
4890 /* For some DIEs we want to follow their children (if any). For C
4891 we have no reason to follow the children of structures; for other
4892 languages we have to, both so that we can get at method physnames
4893 to infer fully qualified class names, and for DW_AT_specification. */
4894 if (last_die->has_children
4895 && (last_die->tag == DW_TAG_namespace
4896 || last_die->tag == DW_TAG_enumeration_type
4897 || (cu->language != language_c
4898 && (last_die->tag == DW_TAG_class_type
4899 || last_die->tag == DW_TAG_structure_type
4900 || last_die->tag == DW_TAG_union_type))))
4901 {
4902 nesting_level++;
4903 parent_die = last_die;
4904 continue;
4905 }
4906
4907 /* Otherwise we skip to the next sibling, if any. */
4908 info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu);
4909
4910 /* Back to the top, do it again. */
4911 }
4912 }
4913
4914 /* Read a minimal amount of information into the minimal die structure. */
4915
4916 static char *
4917 read_partial_die (struct partial_die_info *part_die,
4918 struct abbrev_info *abbrev,
4919 unsigned int abbrev_len, bfd *abfd,
4920 char *info_ptr, struct dwarf2_cu *cu)
4921 {
4922 unsigned int bytes_read, i;
4923 struct attribute attr;
4924 int has_low_pc_attr = 0;
4925 int has_high_pc_attr = 0;
4926
4927 memset (part_die, 0, sizeof (struct partial_die_info));
4928
4929 part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer;
4930
4931 info_ptr += abbrev_len;
4932
4933 if (abbrev == NULL)
4934 return info_ptr;
4935
4936 part_die->tag = abbrev->tag;
4937 part_die->has_children = abbrev->has_children;
4938
4939 for (i = 0; i < abbrev->num_attrs; ++i)
4940 {
4941 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
4942
4943 /* Store the data if it is of an attribute we want to keep in a
4944 partial symbol table. */
4945 switch (attr.name)
4946 {
4947 case DW_AT_name:
4948
4949 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
4950 if (part_die->name == NULL)
4951 part_die->name = DW_STRING (&attr);
4952 break;
4953 case DW_AT_comp_dir:
4954 if (part_die->dirname == NULL)
4955 part_die->dirname = DW_STRING (&attr);
4956 break;
4957 case DW_AT_MIPS_linkage_name:
4958 part_die->name = DW_STRING (&attr);
4959 break;
4960 case DW_AT_low_pc:
4961 has_low_pc_attr = 1;
4962 part_die->lowpc = DW_ADDR (&attr);
4963 break;
4964 case DW_AT_high_pc:
4965 has_high_pc_attr = 1;
4966 part_die->highpc = DW_ADDR (&attr);
4967 break;
4968 case DW_AT_location:
4969 /* Support the .debug_loc offsets */
4970 if (attr_form_is_block (&attr))
4971 {
4972 part_die->locdesc = DW_BLOCK (&attr);
4973 }
4974 else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8)
4975 {
4976 dwarf2_complex_location_expr_complaint ();
4977 }
4978 else
4979 {
4980 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4981 "partial symbol information");
4982 }
4983 break;
4984 case DW_AT_language:
4985 part_die->language = DW_UNSND (&attr);
4986 break;
4987 case DW_AT_external:
4988 part_die->is_external = DW_UNSND (&attr);
4989 break;
4990 case DW_AT_declaration:
4991 part_die->is_declaration = DW_UNSND (&attr);
4992 break;
4993 case DW_AT_type:
4994 part_die->has_type = 1;
4995 break;
4996 case DW_AT_abstract_origin:
4997 case DW_AT_specification:
4998 case DW_AT_extension:
4999 part_die->has_specification = 1;
5000 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu);
5001 break;
5002 case DW_AT_sibling:
5003 /* Ignore absolute siblings, they might point outside of
5004 the current compile unit. */
5005 if (attr.form == DW_FORM_ref_addr)
5006 complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling");
5007 else
5008 part_die->sibling = dwarf2_per_objfile->info_buffer
5009 + dwarf2_get_ref_die_offset (&attr, cu);
5010 break;
5011 case DW_AT_stmt_list:
5012 part_die->has_stmt_list = 1;
5013 part_die->line_offset = DW_UNSND (&attr);
5014 break;
5015 default:
5016 break;
5017 }
5018 }
5019
5020 /* When using the GNU linker, .gnu.linkonce. sections are used to
5021 eliminate duplicate copies of functions and vtables and such.
5022 The linker will arbitrarily choose one and discard the others.
5023 The AT_*_pc values for such functions refer to local labels in
5024 these sections. If the section from that file was discarded, the
5025 labels are not in the output, so the relocs get a value of 0.
5026 If this is a discarded function, mark the pc bounds as invalid,
5027 so that GDB will ignore it. */
5028 if (has_low_pc_attr && has_high_pc_attr
5029 && part_die->lowpc < part_die->highpc
5030 && (part_die->lowpc != 0
5031 || (bfd_get_file_flags (abfd) & HAS_RELOC)))
5032 part_die->has_pc_info = 1;
5033 return info_ptr;
5034 }
5035
5036 /* Find a cached partial DIE at OFFSET in CU. */
5037
5038 static struct partial_die_info *
5039 find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu)
5040 {
5041 struct partial_die_info *lookup_die = NULL;
5042 struct partial_die_info part_die;
5043
5044 part_die.offset = offset;
5045 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
5046
5047 if (lookup_die == NULL)
5048 internal_error (__FILE__, __LINE__,
5049 "could not find partial DIE in cache\n");
5050
5051 return lookup_die;
5052 }
5053
5054 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5055
5056 static struct partial_die_info *
5057 find_partial_die (unsigned long offset, struct dwarf2_cu *cu,
5058 struct dwarf2_cu **target_cu)
5059 {
5060 struct dwarf2_per_cu_data *per_cu;
5061
5062 if (offset >= cu->header.offset
5063 && offset < cu->header.offset + cu->header.length)
5064 {
5065 *target_cu = cu;
5066 return find_partial_die_in_comp_unit (offset, cu);
5067 }
5068
5069 internal_error (__FILE__, __LINE__,
5070 "unsupported inter-compilation-unit reference");
5071 }
5072
5073 /* Adjust PART_DIE before generating a symbol for it. This function
5074 may set the is_external flag or change the DIE's name. */
5075
5076 static void
5077 fixup_partial_die (struct partial_die_info *part_die,
5078 struct dwarf2_cu *cu)
5079 {
5080 /* If we found a reference attribute and the DIE has no name, try
5081 to find a name in the referred to DIE. */
5082
5083 if (part_die->name == NULL && part_die->has_specification)
5084 {
5085 struct partial_die_info *spec_die;
5086 struct dwarf2_cu *spec_cu;
5087
5088 spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu);
5089
5090 fixup_partial_die (spec_die, spec_cu);
5091
5092 if (spec_die->name)
5093 {
5094 part_die->name = spec_die->name;
5095
5096 /* Copy DW_AT_external attribute if it is set. */
5097 if (spec_die->is_external)
5098 part_die->is_external = spec_die->is_external;
5099 }
5100 }
5101
5102 /* Set default names for some unnamed DIEs. */
5103 if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type
5104 || part_die->tag == DW_TAG_class_type))
5105 part_die->name = "(anonymous class)";
5106
5107 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
5108 part_die->name = "(anonymous namespace)";
5109
5110 if (part_die->tag == DW_TAG_structure_type
5111 || part_die->tag == DW_TAG_class_type
5112 || part_die->tag == DW_TAG_union_type)
5113 guess_structure_name (part_die, cu);
5114 }
5115
5116 /* Read the die from the .debug_info section buffer. Set DIEP to
5117 point to a newly allocated die with its information, except for its
5118 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5119 whether the die has children or not. */
5120
5121 static char *
5122 read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr,
5123 struct dwarf2_cu *cu, int *has_children)
5124 {
5125 unsigned int abbrev_number, bytes_read, i, offset;
5126 struct abbrev_info *abbrev;
5127 struct die_info *die;
5128
5129 offset = info_ptr - dwarf2_per_objfile->info_buffer;
5130 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5131 info_ptr += bytes_read;
5132 if (!abbrev_number)
5133 {
5134 die = dwarf_alloc_die ();
5135 die->tag = 0;
5136 die->abbrev = abbrev_number;
5137 die->type = NULL;
5138 *diep = die;
5139 *has_children = 0;
5140 return info_ptr;
5141 }
5142
5143 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
5144 if (!abbrev)
5145 {
5146 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5147 abbrev_number,
5148 bfd_get_filename (abfd));
5149 }
5150 die = dwarf_alloc_die ();
5151 die->offset = offset;
5152 die->tag = abbrev->tag;
5153 die->abbrev = abbrev_number;
5154 die->type = NULL;
5155
5156 die->num_attrs = abbrev->num_attrs;
5157 die->attrs = (struct attribute *)
5158 xmalloc (die->num_attrs * sizeof (struct attribute));
5159
5160 for (i = 0; i < abbrev->num_attrs; ++i)
5161 {
5162 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
5163 abfd, info_ptr, cu);
5164 }
5165
5166 *diep = die;
5167 *has_children = abbrev->has_children;
5168 return info_ptr;
5169 }
5170
5171 /* Read an attribute value described by an attribute form. */
5172
5173 static char *
5174 read_attribute_value (struct attribute *attr, unsigned form,
5175 bfd *abfd, char *info_ptr,
5176 struct dwarf2_cu *cu)
5177 {
5178 struct comp_unit_head *cu_header = &cu->header;
5179 unsigned int bytes_read;
5180 struct dwarf_block *blk;
5181
5182 attr->form = form;
5183 switch (form)
5184 {
5185 case DW_FORM_addr:
5186 case DW_FORM_ref_addr:
5187 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
5188 info_ptr += bytes_read;
5189 break;
5190 case DW_FORM_block2:
5191 blk = dwarf_alloc_block (cu);
5192 blk->size = read_2_bytes (abfd, info_ptr);
5193 info_ptr += 2;
5194 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5195 info_ptr += blk->size;
5196 DW_BLOCK (attr) = blk;
5197 break;
5198 case DW_FORM_block4:
5199 blk = dwarf_alloc_block (cu);
5200 blk->size = read_4_bytes (abfd, info_ptr);
5201 info_ptr += 4;
5202 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5203 info_ptr += blk->size;
5204 DW_BLOCK (attr) = blk;
5205 break;
5206 case DW_FORM_data2:
5207 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5208 info_ptr += 2;
5209 break;
5210 case DW_FORM_data4:
5211 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5212 info_ptr += 4;
5213 break;
5214 case DW_FORM_data8:
5215 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5216 info_ptr += 8;
5217 break;
5218 case DW_FORM_string:
5219 DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
5220 info_ptr += bytes_read;
5221 break;
5222 case DW_FORM_strp:
5223 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
5224 &bytes_read);
5225 info_ptr += bytes_read;
5226 break;
5227 case DW_FORM_block:
5228 blk = dwarf_alloc_block (cu);
5229 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5230 info_ptr += bytes_read;
5231 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5232 info_ptr += blk->size;
5233 DW_BLOCK (attr) = blk;
5234 break;
5235 case DW_FORM_block1:
5236 blk = dwarf_alloc_block (cu);
5237 blk->size = read_1_byte (abfd, info_ptr);
5238 info_ptr += 1;
5239 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
5240 info_ptr += blk->size;
5241 DW_BLOCK (attr) = blk;
5242 break;
5243 case DW_FORM_data1:
5244 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5245 info_ptr += 1;
5246 break;
5247 case DW_FORM_flag:
5248 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5249 info_ptr += 1;
5250 break;
5251 case DW_FORM_sdata:
5252 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
5253 info_ptr += bytes_read;
5254 break;
5255 case DW_FORM_udata:
5256 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5257 info_ptr += bytes_read;
5258 break;
5259 case DW_FORM_ref1:
5260 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
5261 info_ptr += 1;
5262 break;
5263 case DW_FORM_ref2:
5264 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
5265 info_ptr += 2;
5266 break;
5267 case DW_FORM_ref4:
5268 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
5269 info_ptr += 4;
5270 break;
5271 case DW_FORM_ref8:
5272 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
5273 info_ptr += 8;
5274 break;
5275 case DW_FORM_ref_udata:
5276 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5277 info_ptr += bytes_read;
5278 break;
5279 case DW_FORM_indirect:
5280 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
5281 info_ptr += bytes_read;
5282 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
5283 break;
5284 default:
5285 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5286 dwarf_form_name (form),
5287 bfd_get_filename (abfd));
5288 }
5289 return info_ptr;
5290 }
5291
5292 /* Read an attribute described by an abbreviated attribute. */
5293
5294 static char *
5295 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
5296 bfd *abfd, char *info_ptr, struct dwarf2_cu *cu)
5297 {
5298 attr->name = abbrev->name;
5299 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
5300 }
5301
5302 /* read dwarf information from a buffer */
5303
5304 static unsigned int
5305 read_1_byte (bfd *abfd, char *buf)
5306 {
5307 return bfd_get_8 (abfd, (bfd_byte *) buf);
5308 }
5309
5310 static int
5311 read_1_signed_byte (bfd *abfd, char *buf)
5312 {
5313 return bfd_get_signed_8 (abfd, (bfd_byte *) buf);
5314 }
5315
5316 static unsigned int
5317 read_2_bytes (bfd *abfd, char *buf)
5318 {
5319 return bfd_get_16 (abfd, (bfd_byte *) buf);
5320 }
5321
5322 static int
5323 read_2_signed_bytes (bfd *abfd, char *buf)
5324 {
5325 return bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5326 }
5327
5328 static unsigned int
5329 read_4_bytes (bfd *abfd, char *buf)
5330 {
5331 return bfd_get_32 (abfd, (bfd_byte *) buf);
5332 }
5333
5334 static int
5335 read_4_signed_bytes (bfd *abfd, char *buf)
5336 {
5337 return bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5338 }
5339
5340 static unsigned long
5341 read_8_bytes (bfd *abfd, char *buf)
5342 {
5343 return bfd_get_64 (abfd, (bfd_byte *) buf);
5344 }
5345
5346 static CORE_ADDR
5347 read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read)
5348 {
5349 struct comp_unit_head *cu_header = &cu->header;
5350 CORE_ADDR retval = 0;
5351
5352 if (cu_header->signed_addr_p)
5353 {
5354 switch (cu_header->addr_size)
5355 {
5356 case 2:
5357 retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf);
5358 break;
5359 case 4:
5360 retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf);
5361 break;
5362 case 8:
5363 retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf);
5364 break;
5365 default:
5366 internal_error (__FILE__, __LINE__,
5367 "read_address: bad switch, signed [in module %s]",
5368 bfd_get_filename (abfd));
5369 }
5370 }
5371 else
5372 {
5373 switch (cu_header->addr_size)
5374 {
5375 case 2:
5376 retval = bfd_get_16 (abfd, (bfd_byte *) buf);
5377 break;
5378 case 4:
5379 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5380 break;
5381 case 8:
5382 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5383 break;
5384 default:
5385 internal_error (__FILE__, __LINE__,
5386 "read_address: bad switch, unsigned [in module %s]",
5387 bfd_get_filename (abfd));
5388 }
5389 }
5390
5391 *bytes_read = cu_header->addr_size;
5392 return retval;
5393 }
5394
5395 /* Read the initial length from a section. The (draft) DWARF 3
5396 specification allows the initial length to take up either 4 bytes
5397 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5398 bytes describe the length and all offsets will be 8 bytes in length
5399 instead of 4.
5400
5401 An older, non-standard 64-bit format is also handled by this
5402 function. The older format in question stores the initial length
5403 as an 8-byte quantity without an escape value. Lengths greater
5404 than 2^32 aren't very common which means that the initial 4 bytes
5405 is almost always zero. Since a length value of zero doesn't make
5406 sense for the 32-bit format, this initial zero can be considered to
5407 be an escape value which indicates the presence of the older 64-bit
5408 format. As written, the code can't detect (old format) lengths
5409 greater than 4GB. If it becomes necessary to handle lengths somewhat
5410 larger than 4GB, we could allow other small values (such as the
5411 non-sensical values of 1, 2, and 3) to also be used as escape values
5412 indicating the presence of the old format.
5413
5414 The value returned via bytes_read should be used to increment
5415 the relevant pointer after calling read_initial_length().
5416
5417 As a side effect, this function sets the fields initial_length_size
5418 and offset_size in cu_header to the values appropriate for the
5419 length field. (The format of the initial length field determines
5420 the width of file offsets to be fetched later with fetch_offset().)
5421
5422 [ Note: read_initial_length() and read_offset() are based on the
5423 document entitled "DWARF Debugging Information Format", revision
5424 3, draft 8, dated November 19, 2001. This document was obtained
5425 from:
5426
5427 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5428
5429 This document is only a draft and is subject to change. (So beware.)
5430
5431 Details regarding the older, non-standard 64-bit format were
5432 determined empirically by examining 64-bit ELF files produced
5433 by the SGI toolchain on an IRIX 6.5 machine.
5434
5435 - Kevin, July 16, 2002
5436 ] */
5437
5438 static LONGEST
5439 read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header,
5440 int *bytes_read)
5441 {
5442 LONGEST retval = 0;
5443
5444 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5445
5446 if (retval == 0xffffffff)
5447 {
5448 retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
5449 *bytes_read = 12;
5450 if (cu_header != NULL)
5451 {
5452 cu_header->initial_length_size = 12;
5453 cu_header->offset_size = 8;
5454 }
5455 }
5456 else if (retval == 0)
5457 {
5458 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5459 by IRIX. */
5460 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5461 *bytes_read = 8;
5462 if (cu_header != NULL)
5463 {
5464 cu_header->initial_length_size = 8;
5465 cu_header->offset_size = 8;
5466 }
5467 }
5468 else
5469 {
5470 *bytes_read = 4;
5471 if (cu_header != NULL)
5472 {
5473 cu_header->initial_length_size = 4;
5474 cu_header->offset_size = 4;
5475 }
5476 }
5477
5478 return retval;
5479 }
5480
5481 /* Read an offset from the data stream. The size of the offset is
5482 given by cu_header->offset_size. */
5483
5484 static LONGEST
5485 read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header,
5486 int *bytes_read)
5487 {
5488 LONGEST retval = 0;
5489
5490 switch (cu_header->offset_size)
5491 {
5492 case 4:
5493 retval = bfd_get_32 (abfd, (bfd_byte *) buf);
5494 *bytes_read = 4;
5495 break;
5496 case 8:
5497 retval = bfd_get_64 (abfd, (bfd_byte *) buf);
5498 *bytes_read = 8;
5499 break;
5500 default:
5501 internal_error (__FILE__, __LINE__,
5502 "read_offset: bad switch [in module %s]",
5503 bfd_get_filename (abfd));
5504 }
5505
5506 return retval;
5507 }
5508
5509 static char *
5510 read_n_bytes (bfd *abfd, char *buf, unsigned int size)
5511 {
5512 /* If the size of a host char is 8 bits, we can return a pointer
5513 to the buffer, otherwise we have to copy the data to a buffer
5514 allocated on the temporary obstack. */
5515 gdb_assert (HOST_CHAR_BIT == 8);
5516 return buf;
5517 }
5518
5519 static char *
5520 read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5521 {
5522 /* If the size of a host char is 8 bits, we can return a pointer
5523 to the string, otherwise we have to copy the string to a buffer
5524 allocated on the temporary obstack. */
5525 gdb_assert (HOST_CHAR_BIT == 8);
5526 if (*buf == '\0')
5527 {
5528 *bytes_read_ptr = 1;
5529 return NULL;
5530 }
5531 *bytes_read_ptr = strlen (buf) + 1;
5532 return buf;
5533 }
5534
5535 static char *
5536 read_indirect_string (bfd *abfd, char *buf,
5537 const struct comp_unit_head *cu_header,
5538 unsigned int *bytes_read_ptr)
5539 {
5540 LONGEST str_offset = read_offset (abfd, buf, cu_header,
5541 (int *) bytes_read_ptr);
5542
5543 if (dwarf2_per_objfile->str_buffer == NULL)
5544 {
5545 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5546 bfd_get_filename (abfd));
5547 return NULL;
5548 }
5549 if (str_offset >= dwarf2_per_objfile->str_size)
5550 {
5551 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5552 bfd_get_filename (abfd));
5553 return NULL;
5554 }
5555 gdb_assert (HOST_CHAR_BIT == 8);
5556 if (dwarf2_per_objfile->str_buffer[str_offset] == '\0')
5557 return NULL;
5558 return dwarf2_per_objfile->str_buffer + str_offset;
5559 }
5560
5561 static unsigned long
5562 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5563 {
5564 unsigned long result;
5565 unsigned int num_read;
5566 int i, shift;
5567 unsigned char byte;
5568
5569 result = 0;
5570 shift = 0;
5571 num_read = 0;
5572 i = 0;
5573 while (1)
5574 {
5575 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5576 buf++;
5577 num_read++;
5578 result |= ((unsigned long)(byte & 127) << shift);
5579 if ((byte & 128) == 0)
5580 {
5581 break;
5582 }
5583 shift += 7;
5584 }
5585 *bytes_read_ptr = num_read;
5586 return result;
5587 }
5588
5589 static long
5590 read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
5591 {
5592 long result;
5593 int i, shift, size, num_read;
5594 unsigned char byte;
5595
5596 result = 0;
5597 shift = 0;
5598 size = 32;
5599 num_read = 0;
5600 i = 0;
5601 while (1)
5602 {
5603 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5604 buf++;
5605 num_read++;
5606 result |= ((long)(byte & 127) << shift);
5607 shift += 7;
5608 if ((byte & 128) == 0)
5609 {
5610 break;
5611 }
5612 }
5613 if ((shift < size) && (byte & 0x40))
5614 {
5615 result |= -(1 << shift);
5616 }
5617 *bytes_read_ptr = num_read;
5618 return result;
5619 }
5620
5621 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5622
5623 static char *
5624 skip_leb128 (bfd *abfd, char *buf)
5625 {
5626 int byte;
5627
5628 while (1)
5629 {
5630 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
5631 buf++;
5632 if ((byte & 128) == 0)
5633 return buf;
5634 }
5635 }
5636
5637 static void
5638 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
5639 {
5640 switch (lang)
5641 {
5642 case DW_LANG_C89:
5643 case DW_LANG_C:
5644 cu->language = language_c;
5645 break;
5646 case DW_LANG_C_plus_plus:
5647 cu->language = language_cplus;
5648 break;
5649 case DW_LANG_Fortran77:
5650 case DW_LANG_Fortran90:
5651 case DW_LANG_Fortran95:
5652 cu->language = language_fortran;
5653 break;
5654 case DW_LANG_Mips_Assembler:
5655 cu->language = language_asm;
5656 break;
5657 case DW_LANG_Java:
5658 cu->language = language_java;
5659 break;
5660 case DW_LANG_Ada83:
5661 case DW_LANG_Ada95:
5662 case DW_LANG_Cobol74:
5663 case DW_LANG_Cobol85:
5664 case DW_LANG_Pascal83:
5665 case DW_LANG_Modula2:
5666 default:
5667 cu->language = language_minimal;
5668 break;
5669 }
5670 cu->language_defn = language_def (cu->language);
5671 }
5672
5673 /* Return the named attribute or NULL if not there. */
5674
5675 static struct attribute *
5676 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
5677 {
5678 unsigned int i;
5679 struct attribute *spec = NULL;
5680
5681 for (i = 0; i < die->num_attrs; ++i)
5682 {
5683 if (die->attrs[i].name == name)
5684 {
5685 return &die->attrs[i];
5686 }
5687 if (die->attrs[i].name == DW_AT_specification
5688 || die->attrs[i].name == DW_AT_abstract_origin)
5689 spec = &die->attrs[i];
5690 }
5691 if (spec)
5692 {
5693 struct die_info *ref_die =
5694 follow_die_ref (dwarf2_get_ref_die_offset (spec, cu));
5695
5696 if (ref_die)
5697 return dwarf2_attr (ref_die, name, cu);
5698 }
5699
5700 return NULL;
5701 }
5702
5703 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5704 and holds a non-zero value. This function should only be used for
5705 DW_FORM_flag attributes. */
5706
5707 static int
5708 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
5709 {
5710 struct attribute *attr = dwarf2_attr (die, name, cu);
5711
5712 return (attr && DW_UNSND (attr));
5713 }
5714
5715 static int
5716 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
5717 {
5718 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5719 which value is non-zero. However, we have to be careful with
5720 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5721 (via dwarf2_flag_true_p) follows this attribute. So we may
5722 end up accidently finding a declaration attribute that belongs
5723 to a different DIE referenced by the specification attribute,
5724 even though the given DIE does not have a declaration attribute. */
5725 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
5726 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
5727 }
5728
5729 /* Return the die giving the specification for DIE, if there is
5730 one. */
5731
5732 static struct die_info *
5733 die_specification (struct die_info *die, struct dwarf2_cu *cu)
5734 {
5735 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu);
5736
5737 if (spec_attr == NULL)
5738 return NULL;
5739 else
5740 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu));
5741 }
5742
5743 /* Free the line_header structure *LH, and any arrays and strings it
5744 refers to. */
5745 static void
5746 free_line_header (struct line_header *lh)
5747 {
5748 if (lh->standard_opcode_lengths)
5749 xfree (lh->standard_opcode_lengths);
5750
5751 /* Remember that all the lh->file_names[i].name pointers are
5752 pointers into debug_line_buffer, and don't need to be freed. */
5753 if (lh->file_names)
5754 xfree (lh->file_names);
5755
5756 /* Similarly for the include directory names. */
5757 if (lh->include_dirs)
5758 xfree (lh->include_dirs);
5759
5760 xfree (lh);
5761 }
5762
5763
5764 /* Add an entry to LH's include directory table. */
5765 static void
5766 add_include_dir (struct line_header *lh, char *include_dir)
5767 {
5768 /* Grow the array if necessary. */
5769 if (lh->include_dirs_size == 0)
5770 {
5771 lh->include_dirs_size = 1; /* for testing */
5772 lh->include_dirs = xmalloc (lh->include_dirs_size
5773 * sizeof (*lh->include_dirs));
5774 }
5775 else if (lh->num_include_dirs >= lh->include_dirs_size)
5776 {
5777 lh->include_dirs_size *= 2;
5778 lh->include_dirs = xrealloc (lh->include_dirs,
5779 (lh->include_dirs_size
5780 * sizeof (*lh->include_dirs)));
5781 }
5782
5783 lh->include_dirs[lh->num_include_dirs++] = include_dir;
5784 }
5785
5786
5787 /* Add an entry to LH's file name table. */
5788 static void
5789 add_file_name (struct line_header *lh,
5790 char *name,
5791 unsigned int dir_index,
5792 unsigned int mod_time,
5793 unsigned int length)
5794 {
5795 struct file_entry *fe;
5796
5797 /* Grow the array if necessary. */
5798 if (lh->file_names_size == 0)
5799 {
5800 lh->file_names_size = 1; /* for testing */
5801 lh->file_names = xmalloc (lh->file_names_size
5802 * sizeof (*lh->file_names));
5803 }
5804 else if (lh->num_file_names >= lh->file_names_size)
5805 {
5806 lh->file_names_size *= 2;
5807 lh->file_names = xrealloc (lh->file_names,
5808 (lh->file_names_size
5809 * sizeof (*lh->file_names)));
5810 }
5811
5812 fe = &lh->file_names[lh->num_file_names++];
5813 fe->name = name;
5814 fe->dir_index = dir_index;
5815 fe->mod_time = mod_time;
5816 fe->length = length;
5817 fe->included_p = 0;
5818 }
5819
5820
5821 /* Read the statement program header starting at OFFSET in
5822 .debug_line, according to the endianness of ABFD. Return a pointer
5823 to a struct line_header, allocated using xmalloc.
5824
5825 NOTE: the strings in the include directory and file name tables of
5826 the returned object point into debug_line_buffer, and must not be
5827 freed. */
5828 static struct line_header *
5829 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
5830 struct dwarf2_cu *cu)
5831 {
5832 struct cleanup *back_to;
5833 struct line_header *lh;
5834 char *line_ptr;
5835 int bytes_read;
5836 int i;
5837 char *cur_dir, *cur_file;
5838
5839 if (dwarf2_per_objfile->line_buffer == NULL)
5840 {
5841 complaint (&symfile_complaints, "missing .debug_line section");
5842 return 0;
5843 }
5844
5845 /* Make sure that at least there's room for the total_length field. That
5846 could be 12 bytes long, but we're just going to fudge that. */
5847 if (offset + 4 >= dwarf2_per_objfile->line_size)
5848 {
5849 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5850 return 0;
5851 }
5852
5853 lh = xmalloc (sizeof (*lh));
5854 memset (lh, 0, sizeof (*lh));
5855 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
5856 (void *) lh);
5857
5858 line_ptr = dwarf2_per_objfile->line_buffer + offset;
5859
5860 /* read in the header */
5861 lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read);
5862 line_ptr += bytes_read;
5863 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer
5864 + dwarf2_per_objfile->line_size))
5865 {
5866 dwarf2_statement_list_fits_in_line_number_section_complaint ();
5867 return 0;
5868 }
5869 lh->statement_program_end = line_ptr + lh->total_length;
5870 lh->version = read_2_bytes (abfd, line_ptr);
5871 line_ptr += 2;
5872 lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read);
5873 line_ptr += bytes_read;
5874 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
5875 line_ptr += 1;
5876 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
5877 line_ptr += 1;
5878 lh->line_base = read_1_signed_byte (abfd, line_ptr);
5879 line_ptr += 1;
5880 lh->line_range = read_1_byte (abfd, line_ptr);
5881 line_ptr += 1;
5882 lh->opcode_base = read_1_byte (abfd, line_ptr);
5883 line_ptr += 1;
5884 lh->standard_opcode_lengths
5885 = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char));
5886
5887 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
5888 for (i = 1; i < lh->opcode_base; ++i)
5889 {
5890 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
5891 line_ptr += 1;
5892 }
5893
5894 /* Read directory table */
5895 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5896 {
5897 line_ptr += bytes_read;
5898 add_include_dir (lh, cur_dir);
5899 }
5900 line_ptr += bytes_read;
5901
5902 /* Read file name table */
5903 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
5904 {
5905 unsigned int dir_index, mod_time, length;
5906
5907 line_ptr += bytes_read;
5908 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5909 line_ptr += bytes_read;
5910 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5911 line_ptr += bytes_read;
5912 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
5913 line_ptr += bytes_read;
5914
5915 add_file_name (lh, cur_file, dir_index, mod_time, length);
5916 }
5917 line_ptr += bytes_read;
5918 lh->statement_program_start = line_ptr;
5919
5920 if (line_ptr > (dwarf2_per_objfile->line_buffer
5921 + dwarf2_per_objfile->line_size))
5922 complaint (&symfile_complaints,
5923 "line number info header doesn't fit in `.debug_line' section");
5924
5925 discard_cleanups (back_to);
5926 return lh;
5927 }
5928
5929 /* This function exists to work around a bug in certain compilers
5930 (particularly GCC 2.95), in which the first line number marker of a
5931 function does not show up until after the prologue, right before
5932 the second line number marker. This function shifts ADDRESS down
5933 to the beginning of the function if necessary, and is called on
5934 addresses passed to record_line. */
5935
5936 static CORE_ADDR
5937 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
5938 {
5939 struct function_range *fn;
5940
5941 /* Find the function_range containing address. */
5942 if (!cu->first_fn)
5943 return address;
5944
5945 if (!cu->cached_fn)
5946 cu->cached_fn = cu->first_fn;
5947
5948 fn = cu->cached_fn;
5949 while (fn)
5950 if (fn->lowpc <= address && fn->highpc > address)
5951 goto found;
5952 else
5953 fn = fn->next;
5954
5955 fn = cu->first_fn;
5956 while (fn && fn != cu->cached_fn)
5957 if (fn->lowpc <= address && fn->highpc > address)
5958 goto found;
5959 else
5960 fn = fn->next;
5961
5962 return address;
5963
5964 found:
5965 if (fn->seen_line)
5966 return address;
5967 if (address != fn->lowpc)
5968 complaint (&symfile_complaints,
5969 "misplaced first line number at 0x%lx for '%s'",
5970 (unsigned long) address, fn->name);
5971 fn->seen_line = 1;
5972 return fn->lowpc;
5973 }
5974
5975 /* Decode the Line Number Program (LNP) for the given line_header
5976 structure and CU. The actual information extracted and the type
5977 of structures created from the LNP depends on the value of PST.
5978
5979 1. If PST is NULL, then this procedure uses the data from the program
5980 to create all necessary symbol tables, and their linetables.
5981 The compilation directory of the file is passed in COMP_DIR,
5982 and must not be NULL.
5983
5984 2. If PST is not NULL, this procedure reads the program to determine
5985 the list of files included by the unit represented by PST, and
5986 builds all the associated partial symbol tables. In this case,
5987 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
5988 is not used to compute the full name of the symtab, and therefore
5989 omitting it when building the partial symtab does not introduce
5990 the potential for inconsistency - a partial symtab and its associated
5991 symbtab having a different fullname -). */
5992
5993 static void
5994 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
5995 struct dwarf2_cu *cu, struct partial_symtab *pst)
5996 {
5997 char *line_ptr;
5998 char *line_end;
5999 unsigned int bytes_read;
6000 unsigned char op_code, extended_op, adj_opcode;
6001 CORE_ADDR baseaddr;
6002 struct objfile *objfile = cu->objfile;
6003 const int decode_for_pst_p = (pst != NULL);
6004
6005 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6006
6007 line_ptr = lh->statement_program_start;
6008 line_end = lh->statement_program_end;
6009
6010 /* Read the statement sequences until there's nothing left. */
6011 while (line_ptr < line_end)
6012 {
6013 /* state machine registers */
6014 CORE_ADDR address = 0;
6015 unsigned int file = 1;
6016 unsigned int line = 1;
6017 unsigned int column = 0;
6018 int is_stmt = lh->default_is_stmt;
6019 int basic_block = 0;
6020 int end_sequence = 0;
6021
6022 if (!decode_for_pst_p && lh->num_file_names >= file)
6023 {
6024 /* Start a subfile for the current file of the state machine. */
6025 /* lh->include_dirs and lh->file_names are 0-based, but the
6026 directory and file name numbers in the statement program
6027 are 1-based. */
6028 struct file_entry *fe = &lh->file_names[file - 1];
6029 char *dir;
6030 if (fe->dir_index)
6031 dir = lh->include_dirs[fe->dir_index - 1];
6032 else
6033 dir = comp_dir;
6034 dwarf2_start_subfile (fe->name, dir);
6035 }
6036
6037 /* Decode the table. */
6038 while (!end_sequence)
6039 {
6040 op_code = read_1_byte (abfd, line_ptr);
6041 line_ptr += 1;
6042
6043 if (op_code >= lh->opcode_base)
6044 { /* Special operand. */
6045 adj_opcode = op_code - lh->opcode_base;
6046 address += (adj_opcode / lh->line_range)
6047 * lh->minimum_instruction_length;
6048 line += lh->line_base + (adj_opcode % lh->line_range);
6049 lh->file_names[file - 1].included_p = 1;
6050 if (!decode_for_pst_p)
6051 {
6052 /* append row to matrix using current values */
6053 record_line (current_subfile, line,
6054 check_cu_functions (address, cu));
6055 }
6056 basic_block = 1;
6057 }
6058 else switch (op_code)
6059 {
6060 case DW_LNS_extended_op:
6061 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6062 line_ptr += bytes_read;
6063 extended_op = read_1_byte (abfd, line_ptr);
6064 line_ptr += 1;
6065 switch (extended_op)
6066 {
6067 case DW_LNE_end_sequence:
6068 end_sequence = 1;
6069 lh->file_names[file - 1].included_p = 1;
6070 if (!decode_for_pst_p)
6071 record_line (current_subfile, 0, address);
6072 break;
6073 case DW_LNE_set_address:
6074 address = read_address (abfd, line_ptr, cu, &bytes_read);
6075 line_ptr += bytes_read;
6076 address += baseaddr;
6077 break;
6078 case DW_LNE_define_file:
6079 {
6080 char *cur_file;
6081 unsigned int dir_index, mod_time, length;
6082
6083 cur_file = read_string (abfd, line_ptr, &bytes_read);
6084 line_ptr += bytes_read;
6085 dir_index =
6086 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6087 line_ptr += bytes_read;
6088 mod_time =
6089 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6090 line_ptr += bytes_read;
6091 length =
6092 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6093 line_ptr += bytes_read;
6094 add_file_name (lh, cur_file, dir_index, mod_time, length);
6095 }
6096 break;
6097 default:
6098 complaint (&symfile_complaints,
6099 "mangled .debug_line section");
6100 return;
6101 }
6102 break;
6103 case DW_LNS_copy:
6104 lh->file_names[file - 1].included_p = 1;
6105 if (!decode_for_pst_p)
6106 record_line (current_subfile, line,
6107 check_cu_functions (address, cu));
6108 basic_block = 0;
6109 break;
6110 case DW_LNS_advance_pc:
6111 address += lh->minimum_instruction_length
6112 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6113 line_ptr += bytes_read;
6114 break;
6115 case DW_LNS_advance_line:
6116 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
6117 line_ptr += bytes_read;
6118 break;
6119 case DW_LNS_set_file:
6120 {
6121 /* lh->include_dirs and lh->file_names are 0-based,
6122 but the directory and file name numbers in the
6123 statement program are 1-based. */
6124 struct file_entry *fe;
6125 char *dir;
6126 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6127 line_ptr += bytes_read;
6128 fe = &lh->file_names[file - 1];
6129 if (fe->dir_index)
6130 dir = lh->include_dirs[fe->dir_index - 1];
6131 else
6132 dir = comp_dir;
6133 if (!decode_for_pst_p)
6134 dwarf2_start_subfile (fe->name, dir);
6135 }
6136 break;
6137 case DW_LNS_set_column:
6138 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6139 line_ptr += bytes_read;
6140 break;
6141 case DW_LNS_negate_stmt:
6142 is_stmt = (!is_stmt);
6143 break;
6144 case DW_LNS_set_basic_block:
6145 basic_block = 1;
6146 break;
6147 /* Add to the address register of the state machine the
6148 address increment value corresponding to special opcode
6149 255. Ie, this value is scaled by the minimum instruction
6150 length since special opcode 255 would have scaled the
6151 the increment. */
6152 case DW_LNS_const_add_pc:
6153 address += (lh->minimum_instruction_length
6154 * ((255 - lh->opcode_base) / lh->line_range));
6155 break;
6156 case DW_LNS_fixed_advance_pc:
6157 address += read_2_bytes (abfd, line_ptr);
6158 line_ptr += 2;
6159 break;
6160 default:
6161 { /* Unknown standard opcode, ignore it. */
6162 int i;
6163 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
6164 {
6165 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
6166 line_ptr += bytes_read;
6167 }
6168 }
6169 }
6170 }
6171 }
6172
6173 if (decode_for_pst_p)
6174 {
6175 int file_index;
6176
6177 /* Now that we're done scanning the Line Header Program, we can
6178 create the psymtab of each included file. */
6179 for (file_index = 0; file_index < lh->num_file_names; file_index++)
6180 if (lh->file_names[file_index].included_p == 1)
6181 {
6182 char *include_name = lh->file_names [file_index].name;
6183
6184 if (strcmp (include_name, pst->filename) != 0)
6185 dwarf2_create_include_psymtab (include_name, pst, objfile);
6186 }
6187 }
6188 }
6189
6190 /* Start a subfile for DWARF. FILENAME is the name of the file and
6191 DIRNAME the name of the source directory which contains FILENAME
6192 or NULL if not known.
6193 This routine tries to keep line numbers from identical absolute and
6194 relative file names in a common subfile.
6195
6196 Using the `list' example from the GDB testsuite, which resides in
6197 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6198 of /srcdir/list0.c yields the following debugging information for list0.c:
6199
6200 DW_AT_name: /srcdir/list0.c
6201 DW_AT_comp_dir: /compdir
6202 files.files[0].name: list0.h
6203 files.files[0].dir: /srcdir
6204 files.files[1].name: list0.c
6205 files.files[1].dir: /srcdir
6206
6207 The line number information for list0.c has to end up in a single
6208 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6209
6210 static void
6211 dwarf2_start_subfile (char *filename, char *dirname)
6212 {
6213 /* If the filename isn't absolute, try to match an existing subfile
6214 with the full pathname. */
6215
6216 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
6217 {
6218 struct subfile *subfile;
6219 char *fullname = concat (dirname, "/", filename, NULL);
6220
6221 for (subfile = subfiles; subfile; subfile = subfile->next)
6222 {
6223 if (FILENAME_CMP (subfile->name, fullname) == 0)
6224 {
6225 current_subfile = subfile;
6226 xfree (fullname);
6227 return;
6228 }
6229 }
6230 xfree (fullname);
6231 }
6232 start_subfile (filename, dirname);
6233 }
6234
6235 static void
6236 var_decode_location (struct attribute *attr, struct symbol *sym,
6237 struct dwarf2_cu *cu)
6238 {
6239 struct objfile *objfile = cu->objfile;
6240 struct comp_unit_head *cu_header = &cu->header;
6241
6242 /* NOTE drow/2003-01-30: There used to be a comment and some special
6243 code here to turn a symbol with DW_AT_external and a
6244 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6245 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6246 with some versions of binutils) where shared libraries could have
6247 relocations against symbols in their debug information - the
6248 minimal symbol would have the right address, but the debug info
6249 would not. It's no longer necessary, because we will explicitly
6250 apply relocations when we read in the debug information now. */
6251
6252 /* A DW_AT_location attribute with no contents indicates that a
6253 variable has been optimized away. */
6254 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
6255 {
6256 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
6257 return;
6258 }
6259
6260 /* Handle one degenerate form of location expression specially, to
6261 preserve GDB's previous behavior when section offsets are
6262 specified. If this is just a DW_OP_addr then mark this symbol
6263 as LOC_STATIC. */
6264
6265 if (attr_form_is_block (attr)
6266 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
6267 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
6268 {
6269 int dummy;
6270
6271 SYMBOL_VALUE_ADDRESS (sym) =
6272 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
6273 fixup_symbol_section (sym, objfile);
6274 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
6275 SYMBOL_SECTION (sym));
6276 SYMBOL_CLASS (sym) = LOC_STATIC;
6277 return;
6278 }
6279
6280 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6281 expression evaluator, and use LOC_COMPUTED only when necessary
6282 (i.e. when the value of a register or memory location is
6283 referenced, or a thread-local block, etc.). Then again, it might
6284 not be worthwhile. I'm assuming that it isn't unless performance
6285 or memory numbers show me otherwise. */
6286
6287 dwarf2_symbol_mark_computed (attr, sym, cu);
6288 SYMBOL_CLASS (sym) = LOC_COMPUTED;
6289 }
6290
6291 /* Given a pointer to a DWARF information entry, figure out if we need
6292 to make a symbol table entry for it, and if so, create a new entry
6293 and return a pointer to it.
6294 If TYPE is NULL, determine symbol type from the die, otherwise
6295 used the passed type. */
6296
6297 static struct symbol *
6298 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
6299 {
6300 struct objfile *objfile = cu->objfile;
6301 struct symbol *sym = NULL;
6302 char *name;
6303 struct attribute *attr = NULL;
6304 struct attribute *attr2 = NULL;
6305 CORE_ADDR baseaddr;
6306
6307 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6308
6309 if (die->tag != DW_TAG_namespace)
6310 name = dwarf2_linkage_name (die, cu);
6311 else
6312 name = TYPE_NAME (type);
6313
6314 if (name)
6315 {
6316 sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
6317 sizeof (struct symbol));
6318 OBJSTAT (objfile, n_syms++);
6319 memset (sym, 0, sizeof (struct symbol));
6320
6321 /* Cache this symbol's name and the name's demangled form (if any). */
6322 SYMBOL_LANGUAGE (sym) = cu->language;
6323 SYMBOL_SET_NAMES (sym, name, strlen (name), objfile);
6324
6325 /* Default assumptions.
6326 Use the passed type or decode it from the die. */
6327 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6328 SYMBOL_CLASS (sym) = LOC_STATIC;
6329 if (type != NULL)
6330 SYMBOL_TYPE (sym) = type;
6331 else
6332 SYMBOL_TYPE (sym) = die_type (die, cu);
6333 attr = dwarf2_attr (die, DW_AT_decl_line, cu);
6334 if (attr)
6335 {
6336 SYMBOL_LINE (sym) = DW_UNSND (attr);
6337 }
6338 switch (die->tag)
6339 {
6340 case DW_TAG_label:
6341 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6342 if (attr)
6343 {
6344 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
6345 }
6346 SYMBOL_CLASS (sym) = LOC_LABEL;
6347 break;
6348 case DW_TAG_subprogram:
6349 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6350 finish_block. */
6351 SYMBOL_CLASS (sym) = LOC_BLOCK;
6352 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6353 if (attr2 && (DW_UNSND (attr2) != 0))
6354 {
6355 add_symbol_to_list (sym, &global_symbols);
6356 }
6357 else
6358 {
6359 add_symbol_to_list (sym, cu->list_in_scope);
6360 }
6361 break;
6362 case DW_TAG_variable:
6363 /* Compilation with minimal debug info may result in variables
6364 with missing type entries. Change the misleading `void' type
6365 to something sensible. */
6366 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
6367 SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT,
6368 TARGET_INT_BIT / HOST_CHAR_BIT, 0,
6369 "<variable, no debug info>",
6370 objfile);
6371 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6372 if (attr)
6373 {
6374 dwarf2_const_value (attr, sym, cu);
6375 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6376 if (attr2 && (DW_UNSND (attr2) != 0))
6377 add_symbol_to_list (sym, &global_symbols);
6378 else
6379 add_symbol_to_list (sym, cu->list_in_scope);
6380 break;
6381 }
6382 attr = dwarf2_attr (die, DW_AT_location, cu);
6383 if (attr)
6384 {
6385 var_decode_location (attr, sym, cu);
6386 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6387 if (attr2 && (DW_UNSND (attr2) != 0))
6388 add_symbol_to_list (sym, &global_symbols);
6389 else
6390 add_symbol_to_list (sym, cu->list_in_scope);
6391 }
6392 else
6393 {
6394 /* We do not know the address of this symbol.
6395 If it is an external symbol and we have type information
6396 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6397 The address of the variable will then be determined from
6398 the minimal symbol table whenever the variable is
6399 referenced. */
6400 attr2 = dwarf2_attr (die, DW_AT_external, cu);
6401 if (attr2 && (DW_UNSND (attr2) != 0)
6402 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
6403 {
6404 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
6405 add_symbol_to_list (sym, &global_symbols);
6406 }
6407 }
6408 break;
6409 case DW_TAG_formal_parameter:
6410 attr = dwarf2_attr (die, DW_AT_location, cu);
6411 if (attr)
6412 {
6413 var_decode_location (attr, sym, cu);
6414 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6415 if (SYMBOL_CLASS (sym) == LOC_COMPUTED)
6416 SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG;
6417 }
6418 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6419 if (attr)
6420 {
6421 dwarf2_const_value (attr, sym, cu);
6422 }
6423 add_symbol_to_list (sym, cu->list_in_scope);
6424 break;
6425 case DW_TAG_unspecified_parameters:
6426 /* From varargs functions; gdb doesn't seem to have any
6427 interest in this information, so just ignore it for now.
6428 (FIXME?) */
6429 break;
6430 case DW_TAG_class_type:
6431 case DW_TAG_structure_type:
6432 case DW_TAG_union_type:
6433 case DW_TAG_enumeration_type:
6434 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6435 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6436
6437 /* Make sure that the symbol includes appropriate enclosing
6438 classes/namespaces in its name. These are calculated in
6439 read_structure_type, and the correct name is saved in
6440 the type. */
6441
6442 if (cu->language == language_cplus
6443 || cu->language == language_java)
6444 {
6445 struct type *type = SYMBOL_TYPE (sym);
6446
6447 if (TYPE_TAG_NAME (type) != NULL)
6448 {
6449 /* FIXME: carlton/2003-11-10: Should this use
6450 SYMBOL_SET_NAMES instead? (The same problem also
6451 arises further down in this function.) */
6452 /* The type's name is already allocated along with
6453 this objfile, so we don't need to duplicate it
6454 for the symbol. */
6455 SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type);
6456 }
6457 }
6458
6459 {
6460 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6461 really ever be static objects: otherwise, if you try
6462 to, say, break of a class's method and you're in a file
6463 which doesn't mention that class, it won't work unless
6464 the check for all static symbols in lookup_symbol_aux
6465 saves you. See the OtherFileClass tests in
6466 gdb.c++/namespace.exp. */
6467
6468 struct pending **list_to_add;
6469
6470 list_to_add = (cu->list_in_scope == &file_symbols
6471 && (cu->language == language_cplus
6472 || cu->language == language_java)
6473 ? &global_symbols : cu->list_in_scope);
6474
6475 add_symbol_to_list (sym, list_to_add);
6476
6477 /* The semantics of C++ state that "struct foo { ... }" also
6478 defines a typedef for "foo". A Java class declaration also
6479 defines a typedef for the class. Synthesize a typedef symbol
6480 so that "ptype foo" works as expected. */
6481 if (cu->language == language_cplus
6482 || cu->language == language_java)
6483 {
6484 struct symbol *typedef_sym = (struct symbol *)
6485 obstack_alloc (&objfile->objfile_obstack,
6486 sizeof (struct symbol));
6487 *typedef_sym = *sym;
6488 SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
6489 /* The symbol's name is already allocated along with
6490 this objfile, so we don't need to duplicate it for
6491 the type. */
6492 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
6493 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym);
6494 add_symbol_to_list (typedef_sym, list_to_add);
6495 }
6496 }
6497 break;
6498 case DW_TAG_typedef:
6499 if (processing_has_namespace_info
6500 && processing_current_prefix[0] != '\0')
6501 {
6502 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6503 processing_current_prefix,
6504 name, cu);
6505 }
6506 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6507 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6508 add_symbol_to_list (sym, cu->list_in_scope);
6509 break;
6510 case DW_TAG_base_type:
6511 case DW_TAG_subrange_type:
6512 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6513 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
6514 add_symbol_to_list (sym, cu->list_in_scope);
6515 break;
6516 case DW_TAG_enumerator:
6517 if (processing_has_namespace_info
6518 && processing_current_prefix[0] != '\0')
6519 {
6520 SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack,
6521 processing_current_prefix,
6522 name, cu);
6523 }
6524 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6525 if (attr)
6526 {
6527 dwarf2_const_value (attr, sym, cu);
6528 }
6529 {
6530 /* NOTE: carlton/2003-11-10: See comment above in the
6531 DW_TAG_class_type, etc. block. */
6532
6533 struct pending **list_to_add;
6534
6535 list_to_add = (cu->list_in_scope == &file_symbols
6536 && (cu->language == language_cplus
6537 || cu->language == language_java)
6538 ? &global_symbols : cu->list_in_scope);
6539
6540 add_symbol_to_list (sym, list_to_add);
6541 }
6542 break;
6543 case DW_TAG_namespace:
6544 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6545 add_symbol_to_list (sym, &global_symbols);
6546 break;
6547 default:
6548 /* Not a tag we recognize. Hopefully we aren't processing
6549 trash data, but since we must specifically ignore things
6550 we don't recognize, there is nothing else we should do at
6551 this point. */
6552 complaint (&symfile_complaints, "unsupported tag: '%s'",
6553 dwarf_tag_name (die->tag));
6554 break;
6555 }
6556 }
6557 return (sym);
6558 }
6559
6560 /* Copy constant value from an attribute to a symbol. */
6561
6562 static void
6563 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
6564 struct dwarf2_cu *cu)
6565 {
6566 struct objfile *objfile = cu->objfile;
6567 struct comp_unit_head *cu_header = &cu->header;
6568 struct dwarf_block *blk;
6569
6570 switch (attr->form)
6571 {
6572 case DW_FORM_addr:
6573 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size)
6574 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6575 cu_header->addr_size,
6576 TYPE_LENGTH (SYMBOL_TYPE
6577 (sym)));
6578 SYMBOL_VALUE_BYTES (sym) = (char *)
6579 obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
6580 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6581 it's body - store_unsigned_integer. */
6582 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
6583 DW_ADDR (attr));
6584 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6585 break;
6586 case DW_FORM_block1:
6587 case DW_FORM_block2:
6588 case DW_FORM_block4:
6589 case DW_FORM_block:
6590 blk = DW_BLOCK (attr);
6591 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size)
6592 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym),
6593 blk->size,
6594 TYPE_LENGTH (SYMBOL_TYPE
6595 (sym)));
6596 SYMBOL_VALUE_BYTES (sym) = (char *)
6597 obstack_alloc (&objfile->objfile_obstack, blk->size);
6598 memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
6599 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
6600 break;
6601
6602 /* The DW_AT_const_value attributes are supposed to carry the
6603 symbol's value "represented as it would be on the target
6604 architecture." By the time we get here, it's already been
6605 converted to host endianness, so we just need to sign- or
6606 zero-extend it as appropriate. */
6607 case DW_FORM_data1:
6608 dwarf2_const_value_data (attr, sym, 8);
6609 break;
6610 case DW_FORM_data2:
6611 dwarf2_const_value_data (attr, sym, 16);
6612 break;
6613 case DW_FORM_data4:
6614 dwarf2_const_value_data (attr, sym, 32);
6615 break;
6616 case DW_FORM_data8:
6617 dwarf2_const_value_data (attr, sym, 64);
6618 break;
6619
6620 case DW_FORM_sdata:
6621 SYMBOL_VALUE (sym) = DW_SND (attr);
6622 SYMBOL_CLASS (sym) = LOC_CONST;
6623 break;
6624
6625 case DW_FORM_udata:
6626 SYMBOL_VALUE (sym) = DW_UNSND (attr);
6627 SYMBOL_CLASS (sym) = LOC_CONST;
6628 break;
6629
6630 default:
6631 complaint (&symfile_complaints,
6632 "unsupported const value attribute form: '%s'",
6633 dwarf_form_name (attr->form));
6634 SYMBOL_VALUE (sym) = 0;
6635 SYMBOL_CLASS (sym) = LOC_CONST;
6636 break;
6637 }
6638 }
6639
6640
6641 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6642 or zero-extend it as appropriate for the symbol's type. */
6643 static void
6644 dwarf2_const_value_data (struct attribute *attr,
6645 struct symbol *sym,
6646 int bits)
6647 {
6648 LONGEST l = DW_UNSND (attr);
6649
6650 if (bits < sizeof (l) * 8)
6651 {
6652 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym)))
6653 l &= ((LONGEST) 1 << bits) - 1;
6654 else
6655 l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits);
6656 }
6657
6658 SYMBOL_VALUE (sym) = l;
6659 SYMBOL_CLASS (sym) = LOC_CONST;
6660 }
6661
6662
6663 /* Return the type of the die in question using its DW_AT_type attribute. */
6664
6665 static struct type *
6666 die_type (struct die_info *die, struct dwarf2_cu *cu)
6667 {
6668 struct type *type;
6669 struct attribute *type_attr;
6670 struct die_info *type_die;
6671 unsigned int ref;
6672
6673 type_attr = dwarf2_attr (die, DW_AT_type, cu);
6674 if (!type_attr)
6675 {
6676 /* A missing DW_AT_type represents a void type. */
6677 return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu);
6678 }
6679 else
6680 {
6681 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6682 type_die = follow_die_ref (ref);
6683 if (!type_die)
6684 {
6685 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6686 ref, cu->objfile->name);
6687 return NULL;
6688 }
6689 }
6690 type = tag_type_to_type (type_die, cu);
6691 if (!type)
6692 {
6693 dump_die (type_die);
6694 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6695 cu->objfile->name);
6696 }
6697 return type;
6698 }
6699
6700 /* Return the containing type of the die in question using its
6701 DW_AT_containing_type attribute. */
6702
6703 static struct type *
6704 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
6705 {
6706 struct type *type = NULL;
6707 struct attribute *type_attr;
6708 struct die_info *type_die = NULL;
6709 unsigned int ref;
6710
6711 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
6712 if (type_attr)
6713 {
6714 ref = dwarf2_get_ref_die_offset (type_attr, cu);
6715 type_die = follow_die_ref (ref);
6716 if (!type_die)
6717 {
6718 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref,
6719 cu->objfile->name);
6720 return NULL;
6721 }
6722 type = tag_type_to_type (type_die, cu);
6723 }
6724 if (!type)
6725 {
6726 if (type_die)
6727 dump_die (type_die);
6728 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
6729 cu->objfile->name);
6730 }
6731 return type;
6732 }
6733
6734 #if 0
6735 static struct type *
6736 type_at_offset (unsigned int offset, struct dwarf2_cu *cu)
6737 {
6738 struct die_info *die;
6739 struct type *type;
6740
6741 die = follow_die_ref (offset);
6742 if (!die)
6743 {
6744 error ("Dwarf Error: Cannot find type referent at offset %d.", offset);
6745 return NULL;
6746 }
6747 type = tag_type_to_type (die, cu);
6748 return type;
6749 }
6750 #endif
6751
6752 static struct type *
6753 tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu)
6754 {
6755 if (die->type)
6756 {
6757 return die->type;
6758 }
6759 else
6760 {
6761 read_type_die (die, cu);
6762 if (!die->type)
6763 {
6764 dump_die (die);
6765 error ("Dwarf Error: Cannot find type of die [in module %s]",
6766 cu->objfile->name);
6767 }
6768 return die->type;
6769 }
6770 }
6771
6772 static void
6773 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
6774 {
6775 char *prefix = determine_prefix (die, cu);
6776 const char *old_prefix = processing_current_prefix;
6777 struct cleanup *back_to = make_cleanup (xfree, prefix);
6778 processing_current_prefix = prefix;
6779
6780 switch (die->tag)
6781 {
6782 case DW_TAG_class_type:
6783 case DW_TAG_structure_type:
6784 case DW_TAG_union_type:
6785 read_structure_type (die, cu);
6786 break;
6787 case DW_TAG_enumeration_type:
6788 read_enumeration_type (die, cu);
6789 break;
6790 case DW_TAG_subprogram:
6791 case DW_TAG_subroutine_type:
6792 read_subroutine_type (die, cu);
6793 break;
6794 case DW_TAG_array_type:
6795 read_array_type (die, cu);
6796 break;
6797 case DW_TAG_pointer_type:
6798 read_tag_pointer_type (die, cu);
6799 break;
6800 case DW_TAG_ptr_to_member_type:
6801 read_tag_ptr_to_member_type (die, cu);
6802 break;
6803 case DW_TAG_reference_type:
6804 read_tag_reference_type (die, cu);
6805 break;
6806 case DW_TAG_const_type:
6807 read_tag_const_type (die, cu);
6808 break;
6809 case DW_TAG_volatile_type:
6810 read_tag_volatile_type (die, cu);
6811 break;
6812 case DW_TAG_string_type:
6813 read_tag_string_type (die, cu);
6814 break;
6815 case DW_TAG_typedef:
6816 read_typedef (die, cu);
6817 break;
6818 case DW_TAG_subrange_type:
6819 read_subrange_type (die, cu);
6820 break;
6821 case DW_TAG_base_type:
6822 read_base_type (die, cu);
6823 break;
6824 default:
6825 complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'",
6826 dwarf_tag_name (die->tag));
6827 break;
6828 }
6829
6830 processing_current_prefix = old_prefix;
6831 do_cleanups (back_to);
6832 }
6833
6834 /* Return the name of the namespace/class that DIE is defined within,
6835 or "" if we can't tell. The caller should xfree the result. */
6836
6837 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
6838 therein) for an example of how to use this function to deal with
6839 DW_AT_specification. */
6840
6841 static char *
6842 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
6843 {
6844 struct die_info *parent;
6845
6846 if (cu->language != language_cplus
6847 && cu->language != language_java)
6848 return NULL;
6849
6850 parent = die->parent;
6851
6852 if (parent == NULL)
6853 {
6854 return xstrdup ("");
6855 }
6856 else
6857 {
6858 switch (parent->tag) {
6859 case DW_TAG_namespace:
6860 {
6861 /* FIXME: carlton/2004-03-05: Should I follow extension dies
6862 before doing this check? */
6863 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6864 {
6865 return xstrdup (TYPE_TAG_NAME (parent->type));
6866 }
6867 else
6868 {
6869 int dummy;
6870 char *parent_prefix = determine_prefix (parent, cu);
6871 char *retval = typename_concat (NULL, parent_prefix,
6872 namespace_name (parent, &dummy,
6873 cu),
6874 cu);
6875 xfree (parent_prefix);
6876 return retval;
6877 }
6878 }
6879 break;
6880 case DW_TAG_class_type:
6881 case DW_TAG_structure_type:
6882 {
6883 if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL)
6884 {
6885 return xstrdup (TYPE_TAG_NAME (parent->type));
6886 }
6887 else
6888 {
6889 const char *old_prefix = processing_current_prefix;
6890 char *new_prefix = determine_prefix (parent, cu);
6891 char *retval;
6892
6893 processing_current_prefix = new_prefix;
6894 retval = determine_class_name (parent, cu);
6895 processing_current_prefix = old_prefix;
6896
6897 xfree (new_prefix);
6898 return retval;
6899 }
6900 }
6901 default:
6902 return determine_prefix (parent, cu);
6903 }
6904 }
6905 }
6906
6907 /* Return a newly-allocated string formed by concatenating PREFIX and
6908 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
6909 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
6910 perform an obconcat, otherwise allocate storage for the result. The CU argument
6911 is used to determine the language and hence, the appropriate separator. */
6912
6913 #define MAX_SEP_LEN 2 /* sizeof ("::") */
6914
6915 static char *
6916 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
6917 struct dwarf2_cu *cu)
6918 {
6919 char *sep;
6920
6921 if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0')
6922 sep = "";
6923 else if (cu->language == language_java)
6924 sep = ".";
6925 else
6926 sep = "::";
6927
6928 if (obs == NULL)
6929 {
6930 char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
6931 retval[0] = '\0';
6932
6933 if (prefix)
6934 {
6935 strcpy (retval, prefix);
6936 strcat (retval, sep);
6937 }
6938 if (suffix)
6939 strcat (retval, suffix);
6940
6941 return retval;
6942 }
6943 else
6944 {
6945 /* We have an obstack. */
6946 return obconcat (obs, prefix, sep, suffix);
6947 }
6948 }
6949
6950 static struct type *
6951 dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu)
6952 {
6953 struct objfile *objfile = cu->objfile;
6954
6955 /* FIXME - this should not produce a new (struct type *)
6956 every time. It should cache base types. */
6957 struct type *type;
6958 switch (encoding)
6959 {
6960 case DW_ATE_address:
6961 type = dwarf2_fundamental_type (objfile, FT_VOID, cu);
6962 return type;
6963 case DW_ATE_boolean:
6964 type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu);
6965 return type;
6966 case DW_ATE_complex_float:
6967 if (size == 16)
6968 {
6969 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu);
6970 }
6971 else
6972 {
6973 type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu);
6974 }
6975 return type;
6976 case DW_ATE_float:
6977 if (size == 8)
6978 {
6979 type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu);
6980 }
6981 else
6982 {
6983 type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
6984 }
6985 return type;
6986 case DW_ATE_signed:
6987 switch (size)
6988 {
6989 case 1:
6990 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
6991 break;
6992 case 2:
6993 type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu);
6994 break;
6995 default:
6996 case 4:
6997 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
6998 break;
6999 }
7000 return type;
7001 case DW_ATE_signed_char:
7002 type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu);
7003 return type;
7004 case DW_ATE_unsigned:
7005 switch (size)
7006 {
7007 case 1:
7008 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7009 break;
7010 case 2:
7011 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu);
7012 break;
7013 default:
7014 case 4:
7015 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu);
7016 break;
7017 }
7018 return type;
7019 case DW_ATE_unsigned_char:
7020 type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu);
7021 return type;
7022 default:
7023 type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu);
7024 return type;
7025 }
7026 }
7027
7028 #if 0
7029 struct die_info *
7030 copy_die (struct die_info *old_die)
7031 {
7032 struct die_info *new_die;
7033 int i, num_attrs;
7034
7035 new_die = (struct die_info *) xmalloc (sizeof (struct die_info));
7036 memset (new_die, 0, sizeof (struct die_info));
7037
7038 new_die->tag = old_die->tag;
7039 new_die->has_children = old_die->has_children;
7040 new_die->abbrev = old_die->abbrev;
7041 new_die->offset = old_die->offset;
7042 new_die->type = NULL;
7043
7044 num_attrs = old_die->num_attrs;
7045 new_die->num_attrs = num_attrs;
7046 new_die->attrs = (struct attribute *)
7047 xmalloc (num_attrs * sizeof (struct attribute));
7048
7049 for (i = 0; i < old_die->num_attrs; ++i)
7050 {
7051 new_die->attrs[i].name = old_die->attrs[i].name;
7052 new_die->attrs[i].form = old_die->attrs[i].form;
7053 new_die->attrs[i].u.addr = old_die->attrs[i].u.addr;
7054 }
7055
7056 new_die->next = NULL;
7057 return new_die;
7058 }
7059 #endif
7060
7061 /* Return sibling of die, NULL if no sibling. */
7062
7063 static struct die_info *
7064 sibling_die (struct die_info *die)
7065 {
7066 return die->sibling;
7067 }
7068
7069 /* Get linkage name of a die, return NULL if not found. */
7070
7071 static char *
7072 dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu)
7073 {
7074 struct attribute *attr;
7075
7076 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7077 if (attr && DW_STRING (attr))
7078 return DW_STRING (attr);
7079 attr = dwarf2_attr (die, DW_AT_name, cu);
7080 if (attr && DW_STRING (attr))
7081 return DW_STRING (attr);
7082 return NULL;
7083 }
7084
7085 /* Get name of a die, return NULL if not found. */
7086
7087 static char *
7088 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
7089 {
7090 struct attribute *attr;
7091
7092 attr = dwarf2_attr (die, DW_AT_name, cu);
7093 if (attr && DW_STRING (attr))
7094 return DW_STRING (attr);
7095 return NULL;
7096 }
7097
7098 /* Return the die that this die in an extension of, or NULL if there
7099 is none. */
7100
7101 static struct die_info *
7102 dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu)
7103 {
7104 struct attribute *attr;
7105 struct die_info *extension_die;
7106 unsigned int ref;
7107
7108 attr = dwarf2_attr (die, DW_AT_extension, cu);
7109 if (attr == NULL)
7110 return NULL;
7111
7112 ref = dwarf2_get_ref_die_offset (attr, cu);
7113 extension_die = follow_die_ref (ref);
7114 if (!extension_die)
7115 {
7116 error ("Dwarf Error: Cannot find referent at offset %d.", ref);
7117 }
7118
7119 return extension_die;
7120 }
7121
7122 /* Convert a DIE tag into its string name. */
7123
7124 static char *
7125 dwarf_tag_name (unsigned tag)
7126 {
7127 switch (tag)
7128 {
7129 case DW_TAG_padding:
7130 return "DW_TAG_padding";
7131 case DW_TAG_array_type:
7132 return "DW_TAG_array_type";
7133 case DW_TAG_class_type:
7134 return "DW_TAG_class_type";
7135 case DW_TAG_entry_point:
7136 return "DW_TAG_entry_point";
7137 case DW_TAG_enumeration_type:
7138 return "DW_TAG_enumeration_type";
7139 case DW_TAG_formal_parameter:
7140 return "DW_TAG_formal_parameter";
7141 case DW_TAG_imported_declaration:
7142 return "DW_TAG_imported_declaration";
7143 case DW_TAG_label:
7144 return "DW_TAG_label";
7145 case DW_TAG_lexical_block:
7146 return "DW_TAG_lexical_block";
7147 case DW_TAG_member:
7148 return "DW_TAG_member";
7149 case DW_TAG_pointer_type:
7150 return "DW_TAG_pointer_type";
7151 case DW_TAG_reference_type:
7152 return "DW_TAG_reference_type";
7153 case DW_TAG_compile_unit:
7154 return "DW_TAG_compile_unit";
7155 case DW_TAG_string_type:
7156 return "DW_TAG_string_type";
7157 case DW_TAG_structure_type:
7158 return "DW_TAG_structure_type";
7159 case DW_TAG_subroutine_type:
7160 return "DW_TAG_subroutine_type";
7161 case DW_TAG_typedef:
7162 return "DW_TAG_typedef";
7163 case DW_TAG_union_type:
7164 return "DW_TAG_union_type";
7165 case DW_TAG_unspecified_parameters:
7166 return "DW_TAG_unspecified_parameters";
7167 case DW_TAG_variant:
7168 return "DW_TAG_variant";
7169 case DW_TAG_common_block:
7170 return "DW_TAG_common_block";
7171 case DW_TAG_common_inclusion:
7172 return "DW_TAG_common_inclusion";
7173 case DW_TAG_inheritance:
7174 return "DW_TAG_inheritance";
7175 case DW_TAG_inlined_subroutine:
7176 return "DW_TAG_inlined_subroutine";
7177 case DW_TAG_module:
7178 return "DW_TAG_module";
7179 case DW_TAG_ptr_to_member_type:
7180 return "DW_TAG_ptr_to_member_type";
7181 case DW_TAG_set_type:
7182 return "DW_TAG_set_type";
7183 case DW_TAG_subrange_type:
7184 return "DW_TAG_subrange_type";
7185 case DW_TAG_with_stmt:
7186 return "DW_TAG_with_stmt";
7187 case DW_TAG_access_declaration:
7188 return "DW_TAG_access_declaration";
7189 case DW_TAG_base_type:
7190 return "DW_TAG_base_type";
7191 case DW_TAG_catch_block:
7192 return "DW_TAG_catch_block";
7193 case DW_TAG_const_type:
7194 return "DW_TAG_const_type";
7195 case DW_TAG_constant:
7196 return "DW_TAG_constant";
7197 case DW_TAG_enumerator:
7198 return "DW_TAG_enumerator";
7199 case DW_TAG_file_type:
7200 return "DW_TAG_file_type";
7201 case DW_TAG_friend:
7202 return "DW_TAG_friend";
7203 case DW_TAG_namelist:
7204 return "DW_TAG_namelist";
7205 case DW_TAG_namelist_item:
7206 return "DW_TAG_namelist_item";
7207 case DW_TAG_packed_type:
7208 return "DW_TAG_packed_type";
7209 case DW_TAG_subprogram:
7210 return "DW_TAG_subprogram";
7211 case DW_TAG_template_type_param:
7212 return "DW_TAG_template_type_param";
7213 case DW_TAG_template_value_param:
7214 return "DW_TAG_template_value_param";
7215 case DW_TAG_thrown_type:
7216 return "DW_TAG_thrown_type";
7217 case DW_TAG_try_block:
7218 return "DW_TAG_try_block";
7219 case DW_TAG_variant_part:
7220 return "DW_TAG_variant_part";
7221 case DW_TAG_variable:
7222 return "DW_TAG_variable";
7223 case DW_TAG_volatile_type:
7224 return "DW_TAG_volatile_type";
7225 case DW_TAG_dwarf_procedure:
7226 return "DW_TAG_dwarf_procedure";
7227 case DW_TAG_restrict_type:
7228 return "DW_TAG_restrict_type";
7229 case DW_TAG_interface_type:
7230 return "DW_TAG_interface_type";
7231 case DW_TAG_namespace:
7232 return "DW_TAG_namespace";
7233 case DW_TAG_imported_module:
7234 return "DW_TAG_imported_module";
7235 case DW_TAG_unspecified_type:
7236 return "DW_TAG_unspecified_type";
7237 case DW_TAG_partial_unit:
7238 return "DW_TAG_partial_unit";
7239 case DW_TAG_imported_unit:
7240 return "DW_TAG_imported_unit";
7241 case DW_TAG_MIPS_loop:
7242 return "DW_TAG_MIPS_loop";
7243 case DW_TAG_format_label:
7244 return "DW_TAG_format_label";
7245 case DW_TAG_function_template:
7246 return "DW_TAG_function_template";
7247 case DW_TAG_class_template:
7248 return "DW_TAG_class_template";
7249 default:
7250 return "DW_TAG_<unknown>";
7251 }
7252 }
7253
7254 /* Convert a DWARF attribute code into its string name. */
7255
7256 static char *
7257 dwarf_attr_name (unsigned attr)
7258 {
7259 switch (attr)
7260 {
7261 case DW_AT_sibling:
7262 return "DW_AT_sibling";
7263 case DW_AT_location:
7264 return "DW_AT_location";
7265 case DW_AT_name:
7266 return "DW_AT_name";
7267 case DW_AT_ordering:
7268 return "DW_AT_ordering";
7269 case DW_AT_subscr_data:
7270 return "DW_AT_subscr_data";
7271 case DW_AT_byte_size:
7272 return "DW_AT_byte_size";
7273 case DW_AT_bit_offset:
7274 return "DW_AT_bit_offset";
7275 case DW_AT_bit_size:
7276 return "DW_AT_bit_size";
7277 case DW_AT_element_list:
7278 return "DW_AT_element_list";
7279 case DW_AT_stmt_list:
7280 return "DW_AT_stmt_list";
7281 case DW_AT_low_pc:
7282 return "DW_AT_low_pc";
7283 case DW_AT_high_pc:
7284 return "DW_AT_high_pc";
7285 case DW_AT_language:
7286 return "DW_AT_language";
7287 case DW_AT_member:
7288 return "DW_AT_member";
7289 case DW_AT_discr:
7290 return "DW_AT_discr";
7291 case DW_AT_discr_value:
7292 return "DW_AT_discr_value";
7293 case DW_AT_visibility:
7294 return "DW_AT_visibility";
7295 case DW_AT_import:
7296 return "DW_AT_import";
7297 case DW_AT_string_length:
7298 return "DW_AT_string_length";
7299 case DW_AT_common_reference:
7300 return "DW_AT_common_reference";
7301 case DW_AT_comp_dir:
7302 return "DW_AT_comp_dir";
7303 case DW_AT_const_value:
7304 return "DW_AT_const_value";
7305 case DW_AT_containing_type:
7306 return "DW_AT_containing_type";
7307 case DW_AT_default_value:
7308 return "DW_AT_default_value";
7309 case DW_AT_inline:
7310 return "DW_AT_inline";
7311 case DW_AT_is_optional:
7312 return "DW_AT_is_optional";
7313 case DW_AT_lower_bound:
7314 return "DW_AT_lower_bound";
7315 case DW_AT_producer:
7316 return "DW_AT_producer";
7317 case DW_AT_prototyped:
7318 return "DW_AT_prototyped";
7319 case DW_AT_return_addr:
7320 return "DW_AT_return_addr";
7321 case DW_AT_start_scope:
7322 return "DW_AT_start_scope";
7323 case DW_AT_stride_size:
7324 return "DW_AT_stride_size";
7325 case DW_AT_upper_bound:
7326 return "DW_AT_upper_bound";
7327 case DW_AT_abstract_origin:
7328 return "DW_AT_abstract_origin";
7329 case DW_AT_accessibility:
7330 return "DW_AT_accessibility";
7331 case DW_AT_address_class:
7332 return "DW_AT_address_class";
7333 case DW_AT_artificial:
7334 return "DW_AT_artificial";
7335 case DW_AT_base_types:
7336 return "DW_AT_base_types";
7337 case DW_AT_calling_convention:
7338 return "DW_AT_calling_convention";
7339 case DW_AT_count:
7340 return "DW_AT_count";
7341 case DW_AT_data_member_location:
7342 return "DW_AT_data_member_location";
7343 case DW_AT_decl_column:
7344 return "DW_AT_decl_column";
7345 case DW_AT_decl_file:
7346 return "DW_AT_decl_file";
7347 case DW_AT_decl_line:
7348 return "DW_AT_decl_line";
7349 case DW_AT_declaration:
7350 return "DW_AT_declaration";
7351 case DW_AT_discr_list:
7352 return "DW_AT_discr_list";
7353 case DW_AT_encoding:
7354 return "DW_AT_encoding";
7355 case DW_AT_external:
7356 return "DW_AT_external";
7357 case DW_AT_frame_base:
7358 return "DW_AT_frame_base";
7359 case DW_AT_friend:
7360 return "DW_AT_friend";
7361 case DW_AT_identifier_case:
7362 return "DW_AT_identifier_case";
7363 case DW_AT_macro_info:
7364 return "DW_AT_macro_info";
7365 case DW_AT_namelist_items:
7366 return "DW_AT_namelist_items";
7367 case DW_AT_priority:
7368 return "DW_AT_priority";
7369 case DW_AT_segment:
7370 return "DW_AT_segment";
7371 case DW_AT_specification:
7372 return "DW_AT_specification";
7373 case DW_AT_static_link:
7374 return "DW_AT_static_link";
7375 case DW_AT_type:
7376 return "DW_AT_type";
7377 case DW_AT_use_location:
7378 return "DW_AT_use_location";
7379 case DW_AT_variable_parameter:
7380 return "DW_AT_variable_parameter";
7381 case DW_AT_virtuality:
7382 return "DW_AT_virtuality";
7383 case DW_AT_vtable_elem_location:
7384 return "DW_AT_vtable_elem_location";
7385 case DW_AT_allocated:
7386 return "DW_AT_allocated";
7387 case DW_AT_associated:
7388 return "DW_AT_associated";
7389 case DW_AT_data_location:
7390 return "DW_AT_data_location";
7391 case DW_AT_stride:
7392 return "DW_AT_stride";
7393 case DW_AT_entry_pc:
7394 return "DW_AT_entry_pc";
7395 case DW_AT_use_UTF8:
7396 return "DW_AT_use_UTF8";
7397 case DW_AT_extension:
7398 return "DW_AT_extension";
7399 case DW_AT_ranges:
7400 return "DW_AT_ranges";
7401 case DW_AT_trampoline:
7402 return "DW_AT_trampoline";
7403 case DW_AT_call_column:
7404 return "DW_AT_call_column";
7405 case DW_AT_call_file:
7406 return "DW_AT_call_file";
7407 case DW_AT_call_line:
7408 return "DW_AT_call_line";
7409 #ifdef MIPS
7410 case DW_AT_MIPS_fde:
7411 return "DW_AT_MIPS_fde";
7412 case DW_AT_MIPS_loop_begin:
7413 return "DW_AT_MIPS_loop_begin";
7414 case DW_AT_MIPS_tail_loop_begin:
7415 return "DW_AT_MIPS_tail_loop_begin";
7416 case DW_AT_MIPS_epilog_begin:
7417 return "DW_AT_MIPS_epilog_begin";
7418 case DW_AT_MIPS_loop_unroll_factor:
7419 return "DW_AT_MIPS_loop_unroll_factor";
7420 case DW_AT_MIPS_software_pipeline_depth:
7421 return "DW_AT_MIPS_software_pipeline_depth";
7422 #endif
7423 case DW_AT_MIPS_linkage_name:
7424 return "DW_AT_MIPS_linkage_name";
7425
7426 case DW_AT_sf_names:
7427 return "DW_AT_sf_names";
7428 case DW_AT_src_info:
7429 return "DW_AT_src_info";
7430 case DW_AT_mac_info:
7431 return "DW_AT_mac_info";
7432 case DW_AT_src_coords:
7433 return "DW_AT_src_coords";
7434 case DW_AT_body_begin:
7435 return "DW_AT_body_begin";
7436 case DW_AT_body_end:
7437 return "DW_AT_body_end";
7438 case DW_AT_GNU_vector:
7439 return "DW_AT_GNU_vector";
7440 default:
7441 return "DW_AT_<unknown>";
7442 }
7443 }
7444
7445 /* Convert a DWARF value form code into its string name. */
7446
7447 static char *
7448 dwarf_form_name (unsigned form)
7449 {
7450 switch (form)
7451 {
7452 case DW_FORM_addr:
7453 return "DW_FORM_addr";
7454 case DW_FORM_block2:
7455 return "DW_FORM_block2";
7456 case DW_FORM_block4:
7457 return "DW_FORM_block4";
7458 case DW_FORM_data2:
7459 return "DW_FORM_data2";
7460 case DW_FORM_data4:
7461 return "DW_FORM_data4";
7462 case DW_FORM_data8:
7463 return "DW_FORM_data8";
7464 case DW_FORM_string:
7465 return "DW_FORM_string";
7466 case DW_FORM_block:
7467 return "DW_FORM_block";
7468 case DW_FORM_block1:
7469 return "DW_FORM_block1";
7470 case DW_FORM_data1:
7471 return "DW_FORM_data1";
7472 case DW_FORM_flag:
7473 return "DW_FORM_flag";
7474 case DW_FORM_sdata:
7475 return "DW_FORM_sdata";
7476 case DW_FORM_strp:
7477 return "DW_FORM_strp";
7478 case DW_FORM_udata:
7479 return "DW_FORM_udata";
7480 case DW_FORM_ref_addr:
7481 return "DW_FORM_ref_addr";
7482 case DW_FORM_ref1:
7483 return "DW_FORM_ref1";
7484 case DW_FORM_ref2:
7485 return "DW_FORM_ref2";
7486 case DW_FORM_ref4:
7487 return "DW_FORM_ref4";
7488 case DW_FORM_ref8:
7489 return "DW_FORM_ref8";
7490 case DW_FORM_ref_udata:
7491 return "DW_FORM_ref_udata";
7492 case DW_FORM_indirect:
7493 return "DW_FORM_indirect";
7494 default:
7495 return "DW_FORM_<unknown>";
7496 }
7497 }
7498
7499 /* Convert a DWARF stack opcode into its string name. */
7500
7501 static char *
7502 dwarf_stack_op_name (unsigned op)
7503 {
7504 switch (op)
7505 {
7506 case DW_OP_addr:
7507 return "DW_OP_addr";
7508 case DW_OP_deref:
7509 return "DW_OP_deref";
7510 case DW_OP_const1u:
7511 return "DW_OP_const1u";
7512 case DW_OP_const1s:
7513 return "DW_OP_const1s";
7514 case DW_OP_const2u:
7515 return "DW_OP_const2u";
7516 case DW_OP_const2s:
7517 return "DW_OP_const2s";
7518 case DW_OP_const4u:
7519 return "DW_OP_const4u";
7520 case DW_OP_const4s:
7521 return "DW_OP_const4s";
7522 case DW_OP_const8u:
7523 return "DW_OP_const8u";
7524 case DW_OP_const8s:
7525 return "DW_OP_const8s";
7526 case DW_OP_constu:
7527 return "DW_OP_constu";
7528 case DW_OP_consts:
7529 return "DW_OP_consts";
7530 case DW_OP_dup:
7531 return "DW_OP_dup";
7532 case DW_OP_drop:
7533 return "DW_OP_drop";
7534 case DW_OP_over:
7535 return "DW_OP_over";
7536 case DW_OP_pick:
7537 return "DW_OP_pick";
7538 case DW_OP_swap:
7539 return "DW_OP_swap";
7540 case DW_OP_rot:
7541 return "DW_OP_rot";
7542 case DW_OP_xderef:
7543 return "DW_OP_xderef";
7544 case DW_OP_abs:
7545 return "DW_OP_abs";
7546 case DW_OP_and:
7547 return "DW_OP_and";
7548 case DW_OP_div:
7549 return "DW_OP_div";
7550 case DW_OP_minus:
7551 return "DW_OP_minus";
7552 case DW_OP_mod:
7553 return "DW_OP_mod";
7554 case DW_OP_mul:
7555 return "DW_OP_mul";
7556 case DW_OP_neg:
7557 return "DW_OP_neg";
7558 case DW_OP_not:
7559 return "DW_OP_not";
7560 case DW_OP_or:
7561 return "DW_OP_or";
7562 case DW_OP_plus:
7563 return "DW_OP_plus";
7564 case DW_OP_plus_uconst:
7565 return "DW_OP_plus_uconst";
7566 case DW_OP_shl:
7567 return "DW_OP_shl";
7568 case DW_OP_shr:
7569 return "DW_OP_shr";
7570 case DW_OP_shra:
7571 return "DW_OP_shra";
7572 case DW_OP_xor:
7573 return "DW_OP_xor";
7574 case DW_OP_bra:
7575 return "DW_OP_bra";
7576 case DW_OP_eq:
7577 return "DW_OP_eq";
7578 case DW_OP_ge:
7579 return "DW_OP_ge";
7580 case DW_OP_gt:
7581 return "DW_OP_gt";
7582 case DW_OP_le:
7583 return "DW_OP_le";
7584 case DW_OP_lt:
7585 return "DW_OP_lt";
7586 case DW_OP_ne:
7587 return "DW_OP_ne";
7588 case DW_OP_skip:
7589 return "DW_OP_skip";
7590 case DW_OP_lit0:
7591 return "DW_OP_lit0";
7592 case DW_OP_lit1:
7593 return "DW_OP_lit1";
7594 case DW_OP_lit2:
7595 return "DW_OP_lit2";
7596 case DW_OP_lit3:
7597 return "DW_OP_lit3";
7598 case DW_OP_lit4:
7599 return "DW_OP_lit4";
7600 case DW_OP_lit5:
7601 return "DW_OP_lit5";
7602 case DW_OP_lit6:
7603 return "DW_OP_lit6";
7604 case DW_OP_lit7:
7605 return "DW_OP_lit7";
7606 case DW_OP_lit8:
7607 return "DW_OP_lit8";
7608 case DW_OP_lit9:
7609 return "DW_OP_lit9";
7610 case DW_OP_lit10:
7611 return "DW_OP_lit10";
7612 case DW_OP_lit11:
7613 return "DW_OP_lit11";
7614 case DW_OP_lit12:
7615 return "DW_OP_lit12";
7616 case DW_OP_lit13:
7617 return "DW_OP_lit13";
7618 case DW_OP_lit14:
7619 return "DW_OP_lit14";
7620 case DW_OP_lit15:
7621 return "DW_OP_lit15";
7622 case DW_OP_lit16:
7623 return "DW_OP_lit16";
7624 case DW_OP_lit17:
7625 return "DW_OP_lit17";
7626 case DW_OP_lit18:
7627 return "DW_OP_lit18";
7628 case DW_OP_lit19:
7629 return "DW_OP_lit19";
7630 case DW_OP_lit20:
7631 return "DW_OP_lit20";
7632 case DW_OP_lit21:
7633 return "DW_OP_lit21";
7634 case DW_OP_lit22:
7635 return "DW_OP_lit22";
7636 case DW_OP_lit23:
7637 return "DW_OP_lit23";
7638 case DW_OP_lit24:
7639 return "DW_OP_lit24";
7640 case DW_OP_lit25:
7641 return "DW_OP_lit25";
7642 case DW_OP_lit26:
7643 return "DW_OP_lit26";
7644 case DW_OP_lit27:
7645 return "DW_OP_lit27";
7646 case DW_OP_lit28:
7647 return "DW_OP_lit28";
7648 case DW_OP_lit29:
7649 return "DW_OP_lit29";
7650 case DW_OP_lit30:
7651 return "DW_OP_lit30";
7652 case DW_OP_lit31:
7653 return "DW_OP_lit31";
7654 case DW_OP_reg0:
7655 return "DW_OP_reg0";
7656 case DW_OP_reg1:
7657 return "DW_OP_reg1";
7658 case DW_OP_reg2:
7659 return "DW_OP_reg2";
7660 case DW_OP_reg3:
7661 return "DW_OP_reg3";
7662 case DW_OP_reg4:
7663 return "DW_OP_reg4";
7664 case DW_OP_reg5:
7665 return "DW_OP_reg5";
7666 case DW_OP_reg6:
7667 return "DW_OP_reg6";
7668 case DW_OP_reg7:
7669 return "DW_OP_reg7";
7670 case DW_OP_reg8:
7671 return "DW_OP_reg8";
7672 case DW_OP_reg9:
7673 return "DW_OP_reg9";
7674 case DW_OP_reg10:
7675 return "DW_OP_reg10";
7676 case DW_OP_reg11:
7677 return "DW_OP_reg11";
7678 case DW_OP_reg12:
7679 return "DW_OP_reg12";
7680 case DW_OP_reg13:
7681 return "DW_OP_reg13";
7682 case DW_OP_reg14:
7683 return "DW_OP_reg14";
7684 case DW_OP_reg15:
7685 return "DW_OP_reg15";
7686 case DW_OP_reg16:
7687 return "DW_OP_reg16";
7688 case DW_OP_reg17:
7689 return "DW_OP_reg17";
7690 case DW_OP_reg18:
7691 return "DW_OP_reg18";
7692 case DW_OP_reg19:
7693 return "DW_OP_reg19";
7694 case DW_OP_reg20:
7695 return "DW_OP_reg20";
7696 case DW_OP_reg21:
7697 return "DW_OP_reg21";
7698 case DW_OP_reg22:
7699 return "DW_OP_reg22";
7700 case DW_OP_reg23:
7701 return "DW_OP_reg23";
7702 case DW_OP_reg24:
7703 return "DW_OP_reg24";
7704 case DW_OP_reg25:
7705 return "DW_OP_reg25";
7706 case DW_OP_reg26:
7707 return "DW_OP_reg26";
7708 case DW_OP_reg27:
7709 return "DW_OP_reg27";
7710 case DW_OP_reg28:
7711 return "DW_OP_reg28";
7712 case DW_OP_reg29:
7713 return "DW_OP_reg29";
7714 case DW_OP_reg30:
7715 return "DW_OP_reg30";
7716 case DW_OP_reg31:
7717 return "DW_OP_reg31";
7718 case DW_OP_breg0:
7719 return "DW_OP_breg0";
7720 case DW_OP_breg1:
7721 return "DW_OP_breg1";
7722 case DW_OP_breg2:
7723 return "DW_OP_breg2";
7724 case DW_OP_breg3:
7725 return "DW_OP_breg3";
7726 case DW_OP_breg4:
7727 return "DW_OP_breg4";
7728 case DW_OP_breg5:
7729 return "DW_OP_breg5";
7730 case DW_OP_breg6:
7731 return "DW_OP_breg6";
7732 case DW_OP_breg7:
7733 return "DW_OP_breg7";
7734 case DW_OP_breg8:
7735 return "DW_OP_breg8";
7736 case DW_OP_breg9:
7737 return "DW_OP_breg9";
7738 case DW_OP_breg10:
7739 return "DW_OP_breg10";
7740 case DW_OP_breg11:
7741 return "DW_OP_breg11";
7742 case DW_OP_breg12:
7743 return "DW_OP_breg12";
7744 case DW_OP_breg13:
7745 return "DW_OP_breg13";
7746 case DW_OP_breg14:
7747 return "DW_OP_breg14";
7748 case DW_OP_breg15:
7749 return "DW_OP_breg15";
7750 case DW_OP_breg16:
7751 return "DW_OP_breg16";
7752 case DW_OP_breg17:
7753 return "DW_OP_breg17";
7754 case DW_OP_breg18:
7755 return "DW_OP_breg18";
7756 case DW_OP_breg19:
7757 return "DW_OP_breg19";
7758 case DW_OP_breg20:
7759 return "DW_OP_breg20";
7760 case DW_OP_breg21:
7761 return "DW_OP_breg21";
7762 case DW_OP_breg22:
7763 return "DW_OP_breg22";
7764 case DW_OP_breg23:
7765 return "DW_OP_breg23";
7766 case DW_OP_breg24:
7767 return "DW_OP_breg24";
7768 case DW_OP_breg25:
7769 return "DW_OP_breg25";
7770 case DW_OP_breg26:
7771 return "DW_OP_breg26";
7772 case DW_OP_breg27:
7773 return "DW_OP_breg27";
7774 case DW_OP_breg28:
7775 return "DW_OP_breg28";
7776 case DW_OP_breg29:
7777 return "DW_OP_breg29";
7778 case DW_OP_breg30:
7779 return "DW_OP_breg30";
7780 case DW_OP_breg31:
7781 return "DW_OP_breg31";
7782 case DW_OP_regx:
7783 return "DW_OP_regx";
7784 case DW_OP_fbreg:
7785 return "DW_OP_fbreg";
7786 case DW_OP_bregx:
7787 return "DW_OP_bregx";
7788 case DW_OP_piece:
7789 return "DW_OP_piece";
7790 case DW_OP_deref_size:
7791 return "DW_OP_deref_size";
7792 case DW_OP_xderef_size:
7793 return "DW_OP_xderef_size";
7794 case DW_OP_nop:
7795 return "DW_OP_nop";
7796 /* DWARF 3 extensions. */
7797 case DW_OP_push_object_address:
7798 return "DW_OP_push_object_address";
7799 case DW_OP_call2:
7800 return "DW_OP_call2";
7801 case DW_OP_call4:
7802 return "DW_OP_call4";
7803 case DW_OP_call_ref:
7804 return "DW_OP_call_ref";
7805 /* GNU extensions. */
7806 case DW_OP_GNU_push_tls_address:
7807 return "DW_OP_GNU_push_tls_address";
7808 default:
7809 return "OP_<unknown>";
7810 }
7811 }
7812
7813 static char *
7814 dwarf_bool_name (unsigned mybool)
7815 {
7816 if (mybool)
7817 return "TRUE";
7818 else
7819 return "FALSE";
7820 }
7821
7822 /* Convert a DWARF type code into its string name. */
7823
7824 static char *
7825 dwarf_type_encoding_name (unsigned enc)
7826 {
7827 switch (enc)
7828 {
7829 case DW_ATE_address:
7830 return "DW_ATE_address";
7831 case DW_ATE_boolean:
7832 return "DW_ATE_boolean";
7833 case DW_ATE_complex_float:
7834 return "DW_ATE_complex_float";
7835 case DW_ATE_float:
7836 return "DW_ATE_float";
7837 case DW_ATE_signed:
7838 return "DW_ATE_signed";
7839 case DW_ATE_signed_char:
7840 return "DW_ATE_signed_char";
7841 case DW_ATE_unsigned:
7842 return "DW_ATE_unsigned";
7843 case DW_ATE_unsigned_char:
7844 return "DW_ATE_unsigned_char";
7845 case DW_ATE_imaginary_float:
7846 return "DW_ATE_imaginary_float";
7847 default:
7848 return "DW_ATE_<unknown>";
7849 }
7850 }
7851
7852 /* Convert a DWARF call frame info operation to its string name. */
7853
7854 #if 0
7855 static char *
7856 dwarf_cfi_name (unsigned cfi_opc)
7857 {
7858 switch (cfi_opc)
7859 {
7860 case DW_CFA_advance_loc:
7861 return "DW_CFA_advance_loc";
7862 case DW_CFA_offset:
7863 return "DW_CFA_offset";
7864 case DW_CFA_restore:
7865 return "DW_CFA_restore";
7866 case DW_CFA_nop:
7867 return "DW_CFA_nop";
7868 case DW_CFA_set_loc:
7869 return "DW_CFA_set_loc";
7870 case DW_CFA_advance_loc1:
7871 return "DW_CFA_advance_loc1";
7872 case DW_CFA_advance_loc2:
7873 return "DW_CFA_advance_loc2";
7874 case DW_CFA_advance_loc4:
7875 return "DW_CFA_advance_loc4";
7876 case DW_CFA_offset_extended:
7877 return "DW_CFA_offset_extended";
7878 case DW_CFA_restore_extended:
7879 return "DW_CFA_restore_extended";
7880 case DW_CFA_undefined:
7881 return "DW_CFA_undefined";
7882 case DW_CFA_same_value:
7883 return "DW_CFA_same_value";
7884 case DW_CFA_register:
7885 return "DW_CFA_register";
7886 case DW_CFA_remember_state:
7887 return "DW_CFA_remember_state";
7888 case DW_CFA_restore_state:
7889 return "DW_CFA_restore_state";
7890 case DW_CFA_def_cfa:
7891 return "DW_CFA_def_cfa";
7892 case DW_CFA_def_cfa_register:
7893 return "DW_CFA_def_cfa_register";
7894 case DW_CFA_def_cfa_offset:
7895 return "DW_CFA_def_cfa_offset";
7896
7897 /* DWARF 3 */
7898 case DW_CFA_def_cfa_expression:
7899 return "DW_CFA_def_cfa_expression";
7900 case DW_CFA_expression:
7901 return "DW_CFA_expression";
7902 case DW_CFA_offset_extended_sf:
7903 return "DW_CFA_offset_extended_sf";
7904 case DW_CFA_def_cfa_sf:
7905 return "DW_CFA_def_cfa_sf";
7906 case DW_CFA_def_cfa_offset_sf:
7907 return "DW_CFA_def_cfa_offset_sf";
7908
7909 /* SGI/MIPS specific */
7910 case DW_CFA_MIPS_advance_loc8:
7911 return "DW_CFA_MIPS_advance_loc8";
7912
7913 /* GNU extensions */
7914 case DW_CFA_GNU_window_save:
7915 return "DW_CFA_GNU_window_save";
7916 case DW_CFA_GNU_args_size:
7917 return "DW_CFA_GNU_args_size";
7918 case DW_CFA_GNU_negative_offset_extended:
7919 return "DW_CFA_GNU_negative_offset_extended";
7920
7921 default:
7922 return "DW_CFA_<unknown>";
7923 }
7924 }
7925 #endif
7926
7927 static void
7928 dump_die (struct die_info *die)
7929 {
7930 unsigned int i;
7931
7932 fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n",
7933 dwarf_tag_name (die->tag), die->abbrev, die->offset);
7934 fprintf_unfiltered (gdb_stderr, "\thas children: %s\n",
7935 dwarf_bool_name (die->child != NULL));
7936
7937 fprintf_unfiltered (gdb_stderr, "\tattributes:\n");
7938 for (i = 0; i < die->num_attrs; ++i)
7939 {
7940 fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ",
7941 dwarf_attr_name (die->attrs[i].name),
7942 dwarf_form_name (die->attrs[i].form));
7943 switch (die->attrs[i].form)
7944 {
7945 case DW_FORM_ref_addr:
7946 case DW_FORM_addr:
7947 fprintf_unfiltered (gdb_stderr, "address: ");
7948 print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr);
7949 break;
7950 case DW_FORM_block2:
7951 case DW_FORM_block4:
7952 case DW_FORM_block:
7953 case DW_FORM_block1:
7954 fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size);
7955 break;
7956 case DW_FORM_data1:
7957 case DW_FORM_data2:
7958 case DW_FORM_data4:
7959 case DW_FORM_data8:
7960 case DW_FORM_ref1:
7961 case DW_FORM_ref2:
7962 case DW_FORM_ref4:
7963 case DW_FORM_udata:
7964 case DW_FORM_sdata:
7965 fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
7966 break;
7967 case DW_FORM_string:
7968 case DW_FORM_strp:
7969 fprintf_unfiltered (gdb_stderr, "string: \"%s\"",
7970 DW_STRING (&die->attrs[i])
7971 ? DW_STRING (&die->attrs[i]) : "");
7972 break;
7973 case DW_FORM_flag:
7974 if (DW_UNSND (&die->attrs[i]))
7975 fprintf_unfiltered (gdb_stderr, "flag: TRUE");
7976 else
7977 fprintf_unfiltered (gdb_stderr, "flag: FALSE");
7978 break;
7979 case DW_FORM_indirect:
7980 /* the reader will have reduced the indirect form to
7981 the "base form" so this form should not occur */
7982 fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect");
7983 break;
7984 default:
7985 fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.",
7986 die->attrs[i].form);
7987 }
7988 fprintf_unfiltered (gdb_stderr, "\n");
7989 }
7990 }
7991
7992 static void
7993 dump_die_list (struct die_info *die)
7994 {
7995 while (die)
7996 {
7997 dump_die (die);
7998 if (die->child != NULL)
7999 dump_die_list (die->child);
8000 if (die->sibling != NULL)
8001 dump_die_list (die->sibling);
8002 }
8003 }
8004
8005 static void
8006 store_in_ref_table (unsigned int offset, struct die_info *die)
8007 {
8008 int h;
8009 struct die_info *old;
8010
8011 h = (offset % REF_HASH_SIZE);
8012 old = die_ref_table[h];
8013 die->next_ref = old;
8014 die_ref_table[h] = die;
8015 }
8016
8017
8018 static void
8019 dwarf2_empty_hash_tables (void)
8020 {
8021 memset (die_ref_table, 0, sizeof (die_ref_table));
8022 }
8023
8024 static unsigned int
8025 dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu)
8026 {
8027 unsigned int result = 0;
8028
8029 switch (attr->form)
8030 {
8031 case DW_FORM_ref_addr:
8032 result = DW_ADDR (attr);
8033 break;
8034 case DW_FORM_ref1:
8035 case DW_FORM_ref2:
8036 case DW_FORM_ref4:
8037 case DW_FORM_ref8:
8038 case DW_FORM_ref_udata:
8039 result = cu->header.offset + DW_UNSND (attr);
8040 break;
8041 default:
8042 complaint (&symfile_complaints,
8043 "unsupported die ref attribute form: '%s'",
8044 dwarf_form_name (attr->form));
8045 }
8046 return result;
8047 }
8048
8049 /* Return the constant value held by the given attribute. Return -1
8050 if the value held by the attribute is not constant. */
8051
8052 static int
8053 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
8054 {
8055 if (attr->form == DW_FORM_sdata)
8056 return DW_SND (attr);
8057 else if (attr->form == DW_FORM_udata
8058 || attr->form == DW_FORM_data1
8059 || attr->form == DW_FORM_data2
8060 || attr->form == DW_FORM_data4
8061 || attr->form == DW_FORM_data8)
8062 return DW_UNSND (attr);
8063 else
8064 {
8065 complaint (&symfile_complaints, "Attribute value is not a constant (%s)",
8066 dwarf_form_name (attr->form));
8067 return default_value;
8068 }
8069 }
8070
8071 static struct die_info *
8072 follow_die_ref (unsigned int offset)
8073 {
8074 struct die_info *die;
8075 int h;
8076
8077 h = (offset % REF_HASH_SIZE);
8078 die = die_ref_table[h];
8079 while (die)
8080 {
8081 if (die->offset == offset)
8082 {
8083 return die;
8084 }
8085 die = die->next_ref;
8086 }
8087 return NULL;
8088 }
8089
8090 static struct type *
8091 dwarf2_fundamental_type (struct objfile *objfile, int typeid,
8092 struct dwarf2_cu *cu)
8093 {
8094 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
8095 {
8096 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8097 typeid, objfile->name);
8098 }
8099
8100 /* Look for this particular type in the fundamental type vector. If
8101 one is not found, create and install one appropriate for the
8102 current language and the current target machine. */
8103
8104 if (cu->ftypes[typeid] == NULL)
8105 {
8106 cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid);
8107 }
8108
8109 return (cu->ftypes[typeid]);
8110 }
8111
8112 /* Decode simple location descriptions.
8113 Given a pointer to a dwarf block that defines a location, compute
8114 the location and return the value.
8115
8116 NOTE drow/2003-11-18: This function is called in two situations
8117 now: for the address of static or global variables (partial symbols
8118 only) and for offsets into structures which are expected to be
8119 (more or less) constant. The partial symbol case should go away,
8120 and only the constant case should remain. That will let this
8121 function complain more accurately. A few special modes are allowed
8122 without complaint for global variables (for instance, global
8123 register values and thread-local values).
8124
8125 A location description containing no operations indicates that the
8126 object is optimized out. The return value is 0 for that case.
8127 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8128 callers will only want a very basic result and this can become a
8129 complaint.
8130
8131 When the result is a register number, the global isreg flag is set,
8132 otherwise it is cleared.
8133
8134 Note that stack[0] is unused except as a default error return.
8135 Note that stack overflow is not yet handled. */
8136
8137 static CORE_ADDR
8138 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
8139 {
8140 struct objfile *objfile = cu->objfile;
8141 struct comp_unit_head *cu_header = &cu->header;
8142 int i;
8143 int size = blk->size;
8144 char *data = blk->data;
8145 CORE_ADDR stack[64];
8146 int stacki;
8147 unsigned int bytes_read, unsnd;
8148 unsigned char op;
8149
8150 i = 0;
8151 stacki = 0;
8152 stack[stacki] = 0;
8153 isreg = 0;
8154
8155 while (i < size)
8156 {
8157 op = data[i++];
8158 switch (op)
8159 {
8160 case DW_OP_lit0:
8161 case DW_OP_lit1:
8162 case DW_OP_lit2:
8163 case DW_OP_lit3:
8164 case DW_OP_lit4:
8165 case DW_OP_lit5:
8166 case DW_OP_lit6:
8167 case DW_OP_lit7:
8168 case DW_OP_lit8:
8169 case DW_OP_lit9:
8170 case DW_OP_lit10:
8171 case DW_OP_lit11:
8172 case DW_OP_lit12:
8173 case DW_OP_lit13:
8174 case DW_OP_lit14:
8175 case DW_OP_lit15:
8176 case DW_OP_lit16:
8177 case DW_OP_lit17:
8178 case DW_OP_lit18:
8179 case DW_OP_lit19:
8180 case DW_OP_lit20:
8181 case DW_OP_lit21:
8182 case DW_OP_lit22:
8183 case DW_OP_lit23:
8184 case DW_OP_lit24:
8185 case DW_OP_lit25:
8186 case DW_OP_lit26:
8187 case DW_OP_lit27:
8188 case DW_OP_lit28:
8189 case DW_OP_lit29:
8190 case DW_OP_lit30:
8191 case DW_OP_lit31:
8192 stack[++stacki] = op - DW_OP_lit0;
8193 break;
8194
8195 case DW_OP_reg0:
8196 case DW_OP_reg1:
8197 case DW_OP_reg2:
8198 case DW_OP_reg3:
8199 case DW_OP_reg4:
8200 case DW_OP_reg5:
8201 case DW_OP_reg6:
8202 case DW_OP_reg7:
8203 case DW_OP_reg8:
8204 case DW_OP_reg9:
8205 case DW_OP_reg10:
8206 case DW_OP_reg11:
8207 case DW_OP_reg12:
8208 case DW_OP_reg13:
8209 case DW_OP_reg14:
8210 case DW_OP_reg15:
8211 case DW_OP_reg16:
8212 case DW_OP_reg17:
8213 case DW_OP_reg18:
8214 case DW_OP_reg19:
8215 case DW_OP_reg20:
8216 case DW_OP_reg21:
8217 case DW_OP_reg22:
8218 case DW_OP_reg23:
8219 case DW_OP_reg24:
8220 case DW_OP_reg25:
8221 case DW_OP_reg26:
8222 case DW_OP_reg27:
8223 case DW_OP_reg28:
8224 case DW_OP_reg29:
8225 case DW_OP_reg30:
8226 case DW_OP_reg31:
8227 isreg = 1;
8228 stack[++stacki] = op - DW_OP_reg0;
8229 if (i < size)
8230 dwarf2_complex_location_expr_complaint ();
8231 break;
8232
8233 case DW_OP_regx:
8234 isreg = 1;
8235 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8236 i += bytes_read;
8237 stack[++stacki] = unsnd;
8238 if (i < size)
8239 dwarf2_complex_location_expr_complaint ();
8240 break;
8241
8242 case DW_OP_addr:
8243 stack[++stacki] = read_address (objfile->obfd, &data[i],
8244 cu, &bytes_read);
8245 i += bytes_read;
8246 break;
8247
8248 case DW_OP_const1u:
8249 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
8250 i += 1;
8251 break;
8252
8253 case DW_OP_const1s:
8254 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
8255 i += 1;
8256 break;
8257
8258 case DW_OP_const2u:
8259 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
8260 i += 2;
8261 break;
8262
8263 case DW_OP_const2s:
8264 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
8265 i += 2;
8266 break;
8267
8268 case DW_OP_const4u:
8269 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
8270 i += 4;
8271 break;
8272
8273 case DW_OP_const4s:
8274 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
8275 i += 4;
8276 break;
8277
8278 case DW_OP_constu:
8279 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
8280 &bytes_read);
8281 i += bytes_read;
8282 break;
8283
8284 case DW_OP_consts:
8285 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
8286 i += bytes_read;
8287 break;
8288
8289 case DW_OP_dup:
8290 stack[stacki + 1] = stack[stacki];
8291 stacki++;
8292 break;
8293
8294 case DW_OP_plus:
8295 stack[stacki - 1] += stack[stacki];
8296 stacki--;
8297 break;
8298
8299 case DW_OP_plus_uconst:
8300 stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read);
8301 i += bytes_read;
8302 break;
8303
8304 case DW_OP_minus:
8305 stack[stacki - 1] -= stack[stacki];
8306 stacki--;
8307 break;
8308
8309 case DW_OP_deref:
8310 /* If we're not the last op, then we definitely can't encode
8311 this using GDB's address_class enum. This is valid for partial
8312 global symbols, although the variable's address will be bogus
8313 in the psymtab. */
8314 if (i < size)
8315 dwarf2_complex_location_expr_complaint ();
8316 break;
8317
8318 case DW_OP_GNU_push_tls_address:
8319 /* The top of the stack has the offset from the beginning
8320 of the thread control block at which the variable is located. */
8321 /* Nothing should follow this operator, so the top of stack would
8322 be returned. */
8323 /* This is valid for partial global symbols, but the variable's
8324 address will be bogus in the psymtab. */
8325 if (i < size)
8326 dwarf2_complex_location_expr_complaint ();
8327 break;
8328
8329 default:
8330 complaint (&symfile_complaints, "unsupported stack op: '%s'",
8331 dwarf_stack_op_name (op));
8332 return (stack[stacki]);
8333 }
8334 }
8335 return (stack[stacki]);
8336 }
8337
8338 /* memory allocation interface */
8339
8340 static struct dwarf_block *
8341 dwarf_alloc_block (struct dwarf2_cu *cu)
8342 {
8343 struct dwarf_block *blk;
8344
8345 blk = (struct dwarf_block *)
8346 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
8347 return (blk);
8348 }
8349
8350 static struct abbrev_info *
8351 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
8352 {
8353 struct abbrev_info *abbrev;
8354
8355 abbrev = (struct abbrev_info *)
8356 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
8357 memset (abbrev, 0, sizeof (struct abbrev_info));
8358 return (abbrev);
8359 }
8360
8361 static struct die_info *
8362 dwarf_alloc_die (void)
8363 {
8364 struct die_info *die;
8365
8366 die = (struct die_info *) xmalloc (sizeof (struct die_info));
8367 memset (die, 0, sizeof (struct die_info));
8368 return (die);
8369 }
8370
8371 \f
8372 /* Macro support. */
8373
8374
8375 /* Return the full name of file number I in *LH's file name table.
8376 Use COMP_DIR as the name of the current directory of the
8377 compilation. The result is allocated using xmalloc; the caller is
8378 responsible for freeing it. */
8379 static char *
8380 file_full_name (int file, struct line_header *lh, const char *comp_dir)
8381 {
8382 struct file_entry *fe = &lh->file_names[file - 1];
8383
8384 if (IS_ABSOLUTE_PATH (fe->name))
8385 return xstrdup (fe->name);
8386 else
8387 {
8388 const char *dir;
8389 int dir_len;
8390 char *full_name;
8391
8392 if (fe->dir_index)
8393 dir = lh->include_dirs[fe->dir_index - 1];
8394 else
8395 dir = comp_dir;
8396
8397 if (dir)
8398 {
8399 dir_len = strlen (dir);
8400 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
8401 strcpy (full_name, dir);
8402 full_name[dir_len] = '/';
8403 strcpy (full_name + dir_len + 1, fe->name);
8404 return full_name;
8405 }
8406 else
8407 return xstrdup (fe->name);
8408 }
8409 }
8410
8411
8412 static struct macro_source_file *
8413 macro_start_file (int file, int line,
8414 struct macro_source_file *current_file,
8415 const char *comp_dir,
8416 struct line_header *lh, struct objfile *objfile)
8417 {
8418 /* The full name of this source file. */
8419 char *full_name = file_full_name (file, lh, comp_dir);
8420
8421 /* We don't create a macro table for this compilation unit
8422 at all until we actually get a filename. */
8423 if (! pending_macros)
8424 pending_macros = new_macro_table (&objfile->objfile_obstack,
8425 objfile->macro_cache);
8426
8427 if (! current_file)
8428 /* If we have no current file, then this must be the start_file
8429 directive for the compilation unit's main source file. */
8430 current_file = macro_set_main (pending_macros, full_name);
8431 else
8432 current_file = macro_include (current_file, line, full_name);
8433
8434 xfree (full_name);
8435
8436 return current_file;
8437 }
8438
8439
8440 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8441 followed by a null byte. */
8442 static char *
8443 copy_string (const char *buf, int len)
8444 {
8445 char *s = xmalloc (len + 1);
8446 memcpy (s, buf, len);
8447 s[len] = '\0';
8448
8449 return s;
8450 }
8451
8452
8453 static const char *
8454 consume_improper_spaces (const char *p, const char *body)
8455 {
8456 if (*p == ' ')
8457 {
8458 complaint (&symfile_complaints,
8459 "macro definition contains spaces in formal argument list:\n`%s'",
8460 body);
8461
8462 while (*p == ' ')
8463 p++;
8464 }
8465
8466 return p;
8467 }
8468
8469
8470 static void
8471 parse_macro_definition (struct macro_source_file *file, int line,
8472 const char *body)
8473 {
8474 const char *p;
8475
8476 /* The body string takes one of two forms. For object-like macro
8477 definitions, it should be:
8478
8479 <macro name> " " <definition>
8480
8481 For function-like macro definitions, it should be:
8482
8483 <macro name> "() " <definition>
8484 or
8485 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8486
8487 Spaces may appear only where explicitly indicated, and in the
8488 <definition>.
8489
8490 The Dwarf 2 spec says that an object-like macro's name is always
8491 followed by a space, but versions of GCC around March 2002 omit
8492 the space when the macro's definition is the empty string.
8493
8494 The Dwarf 2 spec says that there should be no spaces between the
8495 formal arguments in a function-like macro's formal argument list,
8496 but versions of GCC around March 2002 include spaces after the
8497 commas. */
8498
8499
8500 /* Find the extent of the macro name. The macro name is terminated
8501 by either a space or null character (for an object-like macro) or
8502 an opening paren (for a function-like macro). */
8503 for (p = body; *p; p++)
8504 if (*p == ' ' || *p == '(')
8505 break;
8506
8507 if (*p == ' ' || *p == '\0')
8508 {
8509 /* It's an object-like macro. */
8510 int name_len = p - body;
8511 char *name = copy_string (body, name_len);
8512 const char *replacement;
8513
8514 if (*p == ' ')
8515 replacement = body + name_len + 1;
8516 else
8517 {
8518 dwarf2_macro_malformed_definition_complaint (body);
8519 replacement = body + name_len;
8520 }
8521
8522 macro_define_object (file, line, name, replacement);
8523
8524 xfree (name);
8525 }
8526 else if (*p == '(')
8527 {
8528 /* It's a function-like macro. */
8529 char *name = copy_string (body, p - body);
8530 int argc = 0;
8531 int argv_size = 1;
8532 char **argv = xmalloc (argv_size * sizeof (*argv));
8533
8534 p++;
8535
8536 p = consume_improper_spaces (p, body);
8537
8538 /* Parse the formal argument list. */
8539 while (*p && *p != ')')
8540 {
8541 /* Find the extent of the current argument name. */
8542 const char *arg_start = p;
8543
8544 while (*p && *p != ',' && *p != ')' && *p != ' ')
8545 p++;
8546
8547 if (! *p || p == arg_start)
8548 dwarf2_macro_malformed_definition_complaint (body);
8549 else
8550 {
8551 /* Make sure argv has room for the new argument. */
8552 if (argc >= argv_size)
8553 {
8554 argv_size *= 2;
8555 argv = xrealloc (argv, argv_size * sizeof (*argv));
8556 }
8557
8558 argv[argc++] = copy_string (arg_start, p - arg_start);
8559 }
8560
8561 p = consume_improper_spaces (p, body);
8562
8563 /* Consume the comma, if present. */
8564 if (*p == ',')
8565 {
8566 p++;
8567
8568 p = consume_improper_spaces (p, body);
8569 }
8570 }
8571
8572 if (*p == ')')
8573 {
8574 p++;
8575
8576 if (*p == ' ')
8577 /* Perfectly formed definition, no complaints. */
8578 macro_define_function (file, line, name,
8579 argc, (const char **) argv,
8580 p + 1);
8581 else if (*p == '\0')
8582 {
8583 /* Complain, but do define it. */
8584 dwarf2_macro_malformed_definition_complaint (body);
8585 macro_define_function (file, line, name,
8586 argc, (const char **) argv,
8587 p);
8588 }
8589 else
8590 /* Just complain. */
8591 dwarf2_macro_malformed_definition_complaint (body);
8592 }
8593 else
8594 /* Just complain. */
8595 dwarf2_macro_malformed_definition_complaint (body);
8596
8597 xfree (name);
8598 {
8599 int i;
8600
8601 for (i = 0; i < argc; i++)
8602 xfree (argv[i]);
8603 }
8604 xfree (argv);
8605 }
8606 else
8607 dwarf2_macro_malformed_definition_complaint (body);
8608 }
8609
8610
8611 static void
8612 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
8613 char *comp_dir, bfd *abfd,
8614 struct dwarf2_cu *cu)
8615 {
8616 char *mac_ptr, *mac_end;
8617 struct macro_source_file *current_file = 0;
8618
8619 if (dwarf2_per_objfile->macinfo_buffer == NULL)
8620 {
8621 complaint (&symfile_complaints, "missing .debug_macinfo section");
8622 return;
8623 }
8624
8625 mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
8626 mac_end = dwarf2_per_objfile->macinfo_buffer
8627 + dwarf2_per_objfile->macinfo_size;
8628
8629 for (;;)
8630 {
8631 enum dwarf_macinfo_record_type macinfo_type;
8632
8633 /* Do we at least have room for a macinfo type byte? */
8634 if (mac_ptr >= mac_end)
8635 {
8636 dwarf2_macros_too_long_complaint ();
8637 return;
8638 }
8639
8640 macinfo_type = read_1_byte (abfd, mac_ptr);
8641 mac_ptr++;
8642
8643 switch (macinfo_type)
8644 {
8645 /* A zero macinfo type indicates the end of the macro
8646 information. */
8647 case 0:
8648 return;
8649
8650 case DW_MACINFO_define:
8651 case DW_MACINFO_undef:
8652 {
8653 int bytes_read;
8654 int line;
8655 char *body;
8656
8657 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8658 mac_ptr += bytes_read;
8659 body = read_string (abfd, mac_ptr, &bytes_read);
8660 mac_ptr += bytes_read;
8661
8662 if (! current_file)
8663 complaint (&symfile_complaints,
8664 "debug info gives macro %s outside of any file: %s",
8665 macinfo_type ==
8666 DW_MACINFO_define ? "definition" : macinfo_type ==
8667 DW_MACINFO_undef ? "undefinition" :
8668 "something-or-other", body);
8669 else
8670 {
8671 if (macinfo_type == DW_MACINFO_define)
8672 parse_macro_definition (current_file, line, body);
8673 else if (macinfo_type == DW_MACINFO_undef)
8674 macro_undef (current_file, line, body);
8675 }
8676 }
8677 break;
8678
8679 case DW_MACINFO_start_file:
8680 {
8681 int bytes_read;
8682 int line, file;
8683
8684 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8685 mac_ptr += bytes_read;
8686 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8687 mac_ptr += bytes_read;
8688
8689 current_file = macro_start_file (file, line,
8690 current_file, comp_dir,
8691 lh, cu->objfile);
8692 }
8693 break;
8694
8695 case DW_MACINFO_end_file:
8696 if (! current_file)
8697 complaint (&symfile_complaints,
8698 "macro debug info has an unmatched `close_file' directive");
8699 else
8700 {
8701 current_file = current_file->included_by;
8702 if (! current_file)
8703 {
8704 enum dwarf_macinfo_record_type next_type;
8705
8706 /* GCC circa March 2002 doesn't produce the zero
8707 type byte marking the end of the compilation
8708 unit. Complain if it's not there, but exit no
8709 matter what. */
8710
8711 /* Do we at least have room for a macinfo type byte? */
8712 if (mac_ptr >= mac_end)
8713 {
8714 dwarf2_macros_too_long_complaint ();
8715 return;
8716 }
8717
8718 /* We don't increment mac_ptr here, so this is just
8719 a look-ahead. */
8720 next_type = read_1_byte (abfd, mac_ptr);
8721 if (next_type != 0)
8722 complaint (&symfile_complaints,
8723 "no terminating 0-type entry for macros in `.debug_macinfo' section");
8724
8725 return;
8726 }
8727 }
8728 break;
8729
8730 case DW_MACINFO_vendor_ext:
8731 {
8732 int bytes_read;
8733 int constant;
8734 char *string;
8735
8736 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
8737 mac_ptr += bytes_read;
8738 string = read_string (abfd, mac_ptr, &bytes_read);
8739 mac_ptr += bytes_read;
8740
8741 /* We don't recognize any vendor extensions. */
8742 }
8743 break;
8744 }
8745 }
8746 }
8747
8748 /* Check if the attribute's form is a DW_FORM_block*
8749 if so return true else false. */
8750 static int
8751 attr_form_is_block (struct attribute *attr)
8752 {
8753 return (attr == NULL ? 0 :
8754 attr->form == DW_FORM_block1
8755 || attr->form == DW_FORM_block2
8756 || attr->form == DW_FORM_block4
8757 || attr->form == DW_FORM_block);
8758 }
8759
8760 static void
8761 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
8762 struct dwarf2_cu *cu)
8763 {
8764 if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8)
8765 {
8766 struct dwarf2_loclist_baton *baton;
8767
8768 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8769 sizeof (struct dwarf2_loclist_baton));
8770 baton->objfile = cu->objfile;
8771
8772 /* We don't know how long the location list is, but make sure we
8773 don't run off the edge of the section. */
8774 baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr);
8775 baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr);
8776 baton->base_address = cu->header.base_address;
8777 if (cu->header.base_known == 0)
8778 complaint (&symfile_complaints,
8779 "Location list used without specifying the CU base address.");
8780
8781 SYMBOL_OPS (sym) = &dwarf2_loclist_funcs;
8782 SYMBOL_LOCATION_BATON (sym) = baton;
8783 }
8784 else
8785 {
8786 struct dwarf2_locexpr_baton *baton;
8787
8788 baton = obstack_alloc (&cu->objfile->objfile_obstack,
8789 sizeof (struct dwarf2_locexpr_baton));
8790 baton->objfile = cu->objfile;
8791
8792 if (attr_form_is_block (attr))
8793 {
8794 /* Note that we're just copying the block's data pointer
8795 here, not the actual data. We're still pointing into the
8796 info_buffer for SYM's objfile; right now we never release
8797 that buffer, but when we do clean up properly this may
8798 need to change. */
8799 baton->size = DW_BLOCK (attr)->size;
8800 baton->data = DW_BLOCK (attr)->data;
8801 }
8802 else
8803 {
8804 dwarf2_invalid_attrib_class_complaint ("location description",
8805 SYMBOL_NATURAL_NAME (sym));
8806 baton->size = 0;
8807 baton->data = NULL;
8808 }
8809
8810 SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs;
8811 SYMBOL_LOCATION_BATON (sym) = baton;
8812 }
8813 }
8814
8815 /* This cleanup function is passed the address of a dwarf2_cu on the stack
8816 when we're finished with it. We can't free the pointer itself, but
8817 release any associated storage.
8818
8819 Only used during partial symbol parsing. */
8820
8821 static void
8822 free_stack_comp_unit (void *data)
8823 {
8824 struct dwarf2_cu *cu = data;
8825
8826 obstack_free (&cu->comp_unit_obstack, NULL);
8827 cu->partial_dies = NULL;
8828 }
8829
8830 /* Allocation function for the libiberty hash table which uses an
8831 obstack. */
8832
8833 static void *
8834 hashtab_obstack_allocate (void *data, size_t size, size_t count)
8835 {
8836 unsigned int total = size * count;
8837 void *ptr = obstack_alloc ((struct obstack *) data, total);
8838 memset (ptr, 0, total);
8839 return ptr;
8840 }
8841
8842 /* Trivial deallocation function for the libiberty splay tree and hash
8843 table - don't deallocate anything. Rely on later deletion of the
8844 obstack. */
8845
8846 static void
8847 dummy_obstack_deallocate (void *object, void *data)
8848 {
8849 return;
8850 }
8851
8852 /* Trivial hash function for partial_die_info: the hash value of a DIE
8853 is its offset in .debug_info for this objfile. */
8854
8855 static hashval_t
8856 partial_die_hash (const void *item)
8857 {
8858 const struct partial_die_info *part_die = item;
8859 return part_die->offset;
8860 }
8861
8862 /* Trivial comparison function for partial_die_info structures: two DIEs
8863 are equal if they have the same offset. */
8864
8865 static int
8866 partial_die_eq (const void *item_lhs, const void *item_rhs)
8867 {
8868 const struct partial_die_info *part_die_lhs = item_lhs;
8869 const struct partial_die_info *part_die_rhs = item_rhs;
8870 return part_die_lhs->offset == part_die_rhs->offset;
8871 }
8872
8873 void _initialize_dwarf2_read (void);
8874
8875 void
8876 _initialize_dwarf2_read (void)
8877 {
8878 dwarf2_objfile_data_key = register_objfile_data ();
8879 }
This page took 0.206986 seconds and 5 git commands to generate.