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