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