gdb/
[deliverable/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, 2010, 2011
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 #include "typeprint.h"
52 #include "jv-lang.h"
53 #include "psympriv.h"
54 #include "exceptions.h"
55 #include "gdb_stat.h"
56 #include "completer.h"
57 #include "vec.h"
58 #include "c-lang.h"
59 #include "valprint.h"
60 #include <ctype.h>
61
62 #include <fcntl.h>
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
66 #ifdef HAVE_ZLIB_H
67 #include <zlib.h>
68 #endif
69 #ifdef HAVE_MMAP
70 #include <sys/mman.h>
71 #ifndef MAP_FAILED
72 #define MAP_FAILED ((void *) -1)
73 #endif
74 #endif
75
76 typedef struct symbol *symbolp;
77 DEF_VEC_P (symbolp);
78
79 #if 0
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
84 {
85 unsigned int length; /* length of the .debug_info
86 contribution */
87 unsigned short version; /* version number -- 2 for DWARF
88 version 2 */
89 unsigned int abbrev_offset; /* offset into .debug_abbrev section */
90 unsigned char addr_size; /* byte size of an address -- 4 */
91 }
92 _COMP_UNIT_HEADER;
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
94 #endif
95
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
100 {
101 unsigned int total_length; /* byte length of the statement
102 information */
103 unsigned short version; /* version number -- 2 for DWARF
104 version 2 */
105 unsigned int prologue_length; /* # bytes between prologue &
106 stmt program */
107 unsigned char minimum_instruction_length; /* byte size of
108 smallest instr */
109 unsigned char default_is_stmt; /* initial value of is_stmt
110 register */
111 char line_base;
112 unsigned char line_range;
113 unsigned char opcode_base; /* number assigned to first special
114 opcode */
115 unsigned char *standard_opcode_lengths;
116 }
117 _STATEMENT_PROLOGUE;
118
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug = 0;
121
122 /* When non-zero, cross-check physname against demangler. */
123 static int check_physname = 0;
124
125 static int pagesize;
126
127 /* When set, the file that we're processing is known to have debugging
128 info for C++ namespaces. GCC 3.3.x did not produce this information,
129 but later versions do. */
130
131 static int processing_has_namespace_info;
132
133 static const struct objfile_data *dwarf2_objfile_data_key;
134
135 struct dwarf2_section_info
136 {
137 asection *asection;
138 gdb_byte *buffer;
139 bfd_size_type size;
140 /* Not NULL if the section was actually mmapped. */
141 void *map_addr;
142 /* Page aligned size of mmapped area. */
143 bfd_size_type map_len;
144 /* True if we have tried to read this section. */
145 int readin;
146 };
147
148 typedef struct dwarf2_section_info dwarf2_section_info_def;
149 DEF_VEC_O (dwarf2_section_info_def);
150
151 /* All offsets in the index are of this type. It must be
152 architecture-independent. */
153 typedef uint32_t offset_type;
154
155 DEF_VEC_I (offset_type);
156
157 /* A description of the mapped index. The file format is described in
158 a comment by the code that writes the index. */
159 struct mapped_index
160 {
161 /* Index data format version. */
162 int version;
163
164 /* The total length of the buffer. */
165 off_t total_size;
166
167 /* A pointer to the address table data. */
168 const gdb_byte *address_table;
169
170 /* Size of the address table data in bytes. */
171 offset_type address_table_size;
172
173 /* The symbol table, implemented as a hash table. */
174 const offset_type *symbol_table;
175
176 /* Size in slots, each slot is 2 offset_types. */
177 offset_type symbol_table_slots;
178
179 /* A pointer to the constant pool. */
180 const char *constant_pool;
181 };
182
183 struct dwarf2_per_objfile
184 {
185 struct dwarf2_section_info info;
186 struct dwarf2_section_info abbrev;
187 struct dwarf2_section_info line;
188 struct dwarf2_section_info loc;
189 struct dwarf2_section_info macinfo;
190 struct dwarf2_section_info macro;
191 struct dwarf2_section_info str;
192 struct dwarf2_section_info ranges;
193 struct dwarf2_section_info frame;
194 struct dwarf2_section_info eh_frame;
195 struct dwarf2_section_info gdb_index;
196
197 VEC (dwarf2_section_info_def) *types;
198
199 /* Back link. */
200 struct objfile *objfile;
201
202 /* A list of all the compilation units. This is used to locate
203 the target compilation unit of a particular reference. */
204 struct dwarf2_per_cu_data **all_comp_units;
205
206 /* The number of compilation units in ALL_COMP_UNITS. */
207 int n_comp_units;
208
209 /* The number of .debug_types-related CUs. */
210 int n_type_comp_units;
211
212 /* The .debug_types-related CUs. */
213 struct dwarf2_per_cu_data **type_comp_units;
214
215 /* A chain of compilation units that are currently read in, so that
216 they can be freed later. */
217 struct dwarf2_per_cu_data *read_in_chain;
218
219 /* A table mapping .debug_types signatures to its signatured_type entry.
220 This is NULL if the .debug_types section hasn't been read in yet. */
221 htab_t signatured_types;
222
223 /* A flag indicating wether this objfile has a section loaded at a
224 VMA of 0. */
225 int has_section_at_zero;
226
227 /* True if we are using the mapped index,
228 or we are faking it for OBJF_READNOW's sake. */
229 unsigned char using_index;
230
231 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
232 struct mapped_index *index_table;
233
234 /* When using index_table, this keeps track of all quick_file_names entries.
235 TUs can share line table entries with CUs or other TUs, and there can be
236 a lot more TUs than unique line tables, so we maintain a separate table
237 of all line table entries to support the sharing. */
238 htab_t quick_file_names_table;
239
240 /* Set during partial symbol reading, to prevent queueing of full
241 symbols. */
242 int reading_partial_symbols;
243
244 /* Table mapping type .debug_info DIE offsets to types.
245 This is NULL if not allocated yet.
246 It (currently) makes sense to allocate debug_types_type_hash lazily.
247 To keep things simple we allocate both lazily. */
248 htab_t debug_info_type_hash;
249
250 /* Table mapping type .debug_types DIE offsets to types.
251 This is NULL if not allocated yet. */
252 htab_t debug_types_type_hash;
253 };
254
255 static struct dwarf2_per_objfile *dwarf2_per_objfile;
256
257 /* Default names of the debugging sections. */
258
259 /* Note that if the debugging section has been compressed, it might
260 have a name like .zdebug_info. */
261
262 static const struct dwarf2_debug_sections dwarf2_elf_names = {
263 { ".debug_info", ".zdebug_info" },
264 { ".debug_abbrev", ".zdebug_abbrev" },
265 { ".debug_line", ".zdebug_line" },
266 { ".debug_loc", ".zdebug_loc" },
267 { ".debug_macinfo", ".zdebug_macinfo" },
268 { ".debug_macro", ".zdebug_macro" },
269 { ".debug_str", ".zdebug_str" },
270 { ".debug_ranges", ".zdebug_ranges" },
271 { ".debug_types", ".zdebug_types" },
272 { ".debug_frame", ".zdebug_frame" },
273 { ".eh_frame", NULL },
274 { ".gdb_index", ".zgdb_index" },
275 23
276 };
277
278 /* local data types */
279
280 /* We hold several abbreviation tables in memory at the same time. */
281 #ifndef ABBREV_HASH_SIZE
282 #define ABBREV_HASH_SIZE 121
283 #endif
284
285 /* The data in a compilation unit header, after target2host
286 translation, looks like this. */
287 struct comp_unit_head
288 {
289 unsigned int length;
290 short version;
291 unsigned char addr_size;
292 unsigned char signed_addr_p;
293 unsigned int abbrev_offset;
294
295 /* Size of file offsets; either 4 or 8. */
296 unsigned int offset_size;
297
298 /* Size of the length field; either 4 or 12. */
299 unsigned int initial_length_size;
300
301 /* Offset to the first byte of this compilation unit header in the
302 .debug_info section, for resolving relative reference dies. */
303 unsigned int offset;
304
305 /* Offset to first die in this cu from the start of the cu.
306 This will be the first byte following the compilation unit header. */
307 unsigned int first_die_offset;
308 };
309
310 /* Type used for delaying computation of method physnames.
311 See comments for compute_delayed_physnames. */
312 struct delayed_method_info
313 {
314 /* The type to which the method is attached, i.e., its parent class. */
315 struct type *type;
316
317 /* The index of the method in the type's function fieldlists. */
318 int fnfield_index;
319
320 /* The index of the method in the fieldlist. */
321 int index;
322
323 /* The name of the DIE. */
324 const char *name;
325
326 /* The DIE associated with this method. */
327 struct die_info *die;
328 };
329
330 typedef struct delayed_method_info delayed_method_info;
331 DEF_VEC_O (delayed_method_info);
332
333 /* Internal state when decoding a particular compilation unit. */
334 struct dwarf2_cu
335 {
336 /* The objfile containing this compilation unit. */
337 struct objfile *objfile;
338
339 /* The header of the compilation unit. */
340 struct comp_unit_head header;
341
342 /* Base address of this compilation unit. */
343 CORE_ADDR base_address;
344
345 /* Non-zero if base_address has been set. */
346 int base_known;
347
348 struct function_range *first_fn, *last_fn, *cached_fn;
349
350 /* The language we are debugging. */
351 enum language language;
352 const struct language_defn *language_defn;
353
354 const char *producer;
355
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
360
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending **list_in_scope;
366
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info **dwarf2_abbrevs;
369
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack;
372
373 /* Hash table holding all the loaded partial DIEs. */
374 htab_t partial_dies;
375
376 /* Storage for things with the same lifetime as this read-in compilation
377 unit, including partial DIEs. */
378 struct obstack comp_unit_obstack;
379
380 /* When multiple dwarf2_cu structures are living in memory, this field
381 chains them all together, so that they can be released efficiently.
382 We will probably also want a generation counter so that most-recently-used
383 compilation units are cached... */
384 struct dwarf2_per_cu_data *read_in_chain;
385
386 /* Backchain to our per_cu entry if the tree has been built. */
387 struct dwarf2_per_cu_data *per_cu;
388
389 /* How many compilation units ago was this CU last referenced? */
390 int last_used;
391
392 /* A hash table of die offsets for following references. */
393 htab_t die_hash;
394
395 /* Full DIEs if read in. */
396 struct die_info *dies;
397
398 /* A set of pointers to dwarf2_per_cu_data objects for compilation
399 units referenced by this one. Only set during full symbol processing;
400 partial symbol tables do not have dependencies. */
401 htab_t dependencies;
402
403 /* Header data from the line table, during full symbol processing. */
404 struct line_header *line_header;
405
406 /* A list of methods which need to have physnames computed
407 after all type information has been read. */
408 VEC (delayed_method_info) *method_list;
409
410 /* Mark used when releasing cached dies. */
411 unsigned int mark : 1;
412
413 /* This flag will be set if this compilation unit might include
414 inter-compilation-unit references. */
415 unsigned int has_form_ref_addr : 1;
416
417 /* This flag will be set if this compilation unit includes any
418 DW_TAG_namespace DIEs. If we know that there are explicit
419 DIEs for namespaces, we don't need to try to infer them
420 from mangled names. */
421 unsigned int has_namespace_info : 1;
422
423 /* This CU references .debug_loc. See the symtab->locations_valid field.
424 This test is imperfect as there may exist optimized debug code not using
425 any location list and still facing inlining issues if handled as
426 unoptimized code. For a future better test see GCC PR other/32998. */
427
428 unsigned int has_loclist : 1;
429 };
430
431 /* Persistent data held for a compilation unit, even when not
432 processing it. We put a pointer to this structure in the
433 read_symtab_private field of the psymtab. If we encounter
434 inter-compilation-unit references, we also maintain a sorted
435 list of all compilation units. */
436
437 struct dwarf2_per_cu_data
438 {
439 /* The start offset and length of this compilation unit. 2**29-1
440 bytes should suffice to store the length of any compilation unit
441 - if it doesn't, GDB will fall over anyway.
442 NOTE: Unlike comp_unit_head.length, this length includes
443 initial_length_size. */
444 unsigned int offset;
445 unsigned int length : 29;
446
447 /* Flag indicating this compilation unit will be read in before
448 any of the current compilation units are processed. */
449 unsigned int queued : 1;
450
451 /* This flag will be set if we need to load absolutely all DIEs
452 for this compilation unit, instead of just the ones we think
453 are interesting. It gets set if we look for a DIE in the
454 hash table and don't find it. */
455 unsigned int load_all_dies : 1;
456
457 /* Non-null if this CU is from .debug_types; in which case it points
458 to the section. Otherwise it's from .debug_info. */
459 struct dwarf2_section_info *debug_type_section;
460
461 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
462 of the CU cache it gets reset to NULL again. */
463 struct dwarf2_cu *cu;
464
465 /* The corresponding objfile. */
466 struct objfile *objfile;
467
468 /* When using partial symbol tables, the 'psymtab' field is active.
469 Otherwise the 'quick' field is active. */
470 union
471 {
472 /* The partial symbol table associated with this compilation unit,
473 or NULL for partial units (which do not have an associated
474 symtab). */
475 struct partial_symtab *psymtab;
476
477 /* Data needed by the "quick" functions. */
478 struct dwarf2_per_cu_quick_data *quick;
479 } v;
480 };
481
482 /* Entry in the signatured_types hash table. */
483
484 struct signatured_type
485 {
486 ULONGEST signature;
487
488 /* Offset in .debug_types of the type defined by this TU. */
489 unsigned int type_offset;
490
491 /* The CU(/TU) of this type. */
492 struct dwarf2_per_cu_data per_cu;
493 };
494
495 /* Struct used to pass misc. parameters to read_die_and_children, et
496 al. which are used for both .debug_info and .debug_types dies.
497 All parameters here are unchanging for the life of the call. This
498 struct exists to abstract away the constant parameters of die
499 reading. */
500
501 struct die_reader_specs
502 {
503 /* The bfd of this objfile. */
504 bfd* abfd;
505
506 /* The CU of the DIE we are parsing. */
507 struct dwarf2_cu *cu;
508
509 /* Pointer to start of section buffer.
510 This is either the start of .debug_info or .debug_types. */
511 const gdb_byte *buffer;
512 };
513
514 /* The line number information for a compilation unit (found in the
515 .debug_line section) begins with a "statement program header",
516 which contains the following information. */
517 struct line_header
518 {
519 unsigned int total_length;
520 unsigned short version;
521 unsigned int header_length;
522 unsigned char minimum_instruction_length;
523 unsigned char maximum_ops_per_instruction;
524 unsigned char default_is_stmt;
525 int line_base;
526 unsigned char line_range;
527 unsigned char opcode_base;
528
529 /* standard_opcode_lengths[i] is the number of operands for the
530 standard opcode whose value is i. This means that
531 standard_opcode_lengths[0] is unused, and the last meaningful
532 element is standard_opcode_lengths[opcode_base - 1]. */
533 unsigned char *standard_opcode_lengths;
534
535 /* The include_directories table. NOTE! These strings are not
536 allocated with xmalloc; instead, they are pointers into
537 debug_line_buffer. If you try to free them, `free' will get
538 indigestion. */
539 unsigned int num_include_dirs, include_dirs_size;
540 char **include_dirs;
541
542 /* The file_names table. NOTE! These strings are not allocated
543 with xmalloc; instead, they are pointers into debug_line_buffer.
544 Don't try to free them directly. */
545 unsigned int num_file_names, file_names_size;
546 struct file_entry
547 {
548 char *name;
549 unsigned int dir_index;
550 unsigned int mod_time;
551 unsigned int length;
552 int included_p; /* Non-zero if referenced by the Line Number Program. */
553 struct symtab *symtab; /* The associated symbol table, if any. */
554 } *file_names;
555
556 /* The start and end of the statement program following this
557 header. These point into dwarf2_per_objfile->line_buffer. */
558 gdb_byte *statement_program_start, *statement_program_end;
559 };
560
561 /* When we construct a partial symbol table entry we only
562 need this much information. */
563 struct partial_die_info
564 {
565 /* Offset of this DIE. */
566 unsigned int offset;
567
568 /* DWARF-2 tag for this DIE. */
569 ENUM_BITFIELD(dwarf_tag) tag : 16;
570
571 /* Assorted flags describing the data found in this DIE. */
572 unsigned int has_children : 1;
573 unsigned int is_external : 1;
574 unsigned int is_declaration : 1;
575 unsigned int has_type : 1;
576 unsigned int has_specification : 1;
577 unsigned int has_pc_info : 1;
578
579 /* Flag set if the SCOPE field of this structure has been
580 computed. */
581 unsigned int scope_set : 1;
582
583 /* Flag set if the DIE has a byte_size attribute. */
584 unsigned int has_byte_size : 1;
585
586 /* Flag set if any of the DIE's children are template arguments. */
587 unsigned int has_template_arguments : 1;
588
589 /* Flag set if fixup_partial_die has been called on this die. */
590 unsigned int fixup_called : 1;
591
592 /* The name of this DIE. Normally the value of DW_AT_name, but
593 sometimes a default name for unnamed DIEs. */
594 char *name;
595
596 /* The linkage name, if present. */
597 const char *linkage_name;
598
599 /* The scope to prepend to our children. This is generally
600 allocated on the comp_unit_obstack, so will disappear
601 when this compilation unit leaves the cache. */
602 char *scope;
603
604 /* The location description associated with this DIE, if any. */
605 struct dwarf_block *locdesc;
606
607 /* If HAS_PC_INFO, the PC range associated with this DIE. */
608 CORE_ADDR lowpc;
609 CORE_ADDR highpc;
610
611 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
612 DW_AT_sibling, if any. */
613 /* NOTE: This member isn't strictly necessary, read_partial_die could
614 return DW_AT_sibling values to its caller load_partial_dies. */
615 gdb_byte *sibling;
616
617 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
618 DW_AT_specification (or DW_AT_abstract_origin or
619 DW_AT_extension). */
620 unsigned int spec_offset;
621
622 /* Pointers to this DIE's parent, first child, and next sibling,
623 if any. */
624 struct partial_die_info *die_parent, *die_child, *die_sibling;
625 };
626
627 /* This data structure holds the information of an abbrev. */
628 struct abbrev_info
629 {
630 unsigned int number; /* number identifying abbrev */
631 enum dwarf_tag tag; /* dwarf tag */
632 unsigned short has_children; /* boolean */
633 unsigned short num_attrs; /* number of attributes */
634 struct attr_abbrev *attrs; /* an array of attribute descriptions */
635 struct abbrev_info *next; /* next in chain */
636 };
637
638 struct attr_abbrev
639 {
640 ENUM_BITFIELD(dwarf_attribute) name : 16;
641 ENUM_BITFIELD(dwarf_form) form : 16;
642 };
643
644 /* Attributes have a name and a value. */
645 struct attribute
646 {
647 ENUM_BITFIELD(dwarf_attribute) name : 16;
648 ENUM_BITFIELD(dwarf_form) form : 15;
649
650 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
651 field should be in u.str (existing only for DW_STRING) but it is kept
652 here for better struct attribute alignment. */
653 unsigned int string_is_canonical : 1;
654
655 union
656 {
657 char *str;
658 struct dwarf_block *blk;
659 ULONGEST unsnd;
660 LONGEST snd;
661 CORE_ADDR addr;
662 struct signatured_type *signatured_type;
663 }
664 u;
665 };
666
667 /* This data structure holds a complete die structure. */
668 struct die_info
669 {
670 /* DWARF-2 tag for this DIE. */
671 ENUM_BITFIELD(dwarf_tag) tag : 16;
672
673 /* Number of attributes */
674 unsigned char num_attrs;
675
676 /* True if we're presently building the full type name for the
677 type derived from this DIE. */
678 unsigned char building_fullname : 1;
679
680 /* Abbrev number */
681 unsigned int abbrev;
682
683 /* Offset in .debug_info or .debug_types section. */
684 unsigned int offset;
685
686 /* The dies in a compilation unit form an n-ary tree. PARENT
687 points to this die's parent; CHILD points to the first child of
688 this node; and all the children of a given node are chained
689 together via their SIBLING fields. */
690 struct die_info *child; /* Its first child, if any. */
691 struct die_info *sibling; /* Its next sibling, if any. */
692 struct die_info *parent; /* Its parent, if any. */
693
694 /* An array of attributes, with NUM_ATTRS elements. There may be
695 zero, but it's not common and zero-sized arrays are not
696 sufficiently portable C. */
697 struct attribute attrs[1];
698 };
699
700 struct function_range
701 {
702 const char *name;
703 CORE_ADDR lowpc, highpc;
704 int seen_line;
705 struct function_range *next;
706 };
707
708 /* Get at parts of an attribute structure. */
709
710 #define DW_STRING(attr) ((attr)->u.str)
711 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
712 #define DW_UNSND(attr) ((attr)->u.unsnd)
713 #define DW_BLOCK(attr) ((attr)->u.blk)
714 #define DW_SND(attr) ((attr)->u.snd)
715 #define DW_ADDR(attr) ((attr)->u.addr)
716 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
717
718 /* Blocks are a bunch of untyped bytes. */
719 struct dwarf_block
720 {
721 unsigned int size;
722 gdb_byte *data;
723 };
724
725 #ifndef ATTR_ALLOC_CHUNK
726 #define ATTR_ALLOC_CHUNK 4
727 #endif
728
729 /* Allocate fields for structs, unions and enums in this size. */
730 #ifndef DW_FIELD_ALLOC_CHUNK
731 #define DW_FIELD_ALLOC_CHUNK 4
732 #endif
733
734 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
735 but this would require a corresponding change in unpack_field_as_long
736 and friends. */
737 static int bits_per_byte = 8;
738
739 /* The routines that read and process dies for a C struct or C++ class
740 pass lists of data member fields and lists of member function fields
741 in an instance of a field_info structure, as defined below. */
742 struct field_info
743 {
744 /* List of data member and baseclasses fields. */
745 struct nextfield
746 {
747 struct nextfield *next;
748 int accessibility;
749 int virtuality;
750 struct field field;
751 }
752 *fields, *baseclasses;
753
754 /* Number of fields (including baseclasses). */
755 int nfields;
756
757 /* Number of baseclasses. */
758 int nbaseclasses;
759
760 /* Set if the accesibility of one of the fields is not public. */
761 int non_public_fields;
762
763 /* Member function fields array, entries are allocated in the order they
764 are encountered in the object file. */
765 struct nextfnfield
766 {
767 struct nextfnfield *next;
768 struct fn_field fnfield;
769 }
770 *fnfields;
771
772 /* Member function fieldlist array, contains name of possibly overloaded
773 member function, number of overloaded member functions and a pointer
774 to the head of the member function field chain. */
775 struct fnfieldlist
776 {
777 char *name;
778 int length;
779 struct nextfnfield *head;
780 }
781 *fnfieldlists;
782
783 /* Number of entries in the fnfieldlists array. */
784 int nfnfields;
785
786 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
787 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
788 struct typedef_field_list
789 {
790 struct typedef_field field;
791 struct typedef_field_list *next;
792 }
793 *typedef_field_list;
794 unsigned typedef_field_list_count;
795 };
796
797 /* One item on the queue of compilation units to read in full symbols
798 for. */
799 struct dwarf2_queue_item
800 {
801 struct dwarf2_per_cu_data *per_cu;
802 struct dwarf2_queue_item *next;
803 };
804
805 /* The current queue. */
806 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
807
808 /* Loaded secondary compilation units are kept in memory until they
809 have not been referenced for the processing of this many
810 compilation units. Set this to zero to disable caching. Cache
811 sizes of up to at least twenty will improve startup time for
812 typical inter-CU-reference binaries, at an obvious memory cost. */
813 static int dwarf2_max_cache_age = 5;
814 static void
815 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
816 struct cmd_list_element *c, const char *value)
817 {
818 fprintf_filtered (file, _("The upper bound on the age of cached "
819 "dwarf2 compilation units is %s.\n"),
820 value);
821 }
822
823
824 /* Various complaints about symbol reading that don't abort the process. */
825
826 static void
827 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
828 {
829 complaint (&symfile_complaints,
830 _("statement list doesn't fit in .debug_line section"));
831 }
832
833 static void
834 dwarf2_debug_line_missing_file_complaint (void)
835 {
836 complaint (&symfile_complaints,
837 _(".debug_line section has line data without a file"));
838 }
839
840 static void
841 dwarf2_debug_line_missing_end_sequence_complaint (void)
842 {
843 complaint (&symfile_complaints,
844 _(".debug_line section has line "
845 "program sequence without an end"));
846 }
847
848 static void
849 dwarf2_complex_location_expr_complaint (void)
850 {
851 complaint (&symfile_complaints, _("location expression too complex"));
852 }
853
854 static void
855 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
856 int arg3)
857 {
858 complaint (&symfile_complaints,
859 _("const value length mismatch for '%s', got %d, expected %d"),
860 arg1, arg2, arg3);
861 }
862
863 static void
864 dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section)
865 {
866 complaint (&symfile_complaints,
867 _("macro info runs off end of `%s' section"),
868 section->asection->name);
869 }
870
871 static void
872 dwarf2_macro_malformed_definition_complaint (const char *arg1)
873 {
874 complaint (&symfile_complaints,
875 _("macro debug info contains a "
876 "malformed macro definition:\n`%s'"),
877 arg1);
878 }
879
880 static void
881 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
882 {
883 complaint (&symfile_complaints,
884 _("invalid attribute class or form for '%s' in '%s'"),
885 arg1, arg2);
886 }
887
888 /* local function prototypes */
889
890 static void dwarf2_locate_sections (bfd *, asection *, void *);
891
892 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
893 struct objfile *);
894
895 static void dwarf2_find_base_address (struct die_info *die,
896 struct dwarf2_cu *cu);
897
898 static void dwarf2_build_psymtabs_hard (struct objfile *);
899
900 static void scan_partial_symbols (struct partial_die_info *,
901 CORE_ADDR *, CORE_ADDR *,
902 int, struct dwarf2_cu *);
903
904 static void add_partial_symbol (struct partial_die_info *,
905 struct dwarf2_cu *);
906
907 static void add_partial_namespace (struct partial_die_info *pdi,
908 CORE_ADDR *lowpc, CORE_ADDR *highpc,
909 int need_pc, struct dwarf2_cu *cu);
910
911 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
912 CORE_ADDR *highpc, int need_pc,
913 struct dwarf2_cu *cu);
914
915 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
916 struct dwarf2_cu *cu);
917
918 static void add_partial_subprogram (struct partial_die_info *pdi,
919 CORE_ADDR *lowpc, CORE_ADDR *highpc,
920 int need_pc, struct dwarf2_cu *cu);
921
922 static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi,
923 gdb_byte *buffer, gdb_byte *info_ptr,
924 bfd *abfd, struct dwarf2_cu *cu);
925
926 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
927
928 static void psymtab_to_symtab_1 (struct partial_symtab *);
929
930 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
931
932 static void dwarf2_free_abbrev_table (void *);
933
934 static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *,
935 struct dwarf2_cu *);
936
937 static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int,
938 struct dwarf2_cu *);
939
940 static struct partial_die_info *load_partial_dies (bfd *,
941 gdb_byte *, gdb_byte *,
942 int, struct dwarf2_cu *);
943
944 static gdb_byte *read_partial_die (struct partial_die_info *,
945 struct abbrev_info *abbrev,
946 unsigned int, bfd *,
947 gdb_byte *, gdb_byte *,
948 struct dwarf2_cu *);
949
950 static struct partial_die_info *find_partial_die (unsigned int,
951 struct dwarf2_cu *);
952
953 static void fixup_partial_die (struct partial_die_info *,
954 struct dwarf2_cu *);
955
956 static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *,
957 bfd *, gdb_byte *, struct dwarf2_cu *);
958
959 static gdb_byte *read_attribute_value (struct attribute *, unsigned,
960 bfd *, gdb_byte *, struct dwarf2_cu *);
961
962 static unsigned int read_1_byte (bfd *, gdb_byte *);
963
964 static int read_1_signed_byte (bfd *, gdb_byte *);
965
966 static unsigned int read_2_bytes (bfd *, gdb_byte *);
967
968 static unsigned int read_4_bytes (bfd *, gdb_byte *);
969
970 static ULONGEST read_8_bytes (bfd *, gdb_byte *);
971
972 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
973 unsigned int *);
974
975 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
976
977 static LONGEST read_checked_initial_length_and_offset
978 (bfd *, gdb_byte *, const struct comp_unit_head *,
979 unsigned int *, unsigned int *);
980
981 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
982 unsigned int *);
983
984 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
985
986 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
987
988 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
989
990 static char *read_indirect_string (bfd *, gdb_byte *,
991 const struct comp_unit_head *,
992 unsigned int *);
993
994 static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
995
996 static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
997
998 static gdb_byte *skip_leb128 (bfd *, gdb_byte *);
999
1000 static void set_cu_language (unsigned int, struct dwarf2_cu *);
1001
1002 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
1003 struct dwarf2_cu *);
1004
1005 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
1006 unsigned int,
1007 struct dwarf2_cu *);
1008
1009 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
1010 struct dwarf2_cu *cu);
1011
1012 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
1013
1014 static struct die_info *die_specification (struct die_info *die,
1015 struct dwarf2_cu **);
1016
1017 static void free_line_header (struct line_header *lh);
1018
1019 static void add_file_name (struct line_header *, char *, unsigned int,
1020 unsigned int, unsigned int);
1021
1022 static struct line_header *(dwarf_decode_line_header
1023 (unsigned int offset,
1024 bfd *abfd, struct dwarf2_cu *cu));
1025
1026 static void dwarf_decode_lines (struct line_header *, const char *, bfd *,
1027 struct dwarf2_cu *, struct partial_symtab *);
1028
1029 static void dwarf2_start_subfile (char *, const char *, const char *);
1030
1031 static struct symbol *new_symbol (struct die_info *, struct type *,
1032 struct dwarf2_cu *);
1033
1034 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1035 struct dwarf2_cu *, struct symbol *);
1036
1037 static void dwarf2_const_value (struct attribute *, struct symbol *,
1038 struct dwarf2_cu *);
1039
1040 static void dwarf2_const_value_attr (struct attribute *attr,
1041 struct type *type,
1042 const char *name,
1043 struct obstack *obstack,
1044 struct dwarf2_cu *cu, long *value,
1045 gdb_byte **bytes,
1046 struct dwarf2_locexpr_baton **baton);
1047
1048 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1049
1050 static int need_gnat_info (struct dwarf2_cu *);
1051
1052 static struct type *die_descriptive_type (struct die_info *,
1053 struct dwarf2_cu *);
1054
1055 static void set_descriptive_type (struct type *, struct die_info *,
1056 struct dwarf2_cu *);
1057
1058 static struct type *die_containing_type (struct die_info *,
1059 struct dwarf2_cu *);
1060
1061 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1062 struct dwarf2_cu *);
1063
1064 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1065
1066 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1067
1068 static char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1069
1070 static char *typename_concat (struct obstack *obs, const char *prefix,
1071 const char *suffix, int physname,
1072 struct dwarf2_cu *cu);
1073
1074 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1075
1076 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1077
1078 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1079
1080 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1081
1082 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1083 struct dwarf2_cu *, struct partial_symtab *);
1084
1085 static int dwarf2_get_pc_bounds (struct die_info *,
1086 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1087 struct partial_symtab *);
1088
1089 static void get_scope_pc_bounds (struct die_info *,
1090 CORE_ADDR *, CORE_ADDR *,
1091 struct dwarf2_cu *);
1092
1093 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1094 CORE_ADDR, struct dwarf2_cu *);
1095
1096 static void dwarf2_add_field (struct field_info *, struct die_info *,
1097 struct dwarf2_cu *);
1098
1099 static void dwarf2_attach_fields_to_type (struct field_info *,
1100 struct type *, struct dwarf2_cu *);
1101
1102 static void dwarf2_add_member_fn (struct field_info *,
1103 struct die_info *, struct type *,
1104 struct dwarf2_cu *);
1105
1106 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1107 struct type *,
1108 struct dwarf2_cu *);
1109
1110 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1111
1112 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1113
1114 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1115
1116 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1117
1118 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1119
1120 static struct type *read_module_type (struct die_info *die,
1121 struct dwarf2_cu *cu);
1122
1123 static const char *namespace_name (struct die_info *die,
1124 int *is_anonymous, struct dwarf2_cu *);
1125
1126 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1127
1128 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1129
1130 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1131 struct dwarf2_cu *);
1132
1133 static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *);
1134
1135 static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader,
1136 gdb_byte *info_ptr,
1137 gdb_byte **new_info_ptr,
1138 struct die_info *parent);
1139
1140 static struct die_info *read_die_and_children (const struct die_reader_specs *reader,
1141 gdb_byte *info_ptr,
1142 gdb_byte **new_info_ptr,
1143 struct die_info *parent);
1144
1145 static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader,
1146 gdb_byte *info_ptr,
1147 gdb_byte **new_info_ptr,
1148 struct die_info *parent);
1149
1150 static gdb_byte *read_full_die (const struct die_reader_specs *reader,
1151 struct die_info **, gdb_byte *,
1152 int *);
1153
1154 static void process_die (struct die_info *, struct dwarf2_cu *);
1155
1156 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1157 struct obstack *);
1158
1159 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1160
1161 static const char *dwarf2_full_name (char *name,
1162 struct die_info *die,
1163 struct dwarf2_cu *cu);
1164
1165 static struct die_info *dwarf2_extension (struct die_info *die,
1166 struct dwarf2_cu **);
1167
1168 static char *dwarf_tag_name (unsigned int);
1169
1170 static char *dwarf_attr_name (unsigned int);
1171
1172 static char *dwarf_form_name (unsigned int);
1173
1174 static char *dwarf_bool_name (unsigned int);
1175
1176 static char *dwarf_type_encoding_name (unsigned int);
1177
1178 #if 0
1179 static char *dwarf_cfi_name (unsigned int);
1180 #endif
1181
1182 static struct die_info *sibling_die (struct die_info *);
1183
1184 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1185
1186 static void dump_die_for_error (struct die_info *);
1187
1188 static void dump_die_1 (struct ui_file *, int level, int max_level,
1189 struct die_info *);
1190
1191 /*static*/ void dump_die (struct die_info *, int max_level);
1192
1193 static void store_in_ref_table (struct die_info *,
1194 struct dwarf2_cu *);
1195
1196 static int is_ref_attr (struct attribute *);
1197
1198 static unsigned int dwarf2_get_ref_die_offset (struct attribute *);
1199
1200 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1201
1202 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1203 struct attribute *,
1204 struct dwarf2_cu **);
1205
1206 static struct die_info *follow_die_ref (struct die_info *,
1207 struct attribute *,
1208 struct dwarf2_cu **);
1209
1210 static struct die_info *follow_die_sig (struct die_info *,
1211 struct attribute *,
1212 struct dwarf2_cu **);
1213
1214 static struct signatured_type *lookup_signatured_type_at_offset
1215 (struct objfile *objfile,
1216 struct dwarf2_section_info *section,
1217 unsigned int offset);
1218
1219 static void read_signatured_type_at_offset (struct objfile *objfile,
1220 struct dwarf2_section_info *sect,
1221 unsigned int offset);
1222
1223 static void read_signatured_type (struct objfile *,
1224 struct signatured_type *type_sig);
1225
1226 /* memory allocation interface */
1227
1228 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1229
1230 static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *);
1231
1232 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1233
1234 static void initialize_cu_func_list (struct dwarf2_cu *);
1235
1236 static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR,
1237 struct dwarf2_cu *);
1238
1239 static void dwarf_decode_macros (struct line_header *, unsigned int,
1240 char *, bfd *, struct dwarf2_cu *,
1241 struct dwarf2_section_info *,
1242 int);
1243
1244 static int attr_form_is_block (struct attribute *);
1245
1246 static int attr_form_is_section_offset (struct attribute *);
1247
1248 static int attr_form_is_constant (struct attribute *);
1249
1250 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1251 struct dwarf2_loclist_baton *baton,
1252 struct attribute *attr);
1253
1254 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1255 struct symbol *sym,
1256 struct dwarf2_cu *cu);
1257
1258 static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
1259 struct abbrev_info *abbrev,
1260 struct dwarf2_cu *cu);
1261
1262 static void free_stack_comp_unit (void *);
1263
1264 static hashval_t partial_die_hash (const void *item);
1265
1266 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1267
1268 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1269 (unsigned int offset, struct objfile *objfile);
1270
1271 static struct dwarf2_per_cu_data *dwarf2_find_comp_unit
1272 (unsigned int offset, struct objfile *objfile);
1273
1274 static void init_one_comp_unit (struct dwarf2_cu *cu,
1275 struct objfile *objfile);
1276
1277 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1278 struct die_info *comp_unit_die);
1279
1280 static void free_one_comp_unit (void *);
1281
1282 static void free_cached_comp_units (void *);
1283
1284 static void age_cached_comp_units (void);
1285
1286 static void free_one_cached_comp_unit (void *);
1287
1288 static struct type *set_die_type (struct die_info *, struct type *,
1289 struct dwarf2_cu *);
1290
1291 static void create_all_comp_units (struct objfile *);
1292
1293 static int create_debug_types_hash_table (struct objfile *objfile);
1294
1295 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1296 struct objfile *);
1297
1298 static void process_full_comp_unit (struct dwarf2_per_cu_data *);
1299
1300 static void dwarf2_add_dependence (struct dwarf2_cu *,
1301 struct dwarf2_per_cu_data *);
1302
1303 static void dwarf2_mark (struct dwarf2_cu *);
1304
1305 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1306
1307 static struct type *get_die_type_at_offset (unsigned int,
1308 struct dwarf2_per_cu_data *per_cu);
1309
1310 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1311
1312 static void dwarf2_release_queue (void *dummy);
1313
1314 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1315 struct objfile *objfile);
1316
1317 static void process_queue (struct objfile *objfile);
1318
1319 static void find_file_and_directory (struct die_info *die,
1320 struct dwarf2_cu *cu,
1321 char **name, char **comp_dir);
1322
1323 static char *file_full_name (int file, struct line_header *lh,
1324 const char *comp_dir);
1325
1326 static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header,
1327 gdb_byte *info_ptr,
1328 gdb_byte *buffer,
1329 unsigned int buffer_size,
1330 bfd *abfd);
1331
1332 static void init_cu_die_reader (struct die_reader_specs *reader,
1333 struct dwarf2_cu *cu);
1334
1335 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1336
1337 #if WORDS_BIGENDIAN
1338
1339 /* Convert VALUE between big- and little-endian. */
1340 static offset_type
1341 byte_swap (offset_type value)
1342 {
1343 offset_type result;
1344
1345 result = (value & 0xff) << 24;
1346 result |= (value & 0xff00) << 8;
1347 result |= (value & 0xff0000) >> 8;
1348 result |= (value & 0xff000000) >> 24;
1349 return result;
1350 }
1351
1352 #define MAYBE_SWAP(V) byte_swap (V)
1353
1354 #else
1355 #define MAYBE_SWAP(V) (V)
1356 #endif /* WORDS_BIGENDIAN */
1357
1358 /* The suffix for an index file. */
1359 #define INDEX_SUFFIX ".gdb-index"
1360
1361 static const char *dwarf2_physname (char *name, struct die_info *die,
1362 struct dwarf2_cu *cu);
1363
1364 /* Try to locate the sections we need for DWARF 2 debugging
1365 information and return true if we have enough to do something.
1366 NAMES points to the dwarf2 section names, or is NULL if the standard
1367 ELF names are used. */
1368
1369 int
1370 dwarf2_has_info (struct objfile *objfile,
1371 const struct dwarf2_debug_sections *names)
1372 {
1373 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1374 if (!dwarf2_per_objfile)
1375 {
1376 /* Initialize per-objfile state. */
1377 struct dwarf2_per_objfile *data
1378 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1379
1380 memset (data, 0, sizeof (*data));
1381 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1382 dwarf2_per_objfile = data;
1383
1384 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1385 (void *) names);
1386 dwarf2_per_objfile->objfile = objfile;
1387 }
1388 return (dwarf2_per_objfile->info.asection != NULL
1389 && dwarf2_per_objfile->abbrev.asection != NULL);
1390 }
1391
1392 /* When loading sections, we look either for uncompressed section or for
1393 compressed section names. */
1394
1395 static int
1396 section_is_p (const char *section_name,
1397 const struct dwarf2_section_names *names)
1398 {
1399 if (names->normal != NULL
1400 && strcmp (section_name, names->normal) == 0)
1401 return 1;
1402 if (names->compressed != NULL
1403 && strcmp (section_name, names->compressed) == 0)
1404 return 1;
1405 return 0;
1406 }
1407
1408 /* This function is mapped across the sections and remembers the
1409 offset and size of each of the debugging sections we are interested
1410 in. */
1411
1412 static void
1413 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1414 {
1415 const struct dwarf2_debug_sections *names;
1416
1417 if (vnames == NULL)
1418 names = &dwarf2_elf_names;
1419 else
1420 names = (const struct dwarf2_debug_sections *) vnames;
1421
1422 if (section_is_p (sectp->name, &names->info))
1423 {
1424 dwarf2_per_objfile->info.asection = sectp;
1425 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1426 }
1427 else if (section_is_p (sectp->name, &names->abbrev))
1428 {
1429 dwarf2_per_objfile->abbrev.asection = sectp;
1430 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1431 }
1432 else if (section_is_p (sectp->name, &names->line))
1433 {
1434 dwarf2_per_objfile->line.asection = sectp;
1435 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1436 }
1437 else if (section_is_p (sectp->name, &names->loc))
1438 {
1439 dwarf2_per_objfile->loc.asection = sectp;
1440 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1441 }
1442 else if (section_is_p (sectp->name, &names->macinfo))
1443 {
1444 dwarf2_per_objfile->macinfo.asection = sectp;
1445 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1446 }
1447 else if (section_is_p (sectp->name, &names->macro))
1448 {
1449 dwarf2_per_objfile->macro.asection = sectp;
1450 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1451 }
1452 else if (section_is_p (sectp->name, &names->str))
1453 {
1454 dwarf2_per_objfile->str.asection = sectp;
1455 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1456 }
1457 else if (section_is_p (sectp->name, &names->frame))
1458 {
1459 dwarf2_per_objfile->frame.asection = sectp;
1460 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1461 }
1462 else if (section_is_p (sectp->name, &names->eh_frame))
1463 {
1464 flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
1465
1466 if (aflag & SEC_HAS_CONTENTS)
1467 {
1468 dwarf2_per_objfile->eh_frame.asection = sectp;
1469 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1470 }
1471 }
1472 else if (section_is_p (sectp->name, &names->ranges))
1473 {
1474 dwarf2_per_objfile->ranges.asection = sectp;
1475 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1476 }
1477 else if (section_is_p (sectp->name, &names->types))
1478 {
1479 struct dwarf2_section_info type_section;
1480
1481 memset (&type_section, 0, sizeof (type_section));
1482 type_section.asection = sectp;
1483 type_section.size = bfd_get_section_size (sectp);
1484
1485 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1486 &type_section);
1487 }
1488 else if (section_is_p (sectp->name, &names->gdb_index))
1489 {
1490 dwarf2_per_objfile->gdb_index.asection = sectp;
1491 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1492 }
1493
1494 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1495 && bfd_section_vma (abfd, sectp) == 0)
1496 dwarf2_per_objfile->has_section_at_zero = 1;
1497 }
1498
1499 /* Decompress a section that was compressed using zlib. Store the
1500 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1501
1502 static void
1503 zlib_decompress_section (struct objfile *objfile, asection *sectp,
1504 gdb_byte **outbuf, bfd_size_type *outsize)
1505 {
1506 bfd *abfd = objfile->obfd;
1507 #ifndef HAVE_ZLIB_H
1508 error (_("Support for zlib-compressed DWARF data (from '%s') "
1509 "is disabled in this copy of GDB"),
1510 bfd_get_filename (abfd));
1511 #else
1512 bfd_size_type compressed_size = bfd_get_section_size (sectp);
1513 gdb_byte *compressed_buffer = xmalloc (compressed_size);
1514 struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer);
1515 bfd_size_type uncompressed_size;
1516 gdb_byte *uncompressed_buffer;
1517 z_stream strm;
1518 int rc;
1519 int header_size = 12;
1520
1521 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1522 || bfd_bread (compressed_buffer,
1523 compressed_size, abfd) != compressed_size)
1524 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1525 bfd_get_filename (abfd));
1526
1527 /* Read the zlib header. In this case, it should be "ZLIB" followed
1528 by the uncompressed section size, 8 bytes in big-endian order. */
1529 if (compressed_size < header_size
1530 || strncmp (compressed_buffer, "ZLIB", 4) != 0)
1531 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1532 bfd_get_filename (abfd));
1533 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
1534 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
1535 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
1536 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
1537 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
1538 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
1539 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
1540 uncompressed_size += compressed_buffer[11];
1541
1542 /* It is possible the section consists of several compressed
1543 buffers concatenated together, so we uncompress in a loop. */
1544 strm.zalloc = NULL;
1545 strm.zfree = NULL;
1546 strm.opaque = NULL;
1547 strm.avail_in = compressed_size - header_size;
1548 strm.next_in = (Bytef*) compressed_buffer + header_size;
1549 strm.avail_out = uncompressed_size;
1550 uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack,
1551 uncompressed_size);
1552 rc = inflateInit (&strm);
1553 while (strm.avail_in > 0)
1554 {
1555 if (rc != Z_OK)
1556 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1557 bfd_get_filename (abfd), rc);
1558 strm.next_out = ((Bytef*) uncompressed_buffer
1559 + (uncompressed_size - strm.avail_out));
1560 rc = inflate (&strm, Z_FINISH);
1561 if (rc != Z_STREAM_END)
1562 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1563 bfd_get_filename (abfd), rc);
1564 rc = inflateReset (&strm);
1565 }
1566 rc = inflateEnd (&strm);
1567 if (rc != Z_OK
1568 || strm.avail_out != 0)
1569 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1570 bfd_get_filename (abfd), rc);
1571
1572 do_cleanups (cleanup);
1573 *outbuf = uncompressed_buffer;
1574 *outsize = uncompressed_size;
1575 #endif
1576 }
1577
1578 /* A helper function that decides whether a section is empty. */
1579
1580 static int
1581 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1582 {
1583 return info->asection == NULL || info->size == 0;
1584 }
1585
1586 /* Read the contents of the section SECTP from object file specified by
1587 OBJFILE, store info about the section into INFO.
1588 If the section is compressed, uncompress it before returning. */
1589
1590 static void
1591 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1592 {
1593 bfd *abfd = objfile->obfd;
1594 asection *sectp = info->asection;
1595 gdb_byte *buf, *retbuf;
1596 unsigned char header[4];
1597
1598 if (info->readin)
1599 return;
1600 info->buffer = NULL;
1601 info->map_addr = NULL;
1602 info->readin = 1;
1603
1604 if (dwarf2_section_empty_p (info))
1605 return;
1606
1607 /* Check if the file has a 4-byte header indicating compression. */
1608 if (info->size > sizeof (header)
1609 && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0
1610 && bfd_bread (header, sizeof (header), abfd) == sizeof (header))
1611 {
1612 /* Upon decompression, update the buffer and its size. */
1613 if (strncmp (header, "ZLIB", sizeof (header)) == 0)
1614 {
1615 zlib_decompress_section (objfile, sectp, &info->buffer,
1616 &info->size);
1617 return;
1618 }
1619 }
1620
1621 #ifdef HAVE_MMAP
1622 if (pagesize == 0)
1623 pagesize = getpagesize ();
1624
1625 /* Only try to mmap sections which are large enough: we don't want to
1626 waste space due to fragmentation. Also, only try mmap for sections
1627 without relocations. */
1628
1629 if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0)
1630 {
1631 info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ,
1632 MAP_PRIVATE, sectp->filepos,
1633 &info->map_addr, &info->map_len);
1634
1635 if ((caddr_t)info->buffer != MAP_FAILED)
1636 {
1637 #if HAVE_POSIX_MADVISE
1638 posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED);
1639 #endif
1640 return;
1641 }
1642 }
1643 #endif
1644
1645 /* If we get here, we are a normal, not-compressed section. */
1646 info->buffer = buf
1647 = obstack_alloc (&objfile->objfile_obstack, info->size);
1648
1649 /* When debugging .o files, we may need to apply relocations; see
1650 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1651 We never compress sections in .o files, so we only need to
1652 try this when the section is not compressed. */
1653 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1654 if (retbuf != NULL)
1655 {
1656 info->buffer = retbuf;
1657 return;
1658 }
1659
1660 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1661 || bfd_bread (buf, info->size, abfd) != info->size)
1662 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1663 bfd_get_filename (abfd));
1664 }
1665
1666 /* A helper function that returns the size of a section in a safe way.
1667 If you are positive that the section has been read before using the
1668 size, then it is safe to refer to the dwarf2_section_info object's
1669 "size" field directly. In other cases, you must call this
1670 function, because for compressed sections the size field is not set
1671 correctly until the section has been read. */
1672
1673 static bfd_size_type
1674 dwarf2_section_size (struct objfile *objfile,
1675 struct dwarf2_section_info *info)
1676 {
1677 if (!info->readin)
1678 dwarf2_read_section (objfile, info);
1679 return info->size;
1680 }
1681
1682 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1683 SECTION_NAME. */
1684
1685 void
1686 dwarf2_get_section_info (struct objfile *objfile,
1687 enum dwarf2_section_enum sect,
1688 asection **sectp, gdb_byte **bufp,
1689 bfd_size_type *sizep)
1690 {
1691 struct dwarf2_per_objfile *data
1692 = objfile_data (objfile, dwarf2_objfile_data_key);
1693 struct dwarf2_section_info *info;
1694
1695 /* We may see an objfile without any DWARF, in which case we just
1696 return nothing. */
1697 if (data == NULL)
1698 {
1699 *sectp = NULL;
1700 *bufp = NULL;
1701 *sizep = 0;
1702 return;
1703 }
1704 switch (sect)
1705 {
1706 case DWARF2_DEBUG_FRAME:
1707 info = &data->frame;
1708 break;
1709 case DWARF2_EH_FRAME:
1710 info = &data->eh_frame;
1711 break;
1712 default:
1713 gdb_assert_not_reached ("unexpected section");
1714 }
1715
1716 dwarf2_read_section (objfile, info);
1717
1718 *sectp = info->asection;
1719 *bufp = info->buffer;
1720 *sizep = info->size;
1721 }
1722
1723 \f
1724 /* DWARF quick_symbols_functions support. */
1725
1726 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1727 unique line tables, so we maintain a separate table of all .debug_line
1728 derived entries to support the sharing.
1729 All the quick functions need is the list of file names. We discard the
1730 line_header when we're done and don't need to record it here. */
1731 struct quick_file_names
1732 {
1733 /* The offset in .debug_line of the line table. We hash on this. */
1734 unsigned int offset;
1735
1736 /* The number of entries in file_names, real_names. */
1737 unsigned int num_file_names;
1738
1739 /* The file names from the line table, after being run through
1740 file_full_name. */
1741 const char **file_names;
1742
1743 /* The file names from the line table after being run through
1744 gdb_realpath. These are computed lazily. */
1745 const char **real_names;
1746 };
1747
1748 /* When using the index (and thus not using psymtabs), each CU has an
1749 object of this type. This is used to hold information needed by
1750 the various "quick" methods. */
1751 struct dwarf2_per_cu_quick_data
1752 {
1753 /* The file table. This can be NULL if there was no file table
1754 or it's currently not read in.
1755 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1756 struct quick_file_names *file_names;
1757
1758 /* The corresponding symbol table. This is NULL if symbols for this
1759 CU have not yet been read. */
1760 struct symtab *symtab;
1761
1762 /* A temporary mark bit used when iterating over all CUs in
1763 expand_symtabs_matching. */
1764 unsigned int mark : 1;
1765
1766 /* True if we've tried to read the file table and found there isn't one.
1767 There will be no point in trying to read it again next time. */
1768 unsigned int no_file_data : 1;
1769 };
1770
1771 /* Hash function for a quick_file_names. */
1772
1773 static hashval_t
1774 hash_file_name_entry (const void *e)
1775 {
1776 const struct quick_file_names *file_data = e;
1777
1778 return file_data->offset;
1779 }
1780
1781 /* Equality function for a quick_file_names. */
1782
1783 static int
1784 eq_file_name_entry (const void *a, const void *b)
1785 {
1786 const struct quick_file_names *ea = a;
1787 const struct quick_file_names *eb = b;
1788
1789 return ea->offset == eb->offset;
1790 }
1791
1792 /* Delete function for a quick_file_names. */
1793
1794 static void
1795 delete_file_name_entry (void *e)
1796 {
1797 struct quick_file_names *file_data = e;
1798 int i;
1799
1800 for (i = 0; i < file_data->num_file_names; ++i)
1801 {
1802 xfree ((void*) file_data->file_names[i]);
1803 if (file_data->real_names)
1804 xfree ((void*) file_data->real_names[i]);
1805 }
1806
1807 /* The space for the struct itself lives on objfile_obstack,
1808 so we don't free it here. */
1809 }
1810
1811 /* Create a quick_file_names hash table. */
1812
1813 static htab_t
1814 create_quick_file_names_table (unsigned int nr_initial_entries)
1815 {
1816 return htab_create_alloc (nr_initial_entries,
1817 hash_file_name_entry, eq_file_name_entry,
1818 delete_file_name_entry, xcalloc, xfree);
1819 }
1820
1821 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1822 have to be created afterwards. You should call age_cached_comp_units after
1823 processing PER_CU->CU. dw2_setup must have been already called. */
1824
1825 static void
1826 load_cu (struct dwarf2_per_cu_data *per_cu)
1827 {
1828 if (per_cu->debug_type_section)
1829 read_signatured_type_at_offset (per_cu->objfile,
1830 per_cu->debug_type_section,
1831 per_cu->offset);
1832 else
1833 load_full_comp_unit (per_cu, per_cu->objfile);
1834
1835 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
1836
1837 gdb_assert (per_cu->cu != NULL);
1838 }
1839
1840 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1841 this CU came. */
1842
1843 static void
1844 dw2_do_instantiate_symtab (struct objfile *objfile,
1845 struct dwarf2_per_cu_data *per_cu)
1846 {
1847 struct cleanup *back_to;
1848
1849 back_to = make_cleanup (dwarf2_release_queue, NULL);
1850
1851 queue_comp_unit (per_cu, objfile);
1852
1853 load_cu (per_cu);
1854
1855 process_queue (objfile);
1856
1857 /* Age the cache, releasing compilation units that have not
1858 been used recently. */
1859 age_cached_comp_units ();
1860
1861 do_cleanups (back_to);
1862 }
1863
1864 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1865 the objfile from which this CU came. Returns the resulting symbol
1866 table. */
1867
1868 static struct symtab *
1869 dw2_instantiate_symtab (struct objfile *objfile,
1870 struct dwarf2_per_cu_data *per_cu)
1871 {
1872 if (!per_cu->v.quick->symtab)
1873 {
1874 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
1875 increment_reading_symtab ();
1876 dw2_do_instantiate_symtab (objfile, per_cu);
1877 do_cleanups (back_to);
1878 }
1879 return per_cu->v.quick->symtab;
1880 }
1881
1882 /* Return the CU given its index. */
1883
1884 static struct dwarf2_per_cu_data *
1885 dw2_get_cu (int index)
1886 {
1887 if (index >= dwarf2_per_objfile->n_comp_units)
1888 {
1889 index -= dwarf2_per_objfile->n_comp_units;
1890 return dwarf2_per_objfile->type_comp_units[index];
1891 }
1892 return dwarf2_per_objfile->all_comp_units[index];
1893 }
1894
1895 /* A helper function that knows how to read a 64-bit value in a way
1896 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1897 otherwise. */
1898
1899 static int
1900 extract_cu_value (const char *bytes, ULONGEST *result)
1901 {
1902 if (sizeof (ULONGEST) < 8)
1903 {
1904 int i;
1905
1906 /* Ignore the upper 4 bytes if they are all zero. */
1907 for (i = 0; i < 4; ++i)
1908 if (bytes[i + 4] != 0)
1909 return 0;
1910
1911 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
1912 }
1913 else
1914 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
1915 return 1;
1916 }
1917
1918 /* Read the CU list from the mapped index, and use it to create all
1919 the CU objects for this objfile. Return 0 if something went wrong,
1920 1 if everything went ok. */
1921
1922 static int
1923 create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list,
1924 offset_type cu_list_elements)
1925 {
1926 offset_type i;
1927
1928 dwarf2_per_objfile->n_comp_units = cu_list_elements / 2;
1929 dwarf2_per_objfile->all_comp_units
1930 = obstack_alloc (&objfile->objfile_obstack,
1931 dwarf2_per_objfile->n_comp_units
1932 * sizeof (struct dwarf2_per_cu_data *));
1933
1934 for (i = 0; i < cu_list_elements; i += 2)
1935 {
1936 struct dwarf2_per_cu_data *the_cu;
1937 ULONGEST offset, length;
1938
1939 if (!extract_cu_value (cu_list, &offset)
1940 || !extract_cu_value (cu_list + 8, &length))
1941 return 0;
1942 cu_list += 2 * 8;
1943
1944 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1945 struct dwarf2_per_cu_data);
1946 the_cu->offset = offset;
1947 the_cu->length = length;
1948 the_cu->objfile = objfile;
1949 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1950 struct dwarf2_per_cu_quick_data);
1951 dwarf2_per_objfile->all_comp_units[i / 2] = the_cu;
1952 }
1953
1954 return 1;
1955 }
1956
1957 /* Create the signatured type hash table from the index. */
1958
1959 static int
1960 create_signatured_type_table_from_index (struct objfile *objfile,
1961 struct dwarf2_section_info *section,
1962 const gdb_byte *bytes,
1963 offset_type elements)
1964 {
1965 offset_type i;
1966 htab_t sig_types_hash;
1967
1968 dwarf2_per_objfile->n_type_comp_units = elements / 3;
1969 dwarf2_per_objfile->type_comp_units
1970 = obstack_alloc (&objfile->objfile_obstack,
1971 dwarf2_per_objfile->n_type_comp_units
1972 * sizeof (struct dwarf2_per_cu_data *));
1973
1974 sig_types_hash = allocate_signatured_type_table (objfile);
1975
1976 for (i = 0; i < elements; i += 3)
1977 {
1978 struct signatured_type *type_sig;
1979 ULONGEST offset, type_offset, signature;
1980 void **slot;
1981
1982 if (!extract_cu_value (bytes, &offset)
1983 || !extract_cu_value (bytes + 8, &type_offset))
1984 return 0;
1985 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
1986 bytes += 3 * 8;
1987
1988 type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1989 struct signatured_type);
1990 type_sig->signature = signature;
1991 type_sig->type_offset = type_offset;
1992 type_sig->per_cu.debug_type_section = section;
1993 type_sig->per_cu.offset = offset;
1994 type_sig->per_cu.objfile = objfile;
1995 type_sig->per_cu.v.quick
1996 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
1997 struct dwarf2_per_cu_quick_data);
1998
1999 slot = htab_find_slot (sig_types_hash, type_sig, INSERT);
2000 *slot = type_sig;
2001
2002 dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu;
2003 }
2004
2005 dwarf2_per_objfile->signatured_types = sig_types_hash;
2006
2007 return 1;
2008 }
2009
2010 /* Read the address map data from the mapped index, and use it to
2011 populate the objfile's psymtabs_addrmap. */
2012
2013 static void
2014 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2015 {
2016 const gdb_byte *iter, *end;
2017 struct obstack temp_obstack;
2018 struct addrmap *mutable_map;
2019 struct cleanup *cleanup;
2020 CORE_ADDR baseaddr;
2021
2022 obstack_init (&temp_obstack);
2023 cleanup = make_cleanup_obstack_free (&temp_obstack);
2024 mutable_map = addrmap_create_mutable (&temp_obstack);
2025
2026 iter = index->address_table;
2027 end = iter + index->address_table_size;
2028
2029 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2030
2031 while (iter < end)
2032 {
2033 ULONGEST hi, lo, cu_index;
2034 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2035 iter += 8;
2036 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2037 iter += 8;
2038 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2039 iter += 4;
2040
2041 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2042 dw2_get_cu (cu_index));
2043 }
2044
2045 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2046 &objfile->objfile_obstack);
2047 do_cleanups (cleanup);
2048 }
2049
2050 /* The hash function for strings in the mapped index. This is the same as
2051 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2052 implementation. This is necessary because the hash function is tied to the
2053 format of the mapped index file. The hash values do not have to match with
2054 SYMBOL_HASH_NEXT.
2055
2056 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2057
2058 static hashval_t
2059 mapped_index_string_hash (int index_version, const void *p)
2060 {
2061 const unsigned char *str = (const unsigned char *) p;
2062 hashval_t r = 0;
2063 unsigned char c;
2064
2065 while ((c = *str++) != 0)
2066 {
2067 if (index_version >= 5)
2068 c = tolower (c);
2069 r = r * 67 + c - 113;
2070 }
2071
2072 return r;
2073 }
2074
2075 /* Find a slot in the mapped index INDEX for the object named NAME.
2076 If NAME is found, set *VEC_OUT to point to the CU vector in the
2077 constant pool and return 1. If NAME cannot be found, return 0. */
2078
2079 static int
2080 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2081 offset_type **vec_out)
2082 {
2083 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2084 offset_type hash;
2085 offset_type slot, step;
2086 int (*cmp) (const char *, const char *);
2087
2088 if (current_language->la_language == language_cplus
2089 || current_language->la_language == language_java
2090 || current_language->la_language == language_fortran)
2091 {
2092 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2093 not contain any. */
2094 const char *paren = strchr (name, '(');
2095
2096 if (paren)
2097 {
2098 char *dup;
2099
2100 dup = xmalloc (paren - name + 1);
2101 memcpy (dup, name, paren - name);
2102 dup[paren - name] = 0;
2103
2104 make_cleanup (xfree, dup);
2105 name = dup;
2106 }
2107 }
2108
2109 /* Index version 4 did not support case insensitive searches. But the
2110 indexes for case insensitive languages are built in lowercase, therefore
2111 simulate our NAME being searched is also lowercased. */
2112 hash = mapped_index_string_hash ((index->version == 4
2113 && case_sensitivity == case_sensitive_off
2114 ? 5 : index->version),
2115 name);
2116
2117 slot = hash & (index->symbol_table_slots - 1);
2118 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2119 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2120
2121 for (;;)
2122 {
2123 /* Convert a slot number to an offset into the table. */
2124 offset_type i = 2 * slot;
2125 const char *str;
2126 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2127 {
2128 do_cleanups (back_to);
2129 return 0;
2130 }
2131
2132 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2133 if (!cmp (name, str))
2134 {
2135 *vec_out = (offset_type *) (index->constant_pool
2136 + MAYBE_SWAP (index->symbol_table[i + 1]));
2137 do_cleanups (back_to);
2138 return 1;
2139 }
2140
2141 slot = (slot + step) & (index->symbol_table_slots - 1);
2142 }
2143 }
2144
2145 /* Read the index file. If everything went ok, initialize the "quick"
2146 elements of all the CUs and return 1. Otherwise, return 0. */
2147
2148 static int
2149 dwarf2_read_index (struct objfile *objfile)
2150 {
2151 char *addr;
2152 struct mapped_index *map;
2153 offset_type *metadata;
2154 const gdb_byte *cu_list;
2155 const gdb_byte *types_list = NULL;
2156 offset_type version, cu_list_elements;
2157 offset_type types_list_elements = 0;
2158 int i;
2159
2160 if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index))
2161 return 0;
2162
2163 /* Older elfutils strip versions could keep the section in the main
2164 executable while splitting it for the separate debug info file. */
2165 if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection)
2166 & SEC_HAS_CONTENTS) == 0)
2167 return 0;
2168
2169 dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index);
2170
2171 addr = dwarf2_per_objfile->gdb_index.buffer;
2172 /* Version check. */
2173 version = MAYBE_SWAP (*(offset_type *) addr);
2174 /* Versions earlier than 3 emitted every copy of a psymbol. This
2175 causes the index to behave very poorly for certain requests. Version 3
2176 contained incomplete addrmap. So, it seems better to just ignore such
2177 indices. Index version 4 uses a different hash function than index
2178 version 5 and later. */
2179 if (version < 4)
2180 return 0;
2181 /* Indexes with higher version than the one supported by GDB may be no
2182 longer backward compatible. */
2183 if (version > 5)
2184 return 0;
2185
2186 map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index);
2187 map->version = version;
2188 map->total_size = dwarf2_per_objfile->gdb_index.size;
2189
2190 metadata = (offset_type *) (addr + sizeof (offset_type));
2191
2192 i = 0;
2193 cu_list = addr + MAYBE_SWAP (metadata[i]);
2194 cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2195 / 8);
2196 ++i;
2197
2198 types_list = addr + MAYBE_SWAP (metadata[i]);
2199 types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2200 - MAYBE_SWAP (metadata[i]))
2201 / 8);
2202 ++i;
2203
2204 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2205 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2206 - MAYBE_SWAP (metadata[i]));
2207 ++i;
2208
2209 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2210 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2211 - MAYBE_SWAP (metadata[i]))
2212 / (2 * sizeof (offset_type)));
2213 ++i;
2214
2215 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2216
2217 if (!create_cus_from_index (objfile, cu_list, cu_list_elements))
2218 return 0;
2219
2220 if (types_list_elements)
2221 {
2222 struct dwarf2_section_info *section;
2223
2224 /* We can only handle a single .debug_types when we have an
2225 index. */
2226 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2227 return 0;
2228
2229 section = VEC_index (dwarf2_section_info_def,
2230 dwarf2_per_objfile->types, 0);
2231
2232 if (!create_signatured_type_table_from_index (objfile, section,
2233 types_list,
2234 types_list_elements))
2235 return 0;
2236 }
2237
2238 create_addrmap_from_index (objfile, map);
2239
2240 dwarf2_per_objfile->index_table = map;
2241 dwarf2_per_objfile->using_index = 1;
2242 dwarf2_per_objfile->quick_file_names_table =
2243 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2244
2245 return 1;
2246 }
2247
2248 /* A helper for the "quick" functions which sets the global
2249 dwarf2_per_objfile according to OBJFILE. */
2250
2251 static void
2252 dw2_setup (struct objfile *objfile)
2253 {
2254 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2255 gdb_assert (dwarf2_per_objfile);
2256 }
2257
2258 /* A helper for the "quick" functions which attempts to read the line
2259 table for THIS_CU. */
2260
2261 static struct quick_file_names *
2262 dw2_get_file_names (struct objfile *objfile,
2263 struct dwarf2_per_cu_data *this_cu)
2264 {
2265 bfd *abfd = objfile->obfd;
2266 struct line_header *lh;
2267 struct attribute *attr;
2268 struct cleanup *cleanups;
2269 struct die_info *comp_unit_die;
2270 struct dwarf2_section_info* sec;
2271 gdb_byte *beg_of_comp_unit, *info_ptr, *buffer;
2272 int has_children, i;
2273 struct dwarf2_cu cu;
2274 unsigned int bytes_read, buffer_size;
2275 struct die_reader_specs reader_specs;
2276 char *name, *comp_dir;
2277 void **slot;
2278 struct quick_file_names *qfn;
2279 unsigned int line_offset;
2280
2281 if (this_cu->v.quick->file_names != NULL)
2282 return this_cu->v.quick->file_names;
2283 /* If we know there is no line data, no point in looking again. */
2284 if (this_cu->v.quick->no_file_data)
2285 return NULL;
2286
2287 init_one_comp_unit (&cu, objfile);
2288 cleanups = make_cleanup (free_stack_comp_unit, &cu);
2289
2290 if (this_cu->debug_type_section)
2291 sec = this_cu->debug_type_section;
2292 else
2293 sec = &dwarf2_per_objfile->info;
2294 dwarf2_read_section (objfile, sec);
2295 buffer_size = sec->size;
2296 buffer = sec->buffer;
2297 info_ptr = buffer + this_cu->offset;
2298 beg_of_comp_unit = info_ptr;
2299
2300 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
2301 buffer, buffer_size,
2302 abfd);
2303
2304 /* Complete the cu_header. */
2305 cu.header.offset = beg_of_comp_unit - buffer;
2306 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
2307
2308 this_cu->cu = &cu;
2309 cu.per_cu = this_cu;
2310
2311 dwarf2_read_abbrevs (abfd, &cu);
2312 make_cleanup (dwarf2_free_abbrev_table, &cu);
2313
2314 if (this_cu->debug_type_section)
2315 info_ptr += 8 /*signature*/ + cu.header.offset_size;
2316 init_cu_die_reader (&reader_specs, &cu);
2317 read_full_die (&reader_specs, &comp_unit_die, info_ptr,
2318 &has_children);
2319
2320 lh = NULL;
2321 slot = NULL;
2322 line_offset = 0;
2323 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu);
2324 if (attr)
2325 {
2326 struct quick_file_names find_entry;
2327
2328 line_offset = DW_UNSND (attr);
2329
2330 /* We may have already read in this line header (TU line header sharing).
2331 If we have we're done. */
2332 find_entry.offset = line_offset;
2333 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2334 &find_entry, INSERT);
2335 if (*slot != NULL)
2336 {
2337 do_cleanups (cleanups);
2338 this_cu->v.quick->file_names = *slot;
2339 return *slot;
2340 }
2341
2342 lh = dwarf_decode_line_header (line_offset, abfd, &cu);
2343 }
2344 if (lh == NULL)
2345 {
2346 do_cleanups (cleanups);
2347 this_cu->v.quick->no_file_data = 1;
2348 return NULL;
2349 }
2350
2351 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2352 qfn->offset = line_offset;
2353 gdb_assert (slot != NULL);
2354 *slot = qfn;
2355
2356 find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir);
2357
2358 qfn->num_file_names = lh->num_file_names;
2359 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2360 lh->num_file_names * sizeof (char *));
2361 for (i = 0; i < lh->num_file_names; ++i)
2362 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2363 qfn->real_names = NULL;
2364
2365 free_line_header (lh);
2366 do_cleanups (cleanups);
2367
2368 this_cu->v.quick->file_names = qfn;
2369 return qfn;
2370 }
2371
2372 /* A helper for the "quick" functions which computes and caches the
2373 real path for a given file name from the line table. */
2374
2375 static const char *
2376 dw2_get_real_path (struct objfile *objfile,
2377 struct quick_file_names *qfn, int index)
2378 {
2379 if (qfn->real_names == NULL)
2380 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2381 qfn->num_file_names, sizeof (char *));
2382
2383 if (qfn->real_names[index] == NULL)
2384 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2385
2386 return qfn->real_names[index];
2387 }
2388
2389 static struct symtab *
2390 dw2_find_last_source_symtab (struct objfile *objfile)
2391 {
2392 int index;
2393
2394 dw2_setup (objfile);
2395 index = dwarf2_per_objfile->n_comp_units - 1;
2396 return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
2397 }
2398
2399 /* Traversal function for dw2_forget_cached_source_info. */
2400
2401 static int
2402 dw2_free_cached_file_names (void **slot, void *info)
2403 {
2404 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2405
2406 if (file_data->real_names)
2407 {
2408 int i;
2409
2410 for (i = 0; i < file_data->num_file_names; ++i)
2411 {
2412 xfree ((void*) file_data->real_names[i]);
2413 file_data->real_names[i] = NULL;
2414 }
2415 }
2416
2417 return 1;
2418 }
2419
2420 static void
2421 dw2_forget_cached_source_info (struct objfile *objfile)
2422 {
2423 dw2_setup (objfile);
2424
2425 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
2426 dw2_free_cached_file_names, NULL);
2427 }
2428
2429 static int
2430 dw2_lookup_symtab (struct objfile *objfile, const char *name,
2431 const char *full_path, const char *real_path,
2432 struct symtab **result)
2433 {
2434 int i;
2435 int check_basename = lbasename (name) == name;
2436 struct dwarf2_per_cu_data *base_cu = NULL;
2437
2438 dw2_setup (objfile);
2439
2440 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2441 + dwarf2_per_objfile->n_type_comp_units); ++i)
2442 {
2443 int j;
2444 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2445 struct quick_file_names *file_data;
2446
2447 if (per_cu->v.quick->symtab)
2448 continue;
2449
2450 file_data = dw2_get_file_names (objfile, per_cu);
2451 if (file_data == NULL)
2452 continue;
2453
2454 for (j = 0; j < file_data->num_file_names; ++j)
2455 {
2456 const char *this_name = file_data->file_names[j];
2457
2458 if (FILENAME_CMP (name, this_name) == 0)
2459 {
2460 *result = dw2_instantiate_symtab (objfile, per_cu);
2461 return 1;
2462 }
2463
2464 if (check_basename && ! base_cu
2465 && FILENAME_CMP (lbasename (this_name), name) == 0)
2466 base_cu = per_cu;
2467
2468 if (full_path != NULL)
2469 {
2470 const char *this_real_name = dw2_get_real_path (objfile,
2471 file_data, j);
2472
2473 if (this_real_name != NULL
2474 && FILENAME_CMP (full_path, this_real_name) == 0)
2475 {
2476 *result = dw2_instantiate_symtab (objfile, per_cu);
2477 return 1;
2478 }
2479 }
2480
2481 if (real_path != NULL)
2482 {
2483 const char *this_real_name = dw2_get_real_path (objfile,
2484 file_data, j);
2485
2486 if (this_real_name != NULL
2487 && FILENAME_CMP (real_path, this_real_name) == 0)
2488 {
2489 *result = dw2_instantiate_symtab (objfile, per_cu);
2490 return 1;
2491 }
2492 }
2493 }
2494 }
2495
2496 if (base_cu)
2497 {
2498 *result = dw2_instantiate_symtab (objfile, base_cu);
2499 return 1;
2500 }
2501
2502 return 0;
2503 }
2504
2505 static struct symtab *
2506 dw2_lookup_symbol (struct objfile *objfile, int block_index,
2507 const char *name, domain_enum domain)
2508 {
2509 /* We do all the work in the pre_expand_symtabs_matching hook
2510 instead. */
2511 return NULL;
2512 }
2513
2514 /* A helper function that expands all symtabs that hold an object
2515 named NAME. */
2516
2517 static void
2518 dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name)
2519 {
2520 dw2_setup (objfile);
2521
2522 /* index_table is NULL if OBJF_READNOW. */
2523 if (dwarf2_per_objfile->index_table)
2524 {
2525 offset_type *vec;
2526
2527 if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2528 name, &vec))
2529 {
2530 offset_type i, len = MAYBE_SWAP (*vec);
2531 for (i = 0; i < len; ++i)
2532 {
2533 offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
2534 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
2535
2536 dw2_instantiate_symtab (objfile, per_cu);
2537 }
2538 }
2539 }
2540 }
2541
2542 static void
2543 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
2544 enum block_enum block_kind, const char *name,
2545 domain_enum domain)
2546 {
2547 dw2_do_expand_symtabs_matching (objfile, name);
2548 }
2549
2550 static void
2551 dw2_print_stats (struct objfile *objfile)
2552 {
2553 int i, count;
2554
2555 dw2_setup (objfile);
2556 count = 0;
2557 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2558 + dwarf2_per_objfile->n_type_comp_units); ++i)
2559 {
2560 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2561
2562 if (!per_cu->v.quick->symtab)
2563 ++count;
2564 }
2565 printf_filtered (_(" Number of unread CUs: %d\n"), count);
2566 }
2567
2568 static void
2569 dw2_dump (struct objfile *objfile)
2570 {
2571 /* Nothing worth printing. */
2572 }
2573
2574 static void
2575 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
2576 struct section_offsets *delta)
2577 {
2578 /* There's nothing to relocate here. */
2579 }
2580
2581 static void
2582 dw2_expand_symtabs_for_function (struct objfile *objfile,
2583 const char *func_name)
2584 {
2585 dw2_do_expand_symtabs_matching (objfile, func_name);
2586 }
2587
2588 static void
2589 dw2_expand_all_symtabs (struct objfile *objfile)
2590 {
2591 int i;
2592
2593 dw2_setup (objfile);
2594
2595 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2596 + dwarf2_per_objfile->n_type_comp_units); ++i)
2597 {
2598 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2599
2600 dw2_instantiate_symtab (objfile, per_cu);
2601 }
2602 }
2603
2604 static void
2605 dw2_expand_symtabs_with_filename (struct objfile *objfile,
2606 const char *filename)
2607 {
2608 int i;
2609
2610 dw2_setup (objfile);
2611
2612 /* We don't need to consider type units here.
2613 This is only called for examining code, e.g. expand_line_sal.
2614 There can be an order of magnitude (or more) more type units
2615 than comp units, and we avoid them if we can. */
2616
2617 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
2618 {
2619 int j;
2620 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2621 struct quick_file_names *file_data;
2622
2623 if (per_cu->v.quick->symtab)
2624 continue;
2625
2626 file_data = dw2_get_file_names (objfile, per_cu);
2627 if (file_data == NULL)
2628 continue;
2629
2630 for (j = 0; j < file_data->num_file_names; ++j)
2631 {
2632 const char *this_name = file_data->file_names[j];
2633 if (FILENAME_CMP (this_name, filename) == 0)
2634 {
2635 dw2_instantiate_symtab (objfile, per_cu);
2636 break;
2637 }
2638 }
2639 }
2640 }
2641
2642 static const char *
2643 dw2_find_symbol_file (struct objfile *objfile, const char *name)
2644 {
2645 struct dwarf2_per_cu_data *per_cu;
2646 offset_type *vec;
2647 struct quick_file_names *file_data;
2648
2649 dw2_setup (objfile);
2650
2651 /* index_table is NULL if OBJF_READNOW. */
2652 if (!dwarf2_per_objfile->index_table)
2653 {
2654 struct symtab *s;
2655
2656 ALL_OBJFILE_SYMTABS (objfile, s)
2657 if (s->primary)
2658 {
2659 struct blockvector *bv = BLOCKVECTOR (s);
2660 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2661 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
2662
2663 if (sym)
2664 return sym->symtab->filename;
2665 }
2666 return NULL;
2667 }
2668
2669 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
2670 name, &vec))
2671 return NULL;
2672
2673 /* Note that this just looks at the very first one named NAME -- but
2674 actually we are looking for a function. find_main_filename
2675 should be rewritten so that it doesn't require a custom hook. It
2676 could just use the ordinary symbol tables. */
2677 /* vec[0] is the length, which must always be >0. */
2678 per_cu = dw2_get_cu (MAYBE_SWAP (vec[1]));
2679
2680 file_data = dw2_get_file_names (objfile, per_cu);
2681 if (file_data == NULL)
2682 return NULL;
2683
2684 return file_data->file_names[file_data->num_file_names - 1];
2685 }
2686
2687 static void
2688 dw2_map_matching_symbols (const char * name, domain_enum namespace,
2689 struct objfile *objfile, int global,
2690 int (*callback) (struct block *,
2691 struct symbol *, void *),
2692 void *data, symbol_compare_ftype *match,
2693 symbol_compare_ftype *ordered_compare)
2694 {
2695 /* Currently unimplemented; used for Ada. The function can be called if the
2696 current language is Ada for a non-Ada objfile using GNU index. As Ada
2697 does not look for non-Ada symbols this function should just return. */
2698 }
2699
2700 static void
2701 dw2_expand_symtabs_matching (struct objfile *objfile,
2702 int (*file_matcher) (const char *, void *),
2703 int (*name_matcher) (const char *, void *),
2704 enum search_domain kind,
2705 void *data)
2706 {
2707 int i;
2708 offset_type iter;
2709 struct mapped_index *index;
2710
2711 dw2_setup (objfile);
2712
2713 /* index_table is NULL if OBJF_READNOW. */
2714 if (!dwarf2_per_objfile->index_table)
2715 return;
2716 index = dwarf2_per_objfile->index_table;
2717
2718 if (file_matcher != NULL)
2719 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2720 + dwarf2_per_objfile->n_type_comp_units); ++i)
2721 {
2722 int j;
2723 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2724 struct quick_file_names *file_data;
2725
2726 per_cu->v.quick->mark = 0;
2727 if (per_cu->v.quick->symtab)
2728 continue;
2729
2730 file_data = dw2_get_file_names (objfile, per_cu);
2731 if (file_data == NULL)
2732 continue;
2733
2734 for (j = 0; j < file_data->num_file_names; ++j)
2735 {
2736 if (file_matcher (file_data->file_names[j], data))
2737 {
2738 per_cu->v.quick->mark = 1;
2739 break;
2740 }
2741 }
2742 }
2743
2744 for (iter = 0; iter < index->symbol_table_slots; ++iter)
2745 {
2746 offset_type idx = 2 * iter;
2747 const char *name;
2748 offset_type *vec, vec_len, vec_idx;
2749
2750 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
2751 continue;
2752
2753 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
2754
2755 if (! (*name_matcher) (name, data))
2756 continue;
2757
2758 /* The name was matched, now expand corresponding CUs that were
2759 marked. */
2760 vec = (offset_type *) (index->constant_pool
2761 + MAYBE_SWAP (index->symbol_table[idx + 1]));
2762 vec_len = MAYBE_SWAP (vec[0]);
2763 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
2764 {
2765 struct dwarf2_per_cu_data *per_cu;
2766
2767 per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
2768 if (file_matcher == NULL || per_cu->v.quick->mark)
2769 dw2_instantiate_symtab (objfile, per_cu);
2770 }
2771 }
2772 }
2773
2774 static struct symtab *
2775 dw2_find_pc_sect_symtab (struct objfile *objfile,
2776 struct minimal_symbol *msymbol,
2777 CORE_ADDR pc,
2778 struct obj_section *section,
2779 int warn_if_readin)
2780 {
2781 struct dwarf2_per_cu_data *data;
2782
2783 dw2_setup (objfile);
2784
2785 if (!objfile->psymtabs_addrmap)
2786 return NULL;
2787
2788 data = addrmap_find (objfile->psymtabs_addrmap, pc);
2789 if (!data)
2790 return NULL;
2791
2792 if (warn_if_readin && data->v.quick->symtab)
2793 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2794 paddress (get_objfile_arch (objfile), pc));
2795
2796 return dw2_instantiate_symtab (objfile, data);
2797 }
2798
2799 static void
2800 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
2801 void *data)
2802 {
2803 int i;
2804
2805 dw2_setup (objfile);
2806
2807 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2808 + dwarf2_per_objfile->n_type_comp_units); ++i)
2809 {
2810 int j;
2811 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2812 struct quick_file_names *file_data;
2813
2814 if (per_cu->v.quick->symtab)
2815 continue;
2816
2817 file_data = dw2_get_file_names (objfile, per_cu);
2818 if (file_data == NULL)
2819 continue;
2820
2821 for (j = 0; j < file_data->num_file_names; ++j)
2822 {
2823 const char *this_real_name = dw2_get_real_path (objfile, file_data,
2824 j);
2825 (*fun) (file_data->file_names[j], this_real_name, data);
2826 }
2827 }
2828 }
2829
2830 static int
2831 dw2_has_symbols (struct objfile *objfile)
2832 {
2833 return 1;
2834 }
2835
2836 const struct quick_symbol_functions dwarf2_gdb_index_functions =
2837 {
2838 dw2_has_symbols,
2839 dw2_find_last_source_symtab,
2840 dw2_forget_cached_source_info,
2841 dw2_lookup_symtab,
2842 dw2_lookup_symbol,
2843 dw2_pre_expand_symtabs_matching,
2844 dw2_print_stats,
2845 dw2_dump,
2846 dw2_relocate,
2847 dw2_expand_symtabs_for_function,
2848 dw2_expand_all_symtabs,
2849 dw2_expand_symtabs_with_filename,
2850 dw2_find_symbol_file,
2851 dw2_map_matching_symbols,
2852 dw2_expand_symtabs_matching,
2853 dw2_find_pc_sect_symtab,
2854 dw2_map_symbol_filenames
2855 };
2856
2857 /* Initialize for reading DWARF for this objfile. Return 0 if this
2858 file will use psymtabs, or 1 if using the GNU index. */
2859
2860 int
2861 dwarf2_initialize_objfile (struct objfile *objfile)
2862 {
2863 /* If we're about to read full symbols, don't bother with the
2864 indices. In this case we also don't care if some other debug
2865 format is making psymtabs, because they are all about to be
2866 expanded anyway. */
2867 if ((objfile->flags & OBJF_READNOW))
2868 {
2869 int i;
2870
2871 dwarf2_per_objfile->using_index = 1;
2872 create_all_comp_units (objfile);
2873 create_debug_types_hash_table (objfile);
2874 dwarf2_per_objfile->quick_file_names_table =
2875 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2876
2877 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2878 + dwarf2_per_objfile->n_type_comp_units); ++i)
2879 {
2880 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2881
2882 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2883 struct dwarf2_per_cu_quick_data);
2884 }
2885
2886 /* Return 1 so that gdb sees the "quick" functions. However,
2887 these functions will be no-ops because we will have expanded
2888 all symtabs. */
2889 return 1;
2890 }
2891
2892 if (dwarf2_read_index (objfile))
2893 return 1;
2894
2895 return 0;
2896 }
2897
2898 \f
2899
2900 /* Build a partial symbol table. */
2901
2902 void
2903 dwarf2_build_psymtabs (struct objfile *objfile)
2904 {
2905 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
2906 {
2907 init_psymbol_list (objfile, 1024);
2908 }
2909
2910 dwarf2_build_psymtabs_hard (objfile);
2911 }
2912
2913 /* Return TRUE if OFFSET is within CU_HEADER. */
2914
2915 static inline int
2916 offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset)
2917 {
2918 unsigned int bottom = cu_header->offset;
2919 unsigned int top = (cu_header->offset
2920 + cu_header->length
2921 + cu_header->initial_length_size);
2922
2923 return (offset >= bottom && offset < top);
2924 }
2925
2926 /* Read in the comp unit header information from the debug_info at info_ptr.
2927 NOTE: This leaves members offset, first_die_offset to be filled in
2928 by the caller. */
2929
2930 static gdb_byte *
2931 read_comp_unit_head (struct comp_unit_head *cu_header,
2932 gdb_byte *info_ptr, bfd *abfd)
2933 {
2934 int signed_addr;
2935 unsigned int bytes_read;
2936
2937 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
2938 cu_header->initial_length_size = bytes_read;
2939 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
2940 info_ptr += bytes_read;
2941 cu_header->version = read_2_bytes (abfd, info_ptr);
2942 info_ptr += 2;
2943 cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header,
2944 &bytes_read);
2945 info_ptr += bytes_read;
2946 cu_header->addr_size = read_1_byte (abfd, info_ptr);
2947 info_ptr += 1;
2948 signed_addr = bfd_get_sign_extend_vma (abfd);
2949 if (signed_addr < 0)
2950 internal_error (__FILE__, __LINE__,
2951 _("read_comp_unit_head: dwarf from non elf file"));
2952 cu_header->signed_addr_p = signed_addr;
2953
2954 return info_ptr;
2955 }
2956
2957 static gdb_byte *
2958 partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr,
2959 gdb_byte *buffer, unsigned int buffer_size,
2960 bfd *abfd)
2961 {
2962 gdb_byte *beg_of_comp_unit = info_ptr;
2963
2964 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
2965
2966 if (header->version != 2 && header->version != 3 && header->version != 4)
2967 error (_("Dwarf Error: wrong version in compilation unit header "
2968 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
2969 bfd_get_filename (abfd));
2970
2971 if (header->abbrev_offset
2972 >= dwarf2_section_size (dwarf2_per_objfile->objfile,
2973 &dwarf2_per_objfile->abbrev))
2974 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2975 "(offset 0x%lx + 6) [in module %s]"),
2976 (long) header->abbrev_offset,
2977 (long) (beg_of_comp_unit - buffer),
2978 bfd_get_filename (abfd));
2979
2980 if (beg_of_comp_unit + header->length + header->initial_length_size
2981 > buffer + buffer_size)
2982 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2983 "(offset 0x%lx + 0) [in module %s]"),
2984 (long) header->length,
2985 (long) (beg_of_comp_unit - buffer),
2986 bfd_get_filename (abfd));
2987
2988 return info_ptr;
2989 }
2990
2991 /* Read in the types comp unit header information from .debug_types entry at
2992 types_ptr. The result is a pointer to one past the end of the header. */
2993
2994 static gdb_byte *
2995 read_type_comp_unit_head (struct comp_unit_head *cu_header,
2996 struct dwarf2_section_info *section,
2997 ULONGEST *signature,
2998 gdb_byte *types_ptr, bfd *abfd)
2999 {
3000 gdb_byte *initial_types_ptr = types_ptr;
3001
3002 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
3003 cu_header->offset = types_ptr - section->buffer;
3004
3005 types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd);
3006
3007 *signature = read_8_bytes (abfd, types_ptr);
3008 types_ptr += 8;
3009 types_ptr += cu_header->offset_size;
3010 cu_header->first_die_offset = types_ptr - initial_types_ptr;
3011
3012 return types_ptr;
3013 }
3014
3015 /* Allocate a new partial symtab for file named NAME and mark this new
3016 partial symtab as being an include of PST. */
3017
3018 static void
3019 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
3020 struct objfile *objfile)
3021 {
3022 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
3023
3024 subpst->section_offsets = pst->section_offsets;
3025 subpst->textlow = 0;
3026 subpst->texthigh = 0;
3027
3028 subpst->dependencies = (struct partial_symtab **)
3029 obstack_alloc (&objfile->objfile_obstack,
3030 sizeof (struct partial_symtab *));
3031 subpst->dependencies[0] = pst;
3032 subpst->number_of_dependencies = 1;
3033
3034 subpst->globals_offset = 0;
3035 subpst->n_global_syms = 0;
3036 subpst->statics_offset = 0;
3037 subpst->n_static_syms = 0;
3038 subpst->symtab = NULL;
3039 subpst->read_symtab = pst->read_symtab;
3040 subpst->readin = 0;
3041
3042 /* No private part is necessary for include psymtabs. This property
3043 can be used to differentiate between such include psymtabs and
3044 the regular ones. */
3045 subpst->read_symtab_private = NULL;
3046 }
3047
3048 /* Read the Line Number Program data and extract the list of files
3049 included by the source file represented by PST. Build an include
3050 partial symtab for each of these included files. */
3051
3052 static void
3053 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
3054 struct die_info *die,
3055 struct partial_symtab *pst)
3056 {
3057 struct objfile *objfile = cu->objfile;
3058 bfd *abfd = objfile->obfd;
3059 struct line_header *lh = NULL;
3060 struct attribute *attr;
3061
3062 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
3063 if (attr)
3064 {
3065 unsigned int line_offset = DW_UNSND (attr);
3066
3067 lh = dwarf_decode_line_header (line_offset, abfd, cu);
3068 }
3069 if (lh == NULL)
3070 return; /* No linetable, so no includes. */
3071
3072 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3073 dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst);
3074
3075 free_line_header (lh);
3076 }
3077
3078 static hashval_t
3079 hash_type_signature (const void *item)
3080 {
3081 const struct signatured_type *type_sig = item;
3082
3083 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3084 return type_sig->signature;
3085 }
3086
3087 static int
3088 eq_type_signature (const void *item_lhs, const void *item_rhs)
3089 {
3090 const struct signatured_type *lhs = item_lhs;
3091 const struct signatured_type *rhs = item_rhs;
3092
3093 return lhs->signature == rhs->signature;
3094 }
3095
3096 /* Allocate a hash table for signatured types. */
3097
3098 static htab_t
3099 allocate_signatured_type_table (struct objfile *objfile)
3100 {
3101 return htab_create_alloc_ex (41,
3102 hash_type_signature,
3103 eq_type_signature,
3104 NULL,
3105 &objfile->objfile_obstack,
3106 hashtab_obstack_allocate,
3107 dummy_obstack_deallocate);
3108 }
3109
3110 /* A helper function to add a signatured type CU to a list. */
3111
3112 static int
3113 add_signatured_type_cu_to_list (void **slot, void *datum)
3114 {
3115 struct signatured_type *sigt = *slot;
3116 struct dwarf2_per_cu_data ***datap = datum;
3117
3118 **datap = &sigt->per_cu;
3119 ++*datap;
3120
3121 return 1;
3122 }
3123
3124 /* Create the hash table of all entries in the .debug_types section.
3125 The result is zero if there is an error (e.g. missing .debug_types section),
3126 otherwise non-zero. */
3127
3128 static int
3129 create_debug_types_hash_table (struct objfile *objfile)
3130 {
3131 htab_t types_htab = NULL;
3132 struct dwarf2_per_cu_data **iter;
3133 int ix;
3134 struct dwarf2_section_info *section;
3135
3136 if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types))
3137 {
3138 dwarf2_per_objfile->signatured_types = NULL;
3139 return 0;
3140 }
3141
3142 for (ix = 0;
3143 VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types,
3144 ix, section);
3145 ++ix)
3146 {
3147 gdb_byte *info_ptr, *end_ptr;
3148
3149 dwarf2_read_section (objfile, section);
3150 info_ptr = section->buffer;
3151
3152 if (info_ptr == NULL)
3153 continue;
3154
3155 if (types_htab == NULL)
3156 types_htab = allocate_signatured_type_table (objfile);
3157
3158 if (dwarf2_die_debug)
3159 fprintf_unfiltered (gdb_stdlog, "Signatured types:\n");
3160
3161 end_ptr = info_ptr + section->size;
3162 while (info_ptr < end_ptr)
3163 {
3164 unsigned int offset;
3165 unsigned int offset_size;
3166 unsigned int type_offset;
3167 unsigned int length, initial_length_size;
3168 unsigned short version;
3169 ULONGEST signature;
3170 struct signatured_type *type_sig;
3171 void **slot;
3172 gdb_byte *ptr = info_ptr;
3173
3174 offset = ptr - section->buffer;
3175
3176 /* We need to read the type's signature in order to build the hash
3177 table, but we don't need to read anything else just yet. */
3178
3179 /* Sanity check to ensure entire cu is present. */
3180 length = read_initial_length (objfile->obfd, ptr,
3181 &initial_length_size);
3182 if (ptr + length + initial_length_size > end_ptr)
3183 {
3184 complaint (&symfile_complaints,
3185 _("debug type entry runs off end "
3186 "of `.debug_types' section, ignored"));
3187 break;
3188 }
3189
3190 offset_size = initial_length_size == 4 ? 4 : 8;
3191 ptr += initial_length_size;
3192 version = bfd_get_16 (objfile->obfd, ptr);
3193 ptr += 2;
3194 ptr += offset_size; /* abbrev offset */
3195 ptr += 1; /* address size */
3196 signature = bfd_get_64 (objfile->obfd, ptr);
3197 ptr += 8;
3198 type_offset = read_offset_1 (objfile->obfd, ptr, offset_size);
3199
3200 type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig));
3201 memset (type_sig, 0, sizeof (*type_sig));
3202 type_sig->signature = signature;
3203 type_sig->type_offset = type_offset;
3204 type_sig->per_cu.objfile = objfile;
3205 type_sig->per_cu.debug_type_section = section;
3206 type_sig->per_cu.offset = offset;
3207
3208 slot = htab_find_slot (types_htab, type_sig, INSERT);
3209 gdb_assert (slot != NULL);
3210 if (*slot != NULL)
3211 {
3212 const struct signatured_type *dup_sig = *slot;
3213
3214 complaint (&symfile_complaints,
3215 _("debug type entry at offset 0x%x is duplicate to the "
3216 "entry at offset 0x%x, signature 0x%s"),
3217 offset, dup_sig->per_cu.offset,
3218 phex (signature, sizeof (signature)));
3219 gdb_assert (signature == dup_sig->signature);
3220 }
3221 *slot = type_sig;
3222
3223 if (dwarf2_die_debug)
3224 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
3225 offset, phex (signature, sizeof (signature)));
3226
3227 info_ptr = info_ptr + initial_length_size + length;
3228 }
3229 }
3230
3231 dwarf2_per_objfile->signatured_types = types_htab;
3232
3233 dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab);
3234 dwarf2_per_objfile->type_comp_units
3235 = obstack_alloc (&objfile->objfile_obstack,
3236 dwarf2_per_objfile->n_type_comp_units
3237 * sizeof (struct dwarf2_per_cu_data *));
3238 iter = &dwarf2_per_objfile->type_comp_units[0];
3239 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter);
3240 gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0]
3241 == dwarf2_per_objfile->n_type_comp_units);
3242
3243 return 1;
3244 }
3245
3246 /* Lookup a signature based type.
3247 Returns NULL if SIG is not present in the table. */
3248
3249 static struct signatured_type *
3250 lookup_signatured_type (struct objfile *objfile, ULONGEST sig)
3251 {
3252 struct signatured_type find_entry, *entry;
3253
3254 if (dwarf2_per_objfile->signatured_types == NULL)
3255 {
3256 complaint (&symfile_complaints,
3257 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3258 return 0;
3259 }
3260
3261 find_entry.signature = sig;
3262 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
3263 return entry;
3264 }
3265
3266 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3267
3268 static void
3269 init_cu_die_reader (struct die_reader_specs *reader,
3270 struct dwarf2_cu *cu)
3271 {
3272 reader->abfd = cu->objfile->obfd;
3273 reader->cu = cu;
3274 if (cu->per_cu->debug_type_section)
3275 {
3276 gdb_assert (cu->per_cu->debug_type_section->readin);
3277 reader->buffer = cu->per_cu->debug_type_section->buffer;
3278 }
3279 else
3280 {
3281 gdb_assert (dwarf2_per_objfile->info.readin);
3282 reader->buffer = dwarf2_per_objfile->info.buffer;
3283 }
3284 }
3285
3286 /* Find the base address of the compilation unit for range lists and
3287 location lists. It will normally be specified by DW_AT_low_pc.
3288 In DWARF-3 draft 4, the base address could be overridden by
3289 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3290 compilation units with discontinuous ranges. */
3291
3292 static void
3293 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3294 {
3295 struct attribute *attr;
3296
3297 cu->base_known = 0;
3298 cu->base_address = 0;
3299
3300 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3301 if (attr)
3302 {
3303 cu->base_address = DW_ADDR (attr);
3304 cu->base_known = 1;
3305 }
3306 else
3307 {
3308 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3309 if (attr)
3310 {
3311 cu->base_address = DW_ADDR (attr);
3312 cu->base_known = 1;
3313 }
3314 }
3315 }
3316
3317 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3318 to combine the common parts.
3319 Process a compilation unit for a psymtab.
3320 BUFFER is a pointer to the beginning of the dwarf section buffer,
3321 either .debug_info or debug_types.
3322 INFO_PTR is a pointer to the start of the CU.
3323 Returns a pointer to the next CU. */
3324
3325 static gdb_byte *
3326 process_psymtab_comp_unit (struct objfile *objfile,
3327 struct dwarf2_per_cu_data *this_cu,
3328 gdb_byte *buffer, gdb_byte *info_ptr,
3329 unsigned int buffer_size)
3330 {
3331 bfd *abfd = objfile->obfd;
3332 gdb_byte *beg_of_comp_unit = info_ptr;
3333 struct die_info *comp_unit_die;
3334 struct partial_symtab *pst;
3335 CORE_ADDR baseaddr;
3336 struct cleanup *back_to_inner;
3337 struct dwarf2_cu cu;
3338 int has_children, has_pc_info;
3339 struct attribute *attr;
3340 CORE_ADDR best_lowpc = 0, best_highpc = 0;
3341 struct die_reader_specs reader_specs;
3342 const char *filename;
3343
3344 init_one_comp_unit (&cu, objfile);
3345 back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
3346
3347 info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
3348 buffer, buffer_size,
3349 abfd);
3350
3351 /* Complete the cu_header. */
3352 cu.header.offset = beg_of_comp_unit - buffer;
3353 cu.header.first_die_offset = info_ptr - beg_of_comp_unit;
3354
3355 cu.list_in_scope = &file_symbols;
3356
3357 /* If this compilation unit was already read in, free the
3358 cached copy in order to read it in again. This is
3359 necessary because we skipped some symbols when we first
3360 read in the compilation unit (see load_partial_dies).
3361 This problem could be avoided, but the benefit is
3362 unclear. */
3363 if (this_cu->cu != NULL)
3364 free_one_cached_comp_unit (this_cu->cu);
3365
3366 /* Note that this is a pointer to our stack frame, being
3367 added to a global data structure. It will be cleaned up
3368 in free_stack_comp_unit when we finish with this
3369 compilation unit. */
3370 this_cu->cu = &cu;
3371 cu.per_cu = this_cu;
3372
3373 /* Read the abbrevs for this compilation unit into a table. */
3374 dwarf2_read_abbrevs (abfd, &cu);
3375 make_cleanup (dwarf2_free_abbrev_table, &cu);
3376
3377 /* Read the compilation unit die. */
3378 if (this_cu->debug_type_section)
3379 info_ptr += 8 /*signature*/ + cu.header.offset_size;
3380 init_cu_die_reader (&reader_specs, &cu);
3381 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3382 &has_children);
3383
3384 if (this_cu->debug_type_section)
3385 {
3386 /* LENGTH has not been set yet for type units. */
3387 gdb_assert (this_cu->offset == cu.header.offset);
3388 this_cu->length = cu.header.length + cu.header.initial_length_size;
3389 }
3390 else if (comp_unit_die->tag == DW_TAG_partial_unit)
3391 {
3392 info_ptr = (beg_of_comp_unit + cu.header.length
3393 + cu.header.initial_length_size);
3394 do_cleanups (back_to_inner);
3395 return info_ptr;
3396 }
3397
3398 prepare_one_comp_unit (&cu, comp_unit_die);
3399
3400 /* Allocate a new partial symbol table structure. */
3401 attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu);
3402 if (attr == NULL || !DW_STRING (attr))
3403 filename = "";
3404 else
3405 filename = DW_STRING (attr);
3406 pst = start_psymtab_common (objfile, objfile->section_offsets,
3407 filename,
3408 /* TEXTLOW and TEXTHIGH are set below. */
3409 0,
3410 objfile->global_psymbols.next,
3411 objfile->static_psymbols.next);
3412
3413 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu);
3414 if (attr != NULL)
3415 pst->dirname = DW_STRING (attr);
3416
3417 pst->read_symtab_private = this_cu;
3418
3419 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3420
3421 /* Store the function that reads in the rest of the symbol table. */
3422 pst->read_symtab = dwarf2_psymtab_to_symtab;
3423
3424 this_cu->v.psymtab = pst;
3425
3426 dwarf2_find_base_address (comp_unit_die, &cu);
3427
3428 /* Possibly set the default values of LOWPC and HIGHPC from
3429 `DW_AT_ranges'. */
3430 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
3431 &best_highpc, &cu, pst);
3432 if (has_pc_info == 1 && best_lowpc < best_highpc)
3433 /* Store the contiguous range if it is not empty; it can be empty for
3434 CUs with no code. */
3435 addrmap_set_empty (objfile->psymtabs_addrmap,
3436 best_lowpc + baseaddr,
3437 best_highpc + baseaddr - 1, pst);
3438
3439 /* Check if comp unit has_children.
3440 If so, read the rest of the partial symbols from this comp unit.
3441 If not, there's no more debug_info for this comp unit. */
3442 if (has_children)
3443 {
3444 struct partial_die_info *first_die;
3445 CORE_ADDR lowpc, highpc;
3446
3447 lowpc = ((CORE_ADDR) -1);
3448 highpc = ((CORE_ADDR) 0);
3449
3450 first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu);
3451
3452 scan_partial_symbols (first_die, &lowpc, &highpc,
3453 ! has_pc_info, &cu);
3454
3455 /* If we didn't find a lowpc, set it to highpc to avoid
3456 complaints from `maint check'. */
3457 if (lowpc == ((CORE_ADDR) -1))
3458 lowpc = highpc;
3459
3460 /* If the compilation unit didn't have an explicit address range,
3461 then use the information extracted from its child dies. */
3462 if (! has_pc_info)
3463 {
3464 best_lowpc = lowpc;
3465 best_highpc = highpc;
3466 }
3467 }
3468 pst->textlow = best_lowpc + baseaddr;
3469 pst->texthigh = best_highpc + baseaddr;
3470
3471 pst->n_global_syms = objfile->global_psymbols.next -
3472 (objfile->global_psymbols.list + pst->globals_offset);
3473 pst->n_static_syms = objfile->static_psymbols.next -
3474 (objfile->static_psymbols.list + pst->statics_offset);
3475 sort_pst_symbols (pst);
3476
3477 info_ptr = (beg_of_comp_unit + cu.header.length
3478 + cu.header.initial_length_size);
3479
3480 if (this_cu->debug_type_section)
3481 {
3482 /* It's not clear we want to do anything with stmt lists here.
3483 Waiting to see what gcc ultimately does. */
3484 }
3485 else
3486 {
3487 /* Get the list of files included in the current compilation unit,
3488 and build a psymtab for each of them. */
3489 dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst);
3490 }
3491
3492 do_cleanups (back_to_inner);
3493
3494 return info_ptr;
3495 }
3496
3497 /* Traversal function for htab_traverse_noresize.
3498 Process one .debug_types comp-unit. */
3499
3500 static int
3501 process_type_comp_unit (void **slot, void *info)
3502 {
3503 struct signatured_type *entry = (struct signatured_type *) *slot;
3504 struct objfile *objfile = (struct objfile *) info;
3505 struct dwarf2_per_cu_data *this_cu;
3506
3507 this_cu = &entry->per_cu;
3508
3509 gdb_assert (this_cu->debug_type_section->readin);
3510 process_psymtab_comp_unit (objfile, this_cu,
3511 this_cu->debug_type_section->buffer,
3512 (this_cu->debug_type_section->buffer
3513 + this_cu->offset),
3514 this_cu->debug_type_section->size);
3515
3516 return 1;
3517 }
3518
3519 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3520 Build partial symbol tables for the .debug_types comp-units. */
3521
3522 static void
3523 build_type_psymtabs (struct objfile *objfile)
3524 {
3525 if (! create_debug_types_hash_table (objfile))
3526 return;
3527
3528 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
3529 process_type_comp_unit, objfile);
3530 }
3531
3532 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3533
3534 static void
3535 psymtabs_addrmap_cleanup (void *o)
3536 {
3537 struct objfile *objfile = o;
3538
3539 objfile->psymtabs_addrmap = NULL;
3540 }
3541
3542 /* Build the partial symbol table by doing a quick pass through the
3543 .debug_info and .debug_abbrev sections. */
3544
3545 static void
3546 dwarf2_build_psymtabs_hard (struct objfile *objfile)
3547 {
3548 gdb_byte *info_ptr;
3549 struct cleanup *back_to, *addrmap_cleanup;
3550 struct obstack temp_obstack;
3551
3552 dwarf2_per_objfile->reading_partial_symbols = 1;
3553
3554 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3555 info_ptr = dwarf2_per_objfile->info.buffer;
3556
3557 /* Any cached compilation units will be linked by the per-objfile
3558 read_in_chain. Make sure to free them when we're done. */
3559 back_to = make_cleanup (free_cached_comp_units, NULL);
3560
3561 build_type_psymtabs (objfile);
3562
3563 create_all_comp_units (objfile);
3564
3565 /* Create a temporary address map on a temporary obstack. We later
3566 copy this to the final obstack. */
3567 obstack_init (&temp_obstack);
3568 make_cleanup_obstack_free (&temp_obstack);
3569 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
3570 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
3571
3572 /* Since the objects we're extracting from .debug_info vary in
3573 length, only the individual functions to extract them (like
3574 read_comp_unit_head and load_partial_die) can really know whether
3575 the buffer is large enough to hold another complete object.
3576
3577 At the moment, they don't actually check that. If .debug_info
3578 holds just one extra byte after the last compilation unit's dies,
3579 then read_comp_unit_head will happily read off the end of the
3580 buffer. read_partial_die is similarly casual. Those functions
3581 should be fixed.
3582
3583 For this loop condition, simply checking whether there's any data
3584 left at all should be sufficient. */
3585
3586 while (info_ptr < (dwarf2_per_objfile->info.buffer
3587 + dwarf2_per_objfile->info.size))
3588 {
3589 struct dwarf2_per_cu_data *this_cu;
3590
3591 this_cu = dwarf2_find_comp_unit (info_ptr
3592 - dwarf2_per_objfile->info.buffer,
3593 objfile);
3594
3595 info_ptr = process_psymtab_comp_unit (objfile, this_cu,
3596 dwarf2_per_objfile->info.buffer,
3597 info_ptr,
3598 dwarf2_per_objfile->info.size);
3599 }
3600
3601 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
3602 &objfile->objfile_obstack);
3603 discard_cleanups (addrmap_cleanup);
3604
3605 do_cleanups (back_to);
3606 }
3607
3608 /* Load the partial DIEs for a secondary CU into memory. */
3609
3610 static void
3611 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
3612 struct objfile *objfile)
3613 {
3614 bfd *abfd = objfile->obfd;
3615 gdb_byte *info_ptr, *beg_of_comp_unit;
3616 struct die_info *comp_unit_die;
3617 struct dwarf2_cu *cu;
3618 struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL;
3619 int has_children;
3620 struct die_reader_specs reader_specs;
3621 int read_cu = 0;
3622
3623 gdb_assert (! this_cu->debug_type_section);
3624
3625 gdb_assert (dwarf2_per_objfile->info.readin);
3626 info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset;
3627 beg_of_comp_unit = info_ptr;
3628
3629 if (this_cu->cu == NULL)
3630 {
3631 cu = xmalloc (sizeof (*cu));
3632 init_one_comp_unit (cu, objfile);
3633
3634 read_cu = 1;
3635
3636 /* If an error occurs while loading, release our storage. */
3637 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
3638
3639 info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
3640 dwarf2_per_objfile->info.buffer,
3641 dwarf2_per_objfile->info.size,
3642 abfd);
3643
3644 /* Complete the cu_header. */
3645 cu->header.offset = this_cu->offset;
3646 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
3647
3648 /* Link this compilation unit into the compilation unit tree. */
3649 this_cu->cu = cu;
3650 cu->per_cu = this_cu;
3651
3652 /* Link this CU into read_in_chain. */
3653 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
3654 dwarf2_per_objfile->read_in_chain = this_cu;
3655 }
3656 else
3657 {
3658 cu = this_cu->cu;
3659 info_ptr += cu->header.first_die_offset;
3660 }
3661
3662 /* Read the abbrevs for this compilation unit into a table. */
3663 gdb_assert (cu->dwarf2_abbrevs == NULL);
3664 dwarf2_read_abbrevs (abfd, cu);
3665 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
3666
3667 /* Read the compilation unit die. */
3668 init_cu_die_reader (&reader_specs, cu);
3669 info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr,
3670 &has_children);
3671
3672 prepare_one_comp_unit (cu, comp_unit_die);
3673
3674 /* Check if comp unit has_children.
3675 If so, read the rest of the partial symbols from this comp unit.
3676 If not, there's no more debug_info for this comp unit. */
3677 if (has_children)
3678 load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu);
3679
3680 do_cleanups (free_abbrevs_cleanup);
3681
3682 if (read_cu)
3683 {
3684 /* We've successfully allocated this compilation unit. Let our
3685 caller clean it up when finished with it. */
3686 discard_cleanups (free_cu_cleanup);
3687 }
3688 }
3689
3690 /* Create a list of all compilation units in OBJFILE. We do this only
3691 if an inter-comp-unit reference is found; presumably if there is one,
3692 there will be many, and one will occur early in the .debug_info section.
3693 So there's no point in building this list incrementally. */
3694
3695 static void
3696 create_all_comp_units (struct objfile *objfile)
3697 {
3698 int n_allocated;
3699 int n_comp_units;
3700 struct dwarf2_per_cu_data **all_comp_units;
3701 gdb_byte *info_ptr;
3702
3703 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
3704 info_ptr = dwarf2_per_objfile->info.buffer;
3705
3706 n_comp_units = 0;
3707 n_allocated = 10;
3708 all_comp_units = xmalloc (n_allocated
3709 * sizeof (struct dwarf2_per_cu_data *));
3710
3711 while (info_ptr < dwarf2_per_objfile->info.buffer
3712 + dwarf2_per_objfile->info.size)
3713 {
3714 unsigned int length, initial_length_size;
3715 struct dwarf2_per_cu_data *this_cu;
3716 unsigned int offset;
3717
3718 offset = info_ptr - dwarf2_per_objfile->info.buffer;
3719
3720 /* Read just enough information to find out where the next
3721 compilation unit is. */
3722 length = read_initial_length (objfile->obfd, info_ptr,
3723 &initial_length_size);
3724
3725 /* Save the compilation unit for later lookup. */
3726 this_cu = obstack_alloc (&objfile->objfile_obstack,
3727 sizeof (struct dwarf2_per_cu_data));
3728 memset (this_cu, 0, sizeof (*this_cu));
3729 this_cu->offset = offset;
3730 this_cu->length = length + initial_length_size;
3731 this_cu->objfile = objfile;
3732
3733 if (n_comp_units == n_allocated)
3734 {
3735 n_allocated *= 2;
3736 all_comp_units = xrealloc (all_comp_units,
3737 n_allocated
3738 * sizeof (struct dwarf2_per_cu_data *));
3739 }
3740 all_comp_units[n_comp_units++] = this_cu;
3741
3742 info_ptr = info_ptr + this_cu->length;
3743 }
3744
3745 dwarf2_per_objfile->all_comp_units
3746 = obstack_alloc (&objfile->objfile_obstack,
3747 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3748 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
3749 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
3750 xfree (all_comp_units);
3751 dwarf2_per_objfile->n_comp_units = n_comp_units;
3752 }
3753
3754 /* Process all loaded DIEs for compilation unit CU, starting at
3755 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3756 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3757 DW_AT_ranges). If NEED_PC is set, then this function will set
3758 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3759 and record the covered ranges in the addrmap. */
3760
3761 static void
3762 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
3763 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
3764 {
3765 struct partial_die_info *pdi;
3766
3767 /* Now, march along the PDI's, descending into ones which have
3768 interesting children but skipping the children of the other ones,
3769 until we reach the end of the compilation unit. */
3770
3771 pdi = first_die;
3772
3773 while (pdi != NULL)
3774 {
3775 fixup_partial_die (pdi, cu);
3776
3777 /* Anonymous namespaces or modules have no name but have interesting
3778 children, so we need to look at them. Ditto for anonymous
3779 enums. */
3780
3781 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
3782 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type)
3783 {
3784 switch (pdi->tag)
3785 {
3786 case DW_TAG_subprogram:
3787 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
3788 break;
3789 case DW_TAG_constant:
3790 case DW_TAG_variable:
3791 case DW_TAG_typedef:
3792 case DW_TAG_union_type:
3793 if (!pdi->is_declaration)
3794 {
3795 add_partial_symbol (pdi, cu);
3796 }
3797 break;
3798 case DW_TAG_class_type:
3799 case DW_TAG_interface_type:
3800 case DW_TAG_structure_type:
3801 if (!pdi->is_declaration)
3802 {
3803 add_partial_symbol (pdi, cu);
3804 }
3805 break;
3806 case DW_TAG_enumeration_type:
3807 if (!pdi->is_declaration)
3808 add_partial_enumeration (pdi, cu);
3809 break;
3810 case DW_TAG_base_type:
3811 case DW_TAG_subrange_type:
3812 /* File scope base type definitions are added to the partial
3813 symbol table. */
3814 add_partial_symbol (pdi, cu);
3815 break;
3816 case DW_TAG_namespace:
3817 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
3818 break;
3819 case DW_TAG_module:
3820 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
3821 break;
3822 default:
3823 break;
3824 }
3825 }
3826
3827 /* If the die has a sibling, skip to the sibling. */
3828
3829 pdi = pdi->die_sibling;
3830 }
3831 }
3832
3833 /* Functions used to compute the fully scoped name of a partial DIE.
3834
3835 Normally, this is simple. For C++, the parent DIE's fully scoped
3836 name is concatenated with "::" and the partial DIE's name. For
3837 Java, the same thing occurs except that "." is used instead of "::".
3838 Enumerators are an exception; they use the scope of their parent
3839 enumeration type, i.e. the name of the enumeration type is not
3840 prepended to the enumerator.
3841
3842 There are two complexities. One is DW_AT_specification; in this
3843 case "parent" means the parent of the target of the specification,
3844 instead of the direct parent of the DIE. The other is compilers
3845 which do not emit DW_TAG_namespace; in this case we try to guess
3846 the fully qualified name of structure types from their members'
3847 linkage names. This must be done using the DIE's children rather
3848 than the children of any DW_AT_specification target. We only need
3849 to do this for structures at the top level, i.e. if the target of
3850 any DW_AT_specification (if any; otherwise the DIE itself) does not
3851 have a parent. */
3852
3853 /* Compute the scope prefix associated with PDI's parent, in
3854 compilation unit CU. The result will be allocated on CU's
3855 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3856 field. NULL is returned if no prefix is necessary. */
3857 static char *
3858 partial_die_parent_scope (struct partial_die_info *pdi,
3859 struct dwarf2_cu *cu)
3860 {
3861 char *grandparent_scope;
3862 struct partial_die_info *parent, *real_pdi;
3863
3864 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3865 then this means the parent of the specification DIE. */
3866
3867 real_pdi = pdi;
3868 while (real_pdi->has_specification)
3869 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
3870
3871 parent = real_pdi->die_parent;
3872 if (parent == NULL)
3873 return NULL;
3874
3875 if (parent->scope_set)
3876 return parent->scope;
3877
3878 fixup_partial_die (parent, cu);
3879
3880 grandparent_scope = partial_die_parent_scope (parent, cu);
3881
3882 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3883 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3884 Work around this problem here. */
3885 if (cu->language == language_cplus
3886 && parent->tag == DW_TAG_namespace
3887 && strcmp (parent->name, "::") == 0
3888 && grandparent_scope == NULL)
3889 {
3890 parent->scope = NULL;
3891 parent->scope_set = 1;
3892 return NULL;
3893 }
3894
3895 if (parent->tag == DW_TAG_namespace
3896 || parent->tag == DW_TAG_module
3897 || parent->tag == DW_TAG_structure_type
3898 || parent->tag == DW_TAG_class_type
3899 || parent->tag == DW_TAG_interface_type
3900 || parent->tag == DW_TAG_union_type
3901 || parent->tag == DW_TAG_enumeration_type)
3902 {
3903 if (grandparent_scope == NULL)
3904 parent->scope = parent->name;
3905 else
3906 parent->scope = typename_concat (&cu->comp_unit_obstack,
3907 grandparent_scope,
3908 parent->name, 0, cu);
3909 }
3910 else if (parent->tag == DW_TAG_enumerator)
3911 /* Enumerators should not get the name of the enumeration as a prefix. */
3912 parent->scope = grandparent_scope;
3913 else
3914 {
3915 /* FIXME drow/2004-04-01: What should we be doing with
3916 function-local names? For partial symbols, we should probably be
3917 ignoring them. */
3918 complaint (&symfile_complaints,
3919 _("unhandled containing DIE tag %d for DIE at %d"),
3920 parent->tag, pdi->offset);
3921 parent->scope = grandparent_scope;
3922 }
3923
3924 parent->scope_set = 1;
3925 return parent->scope;
3926 }
3927
3928 /* Return the fully scoped name associated with PDI, from compilation unit
3929 CU. The result will be allocated with malloc. */
3930 static char *
3931 partial_die_full_name (struct partial_die_info *pdi,
3932 struct dwarf2_cu *cu)
3933 {
3934 char *parent_scope;
3935
3936 /* If this is a template instantiation, we can not work out the
3937 template arguments from partial DIEs. So, unfortunately, we have
3938 to go through the full DIEs. At least any work we do building
3939 types here will be reused if full symbols are loaded later. */
3940 if (pdi->has_template_arguments)
3941 {
3942 fixup_partial_die (pdi, cu);
3943
3944 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
3945 {
3946 struct die_info *die;
3947 struct attribute attr;
3948 struct dwarf2_cu *ref_cu = cu;
3949
3950 attr.name = 0;
3951 attr.form = DW_FORM_ref_addr;
3952 attr.u.addr = pdi->offset;
3953 die = follow_die_ref (NULL, &attr, &ref_cu);
3954
3955 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
3956 }
3957 }
3958
3959 parent_scope = partial_die_parent_scope (pdi, cu);
3960 if (parent_scope == NULL)
3961 return NULL;
3962 else
3963 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
3964 }
3965
3966 static void
3967 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
3968 {
3969 struct objfile *objfile = cu->objfile;
3970 CORE_ADDR addr = 0;
3971 char *actual_name = NULL;
3972 const struct partial_symbol *psym = NULL;
3973 CORE_ADDR baseaddr;
3974 int built_actual_name = 0;
3975
3976 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3977
3978 actual_name = partial_die_full_name (pdi, cu);
3979 if (actual_name)
3980 built_actual_name = 1;
3981
3982 if (actual_name == NULL)
3983 actual_name = pdi->name;
3984
3985 switch (pdi->tag)
3986 {
3987 case DW_TAG_subprogram:
3988 if (pdi->is_external || cu->language == language_ada)
3989 {
3990 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3991 of the global scope. But in Ada, we want to be able to access
3992 nested procedures globally. So all Ada subprograms are stored
3993 in the global scope. */
3994 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3995 mst_text, objfile); */
3996 add_psymbol_to_list (actual_name, strlen (actual_name),
3997 built_actual_name,
3998 VAR_DOMAIN, LOC_BLOCK,
3999 &objfile->global_psymbols,
4000 0, pdi->lowpc + baseaddr,
4001 cu->language, objfile);
4002 }
4003 else
4004 {
4005 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4006 mst_file_text, objfile); */
4007 add_psymbol_to_list (actual_name, strlen (actual_name),
4008 built_actual_name,
4009 VAR_DOMAIN, LOC_BLOCK,
4010 &objfile->static_psymbols,
4011 0, pdi->lowpc + baseaddr,
4012 cu->language, objfile);
4013 }
4014 break;
4015 case DW_TAG_constant:
4016 {
4017 struct psymbol_allocation_list *list;
4018
4019 if (pdi->is_external)
4020 list = &objfile->global_psymbols;
4021 else
4022 list = &objfile->static_psymbols;
4023 add_psymbol_to_list (actual_name, strlen (actual_name),
4024 built_actual_name, VAR_DOMAIN, LOC_STATIC,
4025 list, 0, 0, cu->language, objfile);
4026 }
4027 break;
4028 case DW_TAG_variable:
4029 if (pdi->locdesc)
4030 addr = decode_locdesc (pdi->locdesc, cu);
4031
4032 if (pdi->locdesc
4033 && addr == 0
4034 && !dwarf2_per_objfile->has_section_at_zero)
4035 {
4036 /* A global or static variable may also have been stripped
4037 out by the linker if unused, in which case its address
4038 will be nullified; do not add such variables into partial
4039 symbol table then. */
4040 }
4041 else if (pdi->is_external)
4042 {
4043 /* Global Variable.
4044 Don't enter into the minimal symbol tables as there is
4045 a minimal symbol table entry from the ELF symbols already.
4046 Enter into partial symbol table if it has a location
4047 descriptor or a type.
4048 If the location descriptor is missing, new_symbol will create
4049 a LOC_UNRESOLVED symbol, the address of the variable will then
4050 be determined from the minimal symbol table whenever the variable
4051 is referenced.
4052 The address for the partial symbol table entry is not
4053 used by GDB, but it comes in handy for debugging partial symbol
4054 table building. */
4055
4056 if (pdi->locdesc || pdi->has_type)
4057 add_psymbol_to_list (actual_name, strlen (actual_name),
4058 built_actual_name,
4059 VAR_DOMAIN, LOC_STATIC,
4060 &objfile->global_psymbols,
4061 0, addr + baseaddr,
4062 cu->language, objfile);
4063 }
4064 else
4065 {
4066 /* Static Variable. Skip symbols without location descriptors. */
4067 if (pdi->locdesc == NULL)
4068 {
4069 if (built_actual_name)
4070 xfree (actual_name);
4071 return;
4072 }
4073 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4074 mst_file_data, objfile); */
4075 add_psymbol_to_list (actual_name, strlen (actual_name),
4076 built_actual_name,
4077 VAR_DOMAIN, LOC_STATIC,
4078 &objfile->static_psymbols,
4079 0, addr + baseaddr,
4080 cu->language, objfile);
4081 }
4082 break;
4083 case DW_TAG_typedef:
4084 case DW_TAG_base_type:
4085 case DW_TAG_subrange_type:
4086 add_psymbol_to_list (actual_name, strlen (actual_name),
4087 built_actual_name,
4088 VAR_DOMAIN, LOC_TYPEDEF,
4089 &objfile->static_psymbols,
4090 0, (CORE_ADDR) 0, cu->language, objfile);
4091 break;
4092 case DW_TAG_namespace:
4093 add_psymbol_to_list (actual_name, strlen (actual_name),
4094 built_actual_name,
4095 VAR_DOMAIN, LOC_TYPEDEF,
4096 &objfile->global_psymbols,
4097 0, (CORE_ADDR) 0, cu->language, objfile);
4098 break;
4099 case DW_TAG_class_type:
4100 case DW_TAG_interface_type:
4101 case DW_TAG_structure_type:
4102 case DW_TAG_union_type:
4103 case DW_TAG_enumeration_type:
4104 /* Skip external references. The DWARF standard says in the section
4105 about "Structure, Union, and Class Type Entries": "An incomplete
4106 structure, union or class type is represented by a structure,
4107 union or class entry that does not have a byte size attribute
4108 and that has a DW_AT_declaration attribute." */
4109 if (!pdi->has_byte_size && pdi->is_declaration)
4110 {
4111 if (built_actual_name)
4112 xfree (actual_name);
4113 return;
4114 }
4115
4116 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4117 static vs. global. */
4118 add_psymbol_to_list (actual_name, strlen (actual_name),
4119 built_actual_name,
4120 STRUCT_DOMAIN, LOC_TYPEDEF,
4121 (cu->language == language_cplus
4122 || cu->language == language_java)
4123 ? &objfile->global_psymbols
4124 : &objfile->static_psymbols,
4125 0, (CORE_ADDR) 0, cu->language, objfile);
4126
4127 break;
4128 case DW_TAG_enumerator:
4129 add_psymbol_to_list (actual_name, strlen (actual_name),
4130 built_actual_name,
4131 VAR_DOMAIN, LOC_CONST,
4132 (cu->language == language_cplus
4133 || cu->language == language_java)
4134 ? &objfile->global_psymbols
4135 : &objfile->static_psymbols,
4136 0, (CORE_ADDR) 0, cu->language, objfile);
4137 break;
4138 default:
4139 break;
4140 }
4141
4142 if (built_actual_name)
4143 xfree (actual_name);
4144 }
4145
4146 /* Read a partial die corresponding to a namespace; also, add a symbol
4147 corresponding to that namespace to the symbol table. NAMESPACE is
4148 the name of the enclosing namespace. */
4149
4150 static void
4151 add_partial_namespace (struct partial_die_info *pdi,
4152 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4153 int need_pc, struct dwarf2_cu *cu)
4154 {
4155 /* Add a symbol for the namespace. */
4156
4157 add_partial_symbol (pdi, cu);
4158
4159 /* Now scan partial symbols in that namespace. */
4160
4161 if (pdi->has_children)
4162 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4163 }
4164
4165 /* Read a partial die corresponding to a Fortran module. */
4166
4167 static void
4168 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
4169 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
4170 {
4171 /* Now scan partial symbols in that module. */
4172
4173 if (pdi->has_children)
4174 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
4175 }
4176
4177 /* Read a partial die corresponding to a subprogram and create a partial
4178 symbol for that subprogram. When the CU language allows it, this
4179 routine also defines a partial symbol for each nested subprogram
4180 that this subprogram contains.
4181
4182 DIE my also be a lexical block, in which case we simply search
4183 recursively for suprograms defined inside that lexical block.
4184 Again, this is only performed when the CU language allows this
4185 type of definitions. */
4186
4187 static void
4188 add_partial_subprogram (struct partial_die_info *pdi,
4189 CORE_ADDR *lowpc, CORE_ADDR *highpc,
4190 int need_pc, struct dwarf2_cu *cu)
4191 {
4192 if (pdi->tag == DW_TAG_subprogram)
4193 {
4194 if (pdi->has_pc_info)
4195 {
4196 if (pdi->lowpc < *lowpc)
4197 *lowpc = pdi->lowpc;
4198 if (pdi->highpc > *highpc)
4199 *highpc = pdi->highpc;
4200 if (need_pc)
4201 {
4202 CORE_ADDR baseaddr;
4203 struct objfile *objfile = cu->objfile;
4204
4205 baseaddr = ANOFFSET (objfile->section_offsets,
4206 SECT_OFF_TEXT (objfile));
4207 addrmap_set_empty (objfile->psymtabs_addrmap,
4208 pdi->lowpc + baseaddr,
4209 pdi->highpc - 1 + baseaddr,
4210 cu->per_cu->v.psymtab);
4211 }
4212 if (!pdi->is_declaration)
4213 /* Ignore subprogram DIEs that do not have a name, they are
4214 illegal. Do not emit a complaint at this point, we will
4215 do so when we convert this psymtab into a symtab. */
4216 if (pdi->name)
4217 add_partial_symbol (pdi, cu);
4218 }
4219 }
4220
4221 if (! pdi->has_children)
4222 return;
4223
4224 if (cu->language == language_ada)
4225 {
4226 pdi = pdi->die_child;
4227 while (pdi != NULL)
4228 {
4229 fixup_partial_die (pdi, cu);
4230 if (pdi->tag == DW_TAG_subprogram
4231 || pdi->tag == DW_TAG_lexical_block)
4232 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
4233 pdi = pdi->die_sibling;
4234 }
4235 }
4236 }
4237
4238 /* Read a partial die corresponding to an enumeration type. */
4239
4240 static void
4241 add_partial_enumeration (struct partial_die_info *enum_pdi,
4242 struct dwarf2_cu *cu)
4243 {
4244 struct partial_die_info *pdi;
4245
4246 if (enum_pdi->name != NULL)
4247 add_partial_symbol (enum_pdi, cu);
4248
4249 pdi = enum_pdi->die_child;
4250 while (pdi)
4251 {
4252 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
4253 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
4254 else
4255 add_partial_symbol (pdi, cu);
4256 pdi = pdi->die_sibling;
4257 }
4258 }
4259
4260 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4261 Return the corresponding abbrev, or NULL if the number is zero (indicating
4262 an empty DIE). In either case *BYTES_READ will be set to the length of
4263 the initial number. */
4264
4265 static struct abbrev_info *
4266 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
4267 struct dwarf2_cu *cu)
4268 {
4269 bfd *abfd = cu->objfile->obfd;
4270 unsigned int abbrev_number;
4271 struct abbrev_info *abbrev;
4272
4273 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
4274
4275 if (abbrev_number == 0)
4276 return NULL;
4277
4278 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
4279 if (!abbrev)
4280 {
4281 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4282 abbrev_number, bfd_get_filename (abfd));
4283 }
4284
4285 return abbrev;
4286 }
4287
4288 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4289 Returns a pointer to the end of a series of DIEs, terminated by an empty
4290 DIE. Any children of the skipped DIEs will also be skipped. */
4291
4292 static gdb_byte *
4293 skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu)
4294 {
4295 struct abbrev_info *abbrev;
4296 unsigned int bytes_read;
4297
4298 while (1)
4299 {
4300 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
4301 if (abbrev == NULL)
4302 return info_ptr + bytes_read;
4303 else
4304 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
4305 }
4306 }
4307
4308 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4309 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4310 abbrev corresponding to that skipped uleb128 should be passed in
4311 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4312 children. */
4313
4314 static gdb_byte *
4315 skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr,
4316 struct abbrev_info *abbrev, struct dwarf2_cu *cu)
4317 {
4318 unsigned int bytes_read;
4319 struct attribute attr;
4320 bfd *abfd = cu->objfile->obfd;
4321 unsigned int form, i;
4322
4323 for (i = 0; i < abbrev->num_attrs; i++)
4324 {
4325 /* The only abbrev we care about is DW_AT_sibling. */
4326 if (abbrev->attrs[i].name == DW_AT_sibling)
4327 {
4328 read_attribute (&attr, &abbrev->attrs[i],
4329 abfd, info_ptr, cu);
4330 if (attr.form == DW_FORM_ref_addr)
4331 complaint (&symfile_complaints,
4332 _("ignoring absolute DW_AT_sibling"));
4333 else
4334 return buffer + dwarf2_get_ref_die_offset (&attr);
4335 }
4336
4337 /* If it isn't DW_AT_sibling, skip this attribute. */
4338 form = abbrev->attrs[i].form;
4339 skip_attribute:
4340 switch (form)
4341 {
4342 case DW_FORM_ref_addr:
4343 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4344 and later it is offset sized. */
4345 if (cu->header.version == 2)
4346 info_ptr += cu->header.addr_size;
4347 else
4348 info_ptr += cu->header.offset_size;
4349 break;
4350 case DW_FORM_addr:
4351 info_ptr += cu->header.addr_size;
4352 break;
4353 case DW_FORM_data1:
4354 case DW_FORM_ref1:
4355 case DW_FORM_flag:
4356 info_ptr += 1;
4357 break;
4358 case DW_FORM_flag_present:
4359 break;
4360 case DW_FORM_data2:
4361 case DW_FORM_ref2:
4362 info_ptr += 2;
4363 break;
4364 case DW_FORM_data4:
4365 case DW_FORM_ref4:
4366 info_ptr += 4;
4367 break;
4368 case DW_FORM_data8:
4369 case DW_FORM_ref8:
4370 case DW_FORM_ref_sig8:
4371 info_ptr += 8;
4372 break;
4373 case DW_FORM_string:
4374 read_direct_string (abfd, info_ptr, &bytes_read);
4375 info_ptr += bytes_read;
4376 break;
4377 case DW_FORM_sec_offset:
4378 case DW_FORM_strp:
4379 info_ptr += cu->header.offset_size;
4380 break;
4381 case DW_FORM_exprloc:
4382 case DW_FORM_block:
4383 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4384 info_ptr += bytes_read;
4385 break;
4386 case DW_FORM_block1:
4387 info_ptr += 1 + read_1_byte (abfd, info_ptr);
4388 break;
4389 case DW_FORM_block2:
4390 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
4391 break;
4392 case DW_FORM_block4:
4393 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
4394 break;
4395 case DW_FORM_sdata:
4396 case DW_FORM_udata:
4397 case DW_FORM_ref_udata:
4398 info_ptr = skip_leb128 (abfd, info_ptr);
4399 break;
4400 case DW_FORM_indirect:
4401 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
4402 info_ptr += bytes_read;
4403 /* We need to continue parsing from here, so just go back to
4404 the top. */
4405 goto skip_attribute;
4406
4407 default:
4408 error (_("Dwarf Error: Cannot handle %s "
4409 "in DWARF reader [in module %s]"),
4410 dwarf_form_name (form),
4411 bfd_get_filename (abfd));
4412 }
4413 }
4414
4415 if (abbrev->has_children)
4416 return skip_children (buffer, info_ptr, cu);
4417 else
4418 return info_ptr;
4419 }
4420
4421 /* Locate ORIG_PDI's sibling.
4422 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4423 in BUFFER. */
4424
4425 static gdb_byte *
4426 locate_pdi_sibling (struct partial_die_info *orig_pdi,
4427 gdb_byte *buffer, gdb_byte *info_ptr,
4428 bfd *abfd, struct dwarf2_cu *cu)
4429 {
4430 /* Do we know the sibling already? */
4431
4432 if (orig_pdi->sibling)
4433 return orig_pdi->sibling;
4434
4435 /* Are there any children to deal with? */
4436
4437 if (!orig_pdi->has_children)
4438 return info_ptr;
4439
4440 /* Skip the children the long way. */
4441
4442 return skip_children (buffer, info_ptr, cu);
4443 }
4444
4445 /* Expand this partial symbol table into a full symbol table. */
4446
4447 static void
4448 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
4449 {
4450 if (pst != NULL)
4451 {
4452 if (pst->readin)
4453 {
4454 warning (_("bug: psymtab for %s is already read in."),
4455 pst->filename);
4456 }
4457 else
4458 {
4459 if (info_verbose)
4460 {
4461 printf_filtered (_("Reading in symbols for %s..."),
4462 pst->filename);
4463 gdb_flush (gdb_stdout);
4464 }
4465
4466 /* Restore our global data. */
4467 dwarf2_per_objfile = objfile_data (pst->objfile,
4468 dwarf2_objfile_data_key);
4469
4470 /* If this psymtab is constructed from a debug-only objfile, the
4471 has_section_at_zero flag will not necessarily be correct. We
4472 can get the correct value for this flag by looking at the data
4473 associated with the (presumably stripped) associated objfile. */
4474 if (pst->objfile->separate_debug_objfile_backlink)
4475 {
4476 struct dwarf2_per_objfile *dpo_backlink
4477 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
4478 dwarf2_objfile_data_key);
4479
4480 dwarf2_per_objfile->has_section_at_zero
4481 = dpo_backlink->has_section_at_zero;
4482 }
4483
4484 dwarf2_per_objfile->reading_partial_symbols = 0;
4485
4486 psymtab_to_symtab_1 (pst);
4487
4488 /* Finish up the debug error message. */
4489 if (info_verbose)
4490 printf_filtered (_("done.\n"));
4491 }
4492 }
4493 }
4494
4495 /* Add PER_CU to the queue. */
4496
4497 static void
4498 queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
4499 {
4500 struct dwarf2_queue_item *item;
4501
4502 per_cu->queued = 1;
4503 item = xmalloc (sizeof (*item));
4504 item->per_cu = per_cu;
4505 item->next = NULL;
4506
4507 if (dwarf2_queue == NULL)
4508 dwarf2_queue = item;
4509 else
4510 dwarf2_queue_tail->next = item;
4511
4512 dwarf2_queue_tail = item;
4513 }
4514
4515 /* Process the queue. */
4516
4517 static void
4518 process_queue (struct objfile *objfile)
4519 {
4520 struct dwarf2_queue_item *item, *next_item;
4521
4522 /* The queue starts out with one item, but following a DIE reference
4523 may load a new CU, adding it to the end of the queue. */
4524 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
4525 {
4526 if (dwarf2_per_objfile->using_index
4527 ? !item->per_cu->v.quick->symtab
4528 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
4529 process_full_comp_unit (item->per_cu);
4530
4531 item->per_cu->queued = 0;
4532 next_item = item->next;
4533 xfree (item);
4534 }
4535
4536 dwarf2_queue_tail = NULL;
4537 }
4538
4539 /* Free all allocated queue entries. This function only releases anything if
4540 an error was thrown; if the queue was processed then it would have been
4541 freed as we went along. */
4542
4543 static void
4544 dwarf2_release_queue (void *dummy)
4545 {
4546 struct dwarf2_queue_item *item, *last;
4547
4548 item = dwarf2_queue;
4549 while (item)
4550 {
4551 /* Anything still marked queued is likely to be in an
4552 inconsistent state, so discard it. */
4553 if (item->per_cu->queued)
4554 {
4555 if (item->per_cu->cu != NULL)
4556 free_one_cached_comp_unit (item->per_cu->cu);
4557 item->per_cu->queued = 0;
4558 }
4559
4560 last = item;
4561 item = item->next;
4562 xfree (last);
4563 }
4564
4565 dwarf2_queue = dwarf2_queue_tail = NULL;
4566 }
4567
4568 /* Read in full symbols for PST, and anything it depends on. */
4569
4570 static void
4571 psymtab_to_symtab_1 (struct partial_symtab *pst)
4572 {
4573 struct dwarf2_per_cu_data *per_cu;
4574 struct cleanup *back_to;
4575 int i;
4576
4577 for (i = 0; i < pst->number_of_dependencies; i++)
4578 if (!pst->dependencies[i]->readin)
4579 {
4580 /* Inform about additional files that need to be read in. */
4581 if (info_verbose)
4582 {
4583 /* FIXME: i18n: Need to make this a single string. */
4584 fputs_filtered (" ", gdb_stdout);
4585 wrap_here ("");
4586 fputs_filtered ("and ", gdb_stdout);
4587 wrap_here ("");
4588 printf_filtered ("%s...", pst->dependencies[i]->filename);
4589 wrap_here (""); /* Flush output. */
4590 gdb_flush (gdb_stdout);
4591 }
4592 psymtab_to_symtab_1 (pst->dependencies[i]);
4593 }
4594
4595 per_cu = pst->read_symtab_private;
4596
4597 if (per_cu == NULL)
4598 {
4599 /* It's an include file, no symbols to read for it.
4600 Everything is in the parent symtab. */
4601 pst->readin = 1;
4602 return;
4603 }
4604
4605 dw2_do_instantiate_symtab (pst->objfile, per_cu);
4606 }
4607
4608 /* Load the DIEs associated with PER_CU into memory. */
4609
4610 static void
4611 load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
4612 struct objfile *objfile)
4613 {
4614 bfd *abfd = objfile->obfd;
4615 struct dwarf2_cu *cu;
4616 unsigned int offset;
4617 gdb_byte *info_ptr, *beg_of_comp_unit;
4618 struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL;
4619 struct attribute *attr;
4620 int read_cu = 0;
4621
4622 gdb_assert (! per_cu->debug_type_section);
4623
4624 /* Set local variables from the partial symbol table info. */
4625 offset = per_cu->offset;
4626
4627 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
4628 info_ptr = dwarf2_per_objfile->info.buffer + offset;
4629 beg_of_comp_unit = info_ptr;
4630
4631 if (per_cu->cu == NULL)
4632 {
4633 cu = xmalloc (sizeof (*cu));
4634 init_one_comp_unit (cu, objfile);
4635
4636 read_cu = 1;
4637
4638 /* If an error occurs while loading, release our storage. */
4639 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
4640
4641 /* Read in the comp_unit header. */
4642 info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
4643
4644 /* Complete the cu_header. */
4645 cu->header.offset = offset;
4646 cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
4647
4648 /* Read the abbrevs for this compilation unit. */
4649 dwarf2_read_abbrevs (abfd, cu);
4650 free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
4651
4652 /* Link this compilation unit into the compilation unit tree. */
4653 per_cu->cu = cu;
4654 cu->per_cu = per_cu;
4655
4656 /* Link this CU into read_in_chain. */
4657 per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4658 dwarf2_per_objfile->read_in_chain = per_cu;
4659 }
4660 else
4661 {
4662 cu = per_cu->cu;
4663 info_ptr += cu->header.first_die_offset;
4664 }
4665
4666 cu->dies = read_comp_unit (info_ptr, cu);
4667
4668 /* We try not to read any attributes in this function, because not
4669 all objfiles needed for references have been loaded yet, and symbol
4670 table processing isn't initialized. But we have to set the CU language,
4671 or we won't be able to build types correctly. */
4672 prepare_one_comp_unit (cu, cu->dies);
4673
4674 /* Similarly, if we do not read the producer, we can not apply
4675 producer-specific interpretation. */
4676 attr = dwarf2_attr (cu->dies, DW_AT_producer, cu);
4677 if (attr)
4678 cu->producer = DW_STRING (attr);
4679
4680 if (read_cu)
4681 {
4682 do_cleanups (free_abbrevs_cleanup);
4683
4684 /* We've successfully allocated this compilation unit. Let our
4685 caller clean it up when finished with it. */
4686 discard_cleanups (free_cu_cleanup);
4687 }
4688 }
4689
4690 /* Add a DIE to the delayed physname list. */
4691
4692 static void
4693 add_to_method_list (struct type *type, int fnfield_index, int index,
4694 const char *name, struct die_info *die,
4695 struct dwarf2_cu *cu)
4696 {
4697 struct delayed_method_info mi;
4698 mi.type = type;
4699 mi.fnfield_index = fnfield_index;
4700 mi.index = index;
4701 mi.name = name;
4702 mi.die = die;
4703 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
4704 }
4705
4706 /* A cleanup for freeing the delayed method list. */
4707
4708 static void
4709 free_delayed_list (void *ptr)
4710 {
4711 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
4712 if (cu->method_list != NULL)
4713 {
4714 VEC_free (delayed_method_info, cu->method_list);
4715 cu->method_list = NULL;
4716 }
4717 }
4718
4719 /* Compute the physnames of any methods on the CU's method list.
4720
4721 The computation of method physnames is delayed in order to avoid the
4722 (bad) condition that one of the method's formal parameters is of an as yet
4723 incomplete type. */
4724
4725 static void
4726 compute_delayed_physnames (struct dwarf2_cu *cu)
4727 {
4728 int i;
4729 struct delayed_method_info *mi;
4730 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
4731 {
4732 const char *physname;
4733 struct fn_fieldlist *fn_flp
4734 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
4735 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
4736 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
4737 }
4738 }
4739
4740 /* Generate full symbol information for PST and CU, whose DIEs have
4741 already been loaded into memory. */
4742
4743 static void
4744 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
4745 {
4746 struct dwarf2_cu *cu = per_cu->cu;
4747 struct objfile *objfile = per_cu->objfile;
4748 CORE_ADDR lowpc, highpc;
4749 struct symtab *symtab;
4750 struct cleanup *back_to, *delayed_list_cleanup;
4751 CORE_ADDR baseaddr;
4752
4753 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4754
4755 buildsym_init ();
4756 back_to = make_cleanup (really_free_pendings, NULL);
4757 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
4758
4759 cu->list_in_scope = &file_symbols;
4760
4761 /* Do line number decoding in read_file_scope () */
4762 process_die (cu->dies, cu);
4763
4764 /* Now that we have processed all the DIEs in the CU, all the types
4765 should be complete, and it should now be safe to compute all of the
4766 physnames. */
4767 compute_delayed_physnames (cu);
4768 do_cleanups (delayed_list_cleanup);
4769
4770 /* Some compilers don't define a DW_AT_high_pc attribute for the
4771 compilation unit. If the DW_AT_high_pc is missing, synthesize
4772 it, by scanning the DIE's below the compilation unit. */
4773 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
4774
4775 symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile));
4776
4777 if (symtab != NULL)
4778 {
4779 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
4780
4781 /* Set symtab language to language from DW_AT_language. If the
4782 compilation is from a C file generated by language preprocessors, do
4783 not set the language if it was already deduced by start_subfile. */
4784 if (!(cu->language == language_c && symtab->language != language_c))
4785 symtab->language = cu->language;
4786
4787 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
4788 produce DW_AT_location with location lists but it can be possibly
4789 invalid without -fvar-tracking.
4790
4791 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
4792 needed, it would be wrong due to missing DW_AT_producer there.
4793
4794 Still one can confuse GDB by using non-standard GCC compilation
4795 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
4796 */
4797 if (cu->has_loclist && gcc_4_minor >= 0)
4798 symtab->locations_valid = 1;
4799
4800 if (gcc_4_minor >= 5)
4801 symtab->epilogue_unwind_valid = 1;
4802 }
4803
4804 if (dwarf2_per_objfile->using_index)
4805 per_cu->v.quick->symtab = symtab;
4806 else
4807 {
4808 struct partial_symtab *pst = per_cu->v.psymtab;
4809 pst->symtab = symtab;
4810 pst->readin = 1;
4811 }
4812
4813 do_cleanups (back_to);
4814 }
4815
4816 /* Process a die and its children. */
4817
4818 static void
4819 process_die (struct die_info *die, struct dwarf2_cu *cu)
4820 {
4821 switch (die->tag)
4822 {
4823 case DW_TAG_padding:
4824 break;
4825 case DW_TAG_compile_unit:
4826 read_file_scope (die, cu);
4827 break;
4828 case DW_TAG_type_unit:
4829 read_type_unit_scope (die, cu);
4830 break;
4831 case DW_TAG_subprogram:
4832 case DW_TAG_inlined_subroutine:
4833 read_func_scope (die, cu);
4834 break;
4835 case DW_TAG_lexical_block:
4836 case DW_TAG_try_block:
4837 case DW_TAG_catch_block:
4838 read_lexical_block_scope (die, cu);
4839 break;
4840 case DW_TAG_class_type:
4841 case DW_TAG_interface_type:
4842 case DW_TAG_structure_type:
4843 case DW_TAG_union_type:
4844 process_structure_scope (die, cu);
4845 break;
4846 case DW_TAG_enumeration_type:
4847 process_enumeration_scope (die, cu);
4848 break;
4849
4850 /* These dies have a type, but processing them does not create
4851 a symbol or recurse to process the children. Therefore we can
4852 read them on-demand through read_type_die. */
4853 case DW_TAG_subroutine_type:
4854 case DW_TAG_set_type:
4855 case DW_TAG_array_type:
4856 case DW_TAG_pointer_type:
4857 case DW_TAG_ptr_to_member_type:
4858 case DW_TAG_reference_type:
4859 case DW_TAG_string_type:
4860 break;
4861
4862 case DW_TAG_base_type:
4863 case DW_TAG_subrange_type:
4864 case DW_TAG_typedef:
4865 /* Add a typedef symbol for the type definition, if it has a
4866 DW_AT_name. */
4867 new_symbol (die, read_type_die (die, cu), cu);
4868 break;
4869 case DW_TAG_common_block:
4870 read_common_block (die, cu);
4871 break;
4872 case DW_TAG_common_inclusion:
4873 break;
4874 case DW_TAG_namespace:
4875 processing_has_namespace_info = 1;
4876 read_namespace (die, cu);
4877 break;
4878 case DW_TAG_module:
4879 processing_has_namespace_info = 1;
4880 read_module (die, cu);
4881 break;
4882 case DW_TAG_imported_declaration:
4883 case DW_TAG_imported_module:
4884 processing_has_namespace_info = 1;
4885 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
4886 || cu->language != language_fortran))
4887 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
4888 dwarf_tag_name (die->tag));
4889 read_import_statement (die, cu);
4890 break;
4891 default:
4892 new_symbol (die, NULL, cu);
4893 break;
4894 }
4895 }
4896
4897 /* A helper function for dwarf2_compute_name which determines whether DIE
4898 needs to have the name of the scope prepended to the name listed in the
4899 die. */
4900
4901 static int
4902 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
4903 {
4904 struct attribute *attr;
4905
4906 switch (die->tag)
4907 {
4908 case DW_TAG_namespace:
4909 case DW_TAG_typedef:
4910 case DW_TAG_class_type:
4911 case DW_TAG_interface_type:
4912 case DW_TAG_structure_type:
4913 case DW_TAG_union_type:
4914 case DW_TAG_enumeration_type:
4915 case DW_TAG_enumerator:
4916 case DW_TAG_subprogram:
4917 case DW_TAG_member:
4918 return 1;
4919
4920 case DW_TAG_variable:
4921 case DW_TAG_constant:
4922 /* We only need to prefix "globally" visible variables. These include
4923 any variable marked with DW_AT_external or any variable that
4924 lives in a namespace. [Variables in anonymous namespaces
4925 require prefixing, but they are not DW_AT_external.] */
4926
4927 if (dwarf2_attr (die, DW_AT_specification, cu))
4928 {
4929 struct dwarf2_cu *spec_cu = cu;
4930
4931 return die_needs_namespace (die_specification (die, &spec_cu),
4932 spec_cu);
4933 }
4934
4935 attr = dwarf2_attr (die, DW_AT_external, cu);
4936 if (attr == NULL && die->parent->tag != DW_TAG_namespace
4937 && die->parent->tag != DW_TAG_module)
4938 return 0;
4939 /* A variable in a lexical block of some kind does not need a
4940 namespace, even though in C++ such variables may be external
4941 and have a mangled name. */
4942 if (die->parent->tag == DW_TAG_lexical_block
4943 || die->parent->tag == DW_TAG_try_block
4944 || die->parent->tag == DW_TAG_catch_block
4945 || die->parent->tag == DW_TAG_subprogram)
4946 return 0;
4947 return 1;
4948
4949 default:
4950 return 0;
4951 }
4952 }
4953
4954 /* Retrieve the last character from a mem_file. */
4955
4956 static void
4957 do_ui_file_peek_last (void *object, const char *buffer, long length)
4958 {
4959 char *last_char_p = (char *) object;
4960
4961 if (length > 0)
4962 *last_char_p = buffer[length - 1];
4963 }
4964
4965 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4966 compute the physname for the object, which include a method's
4967 formal parameters (C++/Java) and return type (Java).
4968
4969 For Ada, return the DIE's linkage name rather than the fully qualified
4970 name. PHYSNAME is ignored..
4971
4972 The result is allocated on the objfile_obstack and canonicalized. */
4973
4974 static const char *
4975 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
4976 int physname)
4977 {
4978 if (name == NULL)
4979 name = dwarf2_name (die, cu);
4980
4981 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4982 compute it by typename_concat inside GDB. */
4983 if (cu->language == language_ada
4984 || (cu->language == language_fortran && physname))
4985 {
4986 /* For Ada unit, we prefer the linkage name over the name, as
4987 the former contains the exported name, which the user expects
4988 to be able to reference. Ideally, we want the user to be able
4989 to reference this entity using either natural or linkage name,
4990 but we haven't started looking at this enhancement yet. */
4991 struct attribute *attr;
4992
4993 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
4994 if (attr == NULL)
4995 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
4996 if (attr && DW_STRING (attr))
4997 return DW_STRING (attr);
4998 }
4999
5000 /* These are the only languages we know how to qualify names in. */
5001 if (name != NULL
5002 && (cu->language == language_cplus || cu->language == language_java
5003 || cu->language == language_fortran))
5004 {
5005 if (die_needs_namespace (die, cu))
5006 {
5007 long length;
5008 char *prefix;
5009 struct ui_file *buf;
5010
5011 prefix = determine_prefix (die, cu);
5012 buf = mem_fileopen ();
5013 if (*prefix != '\0')
5014 {
5015 char *prefixed_name = typename_concat (NULL, prefix, name,
5016 physname, cu);
5017
5018 fputs_unfiltered (prefixed_name, buf);
5019 xfree (prefixed_name);
5020 }
5021 else
5022 fputs_unfiltered (name, buf);
5023
5024 /* Template parameters may be specified in the DIE's DW_AT_name, or
5025 as children with DW_TAG_template_type_param or
5026 DW_TAG_value_type_param. If the latter, add them to the name
5027 here. If the name already has template parameters, then
5028 skip this step; some versions of GCC emit both, and
5029 it is more efficient to use the pre-computed name.
5030
5031 Something to keep in mind about this process: it is very
5032 unlikely, or in some cases downright impossible, to produce
5033 something that will match the mangled name of a function.
5034 If the definition of the function has the same debug info,
5035 we should be able to match up with it anyway. But fallbacks
5036 using the minimal symbol, for instance to find a method
5037 implemented in a stripped copy of libstdc++, will not work.
5038 If we do not have debug info for the definition, we will have to
5039 match them up some other way.
5040
5041 When we do name matching there is a related problem with function
5042 templates; two instantiated function templates are allowed to
5043 differ only by their return types, which we do not add here. */
5044
5045 if (cu->language == language_cplus && strchr (name, '<') == NULL)
5046 {
5047 struct attribute *attr;
5048 struct die_info *child;
5049 int first = 1;
5050
5051 die->building_fullname = 1;
5052
5053 for (child = die->child; child != NULL; child = child->sibling)
5054 {
5055 struct type *type;
5056 long value;
5057 gdb_byte *bytes;
5058 struct dwarf2_locexpr_baton *baton;
5059 struct value *v;
5060
5061 if (child->tag != DW_TAG_template_type_param
5062 && child->tag != DW_TAG_template_value_param)
5063 continue;
5064
5065 if (first)
5066 {
5067 fputs_unfiltered ("<", buf);
5068 first = 0;
5069 }
5070 else
5071 fputs_unfiltered (", ", buf);
5072
5073 attr = dwarf2_attr (child, DW_AT_type, cu);
5074 if (attr == NULL)
5075 {
5076 complaint (&symfile_complaints,
5077 _("template parameter missing DW_AT_type"));
5078 fputs_unfiltered ("UNKNOWN_TYPE", buf);
5079 continue;
5080 }
5081 type = die_type (child, cu);
5082
5083 if (child->tag == DW_TAG_template_type_param)
5084 {
5085 c_print_type (type, "", buf, -1, 0);
5086 continue;
5087 }
5088
5089 attr = dwarf2_attr (child, DW_AT_const_value, cu);
5090 if (attr == NULL)
5091 {
5092 complaint (&symfile_complaints,
5093 _("template parameter missing "
5094 "DW_AT_const_value"));
5095 fputs_unfiltered ("UNKNOWN_VALUE", buf);
5096 continue;
5097 }
5098
5099 dwarf2_const_value_attr (attr, type, name,
5100 &cu->comp_unit_obstack, cu,
5101 &value, &bytes, &baton);
5102
5103 if (TYPE_NOSIGN (type))
5104 /* GDB prints characters as NUMBER 'CHAR'. If that's
5105 changed, this can use value_print instead. */
5106 c_printchar (value, type, buf);
5107 else
5108 {
5109 struct value_print_options opts;
5110
5111 if (baton != NULL)
5112 v = dwarf2_evaluate_loc_desc (type, NULL,
5113 baton->data,
5114 baton->size,
5115 baton->per_cu);
5116 else if (bytes != NULL)
5117 {
5118 v = allocate_value (type);
5119 memcpy (value_contents_writeable (v), bytes,
5120 TYPE_LENGTH (type));
5121 }
5122 else
5123 v = value_from_longest (type, value);
5124
5125 /* Specify decimal so that we do not depend on
5126 the radix. */
5127 get_formatted_print_options (&opts, 'd');
5128 opts.raw = 1;
5129 value_print (v, buf, &opts);
5130 release_value (v);
5131 value_free (v);
5132 }
5133 }
5134
5135 die->building_fullname = 0;
5136
5137 if (!first)
5138 {
5139 /* Close the argument list, with a space if necessary
5140 (nested templates). */
5141 char last_char = '\0';
5142 ui_file_put (buf, do_ui_file_peek_last, &last_char);
5143 if (last_char == '>')
5144 fputs_unfiltered (" >", buf);
5145 else
5146 fputs_unfiltered (">", buf);
5147 }
5148 }
5149
5150 /* For Java and C++ methods, append formal parameter type
5151 information, if PHYSNAME. */
5152
5153 if (physname && die->tag == DW_TAG_subprogram
5154 && (cu->language == language_cplus
5155 || cu->language == language_java))
5156 {
5157 struct type *type = read_type_die (die, cu);
5158
5159 c_type_print_args (type, buf, 1, cu->language);
5160
5161 if (cu->language == language_java)
5162 {
5163 /* For java, we must append the return type to method
5164 names. */
5165 if (die->tag == DW_TAG_subprogram)
5166 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
5167 0, 0);
5168 }
5169 else if (cu->language == language_cplus)
5170 {
5171 /* Assume that an artificial first parameter is
5172 "this", but do not crash if it is not. RealView
5173 marks unnamed (and thus unused) parameters as
5174 artificial; there is no way to differentiate
5175 the two cases. */
5176 if (TYPE_NFIELDS (type) > 0
5177 && TYPE_FIELD_ARTIFICIAL (type, 0)
5178 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
5179 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
5180 0))))
5181 fputs_unfiltered (" const", buf);
5182 }
5183 }
5184
5185 name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
5186 &length);
5187 ui_file_delete (buf);
5188
5189 if (cu->language == language_cplus)
5190 {
5191 char *cname
5192 = dwarf2_canonicalize_name (name, cu,
5193 &cu->objfile->objfile_obstack);
5194
5195 if (cname != NULL)
5196 name = cname;
5197 }
5198 }
5199 }
5200
5201 return name;
5202 }
5203
5204 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5205 If scope qualifiers are appropriate they will be added. The result
5206 will be allocated on the objfile_obstack, or NULL if the DIE does
5207 not have a name. NAME may either be from a previous call to
5208 dwarf2_name or NULL.
5209
5210 The output string will be canonicalized (if C++/Java). */
5211
5212 static const char *
5213 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
5214 {
5215 return dwarf2_compute_name (name, die, cu, 0);
5216 }
5217
5218 /* Construct a physname for the given DIE in CU. NAME may either be
5219 from a previous call to dwarf2_name or NULL. The result will be
5220 allocated on the objfile_objstack or NULL if the DIE does not have a
5221 name.
5222
5223 The output string will be canonicalized (if C++/Java). */
5224
5225 static const char *
5226 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
5227 {
5228 struct attribute *attr;
5229 const char *retval, *mangled = NULL, *canon = NULL;
5230 struct cleanup *back_to;
5231 int need_copy = 1;
5232
5233 /* In this case dwarf2_compute_name is just a shortcut not building anything
5234 on its own. */
5235 if (!die_needs_namespace (die, cu))
5236 return dwarf2_compute_name (name, die, cu, 1);
5237
5238 back_to = make_cleanup (null_cleanup, NULL);
5239
5240 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
5241 if (!attr)
5242 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
5243
5244 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5245 has computed. */
5246 if (attr && DW_STRING (attr))
5247 {
5248 char *demangled;
5249
5250 mangled = DW_STRING (attr);
5251
5252 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5253 type. It is easier for GDB users to search for such functions as
5254 `name(params)' than `long name(params)'. In such case the minimal
5255 symbol names do not match the full symbol names but for template
5256 functions there is never a need to look up their definition from their
5257 declaration so the only disadvantage remains the minimal symbol
5258 variant `long name(params)' does not have the proper inferior type.
5259 */
5260
5261 demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
5262 | (cu->language == language_java
5263 ? DMGL_JAVA | DMGL_RET_POSTFIX
5264 : DMGL_RET_DROP)));
5265 if (demangled)
5266 {
5267 make_cleanup (xfree, demangled);
5268 canon = demangled;
5269 }
5270 else
5271 {
5272 canon = mangled;
5273 need_copy = 0;
5274 }
5275 }
5276
5277 if (canon == NULL || check_physname)
5278 {
5279 const char *physname = dwarf2_compute_name (name, die, cu, 1);
5280
5281 if (canon != NULL && strcmp (physname, canon) != 0)
5282 {
5283 /* It may not mean a bug in GDB. The compiler could also
5284 compute DW_AT_linkage_name incorrectly. But in such case
5285 GDB would need to be bug-to-bug compatible. */
5286
5287 complaint (&symfile_complaints,
5288 _("Computed physname <%s> does not match demangled <%s> "
5289 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5290 physname, canon, mangled, die->offset, cu->objfile->name);
5291
5292 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5293 is available here - over computed PHYSNAME. It is safer
5294 against both buggy GDB and buggy compilers. */
5295
5296 retval = canon;
5297 }
5298 else
5299 {
5300 retval = physname;
5301 need_copy = 0;
5302 }
5303 }
5304 else
5305 retval = canon;
5306
5307 if (need_copy)
5308 retval = obsavestring (retval, strlen (retval),
5309 &cu->objfile->objfile_obstack);
5310
5311 do_cleanups (back_to);
5312 return retval;
5313 }
5314
5315 /* Read the import statement specified by the given die and record it. */
5316
5317 static void
5318 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
5319 {
5320 struct attribute *import_attr;
5321 struct die_info *imported_die, *child_die;
5322 struct dwarf2_cu *imported_cu;
5323 const char *imported_name;
5324 const char *imported_name_prefix;
5325 const char *canonical_name;
5326 const char *import_alias;
5327 const char *imported_declaration = NULL;
5328 const char *import_prefix;
5329 VEC (const_char_ptr) *excludes = NULL;
5330 struct cleanup *cleanups;
5331
5332 char *temp;
5333
5334 import_attr = dwarf2_attr (die, DW_AT_import, cu);
5335 if (import_attr == NULL)
5336 {
5337 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5338 dwarf_tag_name (die->tag));
5339 return;
5340 }
5341
5342 imported_cu = cu;
5343 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
5344 imported_name = dwarf2_name (imported_die, imported_cu);
5345 if (imported_name == NULL)
5346 {
5347 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5348
5349 The import in the following code:
5350 namespace A
5351 {
5352 typedef int B;
5353 }
5354
5355 int main ()
5356 {
5357 using A::B;
5358 B b;
5359 return b;
5360 }
5361
5362 ...
5363 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5364 <52> DW_AT_decl_file : 1
5365 <53> DW_AT_decl_line : 6
5366 <54> DW_AT_import : <0x75>
5367 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5368 <59> DW_AT_name : B
5369 <5b> DW_AT_decl_file : 1
5370 <5c> DW_AT_decl_line : 2
5371 <5d> DW_AT_type : <0x6e>
5372 ...
5373 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5374 <76> DW_AT_byte_size : 4
5375 <77> DW_AT_encoding : 5 (signed)
5376
5377 imports the wrong die ( 0x75 instead of 0x58 ).
5378 This case will be ignored until the gcc bug is fixed. */
5379 return;
5380 }
5381
5382 /* Figure out the local name after import. */
5383 import_alias = dwarf2_name (die, cu);
5384
5385 /* Figure out where the statement is being imported to. */
5386 import_prefix = determine_prefix (die, cu);
5387
5388 /* Figure out what the scope of the imported die is and prepend it
5389 to the name of the imported die. */
5390 imported_name_prefix = determine_prefix (imported_die, imported_cu);
5391
5392 if (imported_die->tag != DW_TAG_namespace
5393 && imported_die->tag != DW_TAG_module)
5394 {
5395 imported_declaration = imported_name;
5396 canonical_name = imported_name_prefix;
5397 }
5398 else if (strlen (imported_name_prefix) > 0)
5399 {
5400 temp = alloca (strlen (imported_name_prefix)
5401 + 2 + strlen (imported_name) + 1);
5402 strcpy (temp, imported_name_prefix);
5403 strcat (temp, "::");
5404 strcat (temp, imported_name);
5405 canonical_name = temp;
5406 }
5407 else
5408 canonical_name = imported_name;
5409
5410 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
5411
5412 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
5413 for (child_die = die->child; child_die && child_die->tag;
5414 child_die = sibling_die (child_die))
5415 {
5416 /* DWARF-4: A Fortran use statement with a “rename list” may be
5417 represented by an imported module entry with an import attribute
5418 referring to the module and owned entries corresponding to those
5419 entities that are renamed as part of being imported. */
5420
5421 if (child_die->tag != DW_TAG_imported_declaration)
5422 {
5423 complaint (&symfile_complaints,
5424 _("child DW_TAG_imported_declaration expected "
5425 "- DIE at 0x%x [in module %s]"),
5426 child_die->offset, cu->objfile->name);
5427 continue;
5428 }
5429
5430 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
5431 if (import_attr == NULL)
5432 {
5433 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
5434 dwarf_tag_name (child_die->tag));
5435 continue;
5436 }
5437
5438 imported_cu = cu;
5439 imported_die = follow_die_ref_or_sig (child_die, import_attr,
5440 &imported_cu);
5441 imported_name = dwarf2_name (imported_die, imported_cu);
5442 if (imported_name == NULL)
5443 {
5444 complaint (&symfile_complaints,
5445 _("child DW_TAG_imported_declaration has unknown "
5446 "imported name - DIE at 0x%x [in module %s]"),
5447 child_die->offset, cu->objfile->name);
5448 continue;
5449 }
5450
5451 VEC_safe_push (const_char_ptr, excludes, imported_name);
5452
5453 process_die (child_die, cu);
5454 }
5455
5456 cp_add_using_directive (import_prefix,
5457 canonical_name,
5458 import_alias,
5459 imported_declaration,
5460 excludes,
5461 &cu->objfile->objfile_obstack);
5462
5463 do_cleanups (cleanups);
5464 }
5465
5466 static void
5467 initialize_cu_func_list (struct dwarf2_cu *cu)
5468 {
5469 cu->first_fn = cu->last_fn = cu->cached_fn = NULL;
5470 }
5471
5472 /* Cleanup function for read_file_scope. */
5473
5474 static void
5475 free_cu_line_header (void *arg)
5476 {
5477 struct dwarf2_cu *cu = arg;
5478
5479 free_line_header (cu->line_header);
5480 cu->line_header = NULL;
5481 }
5482
5483 static void
5484 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
5485 char **name, char **comp_dir)
5486 {
5487 struct attribute *attr;
5488
5489 *name = NULL;
5490 *comp_dir = NULL;
5491
5492 /* Find the filename. Do not use dwarf2_name here, since the filename
5493 is not a source language identifier. */
5494 attr = dwarf2_attr (die, DW_AT_name, cu);
5495 if (attr)
5496 {
5497 *name = DW_STRING (attr);
5498 }
5499
5500 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5501 if (attr)
5502 *comp_dir = DW_STRING (attr);
5503 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
5504 {
5505 *comp_dir = ldirname (*name);
5506 if (*comp_dir != NULL)
5507 make_cleanup (xfree, *comp_dir);
5508 }
5509 if (*comp_dir != NULL)
5510 {
5511 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5512 directory, get rid of it. */
5513 char *cp = strchr (*comp_dir, ':');
5514
5515 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
5516 *comp_dir = cp + 1;
5517 }
5518
5519 if (*name == NULL)
5520 *name = "<unknown>";
5521 }
5522
5523 /* Handle DW_AT_stmt_list for a compilation unit. */
5524
5525 static void
5526 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
5527 const char *comp_dir)
5528 {
5529 struct attribute *attr;
5530 struct objfile *objfile = cu->objfile;
5531 bfd *abfd = objfile->obfd;
5532
5533 /* Decode line number information if present. We do this before
5534 processing child DIEs, so that the line header table is available
5535 for DW_AT_decl_file. */
5536 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
5537 if (attr)
5538 {
5539 unsigned int line_offset = DW_UNSND (attr);
5540 struct line_header *line_header
5541 = dwarf_decode_line_header (line_offset, abfd, cu);
5542
5543 if (line_header)
5544 {
5545 cu->line_header = line_header;
5546 make_cleanup (free_cu_line_header, cu);
5547 dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL);
5548 }
5549 }
5550 }
5551
5552 /* Process DW_TAG_compile_unit. */
5553
5554 static void
5555 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
5556 {
5557 struct objfile *objfile = cu->objfile;
5558 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5559 CORE_ADDR lowpc = ((CORE_ADDR) -1);
5560 CORE_ADDR highpc = ((CORE_ADDR) 0);
5561 struct attribute *attr;
5562 char *name = NULL;
5563 char *comp_dir = NULL;
5564 struct die_info *child_die;
5565 bfd *abfd = objfile->obfd;
5566 CORE_ADDR baseaddr;
5567
5568 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5569
5570 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
5571
5572 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5573 from finish_block. */
5574 if (lowpc == ((CORE_ADDR) -1))
5575 lowpc = highpc;
5576 lowpc += baseaddr;
5577 highpc += baseaddr;
5578
5579 find_file_and_directory (die, cu, &name, &comp_dir);
5580
5581 attr = dwarf2_attr (die, DW_AT_language, cu);
5582 if (attr)
5583 {
5584 set_cu_language (DW_UNSND (attr), cu);
5585 }
5586
5587 attr = dwarf2_attr (die, DW_AT_producer, cu);
5588 if (attr)
5589 cu->producer = DW_STRING (attr);
5590
5591 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5592 standardised yet. As a workaround for the language detection we fall
5593 back to the DW_AT_producer string. */
5594 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
5595 cu->language = language_opencl;
5596
5597 /* We assume that we're processing GCC output. */
5598 processing_gcc_compilation = 2;
5599
5600 processing_has_namespace_info = 0;
5601
5602 start_symtab (name, comp_dir, lowpc);
5603 record_debugformat ("DWARF 2");
5604 record_producer (cu->producer);
5605
5606 initialize_cu_func_list (cu);
5607
5608 handle_DW_AT_stmt_list (die, cu, comp_dir);
5609
5610 /* Process all dies in compilation unit. */
5611 if (die->child != NULL)
5612 {
5613 child_die = die->child;
5614 while (child_die && child_die->tag)
5615 {
5616 process_die (child_die, cu);
5617 child_die = sibling_die (child_die);
5618 }
5619 }
5620
5621 /* Decode macro information, if present. Dwarf 2 macro information
5622 refers to information in the line number info statement program
5623 header, so we can only read it if we've read the header
5624 successfully. */
5625 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
5626 if (attr && cu->line_header)
5627 {
5628 if (dwarf2_attr (die, DW_AT_macro_info, cu))
5629 complaint (&symfile_complaints,
5630 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
5631
5632 dwarf_decode_macros (cu->line_header, DW_UNSND (attr),
5633 comp_dir, abfd, cu,
5634 &dwarf2_per_objfile->macro, 1);
5635 }
5636 else
5637 {
5638 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
5639 if (attr && cu->line_header)
5640 {
5641 unsigned int macro_offset = DW_UNSND (attr);
5642
5643 dwarf_decode_macros (cu->line_header, macro_offset,
5644 comp_dir, abfd, cu,
5645 &dwarf2_per_objfile->macinfo, 0);
5646 }
5647 }
5648 do_cleanups (back_to);
5649 }
5650
5651 /* Process DW_TAG_type_unit.
5652 For TUs we want to skip the first top level sibling if it's not the
5653 actual type being defined by this TU. In this case the first top
5654 level sibling is there to provide context only. */
5655
5656 static void
5657 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
5658 {
5659 struct objfile *objfile = cu->objfile;
5660 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
5661 CORE_ADDR lowpc;
5662 struct attribute *attr;
5663 char *name = NULL;
5664 char *comp_dir = NULL;
5665 struct die_info *child_die;
5666 bfd *abfd = objfile->obfd;
5667
5668 /* start_symtab needs a low pc, but we don't really have one.
5669 Do what read_file_scope would do in the absence of such info. */
5670 lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5671
5672 /* Find the filename. Do not use dwarf2_name here, since the filename
5673 is not a source language identifier. */
5674 attr = dwarf2_attr (die, DW_AT_name, cu);
5675 if (attr)
5676 name = DW_STRING (attr);
5677
5678 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
5679 if (attr)
5680 comp_dir = DW_STRING (attr);
5681 else if (name != NULL && IS_ABSOLUTE_PATH (name))
5682 {
5683 comp_dir = ldirname (name);
5684 if (comp_dir != NULL)
5685 make_cleanup (xfree, comp_dir);
5686 }
5687
5688 if (name == NULL)
5689 name = "<unknown>";
5690
5691 attr = dwarf2_attr (die, DW_AT_language, cu);
5692 if (attr)
5693 set_cu_language (DW_UNSND (attr), cu);
5694
5695 /* This isn't technically needed today. It is done for symmetry
5696 with read_file_scope. */
5697 attr = dwarf2_attr (die, DW_AT_producer, cu);
5698 if (attr)
5699 cu->producer = DW_STRING (attr);
5700
5701 /* We assume that we're processing GCC output. */
5702 processing_gcc_compilation = 2;
5703
5704 processing_has_namespace_info = 0;
5705
5706 start_symtab (name, comp_dir, lowpc);
5707 record_debugformat ("DWARF 2");
5708 record_producer (cu->producer);
5709
5710 handle_DW_AT_stmt_list (die, cu, comp_dir);
5711
5712 /* Process the dies in the type unit. */
5713 if (die->child == NULL)
5714 {
5715 dump_die_for_error (die);
5716 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5717 bfd_get_filename (abfd));
5718 }
5719
5720 child_die = die->child;
5721
5722 while (child_die && child_die->tag)
5723 {
5724 process_die (child_die, cu);
5725
5726 child_die = sibling_die (child_die);
5727 }
5728
5729 do_cleanups (back_to);
5730 }
5731
5732 static void
5733 add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc,
5734 struct dwarf2_cu *cu)
5735 {
5736 struct function_range *thisfn;
5737
5738 thisfn = (struct function_range *)
5739 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range));
5740 thisfn->name = name;
5741 thisfn->lowpc = lowpc;
5742 thisfn->highpc = highpc;
5743 thisfn->seen_line = 0;
5744 thisfn->next = NULL;
5745
5746 if (cu->last_fn == NULL)
5747 cu->first_fn = thisfn;
5748 else
5749 cu->last_fn->next = thisfn;
5750
5751 cu->last_fn = thisfn;
5752 }
5753
5754 /* qsort helper for inherit_abstract_dies. */
5755
5756 static int
5757 unsigned_int_compar (const void *ap, const void *bp)
5758 {
5759 unsigned int a = *(unsigned int *) ap;
5760 unsigned int b = *(unsigned int *) bp;
5761
5762 return (a > b) - (b > a);
5763 }
5764
5765 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5766 Inherit only the children of the DW_AT_abstract_origin DIE not being
5767 already referenced by DW_AT_abstract_origin from the children of the
5768 current DIE. */
5769
5770 static void
5771 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
5772 {
5773 struct die_info *child_die;
5774 unsigned die_children_count;
5775 /* CU offsets which were referenced by children of the current DIE. */
5776 unsigned *offsets;
5777 unsigned *offsets_end, *offsetp;
5778 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5779 struct die_info *origin_die;
5780 /* Iterator of the ORIGIN_DIE children. */
5781 struct die_info *origin_child_die;
5782 struct cleanup *cleanups;
5783 struct attribute *attr;
5784 struct dwarf2_cu *origin_cu;
5785 struct pending **origin_previous_list_in_scope;
5786
5787 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
5788 if (!attr)
5789 return;
5790
5791 /* Note that following die references may follow to a die in a
5792 different cu. */
5793
5794 origin_cu = cu;
5795 origin_die = follow_die_ref (die, attr, &origin_cu);
5796
5797 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5798 symbols in. */
5799 origin_previous_list_in_scope = origin_cu->list_in_scope;
5800 origin_cu->list_in_scope = cu->list_in_scope;
5801
5802 if (die->tag != origin_die->tag
5803 && !(die->tag == DW_TAG_inlined_subroutine
5804 && origin_die->tag == DW_TAG_subprogram))
5805 complaint (&symfile_complaints,
5806 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5807 die->offset, origin_die->offset);
5808
5809 child_die = die->child;
5810 die_children_count = 0;
5811 while (child_die && child_die->tag)
5812 {
5813 child_die = sibling_die (child_die);
5814 die_children_count++;
5815 }
5816 offsets = xmalloc (sizeof (*offsets) * die_children_count);
5817 cleanups = make_cleanup (xfree, offsets);
5818
5819 offsets_end = offsets;
5820 child_die = die->child;
5821 while (child_die && child_die->tag)
5822 {
5823 /* For each CHILD_DIE, find the corresponding child of
5824 ORIGIN_DIE. If there is more than one layer of
5825 DW_AT_abstract_origin, follow them all; there shouldn't be,
5826 but GCC versions at least through 4.4 generate this (GCC PR
5827 40573). */
5828 struct die_info *child_origin_die = child_die;
5829 struct dwarf2_cu *child_origin_cu = cu;
5830
5831 while (1)
5832 {
5833 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
5834 child_origin_cu);
5835 if (attr == NULL)
5836 break;
5837 child_origin_die = follow_die_ref (child_origin_die, attr,
5838 &child_origin_cu);
5839 }
5840
5841 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5842 counterpart may exist. */
5843 if (child_origin_die != child_die)
5844 {
5845 if (child_die->tag != child_origin_die->tag
5846 && !(child_die->tag == DW_TAG_inlined_subroutine
5847 && child_origin_die->tag == DW_TAG_subprogram))
5848 complaint (&symfile_complaints,
5849 _("Child DIE 0x%x and its abstract origin 0x%x have "
5850 "different tags"), child_die->offset,
5851 child_origin_die->offset);
5852 if (child_origin_die->parent != origin_die)
5853 complaint (&symfile_complaints,
5854 _("Child DIE 0x%x and its abstract origin 0x%x have "
5855 "different parents"), child_die->offset,
5856 child_origin_die->offset);
5857 else
5858 *offsets_end++ = child_origin_die->offset;
5859 }
5860 child_die = sibling_die (child_die);
5861 }
5862 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
5863 unsigned_int_compar);
5864 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
5865 if (offsetp[-1] == *offsetp)
5866 complaint (&symfile_complaints,
5867 _("Multiple children of DIE 0x%x refer "
5868 "to DIE 0x%x as their abstract origin"),
5869 die->offset, *offsetp);
5870
5871 offsetp = offsets;
5872 origin_child_die = origin_die->child;
5873 while (origin_child_die && origin_child_die->tag)
5874 {
5875 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5876 while (offsetp < offsets_end && *offsetp < origin_child_die->offset)
5877 offsetp++;
5878 if (offsetp >= offsets_end || *offsetp > origin_child_die->offset)
5879 {
5880 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5881 process_die (origin_child_die, origin_cu);
5882 }
5883 origin_child_die = sibling_die (origin_child_die);
5884 }
5885 origin_cu->list_in_scope = origin_previous_list_in_scope;
5886
5887 do_cleanups (cleanups);
5888 }
5889
5890 static void
5891 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
5892 {
5893 struct objfile *objfile = cu->objfile;
5894 struct context_stack *new;
5895 CORE_ADDR lowpc;
5896 CORE_ADDR highpc;
5897 struct die_info *child_die;
5898 struct attribute *attr, *call_line, *call_file;
5899 char *name;
5900 CORE_ADDR baseaddr;
5901 struct block *block;
5902 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
5903 VEC (symbolp) *template_args = NULL;
5904 struct template_symbol *templ_func = NULL;
5905
5906 if (inlined_func)
5907 {
5908 /* If we do not have call site information, we can't show the
5909 caller of this inlined function. That's too confusing, so
5910 only use the scope for local variables. */
5911 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
5912 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
5913 if (call_line == NULL || call_file == NULL)
5914 {
5915 read_lexical_block_scope (die, cu);
5916 return;
5917 }
5918 }
5919
5920 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5921
5922 name = dwarf2_name (die, cu);
5923
5924 /* Ignore functions with missing or empty names. These are actually
5925 illegal according to the DWARF standard. */
5926 if (name == NULL)
5927 {
5928 complaint (&symfile_complaints,
5929 _("missing name for subprogram DIE at %d"), die->offset);
5930 return;
5931 }
5932
5933 /* Ignore functions with missing or invalid low and high pc attributes. */
5934 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
5935 {
5936 attr = dwarf2_attr (die, DW_AT_external, cu);
5937 if (!attr || !DW_UNSND (attr))
5938 complaint (&symfile_complaints,
5939 _("cannot get low and high bounds "
5940 "for subprogram DIE at %d"),
5941 die->offset);
5942 return;
5943 }
5944
5945 lowpc += baseaddr;
5946 highpc += baseaddr;
5947
5948 /* Record the function range for dwarf_decode_lines. */
5949 add_to_cu_func_list (name, lowpc, highpc, cu);
5950
5951 /* If we have any template arguments, then we must allocate a
5952 different sort of symbol. */
5953 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
5954 {
5955 if (child_die->tag == DW_TAG_template_type_param
5956 || child_die->tag == DW_TAG_template_value_param)
5957 {
5958 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5959 struct template_symbol);
5960 templ_func->base.is_cplus_template_function = 1;
5961 break;
5962 }
5963 }
5964
5965 new = push_context (0, lowpc);
5966 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
5967 (struct symbol *) templ_func);
5968
5969 /* If there is a location expression for DW_AT_frame_base, record
5970 it. */
5971 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
5972 if (attr)
5973 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5974 expression is being recorded directly in the function's symbol
5975 and not in a separate frame-base object. I guess this hack is
5976 to avoid adding some sort of frame-base adjunct/annex to the
5977 function's symbol :-(. The problem with doing this is that it
5978 results in a function symbol with a location expression that
5979 has nothing to do with the location of the function, ouch! The
5980 relationship should be: a function's symbol has-a frame base; a
5981 frame-base has-a location expression. */
5982 dwarf2_symbol_mark_computed (attr, new->name, cu);
5983
5984 cu->list_in_scope = &local_symbols;
5985
5986 if (die->child != NULL)
5987 {
5988 child_die = die->child;
5989 while (child_die && child_die->tag)
5990 {
5991 if (child_die->tag == DW_TAG_template_type_param
5992 || child_die->tag == DW_TAG_template_value_param)
5993 {
5994 struct symbol *arg = new_symbol (child_die, NULL, cu);
5995
5996 if (arg != NULL)
5997 VEC_safe_push (symbolp, template_args, arg);
5998 }
5999 else
6000 process_die (child_die, cu);
6001 child_die = sibling_die (child_die);
6002 }
6003 }
6004
6005 inherit_abstract_dies (die, cu);
6006
6007 /* If we have a DW_AT_specification, we might need to import using
6008 directives from the context of the specification DIE. See the
6009 comment in determine_prefix. */
6010 if (cu->language == language_cplus
6011 && dwarf2_attr (die, DW_AT_specification, cu))
6012 {
6013 struct dwarf2_cu *spec_cu = cu;
6014 struct die_info *spec_die = die_specification (die, &spec_cu);
6015
6016 while (spec_die)
6017 {
6018 child_die = spec_die->child;
6019 while (child_die && child_die->tag)
6020 {
6021 if (child_die->tag == DW_TAG_imported_module)
6022 process_die (child_die, spec_cu);
6023 child_die = sibling_die (child_die);
6024 }
6025
6026 /* In some cases, GCC generates specification DIEs that
6027 themselves contain DW_AT_specification attributes. */
6028 spec_die = die_specification (spec_die, &spec_cu);
6029 }
6030 }
6031
6032 new = pop_context ();
6033 /* Make a block for the local symbols within. */
6034 block = finish_block (new->name, &local_symbols, new->old_blocks,
6035 lowpc, highpc, objfile);
6036
6037 /* For C++, set the block's scope. */
6038 if (cu->language == language_cplus || cu->language == language_fortran)
6039 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
6040 determine_prefix (die, cu),
6041 processing_has_namespace_info);
6042
6043 /* If we have address ranges, record them. */
6044 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6045
6046 /* Attach template arguments to function. */
6047 if (! VEC_empty (symbolp, template_args))
6048 {
6049 gdb_assert (templ_func != NULL);
6050
6051 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
6052 templ_func->template_arguments
6053 = obstack_alloc (&objfile->objfile_obstack,
6054 (templ_func->n_template_arguments
6055 * sizeof (struct symbol *)));
6056 memcpy (templ_func->template_arguments,
6057 VEC_address (symbolp, template_args),
6058 (templ_func->n_template_arguments * sizeof (struct symbol *)));
6059 VEC_free (symbolp, template_args);
6060 }
6061
6062 /* In C++, we can have functions nested inside functions (e.g., when
6063 a function declares a class that has methods). This means that
6064 when we finish processing a function scope, we may need to go
6065 back to building a containing block's symbol lists. */
6066 local_symbols = new->locals;
6067 param_symbols = new->params;
6068 using_directives = new->using_directives;
6069
6070 /* If we've finished processing a top-level function, subsequent
6071 symbols go in the file symbol list. */
6072 if (outermost_context_p ())
6073 cu->list_in_scope = &file_symbols;
6074 }
6075
6076 /* Process all the DIES contained within a lexical block scope. Start
6077 a new scope, process the dies, and then close the scope. */
6078
6079 static void
6080 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
6081 {
6082 struct objfile *objfile = cu->objfile;
6083 struct context_stack *new;
6084 CORE_ADDR lowpc, highpc;
6085 struct die_info *child_die;
6086 CORE_ADDR baseaddr;
6087
6088 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6089
6090 /* Ignore blocks with missing or invalid low and high pc attributes. */
6091 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
6092 as multiple lexical blocks? Handling children in a sane way would
6093 be nasty. Might be easier to properly extend generic blocks to
6094 describe ranges. */
6095 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
6096 return;
6097 lowpc += baseaddr;
6098 highpc += baseaddr;
6099
6100 push_context (0, lowpc);
6101 if (die->child != NULL)
6102 {
6103 child_die = die->child;
6104 while (child_die && child_die->tag)
6105 {
6106 process_die (child_die, cu);
6107 child_die = sibling_die (child_die);
6108 }
6109 }
6110 new = pop_context ();
6111
6112 if (local_symbols != NULL || using_directives != NULL)
6113 {
6114 struct block *block
6115 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
6116 highpc, objfile);
6117
6118 /* Note that recording ranges after traversing children, as we
6119 do here, means that recording a parent's ranges entails
6120 walking across all its children's ranges as they appear in
6121 the address map, which is quadratic behavior.
6122
6123 It would be nicer to record the parent's ranges before
6124 traversing its children, simply overriding whatever you find
6125 there. But since we don't even decide whether to create a
6126 block until after we've traversed its children, that's hard
6127 to do. */
6128 dwarf2_record_block_ranges (die, block, baseaddr, cu);
6129 }
6130 local_symbols = new->locals;
6131 using_directives = new->using_directives;
6132 }
6133
6134 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
6135 Return 1 if the attributes are present and valid, otherwise, return 0.
6136 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
6137
6138 static int
6139 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
6140 CORE_ADDR *high_return, struct dwarf2_cu *cu,
6141 struct partial_symtab *ranges_pst)
6142 {
6143 struct objfile *objfile = cu->objfile;
6144 struct comp_unit_head *cu_header = &cu->header;
6145 bfd *obfd = objfile->obfd;
6146 unsigned int addr_size = cu_header->addr_size;
6147 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6148 /* Base address selection entry. */
6149 CORE_ADDR base;
6150 int found_base;
6151 unsigned int dummy;
6152 gdb_byte *buffer;
6153 CORE_ADDR marker;
6154 int low_set;
6155 CORE_ADDR low = 0;
6156 CORE_ADDR high = 0;
6157 CORE_ADDR baseaddr;
6158
6159 found_base = cu->base_known;
6160 base = cu->base_address;
6161
6162 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
6163 if (offset >= dwarf2_per_objfile->ranges.size)
6164 {
6165 complaint (&symfile_complaints,
6166 _("Offset %d out of bounds for DW_AT_ranges attribute"),
6167 offset);
6168 return 0;
6169 }
6170 buffer = dwarf2_per_objfile->ranges.buffer + offset;
6171
6172 /* Read in the largest possible address. */
6173 marker = read_address (obfd, buffer, cu, &dummy);
6174 if ((marker & mask) == mask)
6175 {
6176 /* If we found the largest possible address, then
6177 read the base address. */
6178 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6179 buffer += 2 * addr_size;
6180 offset += 2 * addr_size;
6181 found_base = 1;
6182 }
6183
6184 low_set = 0;
6185
6186 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6187
6188 while (1)
6189 {
6190 CORE_ADDR range_beginning, range_end;
6191
6192 range_beginning = read_address (obfd, buffer, cu, &dummy);
6193 buffer += addr_size;
6194 range_end = read_address (obfd, buffer, cu, &dummy);
6195 buffer += addr_size;
6196 offset += 2 * addr_size;
6197
6198 /* An end of list marker is a pair of zero addresses. */
6199 if (range_beginning == 0 && range_end == 0)
6200 /* Found the end of list entry. */
6201 break;
6202
6203 /* Each base address selection entry is a pair of 2 values.
6204 The first is the largest possible address, the second is
6205 the base address. Check for a base address here. */
6206 if ((range_beginning & mask) == mask)
6207 {
6208 /* If we found the largest possible address, then
6209 read the base address. */
6210 base = read_address (obfd, buffer + addr_size, cu, &dummy);
6211 found_base = 1;
6212 continue;
6213 }
6214
6215 if (!found_base)
6216 {
6217 /* We have no valid base address for the ranges
6218 data. */
6219 complaint (&symfile_complaints,
6220 _("Invalid .debug_ranges data (no base address)"));
6221 return 0;
6222 }
6223
6224 if (range_beginning > range_end)
6225 {
6226 /* Inverted range entries are invalid. */
6227 complaint (&symfile_complaints,
6228 _("Invalid .debug_ranges data (inverted range)"));
6229 return 0;
6230 }
6231
6232 /* Empty range entries have no effect. */
6233 if (range_beginning == range_end)
6234 continue;
6235
6236 range_beginning += base;
6237 range_end += base;
6238
6239 if (ranges_pst != NULL)
6240 addrmap_set_empty (objfile->psymtabs_addrmap,
6241 range_beginning + baseaddr,
6242 range_end - 1 + baseaddr,
6243 ranges_pst);
6244
6245 /* FIXME: This is recording everything as a low-high
6246 segment of consecutive addresses. We should have a
6247 data structure for discontiguous block ranges
6248 instead. */
6249 if (! low_set)
6250 {
6251 low = range_beginning;
6252 high = range_end;
6253 low_set = 1;
6254 }
6255 else
6256 {
6257 if (range_beginning < low)
6258 low = range_beginning;
6259 if (range_end > high)
6260 high = range_end;
6261 }
6262 }
6263
6264 if (! low_set)
6265 /* If the first entry is an end-of-list marker, the range
6266 describes an empty scope, i.e. no instructions. */
6267 return 0;
6268
6269 if (low_return)
6270 *low_return = low;
6271 if (high_return)
6272 *high_return = high;
6273 return 1;
6274 }
6275
6276 /* Get low and high pc attributes from a die. Return 1 if the attributes
6277 are present and valid, otherwise, return 0. Return -1 if the range is
6278 discontinuous, i.e. derived from DW_AT_ranges information. */
6279 static int
6280 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
6281 CORE_ADDR *highpc, struct dwarf2_cu *cu,
6282 struct partial_symtab *pst)
6283 {
6284 struct attribute *attr;
6285 CORE_ADDR low = 0;
6286 CORE_ADDR high = 0;
6287 int ret = 0;
6288
6289 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6290 if (attr)
6291 {
6292 high = DW_ADDR (attr);
6293 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6294 if (attr)
6295 low = DW_ADDR (attr);
6296 else
6297 /* Found high w/o low attribute. */
6298 return 0;
6299
6300 /* Found consecutive range of addresses. */
6301 ret = 1;
6302 }
6303 else
6304 {
6305 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6306 if (attr != NULL)
6307 {
6308 /* Value of the DW_AT_ranges attribute is the offset in the
6309 .debug_ranges section. */
6310 if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst))
6311 return 0;
6312 /* Found discontinuous range of addresses. */
6313 ret = -1;
6314 }
6315 }
6316
6317 /* read_partial_die has also the strict LOW < HIGH requirement. */
6318 if (high <= low)
6319 return 0;
6320
6321 /* When using the GNU linker, .gnu.linkonce. sections are used to
6322 eliminate duplicate copies of functions and vtables and such.
6323 The linker will arbitrarily choose one and discard the others.
6324 The AT_*_pc values for such functions refer to local labels in
6325 these sections. If the section from that file was discarded, the
6326 labels are not in the output, so the relocs get a value of 0.
6327 If this is a discarded function, mark the pc bounds as invalid,
6328 so that GDB will ignore it. */
6329 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
6330 return 0;
6331
6332 *lowpc = low;
6333 *highpc = high;
6334 return ret;
6335 }
6336
6337 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6338 its low and high PC addresses. Do nothing if these addresses could not
6339 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6340 and HIGHPC to the high address if greater than HIGHPC. */
6341
6342 static void
6343 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
6344 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6345 struct dwarf2_cu *cu)
6346 {
6347 CORE_ADDR low, high;
6348 struct die_info *child = die->child;
6349
6350 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
6351 {
6352 *lowpc = min (*lowpc, low);
6353 *highpc = max (*highpc, high);
6354 }
6355
6356 /* If the language does not allow nested subprograms (either inside
6357 subprograms or lexical blocks), we're done. */
6358 if (cu->language != language_ada)
6359 return;
6360
6361 /* Check all the children of the given DIE. If it contains nested
6362 subprograms, then check their pc bounds. Likewise, we need to
6363 check lexical blocks as well, as they may also contain subprogram
6364 definitions. */
6365 while (child && child->tag)
6366 {
6367 if (child->tag == DW_TAG_subprogram
6368 || child->tag == DW_TAG_lexical_block)
6369 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
6370 child = sibling_die (child);
6371 }
6372 }
6373
6374 /* Get the low and high pc's represented by the scope DIE, and store
6375 them in *LOWPC and *HIGHPC. If the correct values can't be
6376 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6377
6378 static void
6379 get_scope_pc_bounds (struct die_info *die,
6380 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6381 struct dwarf2_cu *cu)
6382 {
6383 CORE_ADDR best_low = (CORE_ADDR) -1;
6384 CORE_ADDR best_high = (CORE_ADDR) 0;
6385 CORE_ADDR current_low, current_high;
6386
6387 if (dwarf2_get_pc_bounds (die, &current_low, &current_high, cu, NULL))
6388 {
6389 best_low = current_low;
6390 best_high = current_high;
6391 }
6392 else
6393 {
6394 struct die_info *child = die->child;
6395
6396 while (child && child->tag)
6397 {
6398 switch (child->tag) {
6399 case DW_TAG_subprogram:
6400 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
6401 break;
6402 case DW_TAG_namespace:
6403 case DW_TAG_module:
6404 /* FIXME: carlton/2004-01-16: Should we do this for
6405 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6406 that current GCC's always emit the DIEs corresponding
6407 to definitions of methods of classes as children of a
6408 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6409 the DIEs giving the declarations, which could be
6410 anywhere). But I don't see any reason why the
6411 standards says that they have to be there. */
6412 get_scope_pc_bounds (child, &current_low, &current_high, cu);
6413
6414 if (current_low != ((CORE_ADDR) -1))
6415 {
6416 best_low = min (best_low, current_low);
6417 best_high = max (best_high, current_high);
6418 }
6419 break;
6420 default:
6421 /* Ignore. */
6422 break;
6423 }
6424
6425 child = sibling_die (child);
6426 }
6427 }
6428
6429 *lowpc = best_low;
6430 *highpc = best_high;
6431 }
6432
6433 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6434 in DIE. */
6435 static void
6436 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
6437 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
6438 {
6439 struct attribute *attr;
6440
6441 attr = dwarf2_attr (die, DW_AT_high_pc, cu);
6442 if (attr)
6443 {
6444 CORE_ADDR high = DW_ADDR (attr);
6445
6446 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
6447 if (attr)
6448 {
6449 CORE_ADDR low = DW_ADDR (attr);
6450
6451 record_block_range (block, baseaddr + low, baseaddr + high - 1);
6452 }
6453 }
6454
6455 attr = dwarf2_attr (die, DW_AT_ranges, cu);
6456 if (attr)
6457 {
6458 bfd *obfd = cu->objfile->obfd;
6459
6460 /* The value of the DW_AT_ranges attribute is the offset of the
6461 address range list in the .debug_ranges section. */
6462 unsigned long offset = DW_UNSND (attr);
6463 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
6464
6465 /* For some target architectures, but not others, the
6466 read_address function sign-extends the addresses it returns.
6467 To recognize base address selection entries, we need a
6468 mask. */
6469 unsigned int addr_size = cu->header.addr_size;
6470 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
6471
6472 /* The base address, to which the next pair is relative. Note
6473 that this 'base' is a DWARF concept: most entries in a range
6474 list are relative, to reduce the number of relocs against the
6475 debugging information. This is separate from this function's
6476 'baseaddr' argument, which GDB uses to relocate debugging
6477 information from a shared library based on the address at
6478 which the library was loaded. */
6479 CORE_ADDR base = cu->base_address;
6480 int base_known = cu->base_known;
6481
6482 gdb_assert (dwarf2_per_objfile->ranges.readin);
6483 if (offset >= dwarf2_per_objfile->ranges.size)
6484 {
6485 complaint (&symfile_complaints,
6486 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6487 offset);
6488 return;
6489 }
6490
6491 for (;;)
6492 {
6493 unsigned int bytes_read;
6494 CORE_ADDR start, end;
6495
6496 start = read_address (obfd, buffer, cu, &bytes_read);
6497 buffer += bytes_read;
6498 end = read_address (obfd, buffer, cu, &bytes_read);
6499 buffer += bytes_read;
6500
6501 /* Did we find the end of the range list? */
6502 if (start == 0 && end == 0)
6503 break;
6504
6505 /* Did we find a base address selection entry? */
6506 else if ((start & base_select_mask) == base_select_mask)
6507 {
6508 base = end;
6509 base_known = 1;
6510 }
6511
6512 /* We found an ordinary address range. */
6513 else
6514 {
6515 if (!base_known)
6516 {
6517 complaint (&symfile_complaints,
6518 _("Invalid .debug_ranges data "
6519 "(no base address)"));
6520 return;
6521 }
6522
6523 if (start > end)
6524 {
6525 /* Inverted range entries are invalid. */
6526 complaint (&symfile_complaints,
6527 _("Invalid .debug_ranges data "
6528 "(inverted range)"));
6529 return;
6530 }
6531
6532 /* Empty range entries have no effect. */
6533 if (start == end)
6534 continue;
6535
6536 record_block_range (block,
6537 baseaddr + base + start,
6538 baseaddr + base + end - 1);
6539 }
6540 }
6541 }
6542 }
6543
6544 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6545 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6546 during 4.6.0 experimental. */
6547
6548 static int
6549 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
6550 {
6551 const char *cs;
6552 int major, minor, release;
6553
6554 if (cu->producer == NULL)
6555 {
6556 /* For unknown compilers expect their behavior is DWARF version
6557 compliant.
6558
6559 GCC started to support .debug_types sections by -gdwarf-4 since
6560 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6561 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6562 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6563 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6564
6565 return 0;
6566 }
6567
6568 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6569
6570 if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0)
6571 {
6572 /* For non-GCC compilers expect their behavior is DWARF version
6573 compliant. */
6574
6575 return 0;
6576 }
6577 cs = &cu->producer[strlen ("GNU ")];
6578 while (*cs && !isdigit (*cs))
6579 cs++;
6580 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
6581 {
6582 /* Not recognized as GCC. */
6583
6584 return 0;
6585 }
6586
6587 return major < 4 || (major == 4 && minor < 6);
6588 }
6589
6590 /* Return the default accessibility type if it is not overriden by
6591 DW_AT_accessibility. */
6592
6593 static enum dwarf_access_attribute
6594 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
6595 {
6596 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
6597 {
6598 /* The default DWARF 2 accessibility for members is public, the default
6599 accessibility for inheritance is private. */
6600
6601 if (die->tag != DW_TAG_inheritance)
6602 return DW_ACCESS_public;
6603 else
6604 return DW_ACCESS_private;
6605 }
6606 else
6607 {
6608 /* DWARF 3+ defines the default accessibility a different way. The same
6609 rules apply now for DW_TAG_inheritance as for the members and it only
6610 depends on the container kind. */
6611
6612 if (die->parent->tag == DW_TAG_class_type)
6613 return DW_ACCESS_private;
6614 else
6615 return DW_ACCESS_public;
6616 }
6617 }
6618
6619 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
6620 offset. If the attribute was not found return 0, otherwise return
6621 1. If it was found but could not properly be handled, set *OFFSET
6622 to 0. */
6623
6624 static int
6625 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
6626 LONGEST *offset)
6627 {
6628 struct attribute *attr;
6629
6630 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
6631 if (attr != NULL)
6632 {
6633 *offset = 0;
6634
6635 /* Note that we do not check for a section offset first here.
6636 This is because DW_AT_data_member_location is new in DWARF 4,
6637 so if we see it, we can assume that a constant form is really
6638 a constant and not a section offset. */
6639 if (attr_form_is_constant (attr))
6640 *offset = dwarf2_get_attr_constant_value (attr, 0);
6641 else if (attr_form_is_section_offset (attr))
6642 dwarf2_complex_location_expr_complaint ();
6643 else if (attr_form_is_block (attr))
6644 *offset = decode_locdesc (DW_BLOCK (attr), cu);
6645 else
6646 dwarf2_complex_location_expr_complaint ();
6647
6648 return 1;
6649 }
6650
6651 return 0;
6652 }
6653
6654 /* Add an aggregate field to the field list. */
6655
6656 static void
6657 dwarf2_add_field (struct field_info *fip, struct die_info *die,
6658 struct dwarf2_cu *cu)
6659 {
6660 struct objfile *objfile = cu->objfile;
6661 struct gdbarch *gdbarch = get_objfile_arch (objfile);
6662 struct nextfield *new_field;
6663 struct attribute *attr;
6664 struct field *fp;
6665 char *fieldname = "";
6666
6667 /* Allocate a new field list entry and link it in. */
6668 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
6669 make_cleanup (xfree, new_field);
6670 memset (new_field, 0, sizeof (struct nextfield));
6671
6672 if (die->tag == DW_TAG_inheritance)
6673 {
6674 new_field->next = fip->baseclasses;
6675 fip->baseclasses = new_field;
6676 }
6677 else
6678 {
6679 new_field->next = fip->fields;
6680 fip->fields = new_field;
6681 }
6682 fip->nfields++;
6683
6684 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
6685 if (attr)
6686 new_field->accessibility = DW_UNSND (attr);
6687 else
6688 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
6689 if (new_field->accessibility != DW_ACCESS_public)
6690 fip->non_public_fields = 1;
6691
6692 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
6693 if (attr)
6694 new_field->virtuality = DW_UNSND (attr);
6695 else
6696 new_field->virtuality = DW_VIRTUALITY_none;
6697
6698 fp = &new_field->field;
6699
6700 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
6701 {
6702 LONGEST offset;
6703
6704 /* Data member other than a C++ static data member. */
6705
6706 /* Get type of field. */
6707 fp->type = die_type (die, cu);
6708
6709 SET_FIELD_BITPOS (*fp, 0);
6710
6711 /* Get bit size of field (zero if none). */
6712 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
6713 if (attr)
6714 {
6715 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
6716 }
6717 else
6718 {
6719 FIELD_BITSIZE (*fp) = 0;
6720 }
6721
6722 /* Get bit offset of field. */
6723 if (handle_data_member_location (die, cu, &offset))
6724 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6725 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
6726 if (attr)
6727 {
6728 if (gdbarch_bits_big_endian (gdbarch))
6729 {
6730 /* For big endian bits, the DW_AT_bit_offset gives the
6731 additional bit offset from the MSB of the containing
6732 anonymous object to the MSB of the field. We don't
6733 have to do anything special since we don't need to
6734 know the size of the anonymous object. */
6735 FIELD_BITPOS (*fp) += DW_UNSND (attr);
6736 }
6737 else
6738 {
6739 /* For little endian bits, compute the bit offset to the
6740 MSB of the anonymous object, subtract off the number of
6741 bits from the MSB of the field to the MSB of the
6742 object, and then subtract off the number of bits of
6743 the field itself. The result is the bit offset of
6744 the LSB of the field. */
6745 int anonymous_size;
6746 int bit_offset = DW_UNSND (attr);
6747
6748 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
6749 if (attr)
6750 {
6751 /* The size of the anonymous object containing
6752 the bit field is explicit, so use the
6753 indicated size (in bytes). */
6754 anonymous_size = DW_UNSND (attr);
6755 }
6756 else
6757 {
6758 /* The size of the anonymous object containing
6759 the bit field must be inferred from the type
6760 attribute of the data member containing the
6761 bit field. */
6762 anonymous_size = TYPE_LENGTH (fp->type);
6763 }
6764 FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte
6765 - bit_offset - FIELD_BITSIZE (*fp);
6766 }
6767 }
6768
6769 /* Get name of field. */
6770 fieldname = dwarf2_name (die, cu);
6771 if (fieldname == NULL)
6772 fieldname = "";
6773
6774 /* The name is already allocated along with this objfile, so we don't
6775 need to duplicate it for the type. */
6776 fp->name = fieldname;
6777
6778 /* Change accessibility for artificial fields (e.g. virtual table
6779 pointer or virtual base class pointer) to private. */
6780 if (dwarf2_attr (die, DW_AT_artificial, cu))
6781 {
6782 FIELD_ARTIFICIAL (*fp) = 1;
6783 new_field->accessibility = DW_ACCESS_private;
6784 fip->non_public_fields = 1;
6785 }
6786 }
6787 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
6788 {
6789 /* C++ static member. */
6790
6791 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6792 is a declaration, but all versions of G++ as of this writing
6793 (so through at least 3.2.1) incorrectly generate
6794 DW_TAG_variable tags. */
6795
6796 const char *physname;
6797
6798 /* Get name of field. */
6799 fieldname = dwarf2_name (die, cu);
6800 if (fieldname == NULL)
6801 return;
6802
6803 attr = dwarf2_attr (die, DW_AT_const_value, cu);
6804 if (attr
6805 /* Only create a symbol if this is an external value.
6806 new_symbol checks this and puts the value in the global symbol
6807 table, which we want. If it is not external, new_symbol
6808 will try to put the value in cu->list_in_scope which is wrong. */
6809 && dwarf2_flag_true_p (die, DW_AT_external, cu))
6810 {
6811 /* A static const member, not much different than an enum as far as
6812 we're concerned, except that we can support more types. */
6813 new_symbol (die, NULL, cu);
6814 }
6815
6816 /* Get physical name. */
6817 physname = dwarf2_physname (fieldname, die, cu);
6818
6819 /* The name is already allocated along with this objfile, so we don't
6820 need to duplicate it for the type. */
6821 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
6822 FIELD_TYPE (*fp) = die_type (die, cu);
6823 FIELD_NAME (*fp) = fieldname;
6824 }
6825 else if (die->tag == DW_TAG_inheritance)
6826 {
6827 LONGEST offset;
6828
6829 /* C++ base class field. */
6830 if (handle_data_member_location (die, cu, &offset))
6831 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
6832 FIELD_BITSIZE (*fp) = 0;
6833 FIELD_TYPE (*fp) = die_type (die, cu);
6834 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
6835 fip->nbaseclasses++;
6836 }
6837 }
6838
6839 /* Add a typedef defined in the scope of the FIP's class. */
6840
6841 static void
6842 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
6843 struct dwarf2_cu *cu)
6844 {
6845 struct objfile *objfile = cu->objfile;
6846 struct typedef_field_list *new_field;
6847 struct attribute *attr;
6848 struct typedef_field *fp;
6849 char *fieldname = "";
6850
6851 /* Allocate a new field list entry and link it in. */
6852 new_field = xzalloc (sizeof (*new_field));
6853 make_cleanup (xfree, new_field);
6854
6855 gdb_assert (die->tag == DW_TAG_typedef);
6856
6857 fp = &new_field->field;
6858
6859 /* Get name of field. */
6860 fp->name = dwarf2_name (die, cu);
6861 if (fp->name == NULL)
6862 return;
6863
6864 fp->type = read_type_die (die, cu);
6865
6866 new_field->next = fip->typedef_field_list;
6867 fip->typedef_field_list = new_field;
6868 fip->typedef_field_list_count++;
6869 }
6870
6871 /* Create the vector of fields, and attach it to the type. */
6872
6873 static void
6874 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
6875 struct dwarf2_cu *cu)
6876 {
6877 int nfields = fip->nfields;
6878
6879 /* Record the field count, allocate space for the array of fields,
6880 and create blank accessibility bitfields if necessary. */
6881 TYPE_NFIELDS (type) = nfields;
6882 TYPE_FIELDS (type) = (struct field *)
6883 TYPE_ALLOC (type, sizeof (struct field) * nfields);
6884 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6885
6886 if (fip->non_public_fields && cu->language != language_ada)
6887 {
6888 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6889
6890 TYPE_FIELD_PRIVATE_BITS (type) =
6891 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6892 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
6893
6894 TYPE_FIELD_PROTECTED_BITS (type) =
6895 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6896 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
6897
6898 TYPE_FIELD_IGNORE_BITS (type) =
6899 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
6900 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
6901 }
6902
6903 /* If the type has baseclasses, allocate and clear a bit vector for
6904 TYPE_FIELD_VIRTUAL_BITS. */
6905 if (fip->nbaseclasses && cu->language != language_ada)
6906 {
6907 int num_bytes = B_BYTES (fip->nbaseclasses);
6908 unsigned char *pointer;
6909
6910 ALLOCATE_CPLUS_STRUCT_TYPE (type);
6911 pointer = TYPE_ALLOC (type, num_bytes);
6912 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
6913 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
6914 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
6915 }
6916
6917 /* Copy the saved-up fields into the field vector. Start from the head of
6918 the list, adding to the tail of the field array, so that they end up in
6919 the same order in the array in which they were added to the list. */
6920 while (nfields-- > 0)
6921 {
6922 struct nextfield *fieldp;
6923
6924 if (fip->fields)
6925 {
6926 fieldp = fip->fields;
6927 fip->fields = fieldp->next;
6928 }
6929 else
6930 {
6931 fieldp = fip->baseclasses;
6932 fip->baseclasses = fieldp->next;
6933 }
6934
6935 TYPE_FIELD (type, nfields) = fieldp->field;
6936 switch (fieldp->accessibility)
6937 {
6938 case DW_ACCESS_private:
6939 if (cu->language != language_ada)
6940 SET_TYPE_FIELD_PRIVATE (type, nfields);
6941 break;
6942
6943 case DW_ACCESS_protected:
6944 if (cu->language != language_ada)
6945 SET_TYPE_FIELD_PROTECTED (type, nfields);
6946 break;
6947
6948 case DW_ACCESS_public:
6949 break;
6950
6951 default:
6952 /* Unknown accessibility. Complain and treat it as public. */
6953 {
6954 complaint (&symfile_complaints, _("unsupported accessibility %d"),
6955 fieldp->accessibility);
6956 }
6957 break;
6958 }
6959 if (nfields < fip->nbaseclasses)
6960 {
6961 switch (fieldp->virtuality)
6962 {
6963 case DW_VIRTUALITY_virtual:
6964 case DW_VIRTUALITY_pure_virtual:
6965 if (cu->language == language_ada)
6966 error (_("unexpected virtuality in component of Ada type"));
6967 SET_TYPE_FIELD_VIRTUAL (type, nfields);
6968 break;
6969 }
6970 }
6971 }
6972 }
6973
6974 /* Add a member function to the proper fieldlist. */
6975
6976 static void
6977 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
6978 struct type *type, struct dwarf2_cu *cu)
6979 {
6980 struct objfile *objfile = cu->objfile;
6981 struct attribute *attr;
6982 struct fnfieldlist *flp;
6983 int i;
6984 struct fn_field *fnp;
6985 char *fieldname;
6986 struct nextfnfield *new_fnfield;
6987 struct type *this_type;
6988 enum dwarf_access_attribute accessibility;
6989
6990 if (cu->language == language_ada)
6991 error (_("unexpected member function in Ada type"));
6992
6993 /* Get name of member function. */
6994 fieldname = dwarf2_name (die, cu);
6995 if (fieldname == NULL)
6996 return;
6997
6998 /* Look up member function name in fieldlist. */
6999 for (i = 0; i < fip->nfnfields; i++)
7000 {
7001 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
7002 break;
7003 }
7004
7005 /* Create new list element if necessary. */
7006 if (i < fip->nfnfields)
7007 flp = &fip->fnfieldlists[i];
7008 else
7009 {
7010 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
7011 {
7012 fip->fnfieldlists = (struct fnfieldlist *)
7013 xrealloc (fip->fnfieldlists,
7014 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
7015 * sizeof (struct fnfieldlist));
7016 if (fip->nfnfields == 0)
7017 make_cleanup (free_current_contents, &fip->fnfieldlists);
7018 }
7019 flp = &fip->fnfieldlists[fip->nfnfields];
7020 flp->name = fieldname;
7021 flp->length = 0;
7022 flp->head = NULL;
7023 i = fip->nfnfields++;
7024 }
7025
7026 /* Create a new member function field and chain it to the field list
7027 entry. */
7028 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
7029 make_cleanup (xfree, new_fnfield);
7030 memset (new_fnfield, 0, sizeof (struct nextfnfield));
7031 new_fnfield->next = flp->head;
7032 flp->head = new_fnfield;
7033 flp->length++;
7034
7035 /* Fill in the member function field info. */
7036 fnp = &new_fnfield->fnfield;
7037
7038 /* Delay processing of the physname until later. */
7039 if (cu->language == language_cplus || cu->language == language_java)
7040 {
7041 add_to_method_list (type, i, flp->length - 1, fieldname,
7042 die, cu);
7043 }
7044 else
7045 {
7046 const char *physname = dwarf2_physname (fieldname, die, cu);
7047 fnp->physname = physname ? physname : "";
7048 }
7049
7050 fnp->type = alloc_type (objfile);
7051 this_type = read_type_die (die, cu);
7052 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
7053 {
7054 int nparams = TYPE_NFIELDS (this_type);
7055
7056 /* TYPE is the domain of this method, and THIS_TYPE is the type
7057 of the method itself (TYPE_CODE_METHOD). */
7058 smash_to_method_type (fnp->type, type,
7059 TYPE_TARGET_TYPE (this_type),
7060 TYPE_FIELDS (this_type),
7061 TYPE_NFIELDS (this_type),
7062 TYPE_VARARGS (this_type));
7063
7064 /* Handle static member functions.
7065 Dwarf2 has no clean way to discern C++ static and non-static
7066 member functions. G++ helps GDB by marking the first
7067 parameter for non-static member functions (which is the this
7068 pointer) as artificial. We obtain this information from
7069 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
7070 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
7071 fnp->voffset = VOFFSET_STATIC;
7072 }
7073 else
7074 complaint (&symfile_complaints, _("member function type missing for '%s'"),
7075 dwarf2_full_name (fieldname, die, cu));
7076
7077 /* Get fcontext from DW_AT_containing_type if present. */
7078 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7079 fnp->fcontext = die_containing_type (die, cu);
7080
7081 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
7082 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
7083
7084 /* Get accessibility. */
7085 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
7086 if (attr)
7087 accessibility = DW_UNSND (attr);
7088 else
7089 accessibility = dwarf2_default_access_attribute (die, cu);
7090 switch (accessibility)
7091 {
7092 case DW_ACCESS_private:
7093 fnp->is_private = 1;
7094 break;
7095 case DW_ACCESS_protected:
7096 fnp->is_protected = 1;
7097 break;
7098 }
7099
7100 /* Check for artificial methods. */
7101 attr = dwarf2_attr (die, DW_AT_artificial, cu);
7102 if (attr && DW_UNSND (attr) != 0)
7103 fnp->is_artificial = 1;
7104
7105 /* Get index in virtual function table if it is a virtual member
7106 function. For older versions of GCC, this is an offset in the
7107 appropriate virtual table, as specified by DW_AT_containing_type.
7108 For everyone else, it is an expression to be evaluated relative
7109 to the object address. */
7110
7111 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
7112 if (attr)
7113 {
7114 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
7115 {
7116 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
7117 {
7118 /* Old-style GCC. */
7119 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
7120 }
7121 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
7122 || (DW_BLOCK (attr)->size > 1
7123 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
7124 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
7125 {
7126 struct dwarf_block blk;
7127 int offset;
7128
7129 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
7130 ? 1 : 2);
7131 blk.size = DW_BLOCK (attr)->size - offset;
7132 blk.data = DW_BLOCK (attr)->data + offset;
7133 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
7134 if ((fnp->voffset % cu->header.addr_size) != 0)
7135 dwarf2_complex_location_expr_complaint ();
7136 else
7137 fnp->voffset /= cu->header.addr_size;
7138 fnp->voffset += 2;
7139 }
7140 else
7141 dwarf2_complex_location_expr_complaint ();
7142
7143 if (!fnp->fcontext)
7144 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
7145 }
7146 else if (attr_form_is_section_offset (attr))
7147 {
7148 dwarf2_complex_location_expr_complaint ();
7149 }
7150 else
7151 {
7152 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
7153 fieldname);
7154 }
7155 }
7156 else
7157 {
7158 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
7159 if (attr && DW_UNSND (attr))
7160 {
7161 /* GCC does this, as of 2008-08-25; PR debug/37237. */
7162 complaint (&symfile_complaints,
7163 _("Member function \"%s\" (offset %d) is virtual "
7164 "but the vtable offset is not specified"),
7165 fieldname, die->offset);
7166 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7167 TYPE_CPLUS_DYNAMIC (type) = 1;
7168 }
7169 }
7170 }
7171
7172 /* Create the vector of member function fields, and attach it to the type. */
7173
7174 static void
7175 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
7176 struct dwarf2_cu *cu)
7177 {
7178 struct fnfieldlist *flp;
7179 int total_length = 0;
7180 int i;
7181
7182 if (cu->language == language_ada)
7183 error (_("unexpected member functions in Ada type"));
7184
7185 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7186 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
7187 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
7188
7189 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
7190 {
7191 struct nextfnfield *nfp = flp->head;
7192 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
7193 int k;
7194
7195 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
7196 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
7197 fn_flp->fn_fields = (struct fn_field *)
7198 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
7199 for (k = flp->length; (k--, nfp); nfp = nfp->next)
7200 fn_flp->fn_fields[k] = nfp->fnfield;
7201
7202 total_length += flp->length;
7203 }
7204
7205 TYPE_NFN_FIELDS (type) = fip->nfnfields;
7206 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
7207 }
7208
7209 /* Returns non-zero if NAME is the name of a vtable member in CU's
7210 language, zero otherwise. */
7211 static int
7212 is_vtable_name (const char *name, struct dwarf2_cu *cu)
7213 {
7214 static const char vptr[] = "_vptr";
7215 static const char vtable[] = "vtable";
7216
7217 /* Look for the C++ and Java forms of the vtable. */
7218 if ((cu->language == language_java
7219 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
7220 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
7221 && is_cplus_marker (name[sizeof (vptr) - 1])))
7222 return 1;
7223
7224 return 0;
7225 }
7226
7227 /* GCC outputs unnamed structures that are really pointers to member
7228 functions, with the ABI-specified layout. If TYPE describes
7229 such a structure, smash it into a member function type.
7230
7231 GCC shouldn't do this; it should just output pointer to member DIEs.
7232 This is GCC PR debug/28767. */
7233
7234 static void
7235 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
7236 {
7237 struct type *pfn_type, *domain_type, *new_type;
7238
7239 /* Check for a structure with no name and two children. */
7240 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
7241 return;
7242
7243 /* Check for __pfn and __delta members. */
7244 if (TYPE_FIELD_NAME (type, 0) == NULL
7245 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
7246 || TYPE_FIELD_NAME (type, 1) == NULL
7247 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
7248 return;
7249
7250 /* Find the type of the method. */
7251 pfn_type = TYPE_FIELD_TYPE (type, 0);
7252 if (pfn_type == NULL
7253 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
7254 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
7255 return;
7256
7257 /* Look for the "this" argument. */
7258 pfn_type = TYPE_TARGET_TYPE (pfn_type);
7259 if (TYPE_NFIELDS (pfn_type) == 0
7260 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
7261 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
7262 return;
7263
7264 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
7265 new_type = alloc_type (objfile);
7266 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
7267 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
7268 TYPE_VARARGS (pfn_type));
7269 smash_to_methodptr_type (type, new_type);
7270 }
7271
7272 /* Called when we find the DIE that starts a structure or union scope
7273 (definition) to create a type for the structure or union. Fill in
7274 the type's name and general properties; the members will not be
7275 processed until process_structure_type.
7276
7277 NOTE: we need to call these functions regardless of whether or not the
7278 DIE has a DW_AT_name attribute, since it might be an anonymous
7279 structure or union. This gets the type entered into our set of
7280 user defined types.
7281
7282 However, if the structure is incomplete (an opaque struct/union)
7283 then suppress creating a symbol table entry for it since gdb only
7284 wants to find the one with the complete definition. Note that if
7285 it is complete, we just call new_symbol, which does it's own
7286 checking about whether the struct/union is anonymous or not (and
7287 suppresses creating a symbol table entry itself). */
7288
7289 static struct type *
7290 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
7291 {
7292 struct objfile *objfile = cu->objfile;
7293 struct type *type;
7294 struct attribute *attr;
7295 char *name;
7296
7297 /* If the definition of this type lives in .debug_types, read that type.
7298 Don't follow DW_AT_specification though, that will take us back up
7299 the chain and we want to go down. */
7300 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7301 if (attr)
7302 {
7303 struct dwarf2_cu *type_cu = cu;
7304 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7305
7306 /* We could just recurse on read_structure_type, but we need to call
7307 get_die_type to ensure only one type for this DIE is created.
7308 This is important, for example, because for c++ classes we need
7309 TYPE_NAME set which is only done by new_symbol. Blech. */
7310 type = read_type_die (type_die, type_cu);
7311
7312 /* TYPE_CU may not be the same as CU.
7313 Ensure TYPE is recorded in CU's type_hash table. */
7314 return set_die_type (die, type, cu);
7315 }
7316
7317 type = alloc_type (objfile);
7318 INIT_CPLUS_SPECIFIC (type);
7319
7320 name = dwarf2_name (die, cu);
7321 if (name != NULL)
7322 {
7323 if (cu->language == language_cplus
7324 || cu->language == language_java)
7325 {
7326 char *full_name = (char *) dwarf2_full_name (name, die, cu);
7327
7328 /* dwarf2_full_name might have already finished building the DIE's
7329 type. If so, there is no need to continue. */
7330 if (get_die_type (die, cu) != NULL)
7331 return get_die_type (die, cu);
7332
7333 TYPE_TAG_NAME (type) = full_name;
7334 if (die->tag == DW_TAG_structure_type
7335 || die->tag == DW_TAG_class_type)
7336 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7337 }
7338 else
7339 {
7340 /* The name is already allocated along with this objfile, so
7341 we don't need to duplicate it for the type. */
7342 TYPE_TAG_NAME (type) = (char *) name;
7343 if (die->tag == DW_TAG_class_type)
7344 TYPE_NAME (type) = TYPE_TAG_NAME (type);
7345 }
7346 }
7347
7348 if (die->tag == DW_TAG_structure_type)
7349 {
7350 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7351 }
7352 else if (die->tag == DW_TAG_union_type)
7353 {
7354 TYPE_CODE (type) = TYPE_CODE_UNION;
7355 }
7356 else
7357 {
7358 TYPE_CODE (type) = TYPE_CODE_CLASS;
7359 }
7360
7361 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
7362 TYPE_DECLARED_CLASS (type) = 1;
7363
7364 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7365 if (attr)
7366 {
7367 TYPE_LENGTH (type) = DW_UNSND (attr);
7368 }
7369 else
7370 {
7371 TYPE_LENGTH (type) = 0;
7372 }
7373
7374 TYPE_STUB_SUPPORTED (type) = 1;
7375 if (die_is_declaration (die, cu))
7376 TYPE_STUB (type) = 1;
7377 else if (attr == NULL && die->child == NULL
7378 && producer_is_realview (cu->producer))
7379 /* RealView does not output the required DW_AT_declaration
7380 on incomplete types. */
7381 TYPE_STUB (type) = 1;
7382
7383 /* We need to add the type field to the die immediately so we don't
7384 infinitely recurse when dealing with pointers to the structure
7385 type within the structure itself. */
7386 set_die_type (die, type, cu);
7387
7388 /* set_die_type should be already done. */
7389 set_descriptive_type (type, die, cu);
7390
7391 return type;
7392 }
7393
7394 /* Finish creating a structure or union type, including filling in
7395 its members and creating a symbol for it. */
7396
7397 static void
7398 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
7399 {
7400 struct objfile *objfile = cu->objfile;
7401 struct die_info *child_die = die->child;
7402 struct type *type;
7403
7404 type = get_die_type (die, cu);
7405 if (type == NULL)
7406 type = read_structure_type (die, cu);
7407
7408 if (die->child != NULL && ! die_is_declaration (die, cu))
7409 {
7410 struct field_info fi;
7411 struct die_info *child_die;
7412 VEC (symbolp) *template_args = NULL;
7413 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7414
7415 memset (&fi, 0, sizeof (struct field_info));
7416
7417 child_die = die->child;
7418
7419 while (child_die && child_die->tag)
7420 {
7421 if (child_die->tag == DW_TAG_member
7422 || child_die->tag == DW_TAG_variable)
7423 {
7424 /* NOTE: carlton/2002-11-05: A C++ static data member
7425 should be a DW_TAG_member that is a declaration, but
7426 all versions of G++ as of this writing (so through at
7427 least 3.2.1) incorrectly generate DW_TAG_variable
7428 tags for them instead. */
7429 dwarf2_add_field (&fi, child_die, cu);
7430 }
7431 else if (child_die->tag == DW_TAG_subprogram)
7432 {
7433 /* C++ member function. */
7434 dwarf2_add_member_fn (&fi, child_die, type, cu);
7435 }
7436 else if (child_die->tag == DW_TAG_inheritance)
7437 {
7438 /* C++ base class field. */
7439 dwarf2_add_field (&fi, child_die, cu);
7440 }
7441 else if (child_die->tag == DW_TAG_typedef)
7442 dwarf2_add_typedef (&fi, child_die, cu);
7443 else if (child_die->tag == DW_TAG_template_type_param
7444 || child_die->tag == DW_TAG_template_value_param)
7445 {
7446 struct symbol *arg = new_symbol (child_die, NULL, cu);
7447
7448 if (arg != NULL)
7449 VEC_safe_push (symbolp, template_args, arg);
7450 }
7451
7452 child_die = sibling_die (child_die);
7453 }
7454
7455 /* Attach template arguments to type. */
7456 if (! VEC_empty (symbolp, template_args))
7457 {
7458 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7459 TYPE_N_TEMPLATE_ARGUMENTS (type)
7460 = VEC_length (symbolp, template_args);
7461 TYPE_TEMPLATE_ARGUMENTS (type)
7462 = obstack_alloc (&objfile->objfile_obstack,
7463 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7464 * sizeof (struct symbol *)));
7465 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
7466 VEC_address (symbolp, template_args),
7467 (TYPE_N_TEMPLATE_ARGUMENTS (type)
7468 * sizeof (struct symbol *)));
7469 VEC_free (symbolp, template_args);
7470 }
7471
7472 /* Attach fields and member functions to the type. */
7473 if (fi.nfields)
7474 dwarf2_attach_fields_to_type (&fi, type, cu);
7475 if (fi.nfnfields)
7476 {
7477 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
7478
7479 /* Get the type which refers to the base class (possibly this
7480 class itself) which contains the vtable pointer for the current
7481 class from the DW_AT_containing_type attribute. This use of
7482 DW_AT_containing_type is a GNU extension. */
7483
7484 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
7485 {
7486 struct type *t = die_containing_type (die, cu);
7487
7488 TYPE_VPTR_BASETYPE (type) = t;
7489 if (type == t)
7490 {
7491 int i;
7492
7493 /* Our own class provides vtbl ptr. */
7494 for (i = TYPE_NFIELDS (t) - 1;
7495 i >= TYPE_N_BASECLASSES (t);
7496 --i)
7497 {
7498 char *fieldname = TYPE_FIELD_NAME (t, i);
7499
7500 if (is_vtable_name (fieldname, cu))
7501 {
7502 TYPE_VPTR_FIELDNO (type) = i;
7503 break;
7504 }
7505 }
7506
7507 /* Complain if virtual function table field not found. */
7508 if (i < TYPE_N_BASECLASSES (t))
7509 complaint (&symfile_complaints,
7510 _("virtual function table pointer "
7511 "not found when defining class '%s'"),
7512 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
7513 "");
7514 }
7515 else
7516 {
7517 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
7518 }
7519 }
7520 else if (cu->producer
7521 && strncmp (cu->producer,
7522 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7523 {
7524 /* The IBM XLC compiler does not provide direct indication
7525 of the containing type, but the vtable pointer is
7526 always named __vfp. */
7527
7528 int i;
7529
7530 for (i = TYPE_NFIELDS (type) - 1;
7531 i >= TYPE_N_BASECLASSES (type);
7532 --i)
7533 {
7534 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
7535 {
7536 TYPE_VPTR_FIELDNO (type) = i;
7537 TYPE_VPTR_BASETYPE (type) = type;
7538 break;
7539 }
7540 }
7541 }
7542 }
7543
7544 /* Copy fi.typedef_field_list linked list elements content into the
7545 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7546 if (fi.typedef_field_list)
7547 {
7548 int i = fi.typedef_field_list_count;
7549
7550 ALLOCATE_CPLUS_STRUCT_TYPE (type);
7551 TYPE_TYPEDEF_FIELD_ARRAY (type)
7552 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
7553 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
7554
7555 /* Reverse the list order to keep the debug info elements order. */
7556 while (--i >= 0)
7557 {
7558 struct typedef_field *dest, *src;
7559
7560 dest = &TYPE_TYPEDEF_FIELD (type, i);
7561 src = &fi.typedef_field_list->field;
7562 fi.typedef_field_list = fi.typedef_field_list->next;
7563 *dest = *src;
7564 }
7565 }
7566
7567 do_cleanups (back_to);
7568
7569 if (HAVE_CPLUS_STRUCT (type))
7570 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
7571 }
7572
7573 quirk_gcc_member_function_pointer (type, cu->objfile);
7574
7575 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7576 snapshots) has been known to create a die giving a declaration
7577 for a class that has, as a child, a die giving a definition for a
7578 nested class. So we have to process our children even if the
7579 current die is a declaration. Normally, of course, a declaration
7580 won't have any children at all. */
7581
7582 while (child_die != NULL && child_die->tag)
7583 {
7584 if (child_die->tag == DW_TAG_member
7585 || child_die->tag == DW_TAG_variable
7586 || child_die->tag == DW_TAG_inheritance
7587 || child_die->tag == DW_TAG_template_value_param
7588 || child_die->tag == DW_TAG_template_type_param)
7589 {
7590 /* Do nothing. */
7591 }
7592 else
7593 process_die (child_die, cu);
7594
7595 child_die = sibling_die (child_die);
7596 }
7597
7598 /* Do not consider external references. According to the DWARF standard,
7599 these DIEs are identified by the fact that they have no byte_size
7600 attribute, and a declaration attribute. */
7601 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
7602 || !die_is_declaration (die, cu))
7603 new_symbol (die, type, cu);
7604 }
7605
7606 /* Given a DW_AT_enumeration_type die, set its type. We do not
7607 complete the type's fields yet, or create any symbols. */
7608
7609 static struct type *
7610 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
7611 {
7612 struct objfile *objfile = cu->objfile;
7613 struct type *type;
7614 struct attribute *attr;
7615 const char *name;
7616
7617 /* If the definition of this type lives in .debug_types, read that type.
7618 Don't follow DW_AT_specification though, that will take us back up
7619 the chain and we want to go down. */
7620 attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu);
7621 if (attr)
7622 {
7623 struct dwarf2_cu *type_cu = cu;
7624 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
7625
7626 type = read_type_die (type_die, type_cu);
7627
7628 /* TYPE_CU may not be the same as CU.
7629 Ensure TYPE is recorded in CU's type_hash table. */
7630 return set_die_type (die, type, cu);
7631 }
7632
7633 type = alloc_type (objfile);
7634
7635 TYPE_CODE (type) = TYPE_CODE_ENUM;
7636 name = dwarf2_full_name (NULL, die, cu);
7637 if (name != NULL)
7638 TYPE_TAG_NAME (type) = (char *) name;
7639
7640 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7641 if (attr)
7642 {
7643 TYPE_LENGTH (type) = DW_UNSND (attr);
7644 }
7645 else
7646 {
7647 TYPE_LENGTH (type) = 0;
7648 }
7649
7650 /* The enumeration DIE can be incomplete. In Ada, any type can be
7651 declared as private in the package spec, and then defined only
7652 inside the package body. Such types are known as Taft Amendment
7653 Types. When another package uses such a type, an incomplete DIE
7654 may be generated by the compiler. */
7655 if (die_is_declaration (die, cu))
7656 TYPE_STUB (type) = 1;
7657
7658 return set_die_type (die, type, cu);
7659 }
7660
7661 /* Given a pointer to a die which begins an enumeration, process all
7662 the dies that define the members of the enumeration, and create the
7663 symbol for the enumeration type.
7664
7665 NOTE: We reverse the order of the element list. */
7666
7667 static void
7668 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
7669 {
7670 struct type *this_type;
7671
7672 this_type = get_die_type (die, cu);
7673 if (this_type == NULL)
7674 this_type = read_enumeration_type (die, cu);
7675
7676 if (die->child != NULL)
7677 {
7678 struct die_info *child_die;
7679 struct symbol *sym;
7680 struct field *fields = NULL;
7681 int num_fields = 0;
7682 int unsigned_enum = 1;
7683 char *name;
7684
7685 child_die = die->child;
7686 while (child_die && child_die->tag)
7687 {
7688 if (child_die->tag != DW_TAG_enumerator)
7689 {
7690 process_die (child_die, cu);
7691 }
7692 else
7693 {
7694 name = dwarf2_name (child_die, cu);
7695 if (name)
7696 {
7697 sym = new_symbol (child_die, this_type, cu);
7698 if (SYMBOL_VALUE (sym) < 0)
7699 unsigned_enum = 0;
7700
7701 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
7702 {
7703 fields = (struct field *)
7704 xrealloc (fields,
7705 (num_fields + DW_FIELD_ALLOC_CHUNK)
7706 * sizeof (struct field));
7707 }
7708
7709 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
7710 FIELD_TYPE (fields[num_fields]) = NULL;
7711 SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym));
7712 FIELD_BITSIZE (fields[num_fields]) = 0;
7713
7714 num_fields++;
7715 }
7716 }
7717
7718 child_die = sibling_die (child_die);
7719 }
7720
7721 if (num_fields)
7722 {
7723 TYPE_NFIELDS (this_type) = num_fields;
7724 TYPE_FIELDS (this_type) = (struct field *)
7725 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
7726 memcpy (TYPE_FIELDS (this_type), fields,
7727 sizeof (struct field) * num_fields);
7728 xfree (fields);
7729 }
7730 if (unsigned_enum)
7731 TYPE_UNSIGNED (this_type) = 1;
7732 }
7733
7734 /* If we are reading an enum from a .debug_types unit, and the enum
7735 is a declaration, and the enum is not the signatured type in the
7736 unit, then we do not want to add a symbol for it. Adding a
7737 symbol would in some cases obscure the true definition of the
7738 enum, giving users an incomplete type when the definition is
7739 actually available. Note that we do not want to do this for all
7740 enums which are just declarations, because C++0x allows forward
7741 enum declarations. */
7742 if (cu->per_cu->debug_type_section
7743 && die_is_declaration (die, cu))
7744 {
7745 struct signatured_type *type_sig;
7746
7747 type_sig
7748 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
7749 cu->per_cu->debug_type_section,
7750 cu->per_cu->offset);
7751 if (type_sig->type_offset != die->offset)
7752 return;
7753 }
7754
7755 new_symbol (die, this_type, cu);
7756 }
7757
7758 /* Extract all information from a DW_TAG_array_type DIE and put it in
7759 the DIE's type field. For now, this only handles one dimensional
7760 arrays. */
7761
7762 static struct type *
7763 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
7764 {
7765 struct objfile *objfile = cu->objfile;
7766 struct die_info *child_die;
7767 struct type *type;
7768 struct type *element_type, *range_type, *index_type;
7769 struct type **range_types = NULL;
7770 struct attribute *attr;
7771 int ndim = 0;
7772 struct cleanup *back_to;
7773 char *name;
7774
7775 element_type = die_type (die, cu);
7776
7777 /* The die_type call above may have already set the type for this DIE. */
7778 type = get_die_type (die, cu);
7779 if (type)
7780 return type;
7781
7782 /* Irix 6.2 native cc creates array types without children for
7783 arrays with unspecified length. */
7784 if (die->child == NULL)
7785 {
7786 index_type = objfile_type (objfile)->builtin_int;
7787 range_type = create_range_type (NULL, index_type, 0, -1);
7788 type = create_array_type (NULL, element_type, range_type);
7789 return set_die_type (die, type, cu);
7790 }
7791
7792 back_to = make_cleanup (null_cleanup, NULL);
7793 child_die = die->child;
7794 while (child_die && child_die->tag)
7795 {
7796 if (child_die->tag == DW_TAG_subrange_type)
7797 {
7798 struct type *child_type = read_type_die (child_die, cu);
7799
7800 if (child_type != NULL)
7801 {
7802 /* The range type was succesfully read. Save it for the
7803 array type creation. */
7804 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
7805 {
7806 range_types = (struct type **)
7807 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
7808 * sizeof (struct type *));
7809 if (ndim == 0)
7810 make_cleanup (free_current_contents, &range_types);
7811 }
7812 range_types[ndim++] = child_type;
7813 }
7814 }
7815 child_die = sibling_die (child_die);
7816 }
7817
7818 /* Dwarf2 dimensions are output from left to right, create the
7819 necessary array types in backwards order. */
7820
7821 type = element_type;
7822
7823 if (read_array_order (die, cu) == DW_ORD_col_major)
7824 {
7825 int i = 0;
7826
7827 while (i < ndim)
7828 type = create_array_type (NULL, type, range_types[i++]);
7829 }
7830 else
7831 {
7832 while (ndim-- > 0)
7833 type = create_array_type (NULL, type, range_types[ndim]);
7834 }
7835
7836 /* Understand Dwarf2 support for vector types (like they occur on
7837 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7838 array type. This is not part of the Dwarf2/3 standard yet, but a
7839 custom vendor extension. The main difference between a regular
7840 array and the vector variant is that vectors are passed by value
7841 to functions. */
7842 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
7843 if (attr)
7844 make_vector_type (type);
7845
7846 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7847 implementation may choose to implement triple vectors using this
7848 attribute. */
7849 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7850 if (attr)
7851 {
7852 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
7853 TYPE_LENGTH (type) = DW_UNSND (attr);
7854 else
7855 complaint (&symfile_complaints,
7856 _("DW_AT_byte_size for array type smaller "
7857 "than the total size of elements"));
7858 }
7859
7860 name = dwarf2_name (die, cu);
7861 if (name)
7862 TYPE_NAME (type) = name;
7863
7864 /* Install the type in the die. */
7865 set_die_type (die, type, cu);
7866
7867 /* set_die_type should be already done. */
7868 set_descriptive_type (type, die, cu);
7869
7870 do_cleanups (back_to);
7871
7872 return type;
7873 }
7874
7875 static enum dwarf_array_dim_ordering
7876 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
7877 {
7878 struct attribute *attr;
7879
7880 attr = dwarf2_attr (die, DW_AT_ordering, cu);
7881
7882 if (attr) return DW_SND (attr);
7883
7884 /* GNU F77 is a special case, as at 08/2004 array type info is the
7885 opposite order to the dwarf2 specification, but data is still
7886 laid out as per normal fortran.
7887
7888 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7889 version checking. */
7890
7891 if (cu->language == language_fortran
7892 && cu->producer && strstr (cu->producer, "GNU F77"))
7893 {
7894 return DW_ORD_row_major;
7895 }
7896
7897 switch (cu->language_defn->la_array_ordering)
7898 {
7899 case array_column_major:
7900 return DW_ORD_col_major;
7901 case array_row_major:
7902 default:
7903 return DW_ORD_row_major;
7904 };
7905 }
7906
7907 /* Extract all information from a DW_TAG_set_type DIE and put it in
7908 the DIE's type field. */
7909
7910 static struct type *
7911 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
7912 {
7913 struct type *domain_type, *set_type;
7914 struct attribute *attr;
7915
7916 domain_type = die_type (die, cu);
7917
7918 /* The die_type call above may have already set the type for this DIE. */
7919 set_type = get_die_type (die, cu);
7920 if (set_type)
7921 return set_type;
7922
7923 set_type = create_set_type (NULL, domain_type);
7924
7925 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
7926 if (attr)
7927 TYPE_LENGTH (set_type) = DW_UNSND (attr);
7928
7929 return set_die_type (die, set_type, cu);
7930 }
7931
7932 /* First cut: install each common block member as a global variable. */
7933
7934 static void
7935 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
7936 {
7937 struct die_info *child_die;
7938 struct attribute *attr;
7939 struct symbol *sym;
7940 CORE_ADDR base = (CORE_ADDR) 0;
7941
7942 attr = dwarf2_attr (die, DW_AT_location, cu);
7943 if (attr)
7944 {
7945 /* Support the .debug_loc offsets. */
7946 if (attr_form_is_block (attr))
7947 {
7948 base = decode_locdesc (DW_BLOCK (attr), cu);
7949 }
7950 else if (attr_form_is_section_offset (attr))
7951 {
7952 dwarf2_complex_location_expr_complaint ();
7953 }
7954 else
7955 {
7956 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7957 "common block member");
7958 }
7959 }
7960 if (die->child != NULL)
7961 {
7962 child_die = die->child;
7963 while (child_die && child_die->tag)
7964 {
7965 LONGEST offset;
7966
7967 sym = new_symbol (child_die, NULL, cu);
7968 if (sym != NULL
7969 && handle_data_member_location (child_die, cu, &offset))
7970 {
7971 SYMBOL_VALUE_ADDRESS (sym) = base + offset;
7972 add_symbol_to_list (sym, &global_symbols);
7973 }
7974 child_die = sibling_die (child_die);
7975 }
7976 }
7977 }
7978
7979 /* Create a type for a C++ namespace. */
7980
7981 static struct type *
7982 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
7983 {
7984 struct objfile *objfile = cu->objfile;
7985 const char *previous_prefix, *name;
7986 int is_anonymous;
7987 struct type *type;
7988
7989 /* For extensions, reuse the type of the original namespace. */
7990 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
7991 {
7992 struct die_info *ext_die;
7993 struct dwarf2_cu *ext_cu = cu;
7994
7995 ext_die = dwarf2_extension (die, &ext_cu);
7996 type = read_type_die (ext_die, ext_cu);
7997
7998 /* EXT_CU may not be the same as CU.
7999 Ensure TYPE is recorded in CU's type_hash table. */
8000 return set_die_type (die, type, cu);
8001 }
8002
8003 name = namespace_name (die, &is_anonymous, cu);
8004
8005 /* Now build the name of the current namespace. */
8006
8007 previous_prefix = determine_prefix (die, cu);
8008 if (previous_prefix[0] != '\0')
8009 name = typename_concat (&objfile->objfile_obstack,
8010 previous_prefix, name, 0, cu);
8011
8012 /* Create the type. */
8013 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
8014 objfile);
8015 TYPE_NAME (type) = (char *) name;
8016 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8017
8018 return set_die_type (die, type, cu);
8019 }
8020
8021 /* Read a C++ namespace. */
8022
8023 static void
8024 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
8025 {
8026 struct objfile *objfile = cu->objfile;
8027 int is_anonymous;
8028
8029 /* Add a symbol associated to this if we haven't seen the namespace
8030 before. Also, add a using directive if it's an anonymous
8031 namespace. */
8032
8033 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
8034 {
8035 struct type *type;
8036
8037 type = read_type_die (die, cu);
8038 new_symbol (die, type, cu);
8039
8040 namespace_name (die, &is_anonymous, cu);
8041 if (is_anonymous)
8042 {
8043 const char *previous_prefix = determine_prefix (die, cu);
8044
8045 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
8046 NULL, NULL, &objfile->objfile_obstack);
8047 }
8048 }
8049
8050 if (die->child != NULL)
8051 {
8052 struct die_info *child_die = die->child;
8053
8054 while (child_die && child_die->tag)
8055 {
8056 process_die (child_die, cu);
8057 child_die = sibling_die (child_die);
8058 }
8059 }
8060 }
8061
8062 /* Read a Fortran module as type. This DIE can be only a declaration used for
8063 imported module. Still we need that type as local Fortran "use ... only"
8064 declaration imports depend on the created type in determine_prefix. */
8065
8066 static struct type *
8067 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
8068 {
8069 struct objfile *objfile = cu->objfile;
8070 char *module_name;
8071 struct type *type;
8072
8073 module_name = dwarf2_name (die, cu);
8074 if (!module_name)
8075 complaint (&symfile_complaints,
8076 _("DW_TAG_module has no name, offset 0x%x"),
8077 die->offset);
8078 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
8079
8080 /* determine_prefix uses TYPE_TAG_NAME. */
8081 TYPE_TAG_NAME (type) = TYPE_NAME (type);
8082
8083 return set_die_type (die, type, cu);
8084 }
8085
8086 /* Read a Fortran module. */
8087
8088 static void
8089 read_module (struct die_info *die, struct dwarf2_cu *cu)
8090 {
8091 struct die_info *child_die = die->child;
8092
8093 while (child_die && child_die->tag)
8094 {
8095 process_die (child_die, cu);
8096 child_die = sibling_die (child_die);
8097 }
8098 }
8099
8100 /* Return the name of the namespace represented by DIE. Set
8101 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
8102 namespace. */
8103
8104 static const char *
8105 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
8106 {
8107 struct die_info *current_die;
8108 const char *name = NULL;
8109
8110 /* Loop through the extensions until we find a name. */
8111
8112 for (current_die = die;
8113 current_die != NULL;
8114 current_die = dwarf2_extension (die, &cu))
8115 {
8116 name = dwarf2_name (current_die, cu);
8117 if (name != NULL)
8118 break;
8119 }
8120
8121 /* Is it an anonymous namespace? */
8122
8123 *is_anonymous = (name == NULL);
8124 if (*is_anonymous)
8125 name = CP_ANONYMOUS_NAMESPACE_STR;
8126
8127 return name;
8128 }
8129
8130 /* Extract all information from a DW_TAG_pointer_type DIE and add to
8131 the user defined type vector. */
8132
8133 static struct type *
8134 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
8135 {
8136 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
8137 struct comp_unit_head *cu_header = &cu->header;
8138 struct type *type;
8139 struct attribute *attr_byte_size;
8140 struct attribute *attr_address_class;
8141 int byte_size, addr_class;
8142 struct type *target_type;
8143
8144 target_type = die_type (die, cu);
8145
8146 /* The die_type call above may have already set the type for this DIE. */
8147 type = get_die_type (die, cu);
8148 if (type)
8149 return type;
8150
8151 type = lookup_pointer_type (target_type);
8152
8153 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
8154 if (attr_byte_size)
8155 byte_size = DW_UNSND (attr_byte_size);
8156 else
8157 byte_size = cu_header->addr_size;
8158
8159 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
8160 if (attr_address_class)
8161 addr_class = DW_UNSND (attr_address_class);
8162 else
8163 addr_class = DW_ADDR_none;
8164
8165 /* If the pointer size or address class is different than the
8166 default, create a type variant marked as such and set the
8167 length accordingly. */
8168 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
8169 {
8170 if (gdbarch_address_class_type_flags_p (gdbarch))
8171 {
8172 int type_flags;
8173
8174 type_flags = gdbarch_address_class_type_flags
8175 (gdbarch, byte_size, addr_class);
8176 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
8177 == 0);
8178 type = make_type_with_address_space (type, type_flags);
8179 }
8180 else if (TYPE_LENGTH (type) != byte_size)
8181 {
8182 complaint (&symfile_complaints,
8183 _("invalid pointer size %d"), byte_size);
8184 }
8185 else
8186 {
8187 /* Should we also complain about unhandled address classes? */
8188 }
8189 }
8190
8191 TYPE_LENGTH (type) = byte_size;
8192 return set_die_type (die, type, cu);
8193 }
8194
8195 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
8196 the user defined type vector. */
8197
8198 static struct type *
8199 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
8200 {
8201 struct type *type;
8202 struct type *to_type;
8203 struct type *domain;
8204
8205 to_type = die_type (die, cu);
8206 domain = die_containing_type (die, cu);
8207
8208 /* The calls above may have already set the type for this DIE. */
8209 type = get_die_type (die, cu);
8210 if (type)
8211 return type;
8212
8213 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
8214 type = lookup_methodptr_type (to_type);
8215 else
8216 type = lookup_memberptr_type (to_type, domain);
8217
8218 return set_die_type (die, type, cu);
8219 }
8220
8221 /* Extract all information from a DW_TAG_reference_type DIE and add to
8222 the user defined type vector. */
8223
8224 static struct type *
8225 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
8226 {
8227 struct comp_unit_head *cu_header = &cu->header;
8228 struct type *type, *target_type;
8229 struct attribute *attr;
8230
8231 target_type = die_type (die, cu);
8232
8233 /* The die_type call above may have already set the type for this DIE. */
8234 type = get_die_type (die, cu);
8235 if (type)
8236 return type;
8237
8238 type = lookup_reference_type (target_type);
8239 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8240 if (attr)
8241 {
8242 TYPE_LENGTH (type) = DW_UNSND (attr);
8243 }
8244 else
8245 {
8246 TYPE_LENGTH (type) = cu_header->addr_size;
8247 }
8248 return set_die_type (die, type, cu);
8249 }
8250
8251 static struct type *
8252 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
8253 {
8254 struct type *base_type, *cv_type;
8255
8256 base_type = die_type (die, cu);
8257
8258 /* The die_type call above may have already set the type for this DIE. */
8259 cv_type = get_die_type (die, cu);
8260 if (cv_type)
8261 return cv_type;
8262
8263 /* In case the const qualifier is applied to an array type, the element type
8264 is so qualified, not the array type (section 6.7.3 of C99). */
8265 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
8266 {
8267 struct type *el_type, *inner_array;
8268
8269 base_type = copy_type (base_type);
8270 inner_array = base_type;
8271
8272 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
8273 {
8274 TYPE_TARGET_TYPE (inner_array) =
8275 copy_type (TYPE_TARGET_TYPE (inner_array));
8276 inner_array = TYPE_TARGET_TYPE (inner_array);
8277 }
8278
8279 el_type = TYPE_TARGET_TYPE (inner_array);
8280 TYPE_TARGET_TYPE (inner_array) =
8281 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
8282
8283 return set_die_type (die, base_type, cu);
8284 }
8285
8286 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
8287 return set_die_type (die, cv_type, cu);
8288 }
8289
8290 static struct type *
8291 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
8292 {
8293 struct type *base_type, *cv_type;
8294
8295 base_type = die_type (die, cu);
8296
8297 /* The die_type call above may have already set the type for this DIE. */
8298 cv_type = get_die_type (die, cu);
8299 if (cv_type)
8300 return cv_type;
8301
8302 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
8303 return set_die_type (die, cv_type, cu);
8304 }
8305
8306 /* Extract all information from a DW_TAG_string_type DIE and add to
8307 the user defined type vector. It isn't really a user defined type,
8308 but it behaves like one, with other DIE's using an AT_user_def_type
8309 attribute to reference it. */
8310
8311 static struct type *
8312 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
8313 {
8314 struct objfile *objfile = cu->objfile;
8315 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8316 struct type *type, *range_type, *index_type, *char_type;
8317 struct attribute *attr;
8318 unsigned int length;
8319
8320 attr = dwarf2_attr (die, DW_AT_string_length, cu);
8321 if (attr)
8322 {
8323 length = DW_UNSND (attr);
8324 }
8325 else
8326 {
8327 /* Check for the DW_AT_byte_size attribute. */
8328 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8329 if (attr)
8330 {
8331 length = DW_UNSND (attr);
8332 }
8333 else
8334 {
8335 length = 1;
8336 }
8337 }
8338
8339 index_type = objfile_type (objfile)->builtin_int;
8340 range_type = create_range_type (NULL, index_type, 1, length);
8341 char_type = language_string_char_type (cu->language_defn, gdbarch);
8342 type = create_string_type (NULL, char_type, range_type);
8343
8344 return set_die_type (die, type, cu);
8345 }
8346
8347 /* Handle DIES due to C code like:
8348
8349 struct foo
8350 {
8351 int (*funcp)(int a, long l);
8352 int b;
8353 };
8354
8355 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8356
8357 static struct type *
8358 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
8359 {
8360 struct type *type; /* Type that this function returns. */
8361 struct type *ftype; /* Function that returns above type. */
8362 struct attribute *attr;
8363
8364 type = die_type (die, cu);
8365
8366 /* The die_type call above may have already set the type for this DIE. */
8367 ftype = get_die_type (die, cu);
8368 if (ftype)
8369 return ftype;
8370
8371 ftype = lookup_function_type (type);
8372
8373 /* All functions in C++, Pascal and Java have prototypes. */
8374 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
8375 if ((attr && (DW_UNSND (attr) != 0))
8376 || cu->language == language_cplus
8377 || cu->language == language_java
8378 || cu->language == language_pascal)
8379 TYPE_PROTOTYPED (ftype) = 1;
8380 else if (producer_is_realview (cu->producer))
8381 /* RealView does not emit DW_AT_prototyped. We can not
8382 distinguish prototyped and unprototyped functions; default to
8383 prototyped, since that is more common in modern code (and
8384 RealView warns about unprototyped functions). */
8385 TYPE_PROTOTYPED (ftype) = 1;
8386
8387 /* Store the calling convention in the type if it's available in
8388 the subroutine die. Otherwise set the calling convention to
8389 the default value DW_CC_normal. */
8390 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
8391 if (attr)
8392 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
8393 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
8394 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
8395 else
8396 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
8397
8398 /* We need to add the subroutine type to the die immediately so
8399 we don't infinitely recurse when dealing with parameters
8400 declared as the same subroutine type. */
8401 set_die_type (die, ftype, cu);
8402
8403 if (die->child != NULL)
8404 {
8405 struct type *void_type = objfile_type (cu->objfile)->builtin_void;
8406 struct die_info *child_die;
8407 int nparams, iparams;
8408
8409 /* Count the number of parameters.
8410 FIXME: GDB currently ignores vararg functions, but knows about
8411 vararg member functions. */
8412 nparams = 0;
8413 child_die = die->child;
8414 while (child_die && child_die->tag)
8415 {
8416 if (child_die->tag == DW_TAG_formal_parameter)
8417 nparams++;
8418 else if (child_die->tag == DW_TAG_unspecified_parameters)
8419 TYPE_VARARGS (ftype) = 1;
8420 child_die = sibling_die (child_die);
8421 }
8422
8423 /* Allocate storage for parameters and fill them in. */
8424 TYPE_NFIELDS (ftype) = nparams;
8425 TYPE_FIELDS (ftype) = (struct field *)
8426 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
8427
8428 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8429 even if we error out during the parameters reading below. */
8430 for (iparams = 0; iparams < nparams; iparams++)
8431 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
8432
8433 iparams = 0;
8434 child_die = die->child;
8435 while (child_die && child_die->tag)
8436 {
8437 if (child_die->tag == DW_TAG_formal_parameter)
8438 {
8439 struct type *arg_type;
8440
8441 /* DWARF version 2 has no clean way to discern C++
8442 static and non-static member functions. G++ helps
8443 GDB by marking the first parameter for non-static
8444 member functions (which is the this pointer) as
8445 artificial. We pass this information to
8446 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8447
8448 DWARF version 3 added DW_AT_object_pointer, which GCC
8449 4.5 does not yet generate. */
8450 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
8451 if (attr)
8452 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
8453 else
8454 {
8455 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
8456
8457 /* GCC/43521: In java, the formal parameter
8458 "this" is sometimes not marked with DW_AT_artificial. */
8459 if (cu->language == language_java)
8460 {
8461 const char *name = dwarf2_name (child_die, cu);
8462
8463 if (name && !strcmp (name, "this"))
8464 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
8465 }
8466 }
8467 arg_type = die_type (child_die, cu);
8468
8469 /* RealView does not mark THIS as const, which the testsuite
8470 expects. GCC marks THIS as const in method definitions,
8471 but not in the class specifications (GCC PR 43053). */
8472 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
8473 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
8474 {
8475 int is_this = 0;
8476 struct dwarf2_cu *arg_cu = cu;
8477 const char *name = dwarf2_name (child_die, cu);
8478
8479 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
8480 if (attr)
8481 {
8482 /* If the compiler emits this, use it. */
8483 if (follow_die_ref (die, attr, &arg_cu) == child_die)
8484 is_this = 1;
8485 }
8486 else if (name && strcmp (name, "this") == 0)
8487 /* Function definitions will have the argument names. */
8488 is_this = 1;
8489 else if (name == NULL && iparams == 0)
8490 /* Declarations may not have the names, so like
8491 elsewhere in GDB, assume an artificial first
8492 argument is "this". */
8493 is_this = 1;
8494
8495 if (is_this)
8496 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
8497 arg_type, 0);
8498 }
8499
8500 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
8501 iparams++;
8502 }
8503 child_die = sibling_die (child_die);
8504 }
8505 }
8506
8507 return ftype;
8508 }
8509
8510 static struct type *
8511 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
8512 {
8513 struct objfile *objfile = cu->objfile;
8514 const char *name = NULL;
8515 struct type *this_type;
8516
8517 name = dwarf2_full_name (NULL, die, cu);
8518 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
8519 TYPE_FLAG_TARGET_STUB, NULL, objfile);
8520 TYPE_NAME (this_type) = (char *) name;
8521 set_die_type (die, this_type, cu);
8522 TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
8523 return this_type;
8524 }
8525
8526 /* Find a representation of a given base type and install
8527 it in the TYPE field of the die. */
8528
8529 static struct type *
8530 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
8531 {
8532 struct objfile *objfile = cu->objfile;
8533 struct type *type;
8534 struct attribute *attr;
8535 int encoding = 0, size = 0;
8536 char *name;
8537 enum type_code code = TYPE_CODE_INT;
8538 int type_flags = 0;
8539 struct type *target_type = NULL;
8540
8541 attr = dwarf2_attr (die, DW_AT_encoding, cu);
8542 if (attr)
8543 {
8544 encoding = DW_UNSND (attr);
8545 }
8546 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8547 if (attr)
8548 {
8549 size = DW_UNSND (attr);
8550 }
8551 name = dwarf2_name (die, cu);
8552 if (!name)
8553 {
8554 complaint (&symfile_complaints,
8555 _("DW_AT_name missing from DW_TAG_base_type"));
8556 }
8557
8558 switch (encoding)
8559 {
8560 case DW_ATE_address:
8561 /* Turn DW_ATE_address into a void * pointer. */
8562 code = TYPE_CODE_PTR;
8563 type_flags |= TYPE_FLAG_UNSIGNED;
8564 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
8565 break;
8566 case DW_ATE_boolean:
8567 code = TYPE_CODE_BOOL;
8568 type_flags |= TYPE_FLAG_UNSIGNED;
8569 break;
8570 case DW_ATE_complex_float:
8571 code = TYPE_CODE_COMPLEX;
8572 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
8573 break;
8574 case DW_ATE_decimal_float:
8575 code = TYPE_CODE_DECFLOAT;
8576 break;
8577 case DW_ATE_float:
8578 code = TYPE_CODE_FLT;
8579 break;
8580 case DW_ATE_signed:
8581 break;
8582 case DW_ATE_unsigned:
8583 type_flags |= TYPE_FLAG_UNSIGNED;
8584 if (cu->language == language_fortran
8585 && name
8586 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
8587 code = TYPE_CODE_CHAR;
8588 break;
8589 case DW_ATE_signed_char:
8590 if (cu->language == language_ada || cu->language == language_m2
8591 || cu->language == language_pascal
8592 || cu->language == language_fortran)
8593 code = TYPE_CODE_CHAR;
8594 break;
8595 case DW_ATE_unsigned_char:
8596 if (cu->language == language_ada || cu->language == language_m2
8597 || cu->language == language_pascal
8598 || cu->language == language_fortran)
8599 code = TYPE_CODE_CHAR;
8600 type_flags |= TYPE_FLAG_UNSIGNED;
8601 break;
8602 case DW_ATE_UTF:
8603 /* We just treat this as an integer and then recognize the
8604 type by name elsewhere. */
8605 break;
8606
8607 default:
8608 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
8609 dwarf_type_encoding_name (encoding));
8610 break;
8611 }
8612
8613 type = init_type (code, size, type_flags, NULL, objfile);
8614 TYPE_NAME (type) = name;
8615 TYPE_TARGET_TYPE (type) = target_type;
8616
8617 if (name && strcmp (name, "char") == 0)
8618 TYPE_NOSIGN (type) = 1;
8619
8620 return set_die_type (die, type, cu);
8621 }
8622
8623 /* Read the given DW_AT_subrange DIE. */
8624
8625 static struct type *
8626 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
8627 {
8628 struct type *base_type;
8629 struct type *range_type;
8630 struct attribute *attr;
8631 LONGEST low = 0;
8632 LONGEST high = -1;
8633 char *name;
8634 LONGEST negative_mask;
8635
8636 base_type = die_type (die, cu);
8637 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8638 check_typedef (base_type);
8639
8640 /* The die_type call above may have already set the type for this DIE. */
8641 range_type = get_die_type (die, cu);
8642 if (range_type)
8643 return range_type;
8644
8645 if (cu->language == language_fortran)
8646 {
8647 /* FORTRAN implies a lower bound of 1, if not given. */
8648 low = 1;
8649 }
8650
8651 /* FIXME: For variable sized arrays either of these could be
8652 a variable rather than a constant value. We'll allow it,
8653 but we don't know how to handle it. */
8654 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
8655 if (attr)
8656 low = dwarf2_get_attr_constant_value (attr, 0);
8657
8658 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
8659 if (attr)
8660 {
8661 if (attr_form_is_block (attr) || is_ref_attr (attr))
8662 {
8663 /* GCC encodes arrays with unspecified or dynamic length
8664 with a DW_FORM_block1 attribute or a reference attribute.
8665 FIXME: GDB does not yet know how to handle dynamic
8666 arrays properly, treat them as arrays with unspecified
8667 length for now.
8668
8669 FIXME: jimb/2003-09-22: GDB does not really know
8670 how to handle arrays of unspecified length
8671 either; we just represent them as zero-length
8672 arrays. Choose an appropriate upper bound given
8673 the lower bound we've computed above. */
8674 high = low - 1;
8675 }
8676 else
8677 high = dwarf2_get_attr_constant_value (attr, 1);
8678 }
8679 else
8680 {
8681 attr = dwarf2_attr (die, DW_AT_count, cu);
8682 if (attr)
8683 {
8684 int count = dwarf2_get_attr_constant_value (attr, 1);
8685 high = low + count - 1;
8686 }
8687 else
8688 {
8689 /* Unspecified array length. */
8690 high = low - 1;
8691 }
8692 }
8693
8694 /* Dwarf-2 specifications explicitly allows to create subrange types
8695 without specifying a base type.
8696 In that case, the base type must be set to the type of
8697 the lower bound, upper bound or count, in that order, if any of these
8698 three attributes references an object that has a type.
8699 If no base type is found, the Dwarf-2 specifications say that
8700 a signed integer type of size equal to the size of an address should
8701 be used.
8702 For the following C code: `extern char gdb_int [];'
8703 GCC produces an empty range DIE.
8704 FIXME: muller/2010-05-28: Possible references to object for low bound,
8705 high bound or count are not yet handled by this code. */
8706 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
8707 {
8708 struct objfile *objfile = cu->objfile;
8709 struct gdbarch *gdbarch = get_objfile_arch (objfile);
8710 int addr_size = gdbarch_addr_bit (gdbarch) /8;
8711 struct type *int_type = objfile_type (objfile)->builtin_int;
8712
8713 /* Test "int", "long int", and "long long int" objfile types,
8714 and select the first one having a size above or equal to the
8715 architecture address size. */
8716 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8717 base_type = int_type;
8718 else
8719 {
8720 int_type = objfile_type (objfile)->builtin_long;
8721 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8722 base_type = int_type;
8723 else
8724 {
8725 int_type = objfile_type (objfile)->builtin_long_long;
8726 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
8727 base_type = int_type;
8728 }
8729 }
8730 }
8731
8732 negative_mask =
8733 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
8734 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
8735 low |= negative_mask;
8736 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
8737 high |= negative_mask;
8738
8739 range_type = create_range_type (NULL, base_type, low, high);
8740
8741 /* Mark arrays with dynamic length at least as an array of unspecified
8742 length. GDB could check the boundary but before it gets implemented at
8743 least allow accessing the array elements. */
8744 if (attr && attr_form_is_block (attr))
8745 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8746
8747 /* Ada expects an empty array on no boundary attributes. */
8748 if (attr == NULL && cu->language != language_ada)
8749 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
8750
8751 name = dwarf2_name (die, cu);
8752 if (name)
8753 TYPE_NAME (range_type) = name;
8754
8755 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
8756 if (attr)
8757 TYPE_LENGTH (range_type) = DW_UNSND (attr);
8758
8759 set_die_type (die, range_type, cu);
8760
8761 /* set_die_type should be already done. */
8762 set_descriptive_type (range_type, die, cu);
8763
8764 return range_type;
8765 }
8766
8767 static struct type *
8768 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
8769 {
8770 struct type *type;
8771
8772 /* For now, we only support the C meaning of an unspecified type: void. */
8773
8774 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
8775 TYPE_NAME (type) = dwarf2_name (die, cu);
8776
8777 return set_die_type (die, type, cu);
8778 }
8779
8780 /* Trivial hash function for die_info: the hash value of a DIE
8781 is its offset in .debug_info for this objfile. */
8782
8783 static hashval_t
8784 die_hash (const void *item)
8785 {
8786 const struct die_info *die = item;
8787
8788 return die->offset;
8789 }
8790
8791 /* Trivial comparison function for die_info structures: two DIEs
8792 are equal if they have the same offset. */
8793
8794 static int
8795 die_eq (const void *item_lhs, const void *item_rhs)
8796 {
8797 const struct die_info *die_lhs = item_lhs;
8798 const struct die_info *die_rhs = item_rhs;
8799
8800 return die_lhs->offset == die_rhs->offset;
8801 }
8802
8803 /* Read a whole compilation unit into a linked list of dies. */
8804
8805 static struct die_info *
8806 read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu)
8807 {
8808 struct die_reader_specs reader_specs;
8809 int read_abbrevs = 0;
8810 struct cleanup *back_to = NULL;
8811 struct die_info *die;
8812
8813 if (cu->dwarf2_abbrevs == NULL)
8814 {
8815 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
8816 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
8817 read_abbrevs = 1;
8818 }
8819
8820 gdb_assert (cu->die_hash == NULL);
8821 cu->die_hash
8822 = htab_create_alloc_ex (cu->header.length / 12,
8823 die_hash,
8824 die_eq,
8825 NULL,
8826 &cu->comp_unit_obstack,
8827 hashtab_obstack_allocate,
8828 dummy_obstack_deallocate);
8829
8830 init_cu_die_reader (&reader_specs, cu);
8831
8832 die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL);
8833
8834 if (read_abbrevs)
8835 do_cleanups (back_to);
8836
8837 return die;
8838 }
8839
8840 /* Main entry point for reading a DIE and all children.
8841 Read the DIE and dump it if requested. */
8842
8843 static struct die_info *
8844 read_die_and_children (const struct die_reader_specs *reader,
8845 gdb_byte *info_ptr,
8846 gdb_byte **new_info_ptr,
8847 struct die_info *parent)
8848 {
8849 struct die_info *result = read_die_and_children_1 (reader, info_ptr,
8850 new_info_ptr, parent);
8851
8852 if (dwarf2_die_debug)
8853 {
8854 fprintf_unfiltered (gdb_stdlog,
8855 "\nRead die from %s of %s:\n",
8856 (reader->cu->per_cu->debug_type_section
8857 ? ".debug_types"
8858 : ".debug_info"),
8859 reader->abfd->filename);
8860 dump_die (result, dwarf2_die_debug);
8861 }
8862
8863 return result;
8864 }
8865
8866 /* Read a single die and all its descendents. Set the die's sibling
8867 field to NULL; set other fields in the die correctly, and set all
8868 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8869 location of the info_ptr after reading all of those dies. PARENT
8870 is the parent of the die in question. */
8871
8872 static struct die_info *
8873 read_die_and_children_1 (const struct die_reader_specs *reader,
8874 gdb_byte *info_ptr,
8875 gdb_byte **new_info_ptr,
8876 struct die_info *parent)
8877 {
8878 struct die_info *die;
8879 gdb_byte *cur_ptr;
8880 int has_children;
8881
8882 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
8883 if (die == NULL)
8884 {
8885 *new_info_ptr = cur_ptr;
8886 return NULL;
8887 }
8888 store_in_ref_table (die, reader->cu);
8889
8890 if (has_children)
8891 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
8892 else
8893 {
8894 die->child = NULL;
8895 *new_info_ptr = cur_ptr;
8896 }
8897
8898 die->sibling = NULL;
8899 die->parent = parent;
8900 return die;
8901 }
8902
8903 /* Read a die, all of its descendents, and all of its siblings; set
8904 all of the fields of all of the dies correctly. Arguments are as
8905 in read_die_and_children. */
8906
8907 static struct die_info *
8908 read_die_and_siblings (const struct die_reader_specs *reader,
8909 gdb_byte *info_ptr,
8910 gdb_byte **new_info_ptr,
8911 struct die_info *parent)
8912 {
8913 struct die_info *first_die, *last_sibling;
8914 gdb_byte *cur_ptr;
8915
8916 cur_ptr = info_ptr;
8917 first_die = last_sibling = NULL;
8918
8919 while (1)
8920 {
8921 struct die_info *die
8922 = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent);
8923
8924 if (die == NULL)
8925 {
8926 *new_info_ptr = cur_ptr;
8927 return first_die;
8928 }
8929
8930 if (!first_die)
8931 first_die = die;
8932 else
8933 last_sibling->sibling = die;
8934
8935 last_sibling = die;
8936 }
8937 }
8938
8939 /* Read the die from the .debug_info section buffer. Set DIEP to
8940 point to a newly allocated die with its information, except for its
8941 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8942 whether the die has children or not. */
8943
8944 static gdb_byte *
8945 read_full_die (const struct die_reader_specs *reader,
8946 struct die_info **diep, gdb_byte *info_ptr,
8947 int *has_children)
8948 {
8949 unsigned int abbrev_number, bytes_read, i, offset;
8950 struct abbrev_info *abbrev;
8951 struct die_info *die;
8952 struct dwarf2_cu *cu = reader->cu;
8953 bfd *abfd = reader->abfd;
8954
8955 offset = info_ptr - reader->buffer;
8956 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
8957 info_ptr += bytes_read;
8958 if (!abbrev_number)
8959 {
8960 *diep = NULL;
8961 *has_children = 0;
8962 return info_ptr;
8963 }
8964
8965 abbrev = dwarf2_lookup_abbrev (abbrev_number, cu);
8966 if (!abbrev)
8967 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8968 abbrev_number,
8969 bfd_get_filename (abfd));
8970
8971 die = dwarf_alloc_die (cu, abbrev->num_attrs);
8972 die->offset = offset;
8973 die->tag = abbrev->tag;
8974 die->abbrev = abbrev_number;
8975
8976 die->num_attrs = abbrev->num_attrs;
8977
8978 for (i = 0; i < abbrev->num_attrs; ++i)
8979 info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i],
8980 abfd, info_ptr, cu);
8981
8982 *diep = die;
8983 *has_children = abbrev->has_children;
8984 return info_ptr;
8985 }
8986
8987 /* In DWARF version 2, the description of the debugging information is
8988 stored in a separate .debug_abbrev section. Before we read any
8989 dies from a section we read in all abbreviations and install them
8990 in a hash table. This function also sets flags in CU describing
8991 the data found in the abbrev table. */
8992
8993 static void
8994 dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
8995 {
8996 struct comp_unit_head *cu_header = &cu->header;
8997 gdb_byte *abbrev_ptr;
8998 struct abbrev_info *cur_abbrev;
8999 unsigned int abbrev_number, bytes_read, abbrev_name;
9000 unsigned int abbrev_form, hash_number;
9001 struct attr_abbrev *cur_attrs;
9002 unsigned int allocated_attrs;
9003
9004 /* Initialize dwarf2 abbrevs. */
9005 obstack_init (&cu->abbrev_obstack);
9006 cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,
9007 (ABBREV_HASH_SIZE
9008 * sizeof (struct abbrev_info *)));
9009 memset (cu->dwarf2_abbrevs, 0,
9010 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
9011
9012 dwarf2_read_section (dwarf2_per_objfile->objfile,
9013 &dwarf2_per_objfile->abbrev);
9014 abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset;
9015 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9016 abbrev_ptr += bytes_read;
9017
9018 allocated_attrs = ATTR_ALLOC_CHUNK;
9019 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
9020
9021 /* Loop until we reach an abbrev number of 0. */
9022 while (abbrev_number)
9023 {
9024 cur_abbrev = dwarf_alloc_abbrev (cu);
9025
9026 /* read in abbrev header */
9027 cur_abbrev->number = abbrev_number;
9028 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9029 abbrev_ptr += bytes_read;
9030 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
9031 abbrev_ptr += 1;
9032
9033 if (cur_abbrev->tag == DW_TAG_namespace)
9034 cu->has_namespace_info = 1;
9035
9036 /* now read in declarations */
9037 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9038 abbrev_ptr += bytes_read;
9039 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9040 abbrev_ptr += bytes_read;
9041 while (abbrev_name)
9042 {
9043 if (cur_abbrev->num_attrs == allocated_attrs)
9044 {
9045 allocated_attrs += ATTR_ALLOC_CHUNK;
9046 cur_attrs
9047 = xrealloc (cur_attrs, (allocated_attrs
9048 * sizeof (struct attr_abbrev)));
9049 }
9050
9051 /* Record whether this compilation unit might have
9052 inter-compilation-unit references. If we don't know what form
9053 this attribute will have, then it might potentially be a
9054 DW_FORM_ref_addr, so we conservatively expect inter-CU
9055 references. */
9056
9057 if (abbrev_form == DW_FORM_ref_addr
9058 || abbrev_form == DW_FORM_indirect)
9059 cu->has_form_ref_addr = 1;
9060
9061 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
9062 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
9063 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9064 abbrev_ptr += bytes_read;
9065 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9066 abbrev_ptr += bytes_read;
9067 }
9068
9069 cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,
9070 (cur_abbrev->num_attrs
9071 * sizeof (struct attr_abbrev)));
9072 memcpy (cur_abbrev->attrs, cur_attrs,
9073 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
9074
9075 hash_number = abbrev_number % ABBREV_HASH_SIZE;
9076 cur_abbrev->next = cu->dwarf2_abbrevs[hash_number];
9077 cu->dwarf2_abbrevs[hash_number] = cur_abbrev;
9078
9079 /* Get next abbreviation.
9080 Under Irix6 the abbreviations for a compilation unit are not
9081 always properly terminated with an abbrev number of 0.
9082 Exit loop if we encounter an abbreviation which we have
9083 already read (which means we are about to read the abbreviations
9084 for the next compile unit) or if the end of the abbreviation
9085 table is reached. */
9086 if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer)
9087 >= dwarf2_per_objfile->abbrev.size)
9088 break;
9089 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
9090 abbrev_ptr += bytes_read;
9091 if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL)
9092 break;
9093 }
9094
9095 xfree (cur_attrs);
9096 }
9097
9098 /* Release the memory used by the abbrev table for a compilation unit. */
9099
9100 static void
9101 dwarf2_free_abbrev_table (void *ptr_to_cu)
9102 {
9103 struct dwarf2_cu *cu = ptr_to_cu;
9104
9105 obstack_free (&cu->abbrev_obstack, NULL);
9106 cu->dwarf2_abbrevs = NULL;
9107 }
9108
9109 /* Lookup an abbrev_info structure in the abbrev hash table. */
9110
9111 static struct abbrev_info *
9112 dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu)
9113 {
9114 unsigned int hash_number;
9115 struct abbrev_info *abbrev;
9116
9117 hash_number = number % ABBREV_HASH_SIZE;
9118 abbrev = cu->dwarf2_abbrevs[hash_number];
9119
9120 while (abbrev)
9121 {
9122 if (abbrev->number == number)
9123 return abbrev;
9124 else
9125 abbrev = abbrev->next;
9126 }
9127 return NULL;
9128 }
9129
9130 /* Returns nonzero if TAG represents a type that we might generate a partial
9131 symbol for. */
9132
9133 static int
9134 is_type_tag_for_partial (int tag)
9135 {
9136 switch (tag)
9137 {
9138 #if 0
9139 /* Some types that would be reasonable to generate partial symbols for,
9140 that we don't at present. */
9141 case DW_TAG_array_type:
9142 case DW_TAG_file_type:
9143 case DW_TAG_ptr_to_member_type:
9144 case DW_TAG_set_type:
9145 case DW_TAG_string_type:
9146 case DW_TAG_subroutine_type:
9147 #endif
9148 case DW_TAG_base_type:
9149 case DW_TAG_class_type:
9150 case DW_TAG_interface_type:
9151 case DW_TAG_enumeration_type:
9152 case DW_TAG_structure_type:
9153 case DW_TAG_subrange_type:
9154 case DW_TAG_typedef:
9155 case DW_TAG_union_type:
9156 return 1;
9157 default:
9158 return 0;
9159 }
9160 }
9161
9162 /* Load all DIEs that are interesting for partial symbols into memory. */
9163
9164 static struct partial_die_info *
9165 load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
9166 int building_psymtab, struct dwarf2_cu *cu)
9167 {
9168 struct partial_die_info *part_die;
9169 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
9170 struct abbrev_info *abbrev;
9171 unsigned int bytes_read;
9172 unsigned int load_all = 0;
9173
9174 int nesting_level = 1;
9175
9176 parent_die = NULL;
9177 last_die = NULL;
9178
9179 if (cu->per_cu && cu->per_cu->load_all_dies)
9180 load_all = 1;
9181
9182 cu->partial_dies
9183 = htab_create_alloc_ex (cu->header.length / 12,
9184 partial_die_hash,
9185 partial_die_eq,
9186 NULL,
9187 &cu->comp_unit_obstack,
9188 hashtab_obstack_allocate,
9189 dummy_obstack_deallocate);
9190
9191 part_die = obstack_alloc (&cu->comp_unit_obstack,
9192 sizeof (struct partial_die_info));
9193
9194 while (1)
9195 {
9196 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
9197
9198 /* A NULL abbrev means the end of a series of children. */
9199 if (abbrev == NULL)
9200 {
9201 if (--nesting_level == 0)
9202 {
9203 /* PART_DIE was probably the last thing allocated on the
9204 comp_unit_obstack, so we could call obstack_free
9205 here. We don't do that because the waste is small,
9206 and will be cleaned up when we're done with this
9207 compilation unit. This way, we're also more robust
9208 against other users of the comp_unit_obstack. */
9209 return first_die;
9210 }
9211 info_ptr += bytes_read;
9212 last_die = parent_die;
9213 parent_die = parent_die->die_parent;
9214 continue;
9215 }
9216
9217 /* Check for template arguments. We never save these; if
9218 they're seen, we just mark the parent, and go on our way. */
9219 if (parent_die != NULL
9220 && cu->language == language_cplus
9221 && (abbrev->tag == DW_TAG_template_type_param
9222 || abbrev->tag == DW_TAG_template_value_param))
9223 {
9224 parent_die->has_template_arguments = 1;
9225
9226 if (!load_all)
9227 {
9228 /* We don't need a partial DIE for the template argument. */
9229 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev,
9230 cu);
9231 continue;
9232 }
9233 }
9234
9235 /* We only recurse into subprograms looking for template arguments.
9236 Skip their other children. */
9237 if (!load_all
9238 && cu->language == language_cplus
9239 && parent_die != NULL
9240 && parent_die->tag == DW_TAG_subprogram)
9241 {
9242 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9243 continue;
9244 }
9245
9246 /* Check whether this DIE is interesting enough to save. Normally
9247 we would not be interested in members here, but there may be
9248 later variables referencing them via DW_AT_specification (for
9249 static members). */
9250 if (!load_all
9251 && !is_type_tag_for_partial (abbrev->tag)
9252 && abbrev->tag != DW_TAG_constant
9253 && abbrev->tag != DW_TAG_enumerator
9254 && abbrev->tag != DW_TAG_subprogram
9255 && abbrev->tag != DW_TAG_lexical_block
9256 && abbrev->tag != DW_TAG_variable
9257 && abbrev->tag != DW_TAG_namespace
9258 && abbrev->tag != DW_TAG_module
9259 && abbrev->tag != DW_TAG_member)
9260 {
9261 /* Otherwise we skip to the next sibling, if any. */
9262 info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu);
9263 continue;
9264 }
9265
9266 info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd,
9267 buffer, info_ptr, cu);
9268
9269 /* This two-pass algorithm for processing partial symbols has a
9270 high cost in cache pressure. Thus, handle some simple cases
9271 here which cover the majority of C partial symbols. DIEs
9272 which neither have specification tags in them, nor could have
9273 specification tags elsewhere pointing at them, can simply be
9274 processed and discarded.
9275
9276 This segment is also optional; scan_partial_symbols and
9277 add_partial_symbol will handle these DIEs if we chain
9278 them in normally. When compilers which do not emit large
9279 quantities of duplicate debug information are more common,
9280 this code can probably be removed. */
9281
9282 /* Any complete simple types at the top level (pretty much all
9283 of them, for a language without namespaces), can be processed
9284 directly. */
9285 if (parent_die == NULL
9286 && part_die->has_specification == 0
9287 && part_die->is_declaration == 0
9288 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
9289 || part_die->tag == DW_TAG_base_type
9290 || part_die->tag == DW_TAG_subrange_type))
9291 {
9292 if (building_psymtab && part_die->name != NULL)
9293 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9294 VAR_DOMAIN, LOC_TYPEDEF,
9295 &cu->objfile->static_psymbols,
9296 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9297 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9298 continue;
9299 }
9300
9301 /* The exception for DW_TAG_typedef with has_children above is
9302 a workaround of GCC PR debug/47510. In the case of this complaint
9303 type_name_no_tag_or_error will error on such types later.
9304
9305 GDB skipped children of DW_TAG_typedef by the shortcut above and then
9306 it could not find the child DIEs referenced later, this is checked
9307 above. In correct DWARF DW_TAG_typedef should have no children. */
9308
9309 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
9310 complaint (&symfile_complaints,
9311 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
9312 "- DIE at 0x%x [in module %s]"),
9313 part_die->offset, cu->objfile->name);
9314
9315 /* If we're at the second level, and we're an enumerator, and
9316 our parent has no specification (meaning possibly lives in a
9317 namespace elsewhere), then we can add the partial symbol now
9318 instead of queueing it. */
9319 if (part_die->tag == DW_TAG_enumerator
9320 && parent_die != NULL
9321 && parent_die->die_parent == NULL
9322 && parent_die->tag == DW_TAG_enumeration_type
9323 && parent_die->has_specification == 0)
9324 {
9325 if (part_die->name == NULL)
9326 complaint (&symfile_complaints,
9327 _("malformed enumerator DIE ignored"));
9328 else if (building_psymtab)
9329 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
9330 VAR_DOMAIN, LOC_CONST,
9331 (cu->language == language_cplus
9332 || cu->language == language_java)
9333 ? &cu->objfile->global_psymbols
9334 : &cu->objfile->static_psymbols,
9335 0, (CORE_ADDR) 0, cu->language, cu->objfile);
9336
9337 info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
9338 continue;
9339 }
9340
9341 /* We'll save this DIE so link it in. */
9342 part_die->die_parent = parent_die;
9343 part_die->die_sibling = NULL;
9344 part_die->die_child = NULL;
9345
9346 if (last_die && last_die == parent_die)
9347 last_die->die_child = part_die;
9348 else if (last_die)
9349 last_die->die_sibling = part_die;
9350
9351 last_die = part_die;
9352
9353 if (first_die == NULL)
9354 first_die = part_die;
9355
9356 /* Maybe add the DIE to the hash table. Not all DIEs that we
9357 find interesting need to be in the hash table, because we
9358 also have the parent/sibling/child chains; only those that we
9359 might refer to by offset later during partial symbol reading.
9360
9361 For now this means things that might have be the target of a
9362 DW_AT_specification, DW_AT_abstract_origin, or
9363 DW_AT_extension. DW_AT_extension will refer only to
9364 namespaces; DW_AT_abstract_origin refers to functions (and
9365 many things under the function DIE, but we do not recurse
9366 into function DIEs during partial symbol reading) and
9367 possibly variables as well; DW_AT_specification refers to
9368 declarations. Declarations ought to have the DW_AT_declaration
9369 flag. It happens that GCC forgets to put it in sometimes, but
9370 only for functions, not for types.
9371
9372 Adding more things than necessary to the hash table is harmless
9373 except for the performance cost. Adding too few will result in
9374 wasted time in find_partial_die, when we reread the compilation
9375 unit with load_all_dies set. */
9376
9377 if (load_all
9378 || abbrev->tag == DW_TAG_constant
9379 || abbrev->tag == DW_TAG_subprogram
9380 || abbrev->tag == DW_TAG_variable
9381 || abbrev->tag == DW_TAG_namespace
9382 || part_die->is_declaration)
9383 {
9384 void **slot;
9385
9386 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
9387 part_die->offset, INSERT);
9388 *slot = part_die;
9389 }
9390
9391 part_die = obstack_alloc (&cu->comp_unit_obstack,
9392 sizeof (struct partial_die_info));
9393
9394 /* For some DIEs we want to follow their children (if any). For C
9395 we have no reason to follow the children of structures; for other
9396 languages we have to, so that we can get at method physnames
9397 to infer fully qualified class names, for DW_AT_specification,
9398 and for C++ template arguments. For C++, we also look one level
9399 inside functions to find template arguments (if the name of the
9400 function does not already contain the template arguments).
9401
9402 For Ada, we need to scan the children of subprograms and lexical
9403 blocks as well because Ada allows the definition of nested
9404 entities that could be interesting for the debugger, such as
9405 nested subprograms for instance. */
9406 if (last_die->has_children
9407 && (load_all
9408 || last_die->tag == DW_TAG_namespace
9409 || last_die->tag == DW_TAG_module
9410 || last_die->tag == DW_TAG_enumeration_type
9411 || (cu->language == language_cplus
9412 && last_die->tag == DW_TAG_subprogram
9413 && (last_die->name == NULL
9414 || strchr (last_die->name, '<') == NULL))
9415 || (cu->language != language_c
9416 && (last_die->tag == DW_TAG_class_type
9417 || last_die->tag == DW_TAG_interface_type
9418 || last_die->tag == DW_TAG_structure_type
9419 || last_die->tag == DW_TAG_union_type))
9420 || (cu->language == language_ada
9421 && (last_die->tag == DW_TAG_subprogram
9422 || last_die->tag == DW_TAG_lexical_block))))
9423 {
9424 nesting_level++;
9425 parent_die = last_die;
9426 continue;
9427 }
9428
9429 /* Otherwise we skip to the next sibling, if any. */
9430 info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu);
9431
9432 /* Back to the top, do it again. */
9433 }
9434 }
9435
9436 /* Read a minimal amount of information into the minimal die structure. */
9437
9438 static gdb_byte *
9439 read_partial_die (struct partial_die_info *part_die,
9440 struct abbrev_info *abbrev,
9441 unsigned int abbrev_len, bfd *abfd,
9442 gdb_byte *buffer, gdb_byte *info_ptr,
9443 struct dwarf2_cu *cu)
9444 {
9445 unsigned int i;
9446 struct attribute attr;
9447 int has_low_pc_attr = 0;
9448 int has_high_pc_attr = 0;
9449
9450 memset (part_die, 0, sizeof (struct partial_die_info));
9451
9452 part_die->offset = info_ptr - buffer;
9453
9454 info_ptr += abbrev_len;
9455
9456 if (abbrev == NULL)
9457 return info_ptr;
9458
9459 part_die->tag = abbrev->tag;
9460 part_die->has_children = abbrev->has_children;
9461
9462 for (i = 0; i < abbrev->num_attrs; ++i)
9463 {
9464 info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu);
9465
9466 /* Store the data if it is of an attribute we want to keep in a
9467 partial symbol table. */
9468 switch (attr.name)
9469 {
9470 case DW_AT_name:
9471 switch (part_die->tag)
9472 {
9473 case DW_TAG_compile_unit:
9474 case DW_TAG_type_unit:
9475 /* Compilation units have a DW_AT_name that is a filename, not
9476 a source language identifier. */
9477 case DW_TAG_enumeration_type:
9478 case DW_TAG_enumerator:
9479 /* These tags always have simple identifiers already; no need
9480 to canonicalize them. */
9481 part_die->name = DW_STRING (&attr);
9482 break;
9483 default:
9484 part_die->name
9485 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
9486 &cu->objfile->objfile_obstack);
9487 break;
9488 }
9489 break;
9490 case DW_AT_linkage_name:
9491 case DW_AT_MIPS_linkage_name:
9492 /* Note that both forms of linkage name might appear. We
9493 assume they will be the same, and we only store the last
9494 one we see. */
9495 if (cu->language == language_ada)
9496 part_die->name = DW_STRING (&attr);
9497 part_die->linkage_name = DW_STRING (&attr);
9498 break;
9499 case DW_AT_low_pc:
9500 has_low_pc_attr = 1;
9501 part_die->lowpc = DW_ADDR (&attr);
9502 break;
9503 case DW_AT_high_pc:
9504 has_high_pc_attr = 1;
9505 part_die->highpc = DW_ADDR (&attr);
9506 break;
9507 case DW_AT_location:
9508 /* Support the .debug_loc offsets. */
9509 if (attr_form_is_block (&attr))
9510 {
9511 part_die->locdesc = DW_BLOCK (&attr);
9512 }
9513 else if (attr_form_is_section_offset (&attr))
9514 {
9515 dwarf2_complex_location_expr_complaint ();
9516 }
9517 else
9518 {
9519 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9520 "partial symbol information");
9521 }
9522 break;
9523 case DW_AT_external:
9524 part_die->is_external = DW_UNSND (&attr);
9525 break;
9526 case DW_AT_declaration:
9527 part_die->is_declaration = DW_UNSND (&attr);
9528 break;
9529 case DW_AT_type:
9530 part_die->has_type = 1;
9531 break;
9532 case DW_AT_abstract_origin:
9533 case DW_AT_specification:
9534 case DW_AT_extension:
9535 part_die->has_specification = 1;
9536 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
9537 break;
9538 case DW_AT_sibling:
9539 /* Ignore absolute siblings, they might point outside of
9540 the current compile unit. */
9541 if (attr.form == DW_FORM_ref_addr)
9542 complaint (&symfile_complaints,
9543 _("ignoring absolute DW_AT_sibling"));
9544 else
9545 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr);
9546 break;
9547 case DW_AT_byte_size:
9548 part_die->has_byte_size = 1;
9549 break;
9550 case DW_AT_calling_convention:
9551 /* DWARF doesn't provide a way to identify a program's source-level
9552 entry point. DW_AT_calling_convention attributes are only meant
9553 to describe functions' calling conventions.
9554
9555 However, because it's a necessary piece of information in
9556 Fortran, and because DW_CC_program is the only piece of debugging
9557 information whose definition refers to a 'main program' at all,
9558 several compilers have begun marking Fortran main programs with
9559 DW_CC_program --- even when those functions use the standard
9560 calling conventions.
9561
9562 So until DWARF specifies a way to provide this information and
9563 compilers pick up the new representation, we'll support this
9564 practice. */
9565 if (DW_UNSND (&attr) == DW_CC_program
9566 && cu->language == language_fortran)
9567 {
9568 set_main_name (part_die->name);
9569
9570 /* As this DIE has a static linkage the name would be difficult
9571 to look up later. */
9572 language_of_main = language_fortran;
9573 }
9574 break;
9575 default:
9576 break;
9577 }
9578 }
9579
9580 if (has_low_pc_attr && has_high_pc_attr)
9581 {
9582 /* When using the GNU linker, .gnu.linkonce. sections are used to
9583 eliminate duplicate copies of functions and vtables and such.
9584 The linker will arbitrarily choose one and discard the others.
9585 The AT_*_pc values for such functions refer to local labels in
9586 these sections. If the section from that file was discarded, the
9587 labels are not in the output, so the relocs get a value of 0.
9588 If this is a discarded function, mark the pc bounds as invalid,
9589 so that GDB will ignore it. */
9590 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
9591 {
9592 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9593
9594 complaint (&symfile_complaints,
9595 _("DW_AT_low_pc %s is zero "
9596 "for DIE at 0x%x [in module %s]"),
9597 paddress (gdbarch, part_die->lowpc),
9598 part_die->offset, cu->objfile->name);
9599 }
9600 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9601 else if (part_die->lowpc >= part_die->highpc)
9602 {
9603 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
9604
9605 complaint (&symfile_complaints,
9606 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9607 "for DIE at 0x%x [in module %s]"),
9608 paddress (gdbarch, part_die->lowpc),
9609 paddress (gdbarch, part_die->highpc),
9610 part_die->offset, cu->objfile->name);
9611 }
9612 else
9613 part_die->has_pc_info = 1;
9614 }
9615
9616 return info_ptr;
9617 }
9618
9619 /* Find a cached partial DIE at OFFSET in CU. */
9620
9621 static struct partial_die_info *
9622 find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu)
9623 {
9624 struct partial_die_info *lookup_die = NULL;
9625 struct partial_die_info part_die;
9626
9627 part_die.offset = offset;
9628 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset);
9629
9630 return lookup_die;
9631 }
9632
9633 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9634 except in the case of .debug_types DIEs which do not reference
9635 outside their CU (they do however referencing other types via
9636 DW_FORM_ref_sig8). */
9637
9638 static struct partial_die_info *
9639 find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
9640 {
9641 struct dwarf2_per_cu_data *per_cu = NULL;
9642 struct partial_die_info *pd = NULL;
9643
9644 if (cu->per_cu->debug_type_section)
9645 {
9646 pd = find_partial_die_in_comp_unit (offset, cu);
9647 if (pd != NULL)
9648 return pd;
9649 goto not_found;
9650 }
9651
9652 if (offset_in_cu_p (&cu->header, offset))
9653 {
9654 pd = find_partial_die_in_comp_unit (offset, cu);
9655 if (pd != NULL)
9656 return pd;
9657 }
9658
9659 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
9660
9661 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
9662 load_partial_comp_unit (per_cu, cu->objfile);
9663
9664 per_cu->cu->last_used = 0;
9665 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9666
9667 if (pd == NULL && per_cu->load_all_dies == 0)
9668 {
9669 struct cleanup *back_to;
9670 struct partial_die_info comp_unit_die;
9671 struct abbrev_info *abbrev;
9672 unsigned int bytes_read;
9673 char *info_ptr;
9674
9675 per_cu->load_all_dies = 1;
9676
9677 /* Re-read the DIEs. */
9678 back_to = make_cleanup (null_cleanup, 0);
9679 if (per_cu->cu->dwarf2_abbrevs == NULL)
9680 {
9681 dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
9682 make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
9683 }
9684 info_ptr = (dwarf2_per_objfile->info.buffer
9685 + per_cu->cu->header.offset
9686 + per_cu->cu->header.first_die_offset);
9687 abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
9688 info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
9689 per_cu->cu->objfile->obfd,
9690 dwarf2_per_objfile->info.buffer, info_ptr,
9691 per_cu->cu);
9692 if (comp_unit_die.has_children)
9693 load_partial_dies (per_cu->cu->objfile->obfd,
9694 dwarf2_per_objfile->info.buffer, info_ptr,
9695 0, per_cu->cu);
9696 do_cleanups (back_to);
9697
9698 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
9699 }
9700
9701 not_found:
9702
9703 if (pd == NULL)
9704 internal_error (__FILE__, __LINE__,
9705 _("could not find partial DIE 0x%x "
9706 "in cache [from module %s]\n"),
9707 offset, bfd_get_filename (cu->objfile->obfd));
9708 return pd;
9709 }
9710
9711 /* See if we can figure out if the class lives in a namespace. We do
9712 this by looking for a member function; its demangled name will
9713 contain namespace info, if there is any. */
9714
9715 static void
9716 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
9717 struct dwarf2_cu *cu)
9718 {
9719 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9720 what template types look like, because the demangler
9721 frequently doesn't give the same name as the debug info. We
9722 could fix this by only using the demangled name to get the
9723 prefix (but see comment in read_structure_type). */
9724
9725 struct partial_die_info *real_pdi;
9726 struct partial_die_info *child_pdi;
9727
9728 /* If this DIE (this DIE's specification, if any) has a parent, then
9729 we should not do this. We'll prepend the parent's fully qualified
9730 name when we create the partial symbol. */
9731
9732 real_pdi = struct_pdi;
9733 while (real_pdi->has_specification)
9734 real_pdi = find_partial_die (real_pdi->spec_offset, cu);
9735
9736 if (real_pdi->die_parent != NULL)
9737 return;
9738
9739 for (child_pdi = struct_pdi->die_child;
9740 child_pdi != NULL;
9741 child_pdi = child_pdi->die_sibling)
9742 {
9743 if (child_pdi->tag == DW_TAG_subprogram
9744 && child_pdi->linkage_name != NULL)
9745 {
9746 char *actual_class_name
9747 = language_class_name_from_physname (cu->language_defn,
9748 child_pdi->linkage_name);
9749 if (actual_class_name != NULL)
9750 {
9751 struct_pdi->name
9752 = obsavestring (actual_class_name,
9753 strlen (actual_class_name),
9754 &cu->objfile->objfile_obstack);
9755 xfree (actual_class_name);
9756 }
9757 break;
9758 }
9759 }
9760 }
9761
9762 /* Adjust PART_DIE before generating a symbol for it. This function
9763 may set the is_external flag or change the DIE's name. */
9764
9765 static void
9766 fixup_partial_die (struct partial_die_info *part_die,
9767 struct dwarf2_cu *cu)
9768 {
9769 /* Once we've fixed up a die, there's no point in doing so again.
9770 This also avoids a memory leak if we were to call
9771 guess_partial_die_structure_name multiple times. */
9772 if (part_die->fixup_called)
9773 return;
9774
9775 /* If we found a reference attribute and the DIE has no name, try
9776 to find a name in the referred to DIE. */
9777
9778 if (part_die->name == NULL && part_die->has_specification)
9779 {
9780 struct partial_die_info *spec_die;
9781
9782 spec_die = find_partial_die (part_die->spec_offset, cu);
9783
9784 fixup_partial_die (spec_die, cu);
9785
9786 if (spec_die->name)
9787 {
9788 part_die->name = spec_die->name;
9789
9790 /* Copy DW_AT_external attribute if it is set. */
9791 if (spec_die->is_external)
9792 part_die->is_external = spec_die->is_external;
9793 }
9794 }
9795
9796 /* Set default names for some unnamed DIEs. */
9797
9798 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
9799 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
9800
9801 /* If there is no parent die to provide a namespace, and there are
9802 children, see if we can determine the namespace from their linkage
9803 name.
9804 NOTE: We need to do this even if cu->has_namespace_info != 0.
9805 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9806 if (cu->language == language_cplus
9807 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
9808 && part_die->die_parent == NULL
9809 && part_die->has_children
9810 && (part_die->tag == DW_TAG_class_type
9811 || part_die->tag == DW_TAG_structure_type
9812 || part_die->tag == DW_TAG_union_type))
9813 guess_partial_die_structure_name (part_die, cu);
9814
9815 /* GCC might emit a nameless struct or union that has a linkage
9816 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9817 if (part_die->name == NULL
9818 && (part_die->tag == DW_TAG_class_type
9819 || part_die->tag == DW_TAG_interface_type
9820 || part_die->tag == DW_TAG_structure_type
9821 || part_die->tag == DW_TAG_union_type)
9822 && part_die->linkage_name != NULL)
9823 {
9824 char *demangled;
9825
9826 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
9827 if (demangled)
9828 {
9829 const char *base;
9830
9831 /* Strip any leading namespaces/classes, keep only the base name.
9832 DW_AT_name for named DIEs does not contain the prefixes. */
9833 base = strrchr (demangled, ':');
9834 if (base && base > demangled && base[-1] == ':')
9835 base++;
9836 else
9837 base = demangled;
9838
9839 part_die->name = obsavestring (base, strlen (base),
9840 &cu->objfile->objfile_obstack);
9841 xfree (demangled);
9842 }
9843 }
9844
9845 part_die->fixup_called = 1;
9846 }
9847
9848 /* Read an attribute value described by an attribute form. */
9849
9850 static gdb_byte *
9851 read_attribute_value (struct attribute *attr, unsigned form,
9852 bfd *abfd, gdb_byte *info_ptr,
9853 struct dwarf2_cu *cu)
9854 {
9855 struct comp_unit_head *cu_header = &cu->header;
9856 unsigned int bytes_read;
9857 struct dwarf_block *blk;
9858
9859 attr->form = form;
9860 switch (form)
9861 {
9862 case DW_FORM_ref_addr:
9863 if (cu->header.version == 2)
9864 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9865 else
9866 DW_ADDR (attr) = read_offset (abfd, info_ptr,
9867 &cu->header, &bytes_read);
9868 info_ptr += bytes_read;
9869 break;
9870 case DW_FORM_addr:
9871 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
9872 info_ptr += bytes_read;
9873 break;
9874 case DW_FORM_block2:
9875 blk = dwarf_alloc_block (cu);
9876 blk->size = read_2_bytes (abfd, info_ptr);
9877 info_ptr += 2;
9878 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9879 info_ptr += blk->size;
9880 DW_BLOCK (attr) = blk;
9881 break;
9882 case DW_FORM_block4:
9883 blk = dwarf_alloc_block (cu);
9884 blk->size = read_4_bytes (abfd, info_ptr);
9885 info_ptr += 4;
9886 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9887 info_ptr += blk->size;
9888 DW_BLOCK (attr) = blk;
9889 break;
9890 case DW_FORM_data2:
9891 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
9892 info_ptr += 2;
9893 break;
9894 case DW_FORM_data4:
9895 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
9896 info_ptr += 4;
9897 break;
9898 case DW_FORM_data8:
9899 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
9900 info_ptr += 8;
9901 break;
9902 case DW_FORM_sec_offset:
9903 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
9904 info_ptr += bytes_read;
9905 break;
9906 case DW_FORM_string:
9907 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
9908 DW_STRING_IS_CANONICAL (attr) = 0;
9909 info_ptr += bytes_read;
9910 break;
9911 case DW_FORM_strp:
9912 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
9913 &bytes_read);
9914 DW_STRING_IS_CANONICAL (attr) = 0;
9915 info_ptr += bytes_read;
9916 break;
9917 case DW_FORM_exprloc:
9918 case DW_FORM_block:
9919 blk = dwarf_alloc_block (cu);
9920 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9921 info_ptr += bytes_read;
9922 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9923 info_ptr += blk->size;
9924 DW_BLOCK (attr) = blk;
9925 break;
9926 case DW_FORM_block1:
9927 blk = dwarf_alloc_block (cu);
9928 blk->size = read_1_byte (abfd, info_ptr);
9929 info_ptr += 1;
9930 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
9931 info_ptr += blk->size;
9932 DW_BLOCK (attr) = blk;
9933 break;
9934 case DW_FORM_data1:
9935 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9936 info_ptr += 1;
9937 break;
9938 case DW_FORM_flag:
9939 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
9940 info_ptr += 1;
9941 break;
9942 case DW_FORM_flag_present:
9943 DW_UNSND (attr) = 1;
9944 break;
9945 case DW_FORM_sdata:
9946 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
9947 info_ptr += bytes_read;
9948 break;
9949 case DW_FORM_udata:
9950 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9951 info_ptr += bytes_read;
9952 break;
9953 case DW_FORM_ref1:
9954 DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr);
9955 info_ptr += 1;
9956 break;
9957 case DW_FORM_ref2:
9958 DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr);
9959 info_ptr += 2;
9960 break;
9961 case DW_FORM_ref4:
9962 DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr);
9963 info_ptr += 4;
9964 break;
9965 case DW_FORM_ref8:
9966 DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr);
9967 info_ptr += 8;
9968 break;
9969 case DW_FORM_ref_sig8:
9970 /* Convert the signature to something we can record in DW_UNSND
9971 for later lookup.
9972 NOTE: This is NULL if the type wasn't found. */
9973 DW_SIGNATURED_TYPE (attr) =
9974 lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr));
9975 info_ptr += 8;
9976 break;
9977 case DW_FORM_ref_udata:
9978 DW_ADDR (attr) = (cu->header.offset
9979 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
9980 info_ptr += bytes_read;
9981 break;
9982 case DW_FORM_indirect:
9983 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
9984 info_ptr += bytes_read;
9985 info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu);
9986 break;
9987 default:
9988 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9989 dwarf_form_name (form),
9990 bfd_get_filename (abfd));
9991 }
9992
9993 /* We have seen instances where the compiler tried to emit a byte
9994 size attribute of -1 which ended up being encoded as an unsigned
9995 0xffffffff. Although 0xffffffff is technically a valid size value,
9996 an object of this size seems pretty unlikely so we can relatively
9997 safely treat these cases as if the size attribute was invalid and
9998 treat them as zero by default. */
9999 if (attr->name == DW_AT_byte_size
10000 && form == DW_FORM_data4
10001 && DW_UNSND (attr) >= 0xffffffff)
10002 {
10003 complaint
10004 (&symfile_complaints,
10005 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
10006 hex_string (DW_UNSND (attr)));
10007 DW_UNSND (attr) = 0;
10008 }
10009
10010 return info_ptr;
10011 }
10012
10013 /* Read an attribute described by an abbreviated attribute. */
10014
10015 static gdb_byte *
10016 read_attribute (struct attribute *attr, struct attr_abbrev *abbrev,
10017 bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu)
10018 {
10019 attr->name = abbrev->name;
10020 return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu);
10021 }
10022
10023 /* Read dwarf information from a buffer. */
10024
10025 static unsigned int
10026 read_1_byte (bfd *abfd, gdb_byte *buf)
10027 {
10028 return bfd_get_8 (abfd, buf);
10029 }
10030
10031 static int
10032 read_1_signed_byte (bfd *abfd, gdb_byte *buf)
10033 {
10034 return bfd_get_signed_8 (abfd, buf);
10035 }
10036
10037 static unsigned int
10038 read_2_bytes (bfd *abfd, gdb_byte *buf)
10039 {
10040 return bfd_get_16 (abfd, buf);
10041 }
10042
10043 static unsigned int
10044 read_4_bytes (bfd *abfd, gdb_byte *buf)
10045 {
10046 return bfd_get_32 (abfd, buf);
10047 }
10048
10049 static ULONGEST
10050 read_8_bytes (bfd *abfd, gdb_byte *buf)
10051 {
10052 return bfd_get_64 (abfd, buf);
10053 }
10054
10055 static CORE_ADDR
10056 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
10057 unsigned int *bytes_read)
10058 {
10059 struct comp_unit_head *cu_header = &cu->header;
10060 CORE_ADDR retval = 0;
10061
10062 if (cu_header->signed_addr_p)
10063 {
10064 switch (cu_header->addr_size)
10065 {
10066 case 2:
10067 retval = bfd_get_signed_16 (abfd, buf);
10068 break;
10069 case 4:
10070 retval = bfd_get_signed_32 (abfd, buf);
10071 break;
10072 case 8:
10073 retval = bfd_get_signed_64 (abfd, buf);
10074 break;
10075 default:
10076 internal_error (__FILE__, __LINE__,
10077 _("read_address: bad switch, signed [in module %s]"),
10078 bfd_get_filename (abfd));
10079 }
10080 }
10081 else
10082 {
10083 switch (cu_header->addr_size)
10084 {
10085 case 2:
10086 retval = bfd_get_16 (abfd, buf);
10087 break;
10088 case 4:
10089 retval = bfd_get_32 (abfd, buf);
10090 break;
10091 case 8:
10092 retval = bfd_get_64 (abfd, buf);
10093 break;
10094 default:
10095 internal_error (__FILE__, __LINE__,
10096 _("read_address: bad switch, "
10097 "unsigned [in module %s]"),
10098 bfd_get_filename (abfd));
10099 }
10100 }
10101
10102 *bytes_read = cu_header->addr_size;
10103 return retval;
10104 }
10105
10106 /* Read the initial length from a section. The (draft) DWARF 3
10107 specification allows the initial length to take up either 4 bytes
10108 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
10109 bytes describe the length and all offsets will be 8 bytes in length
10110 instead of 4.
10111
10112 An older, non-standard 64-bit format is also handled by this
10113 function. The older format in question stores the initial length
10114 as an 8-byte quantity without an escape value. Lengths greater
10115 than 2^32 aren't very common which means that the initial 4 bytes
10116 is almost always zero. Since a length value of zero doesn't make
10117 sense for the 32-bit format, this initial zero can be considered to
10118 be an escape value which indicates the presence of the older 64-bit
10119 format. As written, the code can't detect (old format) lengths
10120 greater than 4GB. If it becomes necessary to handle lengths
10121 somewhat larger than 4GB, we could allow other small values (such
10122 as the non-sensical values of 1, 2, and 3) to also be used as
10123 escape values indicating the presence of the old format.
10124
10125 The value returned via bytes_read should be used to increment the
10126 relevant pointer after calling read_initial_length().
10127
10128 [ Note: read_initial_length() and read_offset() are based on the
10129 document entitled "DWARF Debugging Information Format", revision
10130 3, draft 8, dated November 19, 2001. This document was obtained
10131 from:
10132
10133 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
10134
10135 This document is only a draft and is subject to change. (So beware.)
10136
10137 Details regarding the older, non-standard 64-bit format were
10138 determined empirically by examining 64-bit ELF files produced by
10139 the SGI toolchain on an IRIX 6.5 machine.
10140
10141 - Kevin, July 16, 2002
10142 ] */
10143
10144 static LONGEST
10145 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
10146 {
10147 LONGEST length = bfd_get_32 (abfd, buf);
10148
10149 if (length == 0xffffffff)
10150 {
10151 length = bfd_get_64 (abfd, buf + 4);
10152 *bytes_read = 12;
10153 }
10154 else if (length == 0)
10155 {
10156 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
10157 length = bfd_get_64 (abfd, buf);
10158 *bytes_read = 8;
10159 }
10160 else
10161 {
10162 *bytes_read = 4;
10163 }
10164
10165 return length;
10166 }
10167
10168 /* Cover function for read_initial_length.
10169 Returns the length of the object at BUF, and stores the size of the
10170 initial length in *BYTES_READ and stores the size that offsets will be in
10171 *OFFSET_SIZE.
10172 If the initial length size is not equivalent to that specified in
10173 CU_HEADER then issue a complaint.
10174 This is useful when reading non-comp-unit headers. */
10175
10176 static LONGEST
10177 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
10178 const struct comp_unit_head *cu_header,
10179 unsigned int *bytes_read,
10180 unsigned int *offset_size)
10181 {
10182 LONGEST length = read_initial_length (abfd, buf, bytes_read);
10183
10184 gdb_assert (cu_header->initial_length_size == 4
10185 || cu_header->initial_length_size == 8
10186 || cu_header->initial_length_size == 12);
10187
10188 if (cu_header->initial_length_size != *bytes_read)
10189 complaint (&symfile_complaints,
10190 _("intermixed 32-bit and 64-bit DWARF sections"));
10191
10192 *offset_size = (*bytes_read == 4) ? 4 : 8;
10193 return length;
10194 }
10195
10196 /* Read an offset from the data stream. The size of the offset is
10197 given by cu_header->offset_size. */
10198
10199 static LONGEST
10200 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
10201 unsigned int *bytes_read)
10202 {
10203 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
10204
10205 *bytes_read = cu_header->offset_size;
10206 return offset;
10207 }
10208
10209 /* Read an offset from the data stream. */
10210
10211 static LONGEST
10212 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
10213 {
10214 LONGEST retval = 0;
10215
10216 switch (offset_size)
10217 {
10218 case 4:
10219 retval = bfd_get_32 (abfd, buf);
10220 break;
10221 case 8:
10222 retval = bfd_get_64 (abfd, buf);
10223 break;
10224 default:
10225 internal_error (__FILE__, __LINE__,
10226 _("read_offset_1: bad switch [in module %s]"),
10227 bfd_get_filename (abfd));
10228 }
10229
10230 return retval;
10231 }
10232
10233 static gdb_byte *
10234 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
10235 {
10236 /* If the size of a host char is 8 bits, we can return a pointer
10237 to the buffer, otherwise we have to copy the data to a buffer
10238 allocated on the temporary obstack. */
10239 gdb_assert (HOST_CHAR_BIT == 8);
10240 return buf;
10241 }
10242
10243 static char *
10244 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10245 {
10246 /* If the size of a host char is 8 bits, we can return a pointer
10247 to the string, otherwise we have to copy the string to a buffer
10248 allocated on the temporary obstack. */
10249 gdb_assert (HOST_CHAR_BIT == 8);
10250 if (*buf == '\0')
10251 {
10252 *bytes_read_ptr = 1;
10253 return NULL;
10254 }
10255 *bytes_read_ptr = strlen ((char *) buf) + 1;
10256 return (char *) buf;
10257 }
10258
10259 static char *
10260 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
10261 {
10262 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
10263 if (dwarf2_per_objfile->str.buffer == NULL)
10264 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
10265 bfd_get_filename (abfd));
10266 if (str_offset >= dwarf2_per_objfile->str.size)
10267 error (_("DW_FORM_strp pointing outside of "
10268 ".debug_str section [in module %s]"),
10269 bfd_get_filename (abfd));
10270 gdb_assert (HOST_CHAR_BIT == 8);
10271 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
10272 return NULL;
10273 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
10274 }
10275
10276 static char *
10277 read_indirect_string (bfd *abfd, gdb_byte *buf,
10278 const struct comp_unit_head *cu_header,
10279 unsigned int *bytes_read_ptr)
10280 {
10281 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
10282
10283 return read_indirect_string_at_offset (abfd, str_offset);
10284 }
10285
10286 static unsigned long
10287 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10288 {
10289 unsigned long result;
10290 unsigned int num_read;
10291 int i, shift;
10292 unsigned char byte;
10293
10294 result = 0;
10295 shift = 0;
10296 num_read = 0;
10297 i = 0;
10298 while (1)
10299 {
10300 byte = bfd_get_8 (abfd, buf);
10301 buf++;
10302 num_read++;
10303 result |= ((unsigned long)(byte & 127) << shift);
10304 if ((byte & 128) == 0)
10305 {
10306 break;
10307 }
10308 shift += 7;
10309 }
10310 *bytes_read_ptr = num_read;
10311 return result;
10312 }
10313
10314 static long
10315 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
10316 {
10317 long result;
10318 int i, shift, num_read;
10319 unsigned char byte;
10320
10321 result = 0;
10322 shift = 0;
10323 num_read = 0;
10324 i = 0;
10325 while (1)
10326 {
10327 byte = bfd_get_8 (abfd, buf);
10328 buf++;
10329 num_read++;
10330 result |= ((long)(byte & 127) << shift);
10331 shift += 7;
10332 if ((byte & 128) == 0)
10333 {
10334 break;
10335 }
10336 }
10337 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
10338 result |= -(((long)1) << shift);
10339 *bytes_read_ptr = num_read;
10340 return result;
10341 }
10342
10343 /* Return a pointer to just past the end of an LEB128 number in BUF. */
10344
10345 static gdb_byte *
10346 skip_leb128 (bfd *abfd, gdb_byte *buf)
10347 {
10348 int byte;
10349
10350 while (1)
10351 {
10352 byte = bfd_get_8 (abfd, buf);
10353 buf++;
10354 if ((byte & 128) == 0)
10355 return buf;
10356 }
10357 }
10358
10359 static void
10360 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
10361 {
10362 switch (lang)
10363 {
10364 case DW_LANG_C89:
10365 case DW_LANG_C99:
10366 case DW_LANG_C:
10367 cu->language = language_c;
10368 break;
10369 case DW_LANG_C_plus_plus:
10370 cu->language = language_cplus;
10371 break;
10372 case DW_LANG_D:
10373 cu->language = language_d;
10374 break;
10375 case DW_LANG_Fortran77:
10376 case DW_LANG_Fortran90:
10377 case DW_LANG_Fortran95:
10378 cu->language = language_fortran;
10379 break;
10380 case DW_LANG_Mips_Assembler:
10381 cu->language = language_asm;
10382 break;
10383 case DW_LANG_Java:
10384 cu->language = language_java;
10385 break;
10386 case DW_LANG_Ada83:
10387 case DW_LANG_Ada95:
10388 cu->language = language_ada;
10389 break;
10390 case DW_LANG_Modula2:
10391 cu->language = language_m2;
10392 break;
10393 case DW_LANG_Pascal83:
10394 cu->language = language_pascal;
10395 break;
10396 case DW_LANG_ObjC:
10397 cu->language = language_objc;
10398 break;
10399 case DW_LANG_Cobol74:
10400 case DW_LANG_Cobol85:
10401 default:
10402 cu->language = language_minimal;
10403 break;
10404 }
10405 cu->language_defn = language_def (cu->language);
10406 }
10407
10408 /* Return the named attribute or NULL if not there. */
10409
10410 static struct attribute *
10411 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
10412 {
10413 unsigned int i;
10414 struct attribute *spec = NULL;
10415
10416 for (i = 0; i < die->num_attrs; ++i)
10417 {
10418 if (die->attrs[i].name == name)
10419 return &die->attrs[i];
10420 if (die->attrs[i].name == DW_AT_specification
10421 || die->attrs[i].name == DW_AT_abstract_origin)
10422 spec = &die->attrs[i];
10423 }
10424
10425 if (spec)
10426 {
10427 die = follow_die_ref (die, spec, &cu);
10428 return dwarf2_attr (die, name, cu);
10429 }
10430
10431 return NULL;
10432 }
10433
10434 /* Return the named attribute or NULL if not there,
10435 but do not follow DW_AT_specification, etc.
10436 This is for use in contexts where we're reading .debug_types dies.
10437 Following DW_AT_specification, DW_AT_abstract_origin will take us
10438 back up the chain, and we want to go down. */
10439
10440 static struct attribute *
10441 dwarf2_attr_no_follow (struct die_info *die, unsigned int name,
10442 struct dwarf2_cu *cu)
10443 {
10444 unsigned int i;
10445
10446 for (i = 0; i < die->num_attrs; ++i)
10447 if (die->attrs[i].name == name)
10448 return &die->attrs[i];
10449
10450 return NULL;
10451 }
10452
10453 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10454 and holds a non-zero value. This function should only be used for
10455 DW_FORM_flag or DW_FORM_flag_present attributes. */
10456
10457 static int
10458 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
10459 {
10460 struct attribute *attr = dwarf2_attr (die, name, cu);
10461
10462 return (attr && DW_UNSND (attr));
10463 }
10464
10465 static int
10466 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
10467 {
10468 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10469 which value is non-zero. However, we have to be careful with
10470 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10471 (via dwarf2_flag_true_p) follows this attribute. So we may
10472 end up accidently finding a declaration attribute that belongs
10473 to a different DIE referenced by the specification attribute,
10474 even though the given DIE does not have a declaration attribute. */
10475 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
10476 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
10477 }
10478
10479 /* Return the die giving the specification for DIE, if there is
10480 one. *SPEC_CU is the CU containing DIE on input, and the CU
10481 containing the return value on output. If there is no
10482 specification, but there is an abstract origin, that is
10483 returned. */
10484
10485 static struct die_info *
10486 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
10487 {
10488 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
10489 *spec_cu);
10490
10491 if (spec_attr == NULL)
10492 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
10493
10494 if (spec_attr == NULL)
10495 return NULL;
10496 else
10497 return follow_die_ref (die, spec_attr, spec_cu);
10498 }
10499
10500 /* Free the line_header structure *LH, and any arrays and strings it
10501 refers to.
10502 NOTE: This is also used as a "cleanup" function. */
10503
10504 static void
10505 free_line_header (struct line_header *lh)
10506 {
10507 if (lh->standard_opcode_lengths)
10508 xfree (lh->standard_opcode_lengths);
10509
10510 /* Remember that all the lh->file_names[i].name pointers are
10511 pointers into debug_line_buffer, and don't need to be freed. */
10512 if (lh->file_names)
10513 xfree (lh->file_names);
10514
10515 /* Similarly for the include directory names. */
10516 if (lh->include_dirs)
10517 xfree (lh->include_dirs);
10518
10519 xfree (lh);
10520 }
10521
10522 /* Add an entry to LH's include directory table. */
10523
10524 static void
10525 add_include_dir (struct line_header *lh, char *include_dir)
10526 {
10527 /* Grow the array if necessary. */
10528 if (lh->include_dirs_size == 0)
10529 {
10530 lh->include_dirs_size = 1; /* for testing */
10531 lh->include_dirs = xmalloc (lh->include_dirs_size
10532 * sizeof (*lh->include_dirs));
10533 }
10534 else if (lh->num_include_dirs >= lh->include_dirs_size)
10535 {
10536 lh->include_dirs_size *= 2;
10537 lh->include_dirs = xrealloc (lh->include_dirs,
10538 (lh->include_dirs_size
10539 * sizeof (*lh->include_dirs)));
10540 }
10541
10542 lh->include_dirs[lh->num_include_dirs++] = include_dir;
10543 }
10544
10545 /* Add an entry to LH's file name table. */
10546
10547 static void
10548 add_file_name (struct line_header *lh,
10549 char *name,
10550 unsigned int dir_index,
10551 unsigned int mod_time,
10552 unsigned int length)
10553 {
10554 struct file_entry *fe;
10555
10556 /* Grow the array if necessary. */
10557 if (lh->file_names_size == 0)
10558 {
10559 lh->file_names_size = 1; /* for testing */
10560 lh->file_names = xmalloc (lh->file_names_size
10561 * sizeof (*lh->file_names));
10562 }
10563 else if (lh->num_file_names >= lh->file_names_size)
10564 {
10565 lh->file_names_size *= 2;
10566 lh->file_names = xrealloc (lh->file_names,
10567 (lh->file_names_size
10568 * sizeof (*lh->file_names)));
10569 }
10570
10571 fe = &lh->file_names[lh->num_file_names++];
10572 fe->name = name;
10573 fe->dir_index = dir_index;
10574 fe->mod_time = mod_time;
10575 fe->length = length;
10576 fe->included_p = 0;
10577 fe->symtab = NULL;
10578 }
10579
10580 /* Read the statement program header starting at OFFSET in
10581 .debug_line, according to the endianness of ABFD. Return a pointer
10582 to a struct line_header, allocated using xmalloc.
10583
10584 NOTE: the strings in the include directory and file name tables of
10585 the returned object point into debug_line_buffer, and must not be
10586 freed. */
10587
10588 static struct line_header *
10589 dwarf_decode_line_header (unsigned int offset, bfd *abfd,
10590 struct dwarf2_cu *cu)
10591 {
10592 struct cleanup *back_to;
10593 struct line_header *lh;
10594 gdb_byte *line_ptr;
10595 unsigned int bytes_read, offset_size;
10596 int i;
10597 char *cur_dir, *cur_file;
10598
10599 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line);
10600 if (dwarf2_per_objfile->line.buffer == NULL)
10601 {
10602 complaint (&symfile_complaints, _("missing .debug_line section"));
10603 return 0;
10604 }
10605
10606 /* Make sure that at least there's room for the total_length field.
10607 That could be 12 bytes long, but we're just going to fudge that. */
10608 if (offset + 4 >= dwarf2_per_objfile->line.size)
10609 {
10610 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10611 return 0;
10612 }
10613
10614 lh = xmalloc (sizeof (*lh));
10615 memset (lh, 0, sizeof (*lh));
10616 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
10617 (void *) lh);
10618
10619 line_ptr = dwarf2_per_objfile->line.buffer + offset;
10620
10621 /* Read in the header. */
10622 lh->total_length =
10623 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
10624 &bytes_read, &offset_size);
10625 line_ptr += bytes_read;
10626 if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer
10627 + dwarf2_per_objfile->line.size))
10628 {
10629 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10630 return 0;
10631 }
10632 lh->statement_program_end = line_ptr + lh->total_length;
10633 lh->version = read_2_bytes (abfd, line_ptr);
10634 line_ptr += 2;
10635 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
10636 line_ptr += offset_size;
10637 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
10638 line_ptr += 1;
10639 if (lh->version >= 4)
10640 {
10641 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
10642 line_ptr += 1;
10643 }
10644 else
10645 lh->maximum_ops_per_instruction = 1;
10646
10647 if (lh->maximum_ops_per_instruction == 0)
10648 {
10649 lh->maximum_ops_per_instruction = 1;
10650 complaint (&symfile_complaints,
10651 _("invalid maximum_ops_per_instruction "
10652 "in `.debug_line' section"));
10653 }
10654
10655 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
10656 line_ptr += 1;
10657 lh->line_base = read_1_signed_byte (abfd, line_ptr);
10658 line_ptr += 1;
10659 lh->line_range = read_1_byte (abfd, line_ptr);
10660 line_ptr += 1;
10661 lh->opcode_base = read_1_byte (abfd, line_ptr);
10662 line_ptr += 1;
10663 lh->standard_opcode_lengths
10664 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
10665
10666 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
10667 for (i = 1; i < lh->opcode_base; ++i)
10668 {
10669 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
10670 line_ptr += 1;
10671 }
10672
10673 /* Read directory table. */
10674 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10675 {
10676 line_ptr += bytes_read;
10677 add_include_dir (lh, cur_dir);
10678 }
10679 line_ptr += bytes_read;
10680
10681 /* Read file name table. */
10682 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
10683 {
10684 unsigned int dir_index, mod_time, length;
10685
10686 line_ptr += bytes_read;
10687 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10688 line_ptr += bytes_read;
10689 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10690 line_ptr += bytes_read;
10691 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
10692 line_ptr += bytes_read;
10693
10694 add_file_name (lh, cur_file, dir_index, mod_time, length);
10695 }
10696 line_ptr += bytes_read;
10697 lh->statement_program_start = line_ptr;
10698
10699 if (line_ptr > (dwarf2_per_objfile->line.buffer
10700 + dwarf2_per_objfile->line.size))
10701 complaint (&symfile_complaints,
10702 _("line number info header doesn't "
10703 "fit in `.debug_line' section"));
10704
10705 discard_cleanups (back_to);
10706 return lh;
10707 }
10708
10709 /* This function exists to work around a bug in certain compilers
10710 (particularly GCC 2.95), in which the first line number marker of a
10711 function does not show up until after the prologue, right before
10712 the second line number marker. This function shifts ADDRESS down
10713 to the beginning of the function if necessary, and is called on
10714 addresses passed to record_line. */
10715
10716 static CORE_ADDR
10717 check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu)
10718 {
10719 struct function_range *fn;
10720
10721 /* Find the function_range containing address. */
10722 if (!cu->first_fn)
10723 return address;
10724
10725 if (!cu->cached_fn)
10726 cu->cached_fn = cu->first_fn;
10727
10728 fn = cu->cached_fn;
10729 while (fn)
10730 if (fn->lowpc <= address && fn->highpc > address)
10731 goto found;
10732 else
10733 fn = fn->next;
10734
10735 fn = cu->first_fn;
10736 while (fn && fn != cu->cached_fn)
10737 if (fn->lowpc <= address && fn->highpc > address)
10738 goto found;
10739 else
10740 fn = fn->next;
10741
10742 return address;
10743
10744 found:
10745 if (fn->seen_line)
10746 return address;
10747 if (address != fn->lowpc)
10748 complaint (&symfile_complaints,
10749 _("misplaced first line number at 0x%lx for '%s'"),
10750 (unsigned long) address, fn->name);
10751 fn->seen_line = 1;
10752 return fn->lowpc;
10753 }
10754
10755 /* Subroutine of dwarf_decode_lines to simplify it.
10756 Return the file name of the psymtab for included file FILE_INDEX
10757 in line header LH of PST.
10758 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10759 If space for the result is malloc'd, it will be freed by a cleanup.
10760 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10761
10762 static char *
10763 psymtab_include_file_name (const struct line_header *lh, int file_index,
10764 const struct partial_symtab *pst,
10765 const char *comp_dir)
10766 {
10767 const struct file_entry fe = lh->file_names [file_index];
10768 char *include_name = fe.name;
10769 char *include_name_to_compare = include_name;
10770 char *dir_name = NULL;
10771 const char *pst_filename;
10772 char *copied_name = NULL;
10773 int file_is_pst;
10774
10775 if (fe.dir_index)
10776 dir_name = lh->include_dirs[fe.dir_index - 1];
10777
10778 if (!IS_ABSOLUTE_PATH (include_name)
10779 && (dir_name != NULL || comp_dir != NULL))
10780 {
10781 /* Avoid creating a duplicate psymtab for PST.
10782 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10783 Before we do the comparison, however, we need to account
10784 for DIR_NAME and COMP_DIR.
10785 First prepend dir_name (if non-NULL). If we still don't
10786 have an absolute path prepend comp_dir (if non-NULL).
10787 However, the directory we record in the include-file's
10788 psymtab does not contain COMP_DIR (to match the
10789 corresponding symtab(s)).
10790
10791 Example:
10792
10793 bash$ cd /tmp
10794 bash$ gcc -g ./hello.c
10795 include_name = "hello.c"
10796 dir_name = "."
10797 DW_AT_comp_dir = comp_dir = "/tmp"
10798 DW_AT_name = "./hello.c" */
10799
10800 if (dir_name != NULL)
10801 {
10802 include_name = concat (dir_name, SLASH_STRING,
10803 include_name, (char *)NULL);
10804 include_name_to_compare = include_name;
10805 make_cleanup (xfree, include_name);
10806 }
10807 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
10808 {
10809 include_name_to_compare = concat (comp_dir, SLASH_STRING,
10810 include_name, (char *)NULL);
10811 }
10812 }
10813
10814 pst_filename = pst->filename;
10815 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
10816 {
10817 copied_name = concat (pst->dirname, SLASH_STRING,
10818 pst_filename, (char *)NULL);
10819 pst_filename = copied_name;
10820 }
10821
10822 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
10823
10824 if (include_name_to_compare != include_name)
10825 xfree (include_name_to_compare);
10826 if (copied_name != NULL)
10827 xfree (copied_name);
10828
10829 if (file_is_pst)
10830 return NULL;
10831 return include_name;
10832 }
10833
10834 /* Ignore this record_line request. */
10835
10836 static void
10837 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
10838 {
10839 return;
10840 }
10841
10842 /* Decode the Line Number Program (LNP) for the given line_header
10843 structure and CU. The actual information extracted and the type
10844 of structures created from the LNP depends on the value of PST.
10845
10846 1. If PST is NULL, then this procedure uses the data from the program
10847 to create all necessary symbol tables, and their linetables.
10848
10849 2. If PST is not NULL, this procedure reads the program to determine
10850 the list of files included by the unit represented by PST, and
10851 builds all the associated partial symbol tables.
10852
10853 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10854 It is used for relative paths in the line table.
10855 NOTE: When processing partial symtabs (pst != NULL),
10856 comp_dir == pst->dirname.
10857
10858 NOTE: It is important that psymtabs have the same file name (via strcmp)
10859 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10860 symtab we don't use it in the name of the psymtabs we create.
10861 E.g. expand_line_sal requires this when finding psymtabs to expand.
10862 A good testcase for this is mb-inline.exp. */
10863
10864 static void
10865 dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd,
10866 struct dwarf2_cu *cu, struct partial_symtab *pst)
10867 {
10868 gdb_byte *line_ptr, *extended_end;
10869 gdb_byte *line_end;
10870 unsigned int bytes_read, extended_len;
10871 unsigned char op_code, extended_op, adj_opcode;
10872 CORE_ADDR baseaddr;
10873 struct objfile *objfile = cu->objfile;
10874 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10875 const int decode_for_pst_p = (pst != NULL);
10876 struct subfile *last_subfile = NULL, *first_subfile = current_subfile;
10877 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
10878 = record_line;
10879
10880 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10881
10882 line_ptr = lh->statement_program_start;
10883 line_end = lh->statement_program_end;
10884
10885 /* Read the statement sequences until there's nothing left. */
10886 while (line_ptr < line_end)
10887 {
10888 /* state machine registers */
10889 CORE_ADDR address = 0;
10890 unsigned int file = 1;
10891 unsigned int line = 1;
10892 unsigned int column = 0;
10893 int is_stmt = lh->default_is_stmt;
10894 int basic_block = 0;
10895 int end_sequence = 0;
10896 CORE_ADDR addr;
10897 unsigned char op_index = 0;
10898
10899 if (!decode_for_pst_p && lh->num_file_names >= file)
10900 {
10901 /* Start a subfile for the current file of the state machine. */
10902 /* lh->include_dirs and lh->file_names are 0-based, but the
10903 directory and file name numbers in the statement program
10904 are 1-based. */
10905 struct file_entry *fe = &lh->file_names[file - 1];
10906 char *dir = NULL;
10907
10908 if (fe->dir_index)
10909 dir = lh->include_dirs[fe->dir_index - 1];
10910
10911 dwarf2_start_subfile (fe->name, dir, comp_dir);
10912 }
10913
10914 /* Decode the table. */
10915 while (!end_sequence)
10916 {
10917 op_code = read_1_byte (abfd, line_ptr);
10918 line_ptr += 1;
10919 if (line_ptr > line_end)
10920 {
10921 dwarf2_debug_line_missing_end_sequence_complaint ();
10922 break;
10923 }
10924
10925 if (op_code >= lh->opcode_base)
10926 {
10927 /* Special operand. */
10928 adj_opcode = op_code - lh->opcode_base;
10929 address += (((op_index + (adj_opcode / lh->line_range))
10930 / lh->maximum_ops_per_instruction)
10931 * lh->minimum_instruction_length);
10932 op_index = ((op_index + (adj_opcode / lh->line_range))
10933 % lh->maximum_ops_per_instruction);
10934 line += lh->line_base + (adj_opcode % lh->line_range);
10935 if (lh->num_file_names < file || file == 0)
10936 dwarf2_debug_line_missing_file_complaint ();
10937 /* For now we ignore lines not starting on an
10938 instruction boundary. */
10939 else if (op_index == 0)
10940 {
10941 lh->file_names[file - 1].included_p = 1;
10942 if (!decode_for_pst_p && is_stmt)
10943 {
10944 if (last_subfile != current_subfile)
10945 {
10946 addr = gdbarch_addr_bits_remove (gdbarch, address);
10947 if (last_subfile)
10948 (*p_record_line) (last_subfile, 0, addr);
10949 last_subfile = current_subfile;
10950 }
10951 /* Append row to matrix using current values. */
10952 addr = check_cu_functions (address, cu);
10953 addr = gdbarch_addr_bits_remove (gdbarch, addr);
10954 (*p_record_line) (current_subfile, line, addr);
10955 }
10956 }
10957 basic_block = 0;
10958 }
10959 else switch (op_code)
10960 {
10961 case DW_LNS_extended_op:
10962 extended_len = read_unsigned_leb128 (abfd, line_ptr,
10963 &bytes_read);
10964 line_ptr += bytes_read;
10965 extended_end = line_ptr + extended_len;
10966 extended_op = read_1_byte (abfd, line_ptr);
10967 line_ptr += 1;
10968 switch (extended_op)
10969 {
10970 case DW_LNE_end_sequence:
10971 p_record_line = record_line;
10972 end_sequence = 1;
10973 break;
10974 case DW_LNE_set_address:
10975 address = read_address (abfd, line_ptr, cu, &bytes_read);
10976
10977 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
10978 {
10979 /* This line table is for a function which has been
10980 GCd by the linker. Ignore it. PR gdb/12528 */
10981
10982 long line_offset
10983 = line_ptr - dwarf2_per_objfile->line.buffer;
10984
10985 complaint (&symfile_complaints,
10986 _(".debug_line address at offset 0x%lx is 0 "
10987 "[in module %s]"),
10988 line_offset, cu->objfile->name);
10989 p_record_line = noop_record_line;
10990 }
10991
10992 op_index = 0;
10993 line_ptr += bytes_read;
10994 address += baseaddr;
10995 break;
10996 case DW_LNE_define_file:
10997 {
10998 char *cur_file;
10999 unsigned int dir_index, mod_time, length;
11000
11001 cur_file = read_direct_string (abfd, line_ptr,
11002 &bytes_read);
11003 line_ptr += bytes_read;
11004 dir_index =
11005 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11006 line_ptr += bytes_read;
11007 mod_time =
11008 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11009 line_ptr += bytes_read;
11010 length =
11011 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11012 line_ptr += bytes_read;
11013 add_file_name (lh, cur_file, dir_index, mod_time, length);
11014 }
11015 break;
11016 case DW_LNE_set_discriminator:
11017 /* The discriminator is not interesting to the debugger;
11018 just ignore it. */
11019 line_ptr = extended_end;
11020 break;
11021 default:
11022 complaint (&symfile_complaints,
11023 _("mangled .debug_line section"));
11024 return;
11025 }
11026 /* Make sure that we parsed the extended op correctly. If e.g.
11027 we expected a different address size than the producer used,
11028 we may have read the wrong number of bytes. */
11029 if (line_ptr != extended_end)
11030 {
11031 complaint (&symfile_complaints,
11032 _("mangled .debug_line section"));
11033 return;
11034 }
11035 break;
11036 case DW_LNS_copy:
11037 if (lh->num_file_names < file || file == 0)
11038 dwarf2_debug_line_missing_file_complaint ();
11039 else
11040 {
11041 lh->file_names[file - 1].included_p = 1;
11042 if (!decode_for_pst_p && is_stmt)
11043 {
11044 if (last_subfile != current_subfile)
11045 {
11046 addr = gdbarch_addr_bits_remove (gdbarch, address);
11047 if (last_subfile)
11048 (*p_record_line) (last_subfile, 0, addr);
11049 last_subfile = current_subfile;
11050 }
11051 addr = check_cu_functions (address, cu);
11052 addr = gdbarch_addr_bits_remove (gdbarch, addr);
11053 (*p_record_line) (current_subfile, line, addr);
11054 }
11055 }
11056 basic_block = 0;
11057 break;
11058 case DW_LNS_advance_pc:
11059 {
11060 CORE_ADDR adjust
11061 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11062
11063 address += (((op_index + adjust)
11064 / lh->maximum_ops_per_instruction)
11065 * lh->minimum_instruction_length);
11066 op_index = ((op_index + adjust)
11067 % lh->maximum_ops_per_instruction);
11068 line_ptr += bytes_read;
11069 }
11070 break;
11071 case DW_LNS_advance_line:
11072 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
11073 line_ptr += bytes_read;
11074 break;
11075 case DW_LNS_set_file:
11076 {
11077 /* The arrays lh->include_dirs and lh->file_names are
11078 0-based, but the directory and file name numbers in
11079 the statement program are 1-based. */
11080 struct file_entry *fe;
11081 char *dir = NULL;
11082
11083 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11084 line_ptr += bytes_read;
11085 if (lh->num_file_names < file || file == 0)
11086 dwarf2_debug_line_missing_file_complaint ();
11087 else
11088 {
11089 fe = &lh->file_names[file - 1];
11090 if (fe->dir_index)
11091 dir = lh->include_dirs[fe->dir_index - 1];
11092 if (!decode_for_pst_p)
11093 {
11094 last_subfile = current_subfile;
11095 dwarf2_start_subfile (fe->name, dir, comp_dir);
11096 }
11097 }
11098 }
11099 break;
11100 case DW_LNS_set_column:
11101 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11102 line_ptr += bytes_read;
11103 break;
11104 case DW_LNS_negate_stmt:
11105 is_stmt = (!is_stmt);
11106 break;
11107 case DW_LNS_set_basic_block:
11108 basic_block = 1;
11109 break;
11110 /* Add to the address register of the state machine the
11111 address increment value corresponding to special opcode
11112 255. I.e., this value is scaled by the minimum
11113 instruction length since special opcode 255 would have
11114 scaled the increment. */
11115 case DW_LNS_const_add_pc:
11116 {
11117 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
11118
11119 address += (((op_index + adjust)
11120 / lh->maximum_ops_per_instruction)
11121 * lh->minimum_instruction_length);
11122 op_index = ((op_index + adjust)
11123 % lh->maximum_ops_per_instruction);
11124 }
11125 break;
11126 case DW_LNS_fixed_advance_pc:
11127 address += read_2_bytes (abfd, line_ptr);
11128 op_index = 0;
11129 line_ptr += 2;
11130 break;
11131 default:
11132 {
11133 /* Unknown standard opcode, ignore it. */
11134 int i;
11135
11136 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
11137 {
11138 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
11139 line_ptr += bytes_read;
11140 }
11141 }
11142 }
11143 }
11144 if (lh->num_file_names < file || file == 0)
11145 dwarf2_debug_line_missing_file_complaint ();
11146 else
11147 {
11148 lh->file_names[file - 1].included_p = 1;
11149 if (!decode_for_pst_p)
11150 {
11151 addr = gdbarch_addr_bits_remove (gdbarch, address);
11152 (*p_record_line) (current_subfile, 0, addr);
11153 }
11154 }
11155 }
11156
11157 if (decode_for_pst_p)
11158 {
11159 int file_index;
11160
11161 /* Now that we're done scanning the Line Header Program, we can
11162 create the psymtab of each included file. */
11163 for (file_index = 0; file_index < lh->num_file_names; file_index++)
11164 if (lh->file_names[file_index].included_p == 1)
11165 {
11166 char *include_name =
11167 psymtab_include_file_name (lh, file_index, pst, comp_dir);
11168 if (include_name != NULL)
11169 dwarf2_create_include_psymtab (include_name, pst, objfile);
11170 }
11171 }
11172 else
11173 {
11174 /* Make sure a symtab is created for every file, even files
11175 which contain only variables (i.e. no code with associated
11176 line numbers). */
11177
11178 int i;
11179 struct file_entry *fe;
11180
11181 for (i = 0; i < lh->num_file_names; i++)
11182 {
11183 char *dir = NULL;
11184
11185 fe = &lh->file_names[i];
11186 if (fe->dir_index)
11187 dir = lh->include_dirs[fe->dir_index - 1];
11188 dwarf2_start_subfile (fe->name, dir, comp_dir);
11189
11190 /* Skip the main file; we don't need it, and it must be
11191 allocated last, so that it will show up before the
11192 non-primary symtabs in the objfile's symtab list. */
11193 if (current_subfile == first_subfile)
11194 continue;
11195
11196 if (current_subfile->symtab == NULL)
11197 current_subfile->symtab = allocate_symtab (current_subfile->name,
11198 cu->objfile);
11199 fe->symtab = current_subfile->symtab;
11200 }
11201 }
11202 }
11203
11204 /* Start a subfile for DWARF. FILENAME is the name of the file and
11205 DIRNAME the name of the source directory which contains FILENAME
11206 or NULL if not known. COMP_DIR is the compilation directory for the
11207 linetable's compilation unit or NULL if not known.
11208 This routine tries to keep line numbers from identical absolute and
11209 relative file names in a common subfile.
11210
11211 Using the `list' example from the GDB testsuite, which resides in
11212 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
11213 of /srcdir/list0.c yields the following debugging information for list0.c:
11214
11215 DW_AT_name: /srcdir/list0.c
11216 DW_AT_comp_dir: /compdir
11217 files.files[0].name: list0.h
11218 files.files[0].dir: /srcdir
11219 files.files[1].name: list0.c
11220 files.files[1].dir: /srcdir
11221
11222 The line number information for list0.c has to end up in a single
11223 subfile, so that `break /srcdir/list0.c:1' works as expected.
11224 start_subfile will ensure that this happens provided that we pass the
11225 concatenation of files.files[1].dir and files.files[1].name as the
11226 subfile's name. */
11227
11228 static void
11229 dwarf2_start_subfile (char *filename, const char *dirname,
11230 const char *comp_dir)
11231 {
11232 char *fullname;
11233
11234 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
11235 `start_symtab' will always pass the contents of DW_AT_comp_dir as
11236 second argument to start_subfile. To be consistent, we do the
11237 same here. In order not to lose the line information directory,
11238 we concatenate it to the filename when it makes sense.
11239 Note that the Dwarf3 standard says (speaking of filenames in line
11240 information): ``The directory index is ignored for file names
11241 that represent full path names''. Thus ignoring dirname in the
11242 `else' branch below isn't an issue. */
11243
11244 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
11245 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
11246 else
11247 fullname = filename;
11248
11249 start_subfile (fullname, comp_dir);
11250
11251 if (fullname != filename)
11252 xfree (fullname);
11253 }
11254
11255 static void
11256 var_decode_location (struct attribute *attr, struct symbol *sym,
11257 struct dwarf2_cu *cu)
11258 {
11259 struct objfile *objfile = cu->objfile;
11260 struct comp_unit_head *cu_header = &cu->header;
11261
11262 /* NOTE drow/2003-01-30: There used to be a comment and some special
11263 code here to turn a symbol with DW_AT_external and a
11264 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
11265 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
11266 with some versions of binutils) where shared libraries could have
11267 relocations against symbols in their debug information - the
11268 minimal symbol would have the right address, but the debug info
11269 would not. It's no longer necessary, because we will explicitly
11270 apply relocations when we read in the debug information now. */
11271
11272 /* A DW_AT_location attribute with no contents indicates that a
11273 variable has been optimized away. */
11274 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
11275 {
11276 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11277 return;
11278 }
11279
11280 /* Handle one degenerate form of location expression specially, to
11281 preserve GDB's previous behavior when section offsets are
11282 specified. If this is just a DW_OP_addr then mark this symbol
11283 as LOC_STATIC. */
11284
11285 if (attr_form_is_block (attr)
11286 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size
11287 && DW_BLOCK (attr)->data[0] == DW_OP_addr)
11288 {
11289 unsigned int dummy;
11290
11291 SYMBOL_VALUE_ADDRESS (sym) =
11292 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
11293 SYMBOL_CLASS (sym) = LOC_STATIC;
11294 fixup_symbol_section (sym, objfile);
11295 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
11296 SYMBOL_SECTION (sym));
11297 return;
11298 }
11299
11300 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
11301 expression evaluator, and use LOC_COMPUTED only when necessary
11302 (i.e. when the value of a register or memory location is
11303 referenced, or a thread-local block, etc.). Then again, it might
11304 not be worthwhile. I'm assuming that it isn't unless performance
11305 or memory numbers show me otherwise. */
11306
11307 dwarf2_symbol_mark_computed (attr, sym, cu);
11308 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11309
11310 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
11311 cu->has_loclist = 1;
11312 }
11313
11314 /* Given a pointer to a DWARF information entry, figure out if we need
11315 to make a symbol table entry for it, and if so, create a new entry
11316 and return a pointer to it.
11317 If TYPE is NULL, determine symbol type from the die, otherwise
11318 used the passed type.
11319 If SPACE is not NULL, use it to hold the new symbol. If it is
11320 NULL, allocate a new symbol on the objfile's obstack. */
11321
11322 static struct symbol *
11323 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
11324 struct symbol *space)
11325 {
11326 struct objfile *objfile = cu->objfile;
11327 struct symbol *sym = NULL;
11328 char *name;
11329 struct attribute *attr = NULL;
11330 struct attribute *attr2 = NULL;
11331 CORE_ADDR baseaddr;
11332 struct pending **list_to_add = NULL;
11333
11334 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
11335
11336 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
11337
11338 name = dwarf2_name (die, cu);
11339 if (name)
11340 {
11341 const char *linkagename;
11342 int suppress_add = 0;
11343
11344 if (space)
11345 sym = space;
11346 else
11347 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
11348 OBJSTAT (objfile, n_syms++);
11349
11350 /* Cache this symbol's name and the name's demangled form (if any). */
11351 SYMBOL_SET_LANGUAGE (sym, cu->language);
11352 linkagename = dwarf2_physname (name, die, cu);
11353 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
11354
11355 /* Fortran does not have mangling standard and the mangling does differ
11356 between gfortran, iFort etc. */
11357 if (cu->language == language_fortran
11358 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
11359 symbol_set_demangled_name (&(sym->ginfo),
11360 (char *) dwarf2_full_name (name, die, cu),
11361 NULL);
11362
11363 /* Default assumptions.
11364 Use the passed type or decode it from the die. */
11365 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11366 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
11367 if (type != NULL)
11368 SYMBOL_TYPE (sym) = type;
11369 else
11370 SYMBOL_TYPE (sym) = die_type (die, cu);
11371 attr = dwarf2_attr (die,
11372 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
11373 cu);
11374 if (attr)
11375 {
11376 SYMBOL_LINE (sym) = DW_UNSND (attr);
11377 }
11378
11379 attr = dwarf2_attr (die,
11380 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
11381 cu);
11382 if (attr)
11383 {
11384 int file_index = DW_UNSND (attr);
11385
11386 if (cu->line_header == NULL
11387 || file_index > cu->line_header->num_file_names)
11388 complaint (&symfile_complaints,
11389 _("file index out of range"));
11390 else if (file_index > 0)
11391 {
11392 struct file_entry *fe;
11393
11394 fe = &cu->line_header->file_names[file_index - 1];
11395 SYMBOL_SYMTAB (sym) = fe->symtab;
11396 }
11397 }
11398
11399 switch (die->tag)
11400 {
11401 case DW_TAG_label:
11402 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
11403 if (attr)
11404 {
11405 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
11406 }
11407 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
11408 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
11409 SYMBOL_CLASS (sym) = LOC_LABEL;
11410 add_symbol_to_list (sym, cu->list_in_scope);
11411 break;
11412 case DW_TAG_subprogram:
11413 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11414 finish_block. */
11415 SYMBOL_CLASS (sym) = LOC_BLOCK;
11416 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11417 if ((attr2 && (DW_UNSND (attr2) != 0))
11418 || cu->language == language_ada)
11419 {
11420 /* Subprograms marked external are stored as a global symbol.
11421 Ada subprograms, whether marked external or not, are always
11422 stored as a global symbol, because we want to be able to
11423 access them globally. For instance, we want to be able
11424 to break on a nested subprogram without having to
11425 specify the context. */
11426 list_to_add = &global_symbols;
11427 }
11428 else
11429 {
11430 list_to_add = cu->list_in_scope;
11431 }
11432 break;
11433 case DW_TAG_inlined_subroutine:
11434 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11435 finish_block. */
11436 SYMBOL_CLASS (sym) = LOC_BLOCK;
11437 SYMBOL_INLINED (sym) = 1;
11438 /* Do not add the symbol to any lists. It will be found via
11439 BLOCK_FUNCTION from the blockvector. */
11440 break;
11441 case DW_TAG_template_value_param:
11442 suppress_add = 1;
11443 /* Fall through. */
11444 case DW_TAG_constant:
11445 case DW_TAG_variable:
11446 case DW_TAG_member:
11447 /* Compilation with minimal debug info may result in
11448 variables with missing type entries. Change the
11449 misleading `void' type to something sensible. */
11450 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
11451 SYMBOL_TYPE (sym)
11452 = objfile_type (objfile)->nodebug_data_symbol;
11453
11454 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11455 /* In the case of DW_TAG_member, we should only be called for
11456 static const members. */
11457 if (die->tag == DW_TAG_member)
11458 {
11459 /* dwarf2_add_field uses die_is_declaration,
11460 so we do the same. */
11461 gdb_assert (die_is_declaration (die, cu));
11462 gdb_assert (attr);
11463 }
11464 if (attr)
11465 {
11466 dwarf2_const_value (attr, sym, cu);
11467 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11468 if (!suppress_add)
11469 {
11470 if (attr2 && (DW_UNSND (attr2) != 0))
11471 list_to_add = &global_symbols;
11472 else
11473 list_to_add = cu->list_in_scope;
11474 }
11475 break;
11476 }
11477 attr = dwarf2_attr (die, DW_AT_location, cu);
11478 if (attr)
11479 {
11480 var_decode_location (attr, sym, cu);
11481 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11482 if (SYMBOL_CLASS (sym) == LOC_STATIC
11483 && SYMBOL_VALUE_ADDRESS (sym) == 0
11484 && !dwarf2_per_objfile->has_section_at_zero)
11485 {
11486 /* When a static variable is eliminated by the linker,
11487 the corresponding debug information is not stripped
11488 out, but the variable address is set to null;
11489 do not add such variables into symbol table. */
11490 }
11491 else if (attr2 && (DW_UNSND (attr2) != 0))
11492 {
11493 /* Workaround gfortran PR debug/40040 - it uses
11494 DW_AT_location for variables in -fPIC libraries which may
11495 get overriden by other libraries/executable and get
11496 a different address. Resolve it by the minimal symbol
11497 which may come from inferior's executable using copy
11498 relocation. Make this workaround only for gfortran as for
11499 other compilers GDB cannot guess the minimal symbol
11500 Fortran mangling kind. */
11501 if (cu->language == language_fortran && die->parent
11502 && die->parent->tag == DW_TAG_module
11503 && cu->producer
11504 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
11505 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11506
11507 /* A variable with DW_AT_external is never static,
11508 but it may be block-scoped. */
11509 list_to_add = (cu->list_in_scope == &file_symbols
11510 ? &global_symbols : cu->list_in_scope);
11511 }
11512 else
11513 list_to_add = cu->list_in_scope;
11514 }
11515 else
11516 {
11517 /* We do not know the address of this symbol.
11518 If it is an external symbol and we have type information
11519 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11520 The address of the variable will then be determined from
11521 the minimal symbol table whenever the variable is
11522 referenced. */
11523 attr2 = dwarf2_attr (die, DW_AT_external, cu);
11524 if (attr2 && (DW_UNSND (attr2) != 0)
11525 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
11526 {
11527 /* A variable with DW_AT_external is never static, but it
11528 may be block-scoped. */
11529 list_to_add = (cu->list_in_scope == &file_symbols
11530 ? &global_symbols : cu->list_in_scope);
11531
11532 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
11533 }
11534 else if (!die_is_declaration (die, cu))
11535 {
11536 /* Use the default LOC_OPTIMIZED_OUT class. */
11537 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
11538 if (!suppress_add)
11539 list_to_add = cu->list_in_scope;
11540 }
11541 }
11542 break;
11543 case DW_TAG_formal_parameter:
11544 /* If we are inside a function, mark this as an argument. If
11545 not, we might be looking at an argument to an inlined function
11546 when we do not have enough information to show inlined frames;
11547 pretend it's a local variable in that case so that the user can
11548 still see it. */
11549 if (context_stack_depth > 0
11550 && context_stack[context_stack_depth - 1].name != NULL)
11551 SYMBOL_IS_ARGUMENT (sym) = 1;
11552 attr = dwarf2_attr (die, DW_AT_location, cu);
11553 if (attr)
11554 {
11555 var_decode_location (attr, sym, cu);
11556 }
11557 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11558 if (attr)
11559 {
11560 dwarf2_const_value (attr, sym, cu);
11561 }
11562
11563 list_to_add = cu->list_in_scope;
11564 break;
11565 case DW_TAG_unspecified_parameters:
11566 /* From varargs functions; gdb doesn't seem to have any
11567 interest in this information, so just ignore it for now.
11568 (FIXME?) */
11569 break;
11570 case DW_TAG_template_type_param:
11571 suppress_add = 1;
11572 /* Fall through. */
11573 case DW_TAG_class_type:
11574 case DW_TAG_interface_type:
11575 case DW_TAG_structure_type:
11576 case DW_TAG_union_type:
11577 case DW_TAG_set_type:
11578 case DW_TAG_enumeration_type:
11579 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11580 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
11581
11582 {
11583 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11584 really ever be static objects: otherwise, if you try
11585 to, say, break of a class's method and you're in a file
11586 which doesn't mention that class, it won't work unless
11587 the check for all static symbols in lookup_symbol_aux
11588 saves you. See the OtherFileClass tests in
11589 gdb.c++/namespace.exp. */
11590
11591 if (!suppress_add)
11592 {
11593 list_to_add = (cu->list_in_scope == &file_symbols
11594 && (cu->language == language_cplus
11595 || cu->language == language_java)
11596 ? &global_symbols : cu->list_in_scope);
11597
11598 /* The semantics of C++ state that "struct foo {
11599 ... }" also defines a typedef for "foo". A Java
11600 class declaration also defines a typedef for the
11601 class. */
11602 if (cu->language == language_cplus
11603 || cu->language == language_java
11604 || cu->language == language_ada)
11605 {
11606 /* The symbol's name is already allocated along
11607 with this objfile, so we don't need to
11608 duplicate it for the type. */
11609 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
11610 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
11611 }
11612 }
11613 }
11614 break;
11615 case DW_TAG_typedef:
11616 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11617 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11618 list_to_add = cu->list_in_scope;
11619 break;
11620 case DW_TAG_base_type:
11621 case DW_TAG_subrange_type:
11622 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11623 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11624 list_to_add = cu->list_in_scope;
11625 break;
11626 case DW_TAG_enumerator:
11627 attr = dwarf2_attr (die, DW_AT_const_value, cu);
11628 if (attr)
11629 {
11630 dwarf2_const_value (attr, sym, cu);
11631 }
11632 {
11633 /* NOTE: carlton/2003-11-10: See comment above in the
11634 DW_TAG_class_type, etc. block. */
11635
11636 list_to_add = (cu->list_in_scope == &file_symbols
11637 && (cu->language == language_cplus
11638 || cu->language == language_java)
11639 ? &global_symbols : cu->list_in_scope);
11640 }
11641 break;
11642 case DW_TAG_namespace:
11643 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
11644 list_to_add = &global_symbols;
11645 break;
11646 default:
11647 /* Not a tag we recognize. Hopefully we aren't processing
11648 trash data, but since we must specifically ignore things
11649 we don't recognize, there is nothing else we should do at
11650 this point. */
11651 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
11652 dwarf_tag_name (die->tag));
11653 break;
11654 }
11655
11656 if (suppress_add)
11657 {
11658 sym->hash_next = objfile->template_symbols;
11659 objfile->template_symbols = sym;
11660 list_to_add = NULL;
11661 }
11662
11663 if (list_to_add != NULL)
11664 add_symbol_to_list (sym, list_to_add);
11665
11666 /* For the benefit of old versions of GCC, check for anonymous
11667 namespaces based on the demangled name. */
11668 if (!processing_has_namespace_info
11669 && cu->language == language_cplus)
11670 cp_scan_for_anonymous_namespaces (sym);
11671 }
11672 return (sym);
11673 }
11674
11675 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11676
11677 static struct symbol *
11678 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
11679 {
11680 return new_symbol_full (die, type, cu, NULL);
11681 }
11682
11683 /* Given an attr with a DW_FORM_dataN value in host byte order,
11684 zero-extend it as appropriate for the symbol's type. The DWARF
11685 standard (v4) is not entirely clear about the meaning of using
11686 DW_FORM_dataN for a constant with a signed type, where the type is
11687 wider than the data. The conclusion of a discussion on the DWARF
11688 list was that this is unspecified. We choose to always zero-extend
11689 because that is the interpretation long in use by GCC. */
11690
11691 static gdb_byte *
11692 dwarf2_const_value_data (struct attribute *attr, struct type *type,
11693 const char *name, struct obstack *obstack,
11694 struct dwarf2_cu *cu, long *value, int bits)
11695 {
11696 struct objfile *objfile = cu->objfile;
11697 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
11698 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
11699 LONGEST l = DW_UNSND (attr);
11700
11701 if (bits < sizeof (*value) * 8)
11702 {
11703 l &= ((LONGEST) 1 << bits) - 1;
11704 *value = l;
11705 }
11706 else if (bits == sizeof (*value) * 8)
11707 *value = l;
11708 else
11709 {
11710 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
11711 store_unsigned_integer (bytes, bits / 8, byte_order, l);
11712 return bytes;
11713 }
11714
11715 return NULL;
11716 }
11717
11718 /* Read a constant value from an attribute. Either set *VALUE, or if
11719 the value does not fit in *VALUE, set *BYTES - either already
11720 allocated on the objfile obstack, or newly allocated on OBSTACK,
11721 or, set *BATON, if we translated the constant to a location
11722 expression. */
11723
11724 static void
11725 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
11726 const char *name, struct obstack *obstack,
11727 struct dwarf2_cu *cu,
11728 long *value, gdb_byte **bytes,
11729 struct dwarf2_locexpr_baton **baton)
11730 {
11731 struct objfile *objfile = cu->objfile;
11732 struct comp_unit_head *cu_header = &cu->header;
11733 struct dwarf_block *blk;
11734 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
11735 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
11736
11737 *value = 0;
11738 *bytes = NULL;
11739 *baton = NULL;
11740
11741 switch (attr->form)
11742 {
11743 case DW_FORM_addr:
11744 {
11745 gdb_byte *data;
11746
11747 if (TYPE_LENGTH (type) != cu_header->addr_size)
11748 dwarf2_const_value_length_mismatch_complaint (name,
11749 cu_header->addr_size,
11750 TYPE_LENGTH (type));
11751 /* Symbols of this form are reasonably rare, so we just
11752 piggyback on the existing location code rather than writing
11753 a new implementation of symbol_computed_ops. */
11754 *baton = obstack_alloc (&objfile->objfile_obstack,
11755 sizeof (struct dwarf2_locexpr_baton));
11756 (*baton)->per_cu = cu->per_cu;
11757 gdb_assert ((*baton)->per_cu);
11758
11759 (*baton)->size = 2 + cu_header->addr_size;
11760 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
11761 (*baton)->data = data;
11762
11763 data[0] = DW_OP_addr;
11764 store_unsigned_integer (&data[1], cu_header->addr_size,
11765 byte_order, DW_ADDR (attr));
11766 data[cu_header->addr_size + 1] = DW_OP_stack_value;
11767 }
11768 break;
11769 case DW_FORM_string:
11770 case DW_FORM_strp:
11771 /* DW_STRING is already allocated on the objfile obstack, point
11772 directly to it. */
11773 *bytes = (gdb_byte *) DW_STRING (attr);
11774 break;
11775 case DW_FORM_block1:
11776 case DW_FORM_block2:
11777 case DW_FORM_block4:
11778 case DW_FORM_block:
11779 case DW_FORM_exprloc:
11780 blk = DW_BLOCK (attr);
11781 if (TYPE_LENGTH (type) != blk->size)
11782 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
11783 TYPE_LENGTH (type));
11784 *bytes = blk->data;
11785 break;
11786
11787 /* The DW_AT_const_value attributes are supposed to carry the
11788 symbol's value "represented as it would be on the target
11789 architecture." By the time we get here, it's already been
11790 converted to host endianness, so we just need to sign- or
11791 zero-extend it as appropriate. */
11792 case DW_FORM_data1:
11793 *bytes = dwarf2_const_value_data (attr, type, name,
11794 obstack, cu, value, 8);
11795 break;
11796 case DW_FORM_data2:
11797 *bytes = dwarf2_const_value_data (attr, type, name,
11798 obstack, cu, value, 16);
11799 break;
11800 case DW_FORM_data4:
11801 *bytes = dwarf2_const_value_data (attr, type, name,
11802 obstack, cu, value, 32);
11803 break;
11804 case DW_FORM_data8:
11805 *bytes = dwarf2_const_value_data (attr, type, name,
11806 obstack, cu, value, 64);
11807 break;
11808
11809 case DW_FORM_sdata:
11810 *value = DW_SND (attr);
11811 break;
11812
11813 case DW_FORM_udata:
11814 *value = DW_UNSND (attr);
11815 break;
11816
11817 default:
11818 complaint (&symfile_complaints,
11819 _("unsupported const value attribute form: '%s'"),
11820 dwarf_form_name (attr->form));
11821 *value = 0;
11822 break;
11823 }
11824 }
11825
11826
11827 /* Copy constant value from an attribute to a symbol. */
11828
11829 static void
11830 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
11831 struct dwarf2_cu *cu)
11832 {
11833 struct objfile *objfile = cu->objfile;
11834 struct comp_unit_head *cu_header = &cu->header;
11835 long value;
11836 gdb_byte *bytes;
11837 struct dwarf2_locexpr_baton *baton;
11838
11839 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
11840 SYMBOL_PRINT_NAME (sym),
11841 &objfile->objfile_obstack, cu,
11842 &value, &bytes, &baton);
11843
11844 if (baton != NULL)
11845 {
11846 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11847 SYMBOL_LOCATION_BATON (sym) = baton;
11848 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11849 }
11850 else if (bytes != NULL)
11851 {
11852 SYMBOL_VALUE_BYTES (sym) = bytes;
11853 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
11854 }
11855 else
11856 {
11857 SYMBOL_VALUE (sym) = value;
11858 SYMBOL_CLASS (sym) = LOC_CONST;
11859 }
11860 }
11861
11862 /* Return the type of the die in question using its DW_AT_type attribute. */
11863
11864 static struct type *
11865 die_type (struct die_info *die, struct dwarf2_cu *cu)
11866 {
11867 struct attribute *type_attr;
11868
11869 type_attr = dwarf2_attr (die, DW_AT_type, cu);
11870 if (!type_attr)
11871 {
11872 /* A missing DW_AT_type represents a void type. */
11873 return objfile_type (cu->objfile)->builtin_void;
11874 }
11875
11876 return lookup_die_type (die, type_attr, cu);
11877 }
11878
11879 /* True iff CU's producer generates GNAT Ada auxiliary information
11880 that allows to find parallel types through that information instead
11881 of having to do expensive parallel lookups by type name. */
11882
11883 static int
11884 need_gnat_info (struct dwarf2_cu *cu)
11885 {
11886 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11887 of GNAT produces this auxiliary information, without any indication
11888 that it is produced. Part of enhancing the FSF version of GNAT
11889 to produce that information will be to put in place an indicator
11890 that we can use in order to determine whether the descriptive type
11891 info is available or not. One suggestion that has been made is
11892 to use a new attribute, attached to the CU die. For now, assume
11893 that the descriptive type info is not available. */
11894 return 0;
11895 }
11896
11897 /* Return the auxiliary type of the die in question using its
11898 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11899 attribute is not present. */
11900
11901 static struct type *
11902 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
11903 {
11904 struct attribute *type_attr;
11905
11906 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
11907 if (!type_attr)
11908 return NULL;
11909
11910 return lookup_die_type (die, type_attr, cu);
11911 }
11912
11913 /* If DIE has a descriptive_type attribute, then set the TYPE's
11914 descriptive type accordingly. */
11915
11916 static void
11917 set_descriptive_type (struct type *type, struct die_info *die,
11918 struct dwarf2_cu *cu)
11919 {
11920 struct type *descriptive_type = die_descriptive_type (die, cu);
11921
11922 if (descriptive_type)
11923 {
11924 ALLOCATE_GNAT_AUX_TYPE (type);
11925 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
11926 }
11927 }
11928
11929 /* Return the containing type of the die in question using its
11930 DW_AT_containing_type attribute. */
11931
11932 static struct type *
11933 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
11934 {
11935 struct attribute *type_attr;
11936
11937 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
11938 if (!type_attr)
11939 error (_("Dwarf Error: Problem turning containing type into gdb type "
11940 "[in module %s]"), cu->objfile->name);
11941
11942 return lookup_die_type (die, type_attr, cu);
11943 }
11944
11945 /* Look up the type of DIE in CU using its type attribute ATTR.
11946 If there is no type substitute an error marker. */
11947
11948 static struct type *
11949 lookup_die_type (struct die_info *die, struct attribute *attr,
11950 struct dwarf2_cu *cu)
11951 {
11952 struct type *this_type;
11953
11954 /* First see if we have it cached. */
11955
11956 if (is_ref_attr (attr))
11957 {
11958 unsigned int offset = dwarf2_get_ref_die_offset (attr);
11959
11960 this_type = get_die_type_at_offset (offset, cu->per_cu);
11961 }
11962 else if (attr->form == DW_FORM_ref_sig8)
11963 {
11964 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
11965 struct dwarf2_cu *sig_cu;
11966 unsigned int offset;
11967
11968 /* sig_type will be NULL if the signatured type is missing from
11969 the debug info. */
11970 if (sig_type == NULL)
11971 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11972 "at 0x%x [in module %s]"),
11973 die->offset, cu->objfile->name);
11974
11975 gdb_assert (sig_type->per_cu.debug_type_section);
11976 offset = sig_type->per_cu.offset + sig_type->type_offset;
11977 this_type = get_die_type_at_offset (offset, &sig_type->per_cu);
11978 }
11979 else
11980 {
11981 dump_die_for_error (die);
11982 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11983 dwarf_attr_name (attr->name), cu->objfile->name);
11984 }
11985
11986 /* If not cached we need to read it in. */
11987
11988 if (this_type == NULL)
11989 {
11990 struct die_info *type_die;
11991 struct dwarf2_cu *type_cu = cu;
11992
11993 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11994 /* If the type is cached, we should have found it above. */
11995 gdb_assert (get_die_type (type_die, type_cu) == NULL);
11996 this_type = read_type_die_1 (type_die, type_cu);
11997 }
11998
11999 /* If we still don't have a type use an error marker. */
12000
12001 if (this_type == NULL)
12002 {
12003 char *message, *saved;
12004
12005 /* read_type_die already issued a complaint. */
12006 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
12007 cu->objfile->name,
12008 cu->header.offset,
12009 die->offset);
12010 saved = obstack_copy0 (&cu->objfile->objfile_obstack,
12011 message, strlen (message));
12012 xfree (message);
12013
12014 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
12015 }
12016
12017 return this_type;
12018 }
12019
12020 /* Return the type in DIE, CU.
12021 Returns NULL for invalid types.
12022
12023 This first does a lookup in the appropriate type_hash table,
12024 and only reads the die in if necessary.
12025
12026 NOTE: This can be called when reading in partial or full symbols. */
12027
12028 static struct type *
12029 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
12030 {
12031 struct type *this_type;
12032
12033 this_type = get_die_type (die, cu);
12034 if (this_type)
12035 return this_type;
12036
12037 return read_type_die_1 (die, cu);
12038 }
12039
12040 /* Read the type in DIE, CU.
12041 Returns NULL for invalid types. */
12042
12043 static struct type *
12044 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
12045 {
12046 struct type *this_type = NULL;
12047
12048 switch (die->tag)
12049 {
12050 case DW_TAG_class_type:
12051 case DW_TAG_interface_type:
12052 case DW_TAG_structure_type:
12053 case DW_TAG_union_type:
12054 this_type = read_structure_type (die, cu);
12055 break;
12056 case DW_TAG_enumeration_type:
12057 this_type = read_enumeration_type (die, cu);
12058 break;
12059 case DW_TAG_subprogram:
12060 case DW_TAG_subroutine_type:
12061 case DW_TAG_inlined_subroutine:
12062 this_type = read_subroutine_type (die, cu);
12063 break;
12064 case DW_TAG_array_type:
12065 this_type = read_array_type (die, cu);
12066 break;
12067 case DW_TAG_set_type:
12068 this_type = read_set_type (die, cu);
12069 break;
12070 case DW_TAG_pointer_type:
12071 this_type = read_tag_pointer_type (die, cu);
12072 break;
12073 case DW_TAG_ptr_to_member_type:
12074 this_type = read_tag_ptr_to_member_type (die, cu);
12075 break;
12076 case DW_TAG_reference_type:
12077 this_type = read_tag_reference_type (die, cu);
12078 break;
12079 case DW_TAG_const_type:
12080 this_type = read_tag_const_type (die, cu);
12081 break;
12082 case DW_TAG_volatile_type:
12083 this_type = read_tag_volatile_type (die, cu);
12084 break;
12085 case DW_TAG_string_type:
12086 this_type = read_tag_string_type (die, cu);
12087 break;
12088 case DW_TAG_typedef:
12089 this_type = read_typedef (die, cu);
12090 break;
12091 case DW_TAG_subrange_type:
12092 this_type = read_subrange_type (die, cu);
12093 break;
12094 case DW_TAG_base_type:
12095 this_type = read_base_type (die, cu);
12096 break;
12097 case DW_TAG_unspecified_type:
12098 this_type = read_unspecified_type (die, cu);
12099 break;
12100 case DW_TAG_namespace:
12101 this_type = read_namespace_type (die, cu);
12102 break;
12103 case DW_TAG_module:
12104 this_type = read_module_type (die, cu);
12105 break;
12106 default:
12107 complaint (&symfile_complaints,
12108 _("unexpected tag in read_type_die: '%s'"),
12109 dwarf_tag_name (die->tag));
12110 break;
12111 }
12112
12113 return this_type;
12114 }
12115
12116 /* See if we can figure out if the class lives in a namespace. We do
12117 this by looking for a member function; its demangled name will
12118 contain namespace info, if there is any.
12119 Return the computed name or NULL.
12120 Space for the result is allocated on the objfile's obstack.
12121 This is the full-die version of guess_partial_die_structure_name.
12122 In this case we know DIE has no useful parent. */
12123
12124 static char *
12125 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
12126 {
12127 struct die_info *spec_die;
12128 struct dwarf2_cu *spec_cu;
12129 struct die_info *child;
12130
12131 spec_cu = cu;
12132 spec_die = die_specification (die, &spec_cu);
12133 if (spec_die != NULL)
12134 {
12135 die = spec_die;
12136 cu = spec_cu;
12137 }
12138
12139 for (child = die->child;
12140 child != NULL;
12141 child = child->sibling)
12142 {
12143 if (child->tag == DW_TAG_subprogram)
12144 {
12145 struct attribute *attr;
12146
12147 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
12148 if (attr == NULL)
12149 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
12150 if (attr != NULL)
12151 {
12152 char *actual_name
12153 = language_class_name_from_physname (cu->language_defn,
12154 DW_STRING (attr));
12155 char *name = NULL;
12156
12157 if (actual_name != NULL)
12158 {
12159 char *die_name = dwarf2_name (die, cu);
12160
12161 if (die_name != NULL
12162 && strcmp (die_name, actual_name) != 0)
12163 {
12164 /* Strip off the class name from the full name.
12165 We want the prefix. */
12166 int die_name_len = strlen (die_name);
12167 int actual_name_len = strlen (actual_name);
12168
12169 /* Test for '::' as a sanity check. */
12170 if (actual_name_len > die_name_len + 2
12171 && actual_name[actual_name_len
12172 - die_name_len - 1] == ':')
12173 name =
12174 obsavestring (actual_name,
12175 actual_name_len - die_name_len - 2,
12176 &cu->objfile->objfile_obstack);
12177 }
12178 }
12179 xfree (actual_name);
12180 return name;
12181 }
12182 }
12183 }
12184
12185 return NULL;
12186 }
12187
12188 /* GCC might emit a nameless typedef that has a linkage name. Determine the
12189 prefix part in such case. See
12190 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12191
12192 static char *
12193 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
12194 {
12195 struct attribute *attr;
12196 char *base;
12197
12198 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
12199 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
12200 return NULL;
12201
12202 attr = dwarf2_attr (die, DW_AT_name, cu);
12203 if (attr != NULL && DW_STRING (attr) != NULL)
12204 return NULL;
12205
12206 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12207 if (attr == NULL)
12208 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12209 if (attr == NULL || DW_STRING (attr) == NULL)
12210 return NULL;
12211
12212 /* dwarf2_name had to be already called. */
12213 gdb_assert (DW_STRING_IS_CANONICAL (attr));
12214
12215 /* Strip the base name, keep any leading namespaces/classes. */
12216 base = strrchr (DW_STRING (attr), ':');
12217 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
12218 return "";
12219
12220 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
12221 &cu->objfile->objfile_obstack);
12222 }
12223
12224 /* Return the name of the namespace/class that DIE is defined within,
12225 or "" if we can't tell. The caller should not xfree the result.
12226
12227 For example, if we're within the method foo() in the following
12228 code:
12229
12230 namespace N {
12231 class C {
12232 void foo () {
12233 }
12234 };
12235 }
12236
12237 then determine_prefix on foo's die will return "N::C". */
12238
12239 static char *
12240 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
12241 {
12242 struct die_info *parent, *spec_die;
12243 struct dwarf2_cu *spec_cu;
12244 struct type *parent_type;
12245 char *retval;
12246
12247 if (cu->language != language_cplus && cu->language != language_java
12248 && cu->language != language_fortran)
12249 return "";
12250
12251 retval = anonymous_struct_prefix (die, cu);
12252 if (retval)
12253 return retval;
12254
12255 /* We have to be careful in the presence of DW_AT_specification.
12256 For example, with GCC 3.4, given the code
12257
12258 namespace N {
12259 void foo() {
12260 // Definition of N::foo.
12261 }
12262 }
12263
12264 then we'll have a tree of DIEs like this:
12265
12266 1: DW_TAG_compile_unit
12267 2: DW_TAG_namespace // N
12268 3: DW_TAG_subprogram // declaration of N::foo
12269 4: DW_TAG_subprogram // definition of N::foo
12270 DW_AT_specification // refers to die #3
12271
12272 Thus, when processing die #4, we have to pretend that we're in
12273 the context of its DW_AT_specification, namely the contex of die
12274 #3. */
12275 spec_cu = cu;
12276 spec_die = die_specification (die, &spec_cu);
12277 if (spec_die == NULL)
12278 parent = die->parent;
12279 else
12280 {
12281 parent = spec_die->parent;
12282 cu = spec_cu;
12283 }
12284
12285 if (parent == NULL)
12286 return "";
12287 else if (parent->building_fullname)
12288 {
12289 const char *name;
12290 const char *parent_name;
12291
12292 /* It has been seen on RealView 2.2 built binaries,
12293 DW_TAG_template_type_param types actually _defined_ as
12294 children of the parent class:
12295
12296 enum E {};
12297 template class <class Enum> Class{};
12298 Class<enum E> class_e;
12299
12300 1: DW_TAG_class_type (Class)
12301 2: DW_TAG_enumeration_type (E)
12302 3: DW_TAG_enumerator (enum1:0)
12303 3: DW_TAG_enumerator (enum2:1)
12304 ...
12305 2: DW_TAG_template_type_param
12306 DW_AT_type DW_FORM_ref_udata (E)
12307
12308 Besides being broken debug info, it can put GDB into an
12309 infinite loop. Consider:
12310
12311 When we're building the full name for Class<E>, we'll start
12312 at Class, and go look over its template type parameters,
12313 finding E. We'll then try to build the full name of E, and
12314 reach here. We're now trying to build the full name of E,
12315 and look over the parent DIE for containing scope. In the
12316 broken case, if we followed the parent DIE of E, we'd again
12317 find Class, and once again go look at its template type
12318 arguments, etc., etc. Simply don't consider such parent die
12319 as source-level parent of this die (it can't be, the language
12320 doesn't allow it), and break the loop here. */
12321 name = dwarf2_name (die, cu);
12322 parent_name = dwarf2_name (parent, cu);
12323 complaint (&symfile_complaints,
12324 _("template param type '%s' defined within parent '%s'"),
12325 name ? name : "<unknown>",
12326 parent_name ? parent_name : "<unknown>");
12327 return "";
12328 }
12329 else
12330 switch (parent->tag)
12331 {
12332 case DW_TAG_namespace:
12333 parent_type = read_type_die (parent, cu);
12334 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
12335 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
12336 Work around this problem here. */
12337 if (cu->language == language_cplus
12338 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
12339 return "";
12340 /* We give a name to even anonymous namespaces. */
12341 return TYPE_TAG_NAME (parent_type);
12342 case DW_TAG_class_type:
12343 case DW_TAG_interface_type:
12344 case DW_TAG_structure_type:
12345 case DW_TAG_union_type:
12346 case DW_TAG_module:
12347 parent_type = read_type_die (parent, cu);
12348 if (TYPE_TAG_NAME (parent_type) != NULL)
12349 return TYPE_TAG_NAME (parent_type);
12350 else
12351 /* An anonymous structure is only allowed non-static data
12352 members; no typedefs, no member functions, et cetera.
12353 So it does not need a prefix. */
12354 return "";
12355 case DW_TAG_compile_unit:
12356 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
12357 if (cu->language == language_cplus
12358 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
12359 && die->child != NULL
12360 && (die->tag == DW_TAG_class_type
12361 || die->tag == DW_TAG_structure_type
12362 || die->tag == DW_TAG_union_type))
12363 {
12364 char *name = guess_full_die_structure_name (die, cu);
12365 if (name != NULL)
12366 return name;
12367 }
12368 return "";
12369 default:
12370 return determine_prefix (parent, cu);
12371 }
12372 }
12373
12374 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
12375 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
12376 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
12377 an obconcat, otherwise allocate storage for the result. The CU argument is
12378 used to determine the language and hence, the appropriate separator. */
12379
12380 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
12381
12382 static char *
12383 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
12384 int physname, struct dwarf2_cu *cu)
12385 {
12386 const char *lead = "";
12387 const char *sep;
12388
12389 if (suffix == NULL || suffix[0] == '\0'
12390 || prefix == NULL || prefix[0] == '\0')
12391 sep = "";
12392 else if (cu->language == language_java)
12393 sep = ".";
12394 else if (cu->language == language_fortran && physname)
12395 {
12396 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12397 DW_AT_MIPS_linkage_name is preferred and used instead. */
12398
12399 lead = "__";
12400 sep = "_MOD_";
12401 }
12402 else
12403 sep = "::";
12404
12405 if (prefix == NULL)
12406 prefix = "";
12407 if (suffix == NULL)
12408 suffix = "";
12409
12410 if (obs == NULL)
12411 {
12412 char *retval
12413 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
12414
12415 strcpy (retval, lead);
12416 strcat (retval, prefix);
12417 strcat (retval, sep);
12418 strcat (retval, suffix);
12419 return retval;
12420 }
12421 else
12422 {
12423 /* We have an obstack. */
12424 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
12425 }
12426 }
12427
12428 /* Return sibling of die, NULL if no sibling. */
12429
12430 static struct die_info *
12431 sibling_die (struct die_info *die)
12432 {
12433 return die->sibling;
12434 }
12435
12436 /* Get name of a die, return NULL if not found. */
12437
12438 static char *
12439 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
12440 struct obstack *obstack)
12441 {
12442 if (name && cu->language == language_cplus)
12443 {
12444 char *canon_name = cp_canonicalize_string (name);
12445
12446 if (canon_name != NULL)
12447 {
12448 if (strcmp (canon_name, name) != 0)
12449 name = obsavestring (canon_name, strlen (canon_name),
12450 obstack);
12451 xfree (canon_name);
12452 }
12453 }
12454
12455 return name;
12456 }
12457
12458 /* Get name of a die, return NULL if not found. */
12459
12460 static char *
12461 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
12462 {
12463 struct attribute *attr;
12464
12465 attr = dwarf2_attr (die, DW_AT_name, cu);
12466 if ((!attr || !DW_STRING (attr))
12467 && die->tag != DW_TAG_class_type
12468 && die->tag != DW_TAG_interface_type
12469 && die->tag != DW_TAG_structure_type
12470 && die->tag != DW_TAG_union_type)
12471 return NULL;
12472
12473 switch (die->tag)
12474 {
12475 case DW_TAG_compile_unit:
12476 /* Compilation units have a DW_AT_name that is a filename, not
12477 a source language identifier. */
12478 case DW_TAG_enumeration_type:
12479 case DW_TAG_enumerator:
12480 /* These tags always have simple identifiers already; no need
12481 to canonicalize them. */
12482 return DW_STRING (attr);
12483
12484 case DW_TAG_subprogram:
12485 /* Java constructors will all be named "<init>", so return
12486 the class name when we see this special case. */
12487 if (cu->language == language_java
12488 && DW_STRING (attr) != NULL
12489 && strcmp (DW_STRING (attr), "<init>") == 0)
12490 {
12491 struct dwarf2_cu *spec_cu = cu;
12492 struct die_info *spec_die;
12493
12494 /* GCJ will output '<init>' for Java constructor names.
12495 For this special case, return the name of the parent class. */
12496
12497 /* GCJ may output suprogram DIEs with AT_specification set.
12498 If so, use the name of the specified DIE. */
12499 spec_die = die_specification (die, &spec_cu);
12500 if (spec_die != NULL)
12501 return dwarf2_name (spec_die, spec_cu);
12502
12503 do
12504 {
12505 die = die->parent;
12506 if (die->tag == DW_TAG_class_type)
12507 return dwarf2_name (die, cu);
12508 }
12509 while (die->tag != DW_TAG_compile_unit);
12510 }
12511 break;
12512
12513 case DW_TAG_class_type:
12514 case DW_TAG_interface_type:
12515 case DW_TAG_structure_type:
12516 case DW_TAG_union_type:
12517 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12518 structures or unions. These were of the form "._%d" in GCC 4.1,
12519 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12520 and GCC 4.4. We work around this problem by ignoring these. */
12521 if (attr && DW_STRING (attr)
12522 && (strncmp (DW_STRING (attr), "._", 2) == 0
12523 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
12524 return NULL;
12525
12526 /* GCC might emit a nameless typedef that has a linkage name. See
12527 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12528 if (!attr || DW_STRING (attr) == NULL)
12529 {
12530 char *demangled = NULL;
12531
12532 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
12533 if (attr == NULL)
12534 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
12535
12536 if (attr == NULL || DW_STRING (attr) == NULL)
12537 return NULL;
12538
12539 /* Avoid demangling DW_STRING (attr) the second time on a second
12540 call for the same DIE. */
12541 if (!DW_STRING_IS_CANONICAL (attr))
12542 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
12543
12544 if (demangled)
12545 {
12546 char *base;
12547
12548 /* FIXME: we already did this for the partial symbol... */
12549 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
12550 &cu->objfile->objfile_obstack);
12551 DW_STRING_IS_CANONICAL (attr) = 1;
12552 xfree (demangled);
12553
12554 /* Strip any leading namespaces/classes, keep only the base name.
12555 DW_AT_name for named DIEs does not contain the prefixes. */
12556 base = strrchr (DW_STRING (attr), ':');
12557 if (base && base > DW_STRING (attr) && base[-1] == ':')
12558 return &base[1];
12559 else
12560 return DW_STRING (attr);
12561 }
12562 }
12563 break;
12564
12565 default:
12566 break;
12567 }
12568
12569 if (!DW_STRING_IS_CANONICAL (attr))
12570 {
12571 DW_STRING (attr)
12572 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
12573 &cu->objfile->objfile_obstack);
12574 DW_STRING_IS_CANONICAL (attr) = 1;
12575 }
12576 return DW_STRING (attr);
12577 }
12578
12579 /* Return the die that this die in an extension of, or NULL if there
12580 is none. *EXT_CU is the CU containing DIE on input, and the CU
12581 containing the return value on output. */
12582
12583 static struct die_info *
12584 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
12585 {
12586 struct attribute *attr;
12587
12588 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
12589 if (attr == NULL)
12590 return NULL;
12591
12592 return follow_die_ref (die, attr, ext_cu);
12593 }
12594
12595 /* Convert a DIE tag into its string name. */
12596
12597 static char *
12598 dwarf_tag_name (unsigned tag)
12599 {
12600 switch (tag)
12601 {
12602 case DW_TAG_padding:
12603 return "DW_TAG_padding";
12604 case DW_TAG_array_type:
12605 return "DW_TAG_array_type";
12606 case DW_TAG_class_type:
12607 return "DW_TAG_class_type";
12608 case DW_TAG_entry_point:
12609 return "DW_TAG_entry_point";
12610 case DW_TAG_enumeration_type:
12611 return "DW_TAG_enumeration_type";
12612 case DW_TAG_formal_parameter:
12613 return "DW_TAG_formal_parameter";
12614 case DW_TAG_imported_declaration:
12615 return "DW_TAG_imported_declaration";
12616 case DW_TAG_label:
12617 return "DW_TAG_label";
12618 case DW_TAG_lexical_block:
12619 return "DW_TAG_lexical_block";
12620 case DW_TAG_member:
12621 return "DW_TAG_member";
12622 case DW_TAG_pointer_type:
12623 return "DW_TAG_pointer_type";
12624 case DW_TAG_reference_type:
12625 return "DW_TAG_reference_type";
12626 case DW_TAG_compile_unit:
12627 return "DW_TAG_compile_unit";
12628 case DW_TAG_string_type:
12629 return "DW_TAG_string_type";
12630 case DW_TAG_structure_type:
12631 return "DW_TAG_structure_type";
12632 case DW_TAG_subroutine_type:
12633 return "DW_TAG_subroutine_type";
12634 case DW_TAG_typedef:
12635 return "DW_TAG_typedef";
12636 case DW_TAG_union_type:
12637 return "DW_TAG_union_type";
12638 case DW_TAG_unspecified_parameters:
12639 return "DW_TAG_unspecified_parameters";
12640 case DW_TAG_variant:
12641 return "DW_TAG_variant";
12642 case DW_TAG_common_block:
12643 return "DW_TAG_common_block";
12644 case DW_TAG_common_inclusion:
12645 return "DW_TAG_common_inclusion";
12646 case DW_TAG_inheritance:
12647 return "DW_TAG_inheritance";
12648 case DW_TAG_inlined_subroutine:
12649 return "DW_TAG_inlined_subroutine";
12650 case DW_TAG_module:
12651 return "DW_TAG_module";
12652 case DW_TAG_ptr_to_member_type:
12653 return "DW_TAG_ptr_to_member_type";
12654 case DW_TAG_set_type:
12655 return "DW_TAG_set_type";
12656 case DW_TAG_subrange_type:
12657 return "DW_TAG_subrange_type";
12658 case DW_TAG_with_stmt:
12659 return "DW_TAG_with_stmt";
12660 case DW_TAG_access_declaration:
12661 return "DW_TAG_access_declaration";
12662 case DW_TAG_base_type:
12663 return "DW_TAG_base_type";
12664 case DW_TAG_catch_block:
12665 return "DW_TAG_catch_block";
12666 case DW_TAG_const_type:
12667 return "DW_TAG_const_type";
12668 case DW_TAG_constant:
12669 return "DW_TAG_constant";
12670 case DW_TAG_enumerator:
12671 return "DW_TAG_enumerator";
12672 case DW_TAG_file_type:
12673 return "DW_TAG_file_type";
12674 case DW_TAG_friend:
12675 return "DW_TAG_friend";
12676 case DW_TAG_namelist:
12677 return "DW_TAG_namelist";
12678 case DW_TAG_namelist_item:
12679 return "DW_TAG_namelist_item";
12680 case DW_TAG_packed_type:
12681 return "DW_TAG_packed_type";
12682 case DW_TAG_subprogram:
12683 return "DW_TAG_subprogram";
12684 case DW_TAG_template_type_param:
12685 return "DW_TAG_template_type_param";
12686 case DW_TAG_template_value_param:
12687 return "DW_TAG_template_value_param";
12688 case DW_TAG_thrown_type:
12689 return "DW_TAG_thrown_type";
12690 case DW_TAG_try_block:
12691 return "DW_TAG_try_block";
12692 case DW_TAG_variant_part:
12693 return "DW_TAG_variant_part";
12694 case DW_TAG_variable:
12695 return "DW_TAG_variable";
12696 case DW_TAG_volatile_type:
12697 return "DW_TAG_volatile_type";
12698 case DW_TAG_dwarf_procedure:
12699 return "DW_TAG_dwarf_procedure";
12700 case DW_TAG_restrict_type:
12701 return "DW_TAG_restrict_type";
12702 case DW_TAG_interface_type:
12703 return "DW_TAG_interface_type";
12704 case DW_TAG_namespace:
12705 return "DW_TAG_namespace";
12706 case DW_TAG_imported_module:
12707 return "DW_TAG_imported_module";
12708 case DW_TAG_unspecified_type:
12709 return "DW_TAG_unspecified_type";
12710 case DW_TAG_partial_unit:
12711 return "DW_TAG_partial_unit";
12712 case DW_TAG_imported_unit:
12713 return "DW_TAG_imported_unit";
12714 case DW_TAG_condition:
12715 return "DW_TAG_condition";
12716 case DW_TAG_shared_type:
12717 return "DW_TAG_shared_type";
12718 case DW_TAG_type_unit:
12719 return "DW_TAG_type_unit";
12720 case DW_TAG_MIPS_loop:
12721 return "DW_TAG_MIPS_loop";
12722 case DW_TAG_HP_array_descriptor:
12723 return "DW_TAG_HP_array_descriptor";
12724 case DW_TAG_format_label:
12725 return "DW_TAG_format_label";
12726 case DW_TAG_function_template:
12727 return "DW_TAG_function_template";
12728 case DW_TAG_class_template:
12729 return "DW_TAG_class_template";
12730 case DW_TAG_GNU_BINCL:
12731 return "DW_TAG_GNU_BINCL";
12732 case DW_TAG_GNU_EINCL:
12733 return "DW_TAG_GNU_EINCL";
12734 case DW_TAG_upc_shared_type:
12735 return "DW_TAG_upc_shared_type";
12736 case DW_TAG_upc_strict_type:
12737 return "DW_TAG_upc_strict_type";
12738 case DW_TAG_upc_relaxed_type:
12739 return "DW_TAG_upc_relaxed_type";
12740 case DW_TAG_PGI_kanji_type:
12741 return "DW_TAG_PGI_kanji_type";
12742 case DW_TAG_PGI_interface_block:
12743 return "DW_TAG_PGI_interface_block";
12744 default:
12745 return "DW_TAG_<unknown>";
12746 }
12747 }
12748
12749 /* Convert a DWARF attribute code into its string name. */
12750
12751 static char *
12752 dwarf_attr_name (unsigned attr)
12753 {
12754 switch (attr)
12755 {
12756 case DW_AT_sibling:
12757 return "DW_AT_sibling";
12758 case DW_AT_location:
12759 return "DW_AT_location";
12760 case DW_AT_name:
12761 return "DW_AT_name";
12762 case DW_AT_ordering:
12763 return "DW_AT_ordering";
12764 case DW_AT_subscr_data:
12765 return "DW_AT_subscr_data";
12766 case DW_AT_byte_size:
12767 return "DW_AT_byte_size";
12768 case DW_AT_bit_offset:
12769 return "DW_AT_bit_offset";
12770 case DW_AT_bit_size:
12771 return "DW_AT_bit_size";
12772 case DW_AT_element_list:
12773 return "DW_AT_element_list";
12774 case DW_AT_stmt_list:
12775 return "DW_AT_stmt_list";
12776 case DW_AT_low_pc:
12777 return "DW_AT_low_pc";
12778 case DW_AT_high_pc:
12779 return "DW_AT_high_pc";
12780 case DW_AT_language:
12781 return "DW_AT_language";
12782 case DW_AT_member:
12783 return "DW_AT_member";
12784 case DW_AT_discr:
12785 return "DW_AT_discr";
12786 case DW_AT_discr_value:
12787 return "DW_AT_discr_value";
12788 case DW_AT_visibility:
12789 return "DW_AT_visibility";
12790 case DW_AT_import:
12791 return "DW_AT_import";
12792 case DW_AT_string_length:
12793 return "DW_AT_string_length";
12794 case DW_AT_common_reference:
12795 return "DW_AT_common_reference";
12796 case DW_AT_comp_dir:
12797 return "DW_AT_comp_dir";
12798 case DW_AT_const_value:
12799 return "DW_AT_const_value";
12800 case DW_AT_containing_type:
12801 return "DW_AT_containing_type";
12802 case DW_AT_default_value:
12803 return "DW_AT_default_value";
12804 case DW_AT_inline:
12805 return "DW_AT_inline";
12806 case DW_AT_is_optional:
12807 return "DW_AT_is_optional";
12808 case DW_AT_lower_bound:
12809 return "DW_AT_lower_bound";
12810 case DW_AT_producer:
12811 return "DW_AT_producer";
12812 case DW_AT_prototyped:
12813 return "DW_AT_prototyped";
12814 case DW_AT_return_addr:
12815 return "DW_AT_return_addr";
12816 case DW_AT_start_scope:
12817 return "DW_AT_start_scope";
12818 case DW_AT_bit_stride:
12819 return "DW_AT_bit_stride";
12820 case DW_AT_upper_bound:
12821 return "DW_AT_upper_bound";
12822 case DW_AT_abstract_origin:
12823 return "DW_AT_abstract_origin";
12824 case DW_AT_accessibility:
12825 return "DW_AT_accessibility";
12826 case DW_AT_address_class:
12827 return "DW_AT_address_class";
12828 case DW_AT_artificial:
12829 return "DW_AT_artificial";
12830 case DW_AT_base_types:
12831 return "DW_AT_base_types";
12832 case DW_AT_calling_convention:
12833 return "DW_AT_calling_convention";
12834 case DW_AT_count:
12835 return "DW_AT_count";
12836 case DW_AT_data_member_location:
12837 return "DW_AT_data_member_location";
12838 case DW_AT_decl_column:
12839 return "DW_AT_decl_column";
12840 case DW_AT_decl_file:
12841 return "DW_AT_decl_file";
12842 case DW_AT_decl_line:
12843 return "DW_AT_decl_line";
12844 case DW_AT_declaration:
12845 return "DW_AT_declaration";
12846 case DW_AT_discr_list:
12847 return "DW_AT_discr_list";
12848 case DW_AT_encoding:
12849 return "DW_AT_encoding";
12850 case DW_AT_external:
12851 return "DW_AT_external";
12852 case DW_AT_frame_base:
12853 return "DW_AT_frame_base";
12854 case DW_AT_friend:
12855 return "DW_AT_friend";
12856 case DW_AT_identifier_case:
12857 return "DW_AT_identifier_case";
12858 case DW_AT_macro_info:
12859 return "DW_AT_macro_info";
12860 case DW_AT_namelist_items:
12861 return "DW_AT_namelist_items";
12862 case DW_AT_priority:
12863 return "DW_AT_priority";
12864 case DW_AT_segment:
12865 return "DW_AT_segment";
12866 case DW_AT_specification:
12867 return "DW_AT_specification";
12868 case DW_AT_static_link:
12869 return "DW_AT_static_link";
12870 case DW_AT_type:
12871 return "DW_AT_type";
12872 case DW_AT_use_location:
12873 return "DW_AT_use_location";
12874 case DW_AT_variable_parameter:
12875 return "DW_AT_variable_parameter";
12876 case DW_AT_virtuality:
12877 return "DW_AT_virtuality";
12878 case DW_AT_vtable_elem_location:
12879 return "DW_AT_vtable_elem_location";
12880 /* DWARF 3 values. */
12881 case DW_AT_allocated:
12882 return "DW_AT_allocated";
12883 case DW_AT_associated:
12884 return "DW_AT_associated";
12885 case DW_AT_data_location:
12886 return "DW_AT_data_location";
12887 case DW_AT_byte_stride:
12888 return "DW_AT_byte_stride";
12889 case DW_AT_entry_pc:
12890 return "DW_AT_entry_pc";
12891 case DW_AT_use_UTF8:
12892 return "DW_AT_use_UTF8";
12893 case DW_AT_extension:
12894 return "DW_AT_extension";
12895 case DW_AT_ranges:
12896 return "DW_AT_ranges";
12897 case DW_AT_trampoline:
12898 return "DW_AT_trampoline";
12899 case DW_AT_call_column:
12900 return "DW_AT_call_column";
12901 case DW_AT_call_file:
12902 return "DW_AT_call_file";
12903 case DW_AT_call_line:
12904 return "DW_AT_call_line";
12905 case DW_AT_description:
12906 return "DW_AT_description";
12907 case DW_AT_binary_scale:
12908 return "DW_AT_binary_scale";
12909 case DW_AT_decimal_scale:
12910 return "DW_AT_decimal_scale";
12911 case DW_AT_small:
12912 return "DW_AT_small";
12913 case DW_AT_decimal_sign:
12914 return "DW_AT_decimal_sign";
12915 case DW_AT_digit_count:
12916 return "DW_AT_digit_count";
12917 case DW_AT_picture_string:
12918 return "DW_AT_picture_string";
12919 case DW_AT_mutable:
12920 return "DW_AT_mutable";
12921 case DW_AT_threads_scaled:
12922 return "DW_AT_threads_scaled";
12923 case DW_AT_explicit:
12924 return "DW_AT_explicit";
12925 case DW_AT_object_pointer:
12926 return "DW_AT_object_pointer";
12927 case DW_AT_endianity:
12928 return "DW_AT_endianity";
12929 case DW_AT_elemental:
12930 return "DW_AT_elemental";
12931 case DW_AT_pure:
12932 return "DW_AT_pure";
12933 case DW_AT_recursive:
12934 return "DW_AT_recursive";
12935 /* DWARF 4 values. */
12936 case DW_AT_signature:
12937 return "DW_AT_signature";
12938 case DW_AT_linkage_name:
12939 return "DW_AT_linkage_name";
12940 /* SGI/MIPS extensions. */
12941 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12942 case DW_AT_MIPS_fde:
12943 return "DW_AT_MIPS_fde";
12944 #endif
12945 case DW_AT_MIPS_loop_begin:
12946 return "DW_AT_MIPS_loop_begin";
12947 case DW_AT_MIPS_tail_loop_begin:
12948 return "DW_AT_MIPS_tail_loop_begin";
12949 case DW_AT_MIPS_epilog_begin:
12950 return "DW_AT_MIPS_epilog_begin";
12951 case DW_AT_MIPS_loop_unroll_factor:
12952 return "DW_AT_MIPS_loop_unroll_factor";
12953 case DW_AT_MIPS_software_pipeline_depth:
12954 return "DW_AT_MIPS_software_pipeline_depth";
12955 case DW_AT_MIPS_linkage_name:
12956 return "DW_AT_MIPS_linkage_name";
12957 case DW_AT_MIPS_stride:
12958 return "DW_AT_MIPS_stride";
12959 case DW_AT_MIPS_abstract_name:
12960 return "DW_AT_MIPS_abstract_name";
12961 case DW_AT_MIPS_clone_origin:
12962 return "DW_AT_MIPS_clone_origin";
12963 case DW_AT_MIPS_has_inlines:
12964 return "DW_AT_MIPS_has_inlines";
12965 /* HP extensions. */
12966 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12967 case DW_AT_HP_block_index:
12968 return "DW_AT_HP_block_index";
12969 #endif
12970 case DW_AT_HP_unmodifiable:
12971 return "DW_AT_HP_unmodifiable";
12972 case DW_AT_HP_actuals_stmt_list:
12973 return "DW_AT_HP_actuals_stmt_list";
12974 case DW_AT_HP_proc_per_section:
12975 return "DW_AT_HP_proc_per_section";
12976 case DW_AT_HP_raw_data_ptr:
12977 return "DW_AT_HP_raw_data_ptr";
12978 case DW_AT_HP_pass_by_reference:
12979 return "DW_AT_HP_pass_by_reference";
12980 case DW_AT_HP_opt_level:
12981 return "DW_AT_HP_opt_level";
12982 case DW_AT_HP_prof_version_id:
12983 return "DW_AT_HP_prof_version_id";
12984 case DW_AT_HP_opt_flags:
12985 return "DW_AT_HP_opt_flags";
12986 case DW_AT_HP_cold_region_low_pc:
12987 return "DW_AT_HP_cold_region_low_pc";
12988 case DW_AT_HP_cold_region_high_pc:
12989 return "DW_AT_HP_cold_region_high_pc";
12990 case DW_AT_HP_all_variables_modifiable:
12991 return "DW_AT_HP_all_variables_modifiable";
12992 case DW_AT_HP_linkage_name:
12993 return "DW_AT_HP_linkage_name";
12994 case DW_AT_HP_prof_flags:
12995 return "DW_AT_HP_prof_flags";
12996 /* GNU extensions. */
12997 case DW_AT_sf_names:
12998 return "DW_AT_sf_names";
12999 case DW_AT_src_info:
13000 return "DW_AT_src_info";
13001 case DW_AT_mac_info:
13002 return "DW_AT_mac_info";
13003 case DW_AT_src_coords:
13004 return "DW_AT_src_coords";
13005 case DW_AT_body_begin:
13006 return "DW_AT_body_begin";
13007 case DW_AT_body_end:
13008 return "DW_AT_body_end";
13009 case DW_AT_GNU_vector:
13010 return "DW_AT_GNU_vector";
13011 case DW_AT_GNU_odr_signature:
13012 return "DW_AT_GNU_odr_signature";
13013 /* VMS extensions. */
13014 case DW_AT_VMS_rtnbeg_pd_address:
13015 return "DW_AT_VMS_rtnbeg_pd_address";
13016 /* UPC extension. */
13017 case DW_AT_upc_threads_scaled:
13018 return "DW_AT_upc_threads_scaled";
13019 /* PGI (STMicroelectronics) extensions. */
13020 case DW_AT_PGI_lbase:
13021 return "DW_AT_PGI_lbase";
13022 case DW_AT_PGI_soffset:
13023 return "DW_AT_PGI_soffset";
13024 case DW_AT_PGI_lstride:
13025 return "DW_AT_PGI_lstride";
13026 default:
13027 return "DW_AT_<unknown>";
13028 }
13029 }
13030
13031 /* Convert a DWARF value form code into its string name. */
13032
13033 static char *
13034 dwarf_form_name (unsigned form)
13035 {
13036 switch (form)
13037 {
13038 case DW_FORM_addr:
13039 return "DW_FORM_addr";
13040 case DW_FORM_block2:
13041 return "DW_FORM_block2";
13042 case DW_FORM_block4:
13043 return "DW_FORM_block4";
13044 case DW_FORM_data2:
13045 return "DW_FORM_data2";
13046 case DW_FORM_data4:
13047 return "DW_FORM_data4";
13048 case DW_FORM_data8:
13049 return "DW_FORM_data8";
13050 case DW_FORM_string:
13051 return "DW_FORM_string";
13052 case DW_FORM_block:
13053 return "DW_FORM_block";
13054 case DW_FORM_block1:
13055 return "DW_FORM_block1";
13056 case DW_FORM_data1:
13057 return "DW_FORM_data1";
13058 case DW_FORM_flag:
13059 return "DW_FORM_flag";
13060 case DW_FORM_sdata:
13061 return "DW_FORM_sdata";
13062 case DW_FORM_strp:
13063 return "DW_FORM_strp";
13064 case DW_FORM_udata:
13065 return "DW_FORM_udata";
13066 case DW_FORM_ref_addr:
13067 return "DW_FORM_ref_addr";
13068 case DW_FORM_ref1:
13069 return "DW_FORM_ref1";
13070 case DW_FORM_ref2:
13071 return "DW_FORM_ref2";
13072 case DW_FORM_ref4:
13073 return "DW_FORM_ref4";
13074 case DW_FORM_ref8:
13075 return "DW_FORM_ref8";
13076 case DW_FORM_ref_udata:
13077 return "DW_FORM_ref_udata";
13078 case DW_FORM_indirect:
13079 return "DW_FORM_indirect";
13080 case DW_FORM_sec_offset:
13081 return "DW_FORM_sec_offset";
13082 case DW_FORM_exprloc:
13083 return "DW_FORM_exprloc";
13084 case DW_FORM_flag_present:
13085 return "DW_FORM_flag_present";
13086 case DW_FORM_ref_sig8:
13087 return "DW_FORM_ref_sig8";
13088 default:
13089 return "DW_FORM_<unknown>";
13090 }
13091 }
13092
13093 /* Convert a DWARF stack opcode into its string name. */
13094
13095 const char *
13096 dwarf_stack_op_name (unsigned op)
13097 {
13098 switch (op)
13099 {
13100 case DW_OP_addr:
13101 return "DW_OP_addr";
13102 case DW_OP_deref:
13103 return "DW_OP_deref";
13104 case DW_OP_const1u:
13105 return "DW_OP_const1u";
13106 case DW_OP_const1s:
13107 return "DW_OP_const1s";
13108 case DW_OP_const2u:
13109 return "DW_OP_const2u";
13110 case DW_OP_const2s:
13111 return "DW_OP_const2s";
13112 case DW_OP_const4u:
13113 return "DW_OP_const4u";
13114 case DW_OP_const4s:
13115 return "DW_OP_const4s";
13116 case DW_OP_const8u:
13117 return "DW_OP_const8u";
13118 case DW_OP_const8s:
13119 return "DW_OP_const8s";
13120 case DW_OP_constu:
13121 return "DW_OP_constu";
13122 case DW_OP_consts:
13123 return "DW_OP_consts";
13124 case DW_OP_dup:
13125 return "DW_OP_dup";
13126 case DW_OP_drop:
13127 return "DW_OP_drop";
13128 case DW_OP_over:
13129 return "DW_OP_over";
13130 case DW_OP_pick:
13131 return "DW_OP_pick";
13132 case DW_OP_swap:
13133 return "DW_OP_swap";
13134 case DW_OP_rot:
13135 return "DW_OP_rot";
13136 case DW_OP_xderef:
13137 return "DW_OP_xderef";
13138 case DW_OP_abs:
13139 return "DW_OP_abs";
13140 case DW_OP_and:
13141 return "DW_OP_and";
13142 case DW_OP_div:
13143 return "DW_OP_div";
13144 case DW_OP_minus:
13145 return "DW_OP_minus";
13146 case DW_OP_mod:
13147 return "DW_OP_mod";
13148 case DW_OP_mul:
13149 return "DW_OP_mul";
13150 case DW_OP_neg:
13151 return "DW_OP_neg";
13152 case DW_OP_not:
13153 return "DW_OP_not";
13154 case DW_OP_or:
13155 return "DW_OP_or";
13156 case DW_OP_plus:
13157 return "DW_OP_plus";
13158 case DW_OP_plus_uconst:
13159 return "DW_OP_plus_uconst";
13160 case DW_OP_shl:
13161 return "DW_OP_shl";
13162 case DW_OP_shr:
13163 return "DW_OP_shr";
13164 case DW_OP_shra:
13165 return "DW_OP_shra";
13166 case DW_OP_xor:
13167 return "DW_OP_xor";
13168 case DW_OP_bra:
13169 return "DW_OP_bra";
13170 case DW_OP_eq:
13171 return "DW_OP_eq";
13172 case DW_OP_ge:
13173 return "DW_OP_ge";
13174 case DW_OP_gt:
13175 return "DW_OP_gt";
13176 case DW_OP_le:
13177 return "DW_OP_le";
13178 case DW_OP_lt:
13179 return "DW_OP_lt";
13180 case DW_OP_ne:
13181 return "DW_OP_ne";
13182 case DW_OP_skip:
13183 return "DW_OP_skip";
13184 case DW_OP_lit0:
13185 return "DW_OP_lit0";
13186 case DW_OP_lit1:
13187 return "DW_OP_lit1";
13188 case DW_OP_lit2:
13189 return "DW_OP_lit2";
13190 case DW_OP_lit3:
13191 return "DW_OP_lit3";
13192 case DW_OP_lit4:
13193 return "DW_OP_lit4";
13194 case DW_OP_lit5:
13195 return "DW_OP_lit5";
13196 case DW_OP_lit6:
13197 return "DW_OP_lit6";
13198 case DW_OP_lit7:
13199 return "DW_OP_lit7";
13200 case DW_OP_lit8:
13201 return "DW_OP_lit8";
13202 case DW_OP_lit9:
13203 return "DW_OP_lit9";
13204 case DW_OP_lit10:
13205 return "DW_OP_lit10";
13206 case DW_OP_lit11:
13207 return "DW_OP_lit11";
13208 case DW_OP_lit12:
13209 return "DW_OP_lit12";
13210 case DW_OP_lit13:
13211 return "DW_OP_lit13";
13212 case DW_OP_lit14:
13213 return "DW_OP_lit14";
13214 case DW_OP_lit15:
13215 return "DW_OP_lit15";
13216 case DW_OP_lit16:
13217 return "DW_OP_lit16";
13218 case DW_OP_lit17:
13219 return "DW_OP_lit17";
13220 case DW_OP_lit18:
13221 return "DW_OP_lit18";
13222 case DW_OP_lit19:
13223 return "DW_OP_lit19";
13224 case DW_OP_lit20:
13225 return "DW_OP_lit20";
13226 case DW_OP_lit21:
13227 return "DW_OP_lit21";
13228 case DW_OP_lit22:
13229 return "DW_OP_lit22";
13230 case DW_OP_lit23:
13231 return "DW_OP_lit23";
13232 case DW_OP_lit24:
13233 return "DW_OP_lit24";
13234 case DW_OP_lit25:
13235 return "DW_OP_lit25";
13236 case DW_OP_lit26:
13237 return "DW_OP_lit26";
13238 case DW_OP_lit27:
13239 return "DW_OP_lit27";
13240 case DW_OP_lit28:
13241 return "DW_OP_lit28";
13242 case DW_OP_lit29:
13243 return "DW_OP_lit29";
13244 case DW_OP_lit30:
13245 return "DW_OP_lit30";
13246 case DW_OP_lit31:
13247 return "DW_OP_lit31";
13248 case DW_OP_reg0:
13249 return "DW_OP_reg0";
13250 case DW_OP_reg1:
13251 return "DW_OP_reg1";
13252 case DW_OP_reg2:
13253 return "DW_OP_reg2";
13254 case DW_OP_reg3:
13255 return "DW_OP_reg3";
13256 case DW_OP_reg4:
13257 return "DW_OP_reg4";
13258 case DW_OP_reg5:
13259 return "DW_OP_reg5";
13260 case DW_OP_reg6:
13261 return "DW_OP_reg6";
13262 case DW_OP_reg7:
13263 return "DW_OP_reg7";
13264 case DW_OP_reg8:
13265 return "DW_OP_reg8";
13266 case DW_OP_reg9:
13267 return "DW_OP_reg9";
13268 case DW_OP_reg10:
13269 return "DW_OP_reg10";
13270 case DW_OP_reg11:
13271 return "DW_OP_reg11";
13272 case DW_OP_reg12:
13273 return "DW_OP_reg12";
13274 case DW_OP_reg13:
13275 return "DW_OP_reg13";
13276 case DW_OP_reg14:
13277 return "DW_OP_reg14";
13278 case DW_OP_reg15:
13279 return "DW_OP_reg15";
13280 case DW_OP_reg16:
13281 return "DW_OP_reg16";
13282 case DW_OP_reg17:
13283 return "DW_OP_reg17";
13284 case DW_OP_reg18:
13285 return "DW_OP_reg18";
13286 case DW_OP_reg19:
13287 return "DW_OP_reg19";
13288 case DW_OP_reg20:
13289 return "DW_OP_reg20";
13290 case DW_OP_reg21:
13291 return "DW_OP_reg21";
13292 case DW_OP_reg22:
13293 return "DW_OP_reg22";
13294 case DW_OP_reg23:
13295 return "DW_OP_reg23";
13296 case DW_OP_reg24:
13297 return "DW_OP_reg24";
13298 case DW_OP_reg25:
13299 return "DW_OP_reg25";
13300 case DW_OP_reg26:
13301 return "DW_OP_reg26";
13302 case DW_OP_reg27:
13303 return "DW_OP_reg27";
13304 case DW_OP_reg28:
13305 return "DW_OP_reg28";
13306 case DW_OP_reg29:
13307 return "DW_OP_reg29";
13308 case DW_OP_reg30:
13309 return "DW_OP_reg30";
13310 case DW_OP_reg31:
13311 return "DW_OP_reg31";
13312 case DW_OP_breg0:
13313 return "DW_OP_breg0";
13314 case DW_OP_breg1:
13315 return "DW_OP_breg1";
13316 case DW_OP_breg2:
13317 return "DW_OP_breg2";
13318 case DW_OP_breg3:
13319 return "DW_OP_breg3";
13320 case DW_OP_breg4:
13321 return "DW_OP_breg4";
13322 case DW_OP_breg5:
13323 return "DW_OP_breg5";
13324 case DW_OP_breg6:
13325 return "DW_OP_breg6";
13326 case DW_OP_breg7:
13327 return "DW_OP_breg7";
13328 case DW_OP_breg8:
13329 return "DW_OP_breg8";
13330 case DW_OP_breg9:
13331 return "DW_OP_breg9";
13332 case DW_OP_breg10:
13333 return "DW_OP_breg10";
13334 case DW_OP_breg11:
13335 return "DW_OP_breg11";
13336 case DW_OP_breg12:
13337 return "DW_OP_breg12";
13338 case DW_OP_breg13:
13339 return "DW_OP_breg13";
13340 case DW_OP_breg14:
13341 return "DW_OP_breg14";
13342 case DW_OP_breg15:
13343 return "DW_OP_breg15";
13344 case DW_OP_breg16:
13345 return "DW_OP_breg16";
13346 case DW_OP_breg17:
13347 return "DW_OP_breg17";
13348 case DW_OP_breg18:
13349 return "DW_OP_breg18";
13350 case DW_OP_breg19:
13351 return "DW_OP_breg19";
13352 case DW_OP_breg20:
13353 return "DW_OP_breg20";
13354 case DW_OP_breg21:
13355 return "DW_OP_breg21";
13356 case DW_OP_breg22:
13357 return "DW_OP_breg22";
13358 case DW_OP_breg23:
13359 return "DW_OP_breg23";
13360 case DW_OP_breg24:
13361 return "DW_OP_breg24";
13362 case DW_OP_breg25:
13363 return "DW_OP_breg25";
13364 case DW_OP_breg26:
13365 return "DW_OP_breg26";
13366 case DW_OP_breg27:
13367 return "DW_OP_breg27";
13368 case DW_OP_breg28:
13369 return "DW_OP_breg28";
13370 case DW_OP_breg29:
13371 return "DW_OP_breg29";
13372 case DW_OP_breg30:
13373 return "DW_OP_breg30";
13374 case DW_OP_breg31:
13375 return "DW_OP_breg31";
13376 case DW_OP_regx:
13377 return "DW_OP_regx";
13378 case DW_OP_fbreg:
13379 return "DW_OP_fbreg";
13380 case DW_OP_bregx:
13381 return "DW_OP_bregx";
13382 case DW_OP_piece:
13383 return "DW_OP_piece";
13384 case DW_OP_deref_size:
13385 return "DW_OP_deref_size";
13386 case DW_OP_xderef_size:
13387 return "DW_OP_xderef_size";
13388 case DW_OP_nop:
13389 return "DW_OP_nop";
13390 /* DWARF 3 extensions. */
13391 case DW_OP_push_object_address:
13392 return "DW_OP_push_object_address";
13393 case DW_OP_call2:
13394 return "DW_OP_call2";
13395 case DW_OP_call4:
13396 return "DW_OP_call4";
13397 case DW_OP_call_ref:
13398 return "DW_OP_call_ref";
13399 case DW_OP_form_tls_address:
13400 return "DW_OP_form_tls_address";
13401 case DW_OP_call_frame_cfa:
13402 return "DW_OP_call_frame_cfa";
13403 case DW_OP_bit_piece:
13404 return "DW_OP_bit_piece";
13405 /* DWARF 4 extensions. */
13406 case DW_OP_implicit_value:
13407 return "DW_OP_implicit_value";
13408 case DW_OP_stack_value:
13409 return "DW_OP_stack_value";
13410 /* GNU extensions. */
13411 case DW_OP_GNU_push_tls_address:
13412 return "DW_OP_GNU_push_tls_address";
13413 case DW_OP_GNU_uninit:
13414 return "DW_OP_GNU_uninit";
13415 case DW_OP_GNU_implicit_pointer:
13416 return "DW_OP_GNU_implicit_pointer";
13417 case DW_OP_GNU_entry_value:
13418 return "DW_OP_GNU_entry_value";
13419 case DW_OP_GNU_const_type:
13420 return "DW_OP_GNU_const_type";
13421 case DW_OP_GNU_regval_type:
13422 return "DW_OP_GNU_regval_type";
13423 case DW_OP_GNU_deref_type:
13424 return "DW_OP_GNU_deref_type";
13425 case DW_OP_GNU_convert:
13426 return "DW_OP_GNU_convert";
13427 case DW_OP_GNU_reinterpret:
13428 return "DW_OP_GNU_reinterpret";
13429 default:
13430 return NULL;
13431 }
13432 }
13433
13434 static char *
13435 dwarf_bool_name (unsigned mybool)
13436 {
13437 if (mybool)
13438 return "TRUE";
13439 else
13440 return "FALSE";
13441 }
13442
13443 /* Convert a DWARF type code into its string name. */
13444
13445 static char *
13446 dwarf_type_encoding_name (unsigned enc)
13447 {
13448 switch (enc)
13449 {
13450 case DW_ATE_void:
13451 return "DW_ATE_void";
13452 case DW_ATE_address:
13453 return "DW_ATE_address";
13454 case DW_ATE_boolean:
13455 return "DW_ATE_boolean";
13456 case DW_ATE_complex_float:
13457 return "DW_ATE_complex_float";
13458 case DW_ATE_float:
13459 return "DW_ATE_float";
13460 case DW_ATE_signed:
13461 return "DW_ATE_signed";
13462 case DW_ATE_signed_char:
13463 return "DW_ATE_signed_char";
13464 case DW_ATE_unsigned:
13465 return "DW_ATE_unsigned";
13466 case DW_ATE_unsigned_char:
13467 return "DW_ATE_unsigned_char";
13468 /* DWARF 3. */
13469 case DW_ATE_imaginary_float:
13470 return "DW_ATE_imaginary_float";
13471 case DW_ATE_packed_decimal:
13472 return "DW_ATE_packed_decimal";
13473 case DW_ATE_numeric_string:
13474 return "DW_ATE_numeric_string";
13475 case DW_ATE_edited:
13476 return "DW_ATE_edited";
13477 case DW_ATE_signed_fixed:
13478 return "DW_ATE_signed_fixed";
13479 case DW_ATE_unsigned_fixed:
13480 return "DW_ATE_unsigned_fixed";
13481 case DW_ATE_decimal_float:
13482 return "DW_ATE_decimal_float";
13483 /* DWARF 4. */
13484 case DW_ATE_UTF:
13485 return "DW_ATE_UTF";
13486 /* HP extensions. */
13487 case DW_ATE_HP_float80:
13488 return "DW_ATE_HP_float80";
13489 case DW_ATE_HP_complex_float80:
13490 return "DW_ATE_HP_complex_float80";
13491 case DW_ATE_HP_float128:
13492 return "DW_ATE_HP_float128";
13493 case DW_ATE_HP_complex_float128:
13494 return "DW_ATE_HP_complex_float128";
13495 case DW_ATE_HP_floathpintel:
13496 return "DW_ATE_HP_floathpintel";
13497 case DW_ATE_HP_imaginary_float80:
13498 return "DW_ATE_HP_imaginary_float80";
13499 case DW_ATE_HP_imaginary_float128:
13500 return "DW_ATE_HP_imaginary_float128";
13501 default:
13502 return "DW_ATE_<unknown>";
13503 }
13504 }
13505
13506 /* Convert a DWARF call frame info operation to its string name. */
13507
13508 #if 0
13509 static char *
13510 dwarf_cfi_name (unsigned cfi_opc)
13511 {
13512 switch (cfi_opc)
13513 {
13514 case DW_CFA_advance_loc:
13515 return "DW_CFA_advance_loc";
13516 case DW_CFA_offset:
13517 return "DW_CFA_offset";
13518 case DW_CFA_restore:
13519 return "DW_CFA_restore";
13520 case DW_CFA_nop:
13521 return "DW_CFA_nop";
13522 case DW_CFA_set_loc:
13523 return "DW_CFA_set_loc";
13524 case DW_CFA_advance_loc1:
13525 return "DW_CFA_advance_loc1";
13526 case DW_CFA_advance_loc2:
13527 return "DW_CFA_advance_loc2";
13528 case DW_CFA_advance_loc4:
13529 return "DW_CFA_advance_loc4";
13530 case DW_CFA_offset_extended:
13531 return "DW_CFA_offset_extended";
13532 case DW_CFA_restore_extended:
13533 return "DW_CFA_restore_extended";
13534 case DW_CFA_undefined:
13535 return "DW_CFA_undefined";
13536 case DW_CFA_same_value:
13537 return "DW_CFA_same_value";
13538 case DW_CFA_register:
13539 return "DW_CFA_register";
13540 case DW_CFA_remember_state:
13541 return "DW_CFA_remember_state";
13542 case DW_CFA_restore_state:
13543 return "DW_CFA_restore_state";
13544 case DW_CFA_def_cfa:
13545 return "DW_CFA_def_cfa";
13546 case DW_CFA_def_cfa_register:
13547 return "DW_CFA_def_cfa_register";
13548 case DW_CFA_def_cfa_offset:
13549 return "DW_CFA_def_cfa_offset";
13550 /* DWARF 3. */
13551 case DW_CFA_def_cfa_expression:
13552 return "DW_CFA_def_cfa_expression";
13553 case DW_CFA_expression:
13554 return "DW_CFA_expression";
13555 case DW_CFA_offset_extended_sf:
13556 return "DW_CFA_offset_extended_sf";
13557 case DW_CFA_def_cfa_sf:
13558 return "DW_CFA_def_cfa_sf";
13559 case DW_CFA_def_cfa_offset_sf:
13560 return "DW_CFA_def_cfa_offset_sf";
13561 case DW_CFA_val_offset:
13562 return "DW_CFA_val_offset";
13563 case DW_CFA_val_offset_sf:
13564 return "DW_CFA_val_offset_sf";
13565 case DW_CFA_val_expression:
13566 return "DW_CFA_val_expression";
13567 /* SGI/MIPS specific. */
13568 case DW_CFA_MIPS_advance_loc8:
13569 return "DW_CFA_MIPS_advance_loc8";
13570 /* GNU extensions. */
13571 case DW_CFA_GNU_window_save:
13572 return "DW_CFA_GNU_window_save";
13573 case DW_CFA_GNU_args_size:
13574 return "DW_CFA_GNU_args_size";
13575 case DW_CFA_GNU_negative_offset_extended:
13576 return "DW_CFA_GNU_negative_offset_extended";
13577 default:
13578 return "DW_CFA_<unknown>";
13579 }
13580 }
13581 #endif
13582
13583 static void
13584 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
13585 {
13586 unsigned int i;
13587
13588 print_spaces (indent, f);
13589 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
13590 dwarf_tag_name (die->tag), die->abbrev, die->offset);
13591
13592 if (die->parent != NULL)
13593 {
13594 print_spaces (indent, f);
13595 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
13596 die->parent->offset);
13597 }
13598
13599 print_spaces (indent, f);
13600 fprintf_unfiltered (f, " has children: %s\n",
13601 dwarf_bool_name (die->child != NULL));
13602
13603 print_spaces (indent, f);
13604 fprintf_unfiltered (f, " attributes:\n");
13605
13606 for (i = 0; i < die->num_attrs; ++i)
13607 {
13608 print_spaces (indent, f);
13609 fprintf_unfiltered (f, " %s (%s) ",
13610 dwarf_attr_name (die->attrs[i].name),
13611 dwarf_form_name (die->attrs[i].form));
13612
13613 switch (die->attrs[i].form)
13614 {
13615 case DW_FORM_ref_addr:
13616 case DW_FORM_addr:
13617 fprintf_unfiltered (f, "address: ");
13618 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
13619 break;
13620 case DW_FORM_block2:
13621 case DW_FORM_block4:
13622 case DW_FORM_block:
13623 case DW_FORM_block1:
13624 fprintf_unfiltered (f, "block: size %d",
13625 DW_BLOCK (&die->attrs[i])->size);
13626 break;
13627 case DW_FORM_exprloc:
13628 fprintf_unfiltered (f, "expression: size %u",
13629 DW_BLOCK (&die->attrs[i])->size);
13630 break;
13631 case DW_FORM_ref1:
13632 case DW_FORM_ref2:
13633 case DW_FORM_ref4:
13634 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
13635 (long) (DW_ADDR (&die->attrs[i])));
13636 break;
13637 case DW_FORM_data1:
13638 case DW_FORM_data2:
13639 case DW_FORM_data4:
13640 case DW_FORM_data8:
13641 case DW_FORM_udata:
13642 case DW_FORM_sdata:
13643 fprintf_unfiltered (f, "constant: %s",
13644 pulongest (DW_UNSND (&die->attrs[i])));
13645 break;
13646 case DW_FORM_sec_offset:
13647 fprintf_unfiltered (f, "section offset: %s",
13648 pulongest (DW_UNSND (&die->attrs[i])));
13649 break;
13650 case DW_FORM_ref_sig8:
13651 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
13652 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
13653 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset);
13654 else
13655 fprintf_unfiltered (f, "signatured type, offset: unknown");
13656 break;
13657 case DW_FORM_string:
13658 case DW_FORM_strp:
13659 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
13660 DW_STRING (&die->attrs[i])
13661 ? DW_STRING (&die->attrs[i]) : "",
13662 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
13663 break;
13664 case DW_FORM_flag:
13665 if (DW_UNSND (&die->attrs[i]))
13666 fprintf_unfiltered (f, "flag: TRUE");
13667 else
13668 fprintf_unfiltered (f, "flag: FALSE");
13669 break;
13670 case DW_FORM_flag_present:
13671 fprintf_unfiltered (f, "flag: TRUE");
13672 break;
13673 case DW_FORM_indirect:
13674 /* The reader will have reduced the indirect form to
13675 the "base form" so this form should not occur. */
13676 fprintf_unfiltered (f,
13677 "unexpected attribute form: DW_FORM_indirect");
13678 break;
13679 default:
13680 fprintf_unfiltered (f, "unsupported attribute form: %d.",
13681 die->attrs[i].form);
13682 break;
13683 }
13684 fprintf_unfiltered (f, "\n");
13685 }
13686 }
13687
13688 static void
13689 dump_die_for_error (struct die_info *die)
13690 {
13691 dump_die_shallow (gdb_stderr, 0, die);
13692 }
13693
13694 static void
13695 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
13696 {
13697 int indent = level * 4;
13698
13699 gdb_assert (die != NULL);
13700
13701 if (level >= max_level)
13702 return;
13703
13704 dump_die_shallow (f, indent, die);
13705
13706 if (die->child != NULL)
13707 {
13708 print_spaces (indent, f);
13709 fprintf_unfiltered (f, " Children:");
13710 if (level + 1 < max_level)
13711 {
13712 fprintf_unfiltered (f, "\n");
13713 dump_die_1 (f, level + 1, max_level, die->child);
13714 }
13715 else
13716 {
13717 fprintf_unfiltered (f,
13718 " [not printed, max nesting level reached]\n");
13719 }
13720 }
13721
13722 if (die->sibling != NULL && level > 0)
13723 {
13724 dump_die_1 (f, level, max_level, die->sibling);
13725 }
13726 }
13727
13728 /* This is called from the pdie macro in gdbinit.in.
13729 It's not static so gcc will keep a copy callable from gdb. */
13730
13731 void
13732 dump_die (struct die_info *die, int max_level)
13733 {
13734 dump_die_1 (gdb_stdlog, 0, max_level, die);
13735 }
13736
13737 static void
13738 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
13739 {
13740 void **slot;
13741
13742 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT);
13743
13744 *slot = die;
13745 }
13746
13747 static int
13748 is_ref_attr (struct attribute *attr)
13749 {
13750 switch (attr->form)
13751 {
13752 case DW_FORM_ref_addr:
13753 case DW_FORM_ref1:
13754 case DW_FORM_ref2:
13755 case DW_FORM_ref4:
13756 case DW_FORM_ref8:
13757 case DW_FORM_ref_udata:
13758 return 1;
13759 default:
13760 return 0;
13761 }
13762 }
13763
13764 static unsigned int
13765 dwarf2_get_ref_die_offset (struct attribute *attr)
13766 {
13767 if (is_ref_attr (attr))
13768 return DW_ADDR (attr);
13769
13770 complaint (&symfile_complaints,
13771 _("unsupported die ref attribute form: '%s'"),
13772 dwarf_form_name (attr->form));
13773 return 0;
13774 }
13775
13776 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13777 * the value held by the attribute is not constant. */
13778
13779 static LONGEST
13780 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
13781 {
13782 if (attr->form == DW_FORM_sdata)
13783 return DW_SND (attr);
13784 else if (attr->form == DW_FORM_udata
13785 || attr->form == DW_FORM_data1
13786 || attr->form == DW_FORM_data2
13787 || attr->form == DW_FORM_data4
13788 || attr->form == DW_FORM_data8)
13789 return DW_UNSND (attr);
13790 else
13791 {
13792 complaint (&symfile_complaints,
13793 _("Attribute value is not a constant (%s)"),
13794 dwarf_form_name (attr->form));
13795 return default_value;
13796 }
13797 }
13798
13799 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13800 unit and add it to our queue.
13801 The result is non-zero if PER_CU was queued, otherwise the result is zero
13802 meaning either PER_CU is already queued or it is already loaded. */
13803
13804 static int
13805 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
13806 struct dwarf2_per_cu_data *per_cu)
13807 {
13808 /* We may arrive here during partial symbol reading, if we need full
13809 DIEs to process an unusual case (e.g. template arguments). Do
13810 not queue PER_CU, just tell our caller to load its DIEs. */
13811 if (dwarf2_per_objfile->reading_partial_symbols)
13812 {
13813 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
13814 return 1;
13815 return 0;
13816 }
13817
13818 /* Mark the dependence relation so that we don't flush PER_CU
13819 too early. */
13820 dwarf2_add_dependence (this_cu, per_cu);
13821
13822 /* If it's already on the queue, we have nothing to do. */
13823 if (per_cu->queued)
13824 return 0;
13825
13826 /* If the compilation unit is already loaded, just mark it as
13827 used. */
13828 if (per_cu->cu != NULL)
13829 {
13830 per_cu->cu->last_used = 0;
13831 return 0;
13832 }
13833
13834 /* Add it to the queue. */
13835 queue_comp_unit (per_cu, this_cu->objfile);
13836
13837 return 1;
13838 }
13839
13840 /* Follow reference or signature attribute ATTR of SRC_DIE.
13841 On entry *REF_CU is the CU of SRC_DIE.
13842 On exit *REF_CU is the CU of the result. */
13843
13844 static struct die_info *
13845 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
13846 struct dwarf2_cu **ref_cu)
13847 {
13848 struct die_info *die;
13849
13850 if (is_ref_attr (attr))
13851 die = follow_die_ref (src_die, attr, ref_cu);
13852 else if (attr->form == DW_FORM_ref_sig8)
13853 die = follow_die_sig (src_die, attr, ref_cu);
13854 else
13855 {
13856 dump_die_for_error (src_die);
13857 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13858 (*ref_cu)->objfile->name);
13859 }
13860
13861 return die;
13862 }
13863
13864 /* Follow reference OFFSET.
13865 On entry *REF_CU is the CU of the source die referencing OFFSET.
13866 On exit *REF_CU is the CU of the result.
13867 Returns NULL if OFFSET is invalid. */
13868
13869 static struct die_info *
13870 follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu)
13871 {
13872 struct die_info temp_die;
13873 struct dwarf2_cu *target_cu, *cu = *ref_cu;
13874
13875 gdb_assert (cu->per_cu != NULL);
13876
13877 target_cu = cu;
13878
13879 if (cu->per_cu->debug_type_section)
13880 {
13881 /* .debug_types CUs cannot reference anything outside their CU.
13882 If they need to, they have to reference a signatured type via
13883 DW_FORM_ref_sig8. */
13884 if (! offset_in_cu_p (&cu->header, offset))
13885 return NULL;
13886 }
13887 else if (! offset_in_cu_p (&cu->header, offset))
13888 {
13889 struct dwarf2_per_cu_data *per_cu;
13890
13891 per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
13892
13893 /* If necessary, add it to the queue and load its DIEs. */
13894 if (maybe_queue_comp_unit (cu, per_cu))
13895 load_full_comp_unit (per_cu, cu->objfile);
13896
13897 target_cu = per_cu->cu;
13898 }
13899 else if (cu->dies == NULL)
13900 {
13901 /* We're loading full DIEs during partial symbol reading. */
13902 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
13903 load_full_comp_unit (cu->per_cu, cu->objfile);
13904 }
13905
13906 *ref_cu = target_cu;
13907 temp_die.offset = offset;
13908 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset);
13909 }
13910
13911 /* Follow reference attribute ATTR of SRC_DIE.
13912 On entry *REF_CU is the CU of SRC_DIE.
13913 On exit *REF_CU is the CU of the result. */
13914
13915 static struct die_info *
13916 follow_die_ref (struct die_info *src_die, struct attribute *attr,
13917 struct dwarf2_cu **ref_cu)
13918 {
13919 unsigned int offset = dwarf2_get_ref_die_offset (attr);
13920 struct dwarf2_cu *cu = *ref_cu;
13921 struct die_info *die;
13922
13923 die = follow_die_offset (offset, ref_cu);
13924 if (!die)
13925 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13926 "at 0x%x [in module %s]"),
13927 offset, src_die->offset, cu->objfile->name);
13928
13929 return die;
13930 }
13931
13932 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
13933 Returned value is intended for DW_OP_call*. Returned
13934 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
13935
13936 struct dwarf2_locexpr_baton
13937 dwarf2_fetch_die_location_block (unsigned int offset,
13938 struct dwarf2_per_cu_data *per_cu,
13939 CORE_ADDR (*get_frame_pc) (void *baton),
13940 void *baton)
13941 {
13942 struct dwarf2_cu *cu;
13943 struct die_info *die;
13944 struct attribute *attr;
13945 struct dwarf2_locexpr_baton retval;
13946
13947 dw2_setup (per_cu->objfile);
13948
13949 if (per_cu->cu == NULL)
13950 load_cu (per_cu);
13951 cu = per_cu->cu;
13952
13953 die = follow_die_offset (offset, &cu);
13954 if (!die)
13955 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13956 offset, per_cu->cu->objfile->name);
13957
13958 attr = dwarf2_attr (die, DW_AT_location, cu);
13959 if (!attr)
13960 {
13961 /* DWARF: "If there is no such attribute, then there is no effect.". */
13962
13963 retval.data = NULL;
13964 retval.size = 0;
13965 }
13966 else if (attr_form_is_section_offset (attr))
13967 {
13968 struct dwarf2_loclist_baton loclist_baton;
13969 CORE_ADDR pc = (*get_frame_pc) (baton);
13970 size_t size;
13971
13972 fill_in_loclist_baton (cu, &loclist_baton, attr);
13973
13974 retval.data = dwarf2_find_location_expression (&loclist_baton,
13975 &size, pc);
13976 retval.size = size;
13977 }
13978 else
13979 {
13980 if (!attr_form_is_block (attr))
13981 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13982 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13983 offset, per_cu->cu->objfile->name);
13984
13985 retval.data = DW_BLOCK (attr)->data;
13986 retval.size = DW_BLOCK (attr)->size;
13987 }
13988 retval.per_cu = cu->per_cu;
13989
13990 age_cached_comp_units ();
13991
13992 return retval;
13993 }
13994
13995 /* Return the type of the DIE at DIE_OFFSET in the CU named by
13996 PER_CU. */
13997
13998 struct type *
13999 dwarf2_get_die_type (unsigned int die_offset,
14000 struct dwarf2_per_cu_data *per_cu)
14001 {
14002 dw2_setup (per_cu->objfile);
14003 return get_die_type_at_offset (die_offset, per_cu);
14004 }
14005
14006 /* Follow the signature attribute ATTR in SRC_DIE.
14007 On entry *REF_CU is the CU of SRC_DIE.
14008 On exit *REF_CU is the CU of the result. */
14009
14010 static struct die_info *
14011 follow_die_sig (struct die_info *src_die, struct attribute *attr,
14012 struct dwarf2_cu **ref_cu)
14013 {
14014 struct objfile *objfile = (*ref_cu)->objfile;
14015 struct die_info temp_die;
14016 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
14017 struct dwarf2_cu *sig_cu;
14018 struct die_info *die;
14019
14020 /* sig_type will be NULL if the signatured type is missing from
14021 the debug info. */
14022 if (sig_type == NULL)
14023 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14024 "at 0x%x [in module %s]"),
14025 src_die->offset, objfile->name);
14026
14027 /* If necessary, add it to the queue and load its DIEs. */
14028
14029 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
14030 read_signatured_type (objfile, sig_type);
14031
14032 gdb_assert (sig_type->per_cu.cu != NULL);
14033
14034 sig_cu = sig_type->per_cu.cu;
14035 temp_die.offset = sig_cu->header.offset + sig_type->type_offset;
14036 die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset);
14037 if (die)
14038 {
14039 *ref_cu = sig_cu;
14040 return die;
14041 }
14042
14043 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14044 "from DIE at 0x%x [in module %s]"),
14045 sig_type->type_offset, src_die->offset, objfile->name);
14046 }
14047
14048 /* Given an offset of a signatured type, return its signatured_type. */
14049
14050 static struct signatured_type *
14051 lookup_signatured_type_at_offset (struct objfile *objfile,
14052 struct dwarf2_section_info *section,
14053 unsigned int offset)
14054 {
14055 gdb_byte *info_ptr = section->buffer + offset;
14056 unsigned int length, initial_length_size;
14057 unsigned int sig_offset;
14058 struct signatured_type find_entry, *type_sig;
14059
14060 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
14061 sig_offset = (initial_length_size
14062 + 2 /*version*/
14063 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
14064 + 1 /*address_size*/);
14065 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
14066 type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
14067
14068 /* This is only used to lookup previously recorded types.
14069 If we didn't find it, it's our bug. */
14070 gdb_assert (type_sig != NULL);
14071 gdb_assert (offset == type_sig->per_cu.offset);
14072
14073 return type_sig;
14074 }
14075
14076 /* Read in signatured type at OFFSET and build its CU and die(s). */
14077
14078 static void
14079 read_signatured_type_at_offset (struct objfile *objfile,
14080 struct dwarf2_section_info *sect,
14081 unsigned int offset)
14082 {
14083 struct signatured_type *type_sig;
14084
14085 dwarf2_read_section (objfile, sect);
14086
14087 /* We have the section offset, but we need the signature to do the
14088 hash table lookup. */
14089 type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
14090
14091 gdb_assert (type_sig->per_cu.cu == NULL);
14092
14093 read_signatured_type (objfile, type_sig);
14094
14095 gdb_assert (type_sig->per_cu.cu != NULL);
14096 }
14097
14098 /* Read in a signatured type and build its CU and DIEs. */
14099
14100 static void
14101 read_signatured_type (struct objfile *objfile,
14102 struct signatured_type *type_sig)
14103 {
14104 gdb_byte *types_ptr;
14105 struct die_reader_specs reader_specs;
14106 struct dwarf2_cu *cu;
14107 ULONGEST signature;
14108 struct cleanup *back_to, *free_cu_cleanup;
14109 struct dwarf2_section_info *section = type_sig->per_cu.debug_type_section;
14110
14111 dwarf2_read_section (objfile, section);
14112 types_ptr = section->buffer + type_sig->per_cu.offset;
14113
14114 gdb_assert (type_sig->per_cu.cu == NULL);
14115
14116 cu = xmalloc (sizeof (*cu));
14117 init_one_comp_unit (cu, objfile);
14118
14119 type_sig->per_cu.cu = cu;
14120 cu->per_cu = &type_sig->per_cu;
14121
14122 /* If an error occurs while loading, release our storage. */
14123 free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
14124
14125 types_ptr = read_type_comp_unit_head (&cu->header, section, &signature,
14126 types_ptr, objfile->obfd);
14127 gdb_assert (signature == type_sig->signature);
14128
14129 cu->die_hash
14130 = htab_create_alloc_ex (cu->header.length / 12,
14131 die_hash,
14132 die_eq,
14133 NULL,
14134 &cu->comp_unit_obstack,
14135 hashtab_obstack_allocate,
14136 dummy_obstack_deallocate);
14137
14138 dwarf2_read_abbrevs (cu->objfile->obfd, cu);
14139 back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
14140
14141 init_cu_die_reader (&reader_specs, cu);
14142
14143 cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr,
14144 NULL /*parent*/);
14145
14146 /* We try not to read any attributes in this function, because not
14147 all objfiles needed for references have been loaded yet, and symbol
14148 table processing isn't initialized. But we have to set the CU language,
14149 or we won't be able to build types correctly. */
14150 prepare_one_comp_unit (cu, cu->dies);
14151
14152 do_cleanups (back_to);
14153
14154 /* We've successfully allocated this compilation unit. Let our caller
14155 clean it up when finished with it. */
14156 discard_cleanups (free_cu_cleanup);
14157
14158 type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
14159 dwarf2_per_objfile->read_in_chain = &type_sig->per_cu;
14160 }
14161
14162 /* Workaround as dwarf_expr_context_funcs.read_mem implementation before
14163 a proper runtime DWARF expressions evaluator gets implemented.
14164 Otherwise gnuv3_baseclass_offset would error by:
14165 Expected a negative vbase offset (old compiler?) */
14166
14167 static void
14168 decode_locdesc_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr,
14169 size_t length)
14170 {
14171 struct dwarf_expr_context *ctx = baton;
14172 struct gdbarch *gdbarch = ctx->gdbarch;
14173 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
14174
14175 memset (buf, 0, length);
14176
14177 if (TYPE_LENGTH (ptr_type) == length)
14178 store_typed_address (buf, ptr_type, addr);
14179 }
14180
14181 static const struct dwarf_expr_context_funcs decode_locdesc_ctx_funcs =
14182 {
14183 ctx_no_read_reg,
14184 decode_locdesc_read_mem,
14185 ctx_no_get_frame_base,
14186 ctx_no_get_frame_cfa,
14187 ctx_no_get_frame_pc,
14188 ctx_no_get_tls_address,
14189 ctx_no_dwarf_call,
14190 ctx_no_get_base_type
14191 };
14192
14193 /* Decode simple location descriptions.
14194 Given a pointer to a dwarf block that defines a location, compute
14195 the location and return the value.
14196
14197 NOTE drow/2003-11-18: This function is called in two situations
14198 now: for the address of static or global variables (partial symbols
14199 only) and for offsets into structures which are expected to be
14200 (more or less) constant. The partial symbol case should go away,
14201 and only the constant case should remain. That will let this
14202 function complain more accurately. A few special modes are allowed
14203 without complaint for global variables (for instance, global
14204 register values and thread-local values).
14205
14206 A location description containing no operations indicates that the
14207 object is optimized out. The return value is 0 for that case.
14208 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14209 callers will only want a very basic result and this can become a
14210 complaint. */
14211
14212 static CORE_ADDR
14213 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
14214 {
14215 struct objfile *objfile = cu->objfile;
14216 struct dwarf_expr_context *ctx;
14217 struct cleanup *old_chain;
14218 volatile struct gdb_exception ex;
14219
14220 ctx = new_dwarf_expr_context ();
14221 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
14222 make_cleanup_value_free_to_mark (value_mark ());
14223
14224 ctx->gdbarch = get_objfile_arch (objfile);
14225 ctx->addr_size = cu->header.addr_size;
14226 ctx->offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
14227 ctx->baton = ctx;
14228 ctx->funcs = &decode_locdesc_ctx_funcs;
14229
14230 /* DW_AT_data_member_location expects the structure address to be pushed on
14231 the stack. Simulate the offset by address 0. */
14232 dwarf_expr_push_address (ctx, 0, 0);
14233
14234 TRY_CATCH (ex, RETURN_MASK_ERROR)
14235 {
14236 dwarf_expr_eval (ctx, blk->data, blk->size);
14237 }
14238 if (ex.reason < 0)
14239 {
14240 if (ex.message)
14241 complaint (&symfile_complaints, "%s", ex.message);
14242 }
14243 else if (ctx->num_pieces == 0)
14244 switch (ctx->location)
14245 {
14246 /* The returned number will be bogus, just do not complain for locations
14247 in global registers - it is here only a partial symbol address. */
14248 case DWARF_VALUE_REGISTER:
14249
14250 case DWARF_VALUE_MEMORY:
14251 case DWARF_VALUE_STACK:
14252 {
14253 CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
14254
14255 do_cleanups (old_chain);
14256 return address;
14257 }
14258 }
14259
14260 do_cleanups (old_chain);
14261 dwarf2_complex_location_expr_complaint ();
14262 return 0;
14263 }
14264
14265 /* memory allocation interface */
14266
14267 static struct dwarf_block *
14268 dwarf_alloc_block (struct dwarf2_cu *cu)
14269 {
14270 struct dwarf_block *blk;
14271
14272 blk = (struct dwarf_block *)
14273 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
14274 return (blk);
14275 }
14276
14277 static struct abbrev_info *
14278 dwarf_alloc_abbrev (struct dwarf2_cu *cu)
14279 {
14280 struct abbrev_info *abbrev;
14281
14282 abbrev = (struct abbrev_info *)
14283 obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info));
14284 memset (abbrev, 0, sizeof (struct abbrev_info));
14285 return (abbrev);
14286 }
14287
14288 static struct die_info *
14289 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
14290 {
14291 struct die_info *die;
14292 size_t size = sizeof (struct die_info);
14293
14294 if (num_attrs > 1)
14295 size += (num_attrs - 1) * sizeof (struct attribute);
14296
14297 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
14298 memset (die, 0, sizeof (struct die_info));
14299 return (die);
14300 }
14301
14302 \f
14303 /* Macro support. */
14304
14305 /* Return the full name of file number I in *LH's file name table.
14306 Use COMP_DIR as the name of the current directory of the
14307 compilation. The result is allocated using xmalloc; the caller is
14308 responsible for freeing it. */
14309 static char *
14310 file_full_name (int file, struct line_header *lh, const char *comp_dir)
14311 {
14312 /* Is the file number a valid index into the line header's file name
14313 table? Remember that file numbers start with one, not zero. */
14314 if (1 <= file && file <= lh->num_file_names)
14315 {
14316 struct file_entry *fe = &lh->file_names[file - 1];
14317
14318 if (IS_ABSOLUTE_PATH (fe->name))
14319 return xstrdup (fe->name);
14320 else
14321 {
14322 const char *dir;
14323 int dir_len;
14324 char *full_name;
14325
14326 if (fe->dir_index)
14327 dir = lh->include_dirs[fe->dir_index - 1];
14328 else
14329 dir = comp_dir;
14330
14331 if (dir)
14332 {
14333 dir_len = strlen (dir);
14334 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
14335 strcpy (full_name, dir);
14336 full_name[dir_len] = '/';
14337 strcpy (full_name + dir_len + 1, fe->name);
14338 return full_name;
14339 }
14340 else
14341 return xstrdup (fe->name);
14342 }
14343 }
14344 else
14345 {
14346 /* The compiler produced a bogus file number. We can at least
14347 record the macro definitions made in the file, even if we
14348 won't be able to find the file by name. */
14349 char fake_name[80];
14350
14351 sprintf (fake_name, "<bad macro file number %d>", file);
14352
14353 complaint (&symfile_complaints,
14354 _("bad file number in macro information (%d)"),
14355 file);
14356
14357 return xstrdup (fake_name);
14358 }
14359 }
14360
14361
14362 static struct macro_source_file *
14363 macro_start_file (int file, int line,
14364 struct macro_source_file *current_file,
14365 const char *comp_dir,
14366 struct line_header *lh, struct objfile *objfile)
14367 {
14368 /* The full name of this source file. */
14369 char *full_name = file_full_name (file, lh, comp_dir);
14370
14371 /* We don't create a macro table for this compilation unit
14372 at all until we actually get a filename. */
14373 if (! pending_macros)
14374 pending_macros = new_macro_table (&objfile->objfile_obstack,
14375 objfile->macro_cache);
14376
14377 if (! current_file)
14378 /* If we have no current file, then this must be the start_file
14379 directive for the compilation unit's main source file. */
14380 current_file = macro_set_main (pending_macros, full_name);
14381 else
14382 current_file = macro_include (current_file, line, full_name);
14383
14384 xfree (full_name);
14385
14386 return current_file;
14387 }
14388
14389
14390 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14391 followed by a null byte. */
14392 static char *
14393 copy_string (const char *buf, int len)
14394 {
14395 char *s = xmalloc (len + 1);
14396
14397 memcpy (s, buf, len);
14398 s[len] = '\0';
14399 return s;
14400 }
14401
14402
14403 static const char *
14404 consume_improper_spaces (const char *p, const char *body)
14405 {
14406 if (*p == ' ')
14407 {
14408 complaint (&symfile_complaints,
14409 _("macro definition contains spaces "
14410 "in formal argument list:\n`%s'"),
14411 body);
14412
14413 while (*p == ' ')
14414 p++;
14415 }
14416
14417 return p;
14418 }
14419
14420
14421 static void
14422 parse_macro_definition (struct macro_source_file *file, int line,
14423 const char *body)
14424 {
14425 const char *p;
14426
14427 /* The body string takes one of two forms. For object-like macro
14428 definitions, it should be:
14429
14430 <macro name> " " <definition>
14431
14432 For function-like macro definitions, it should be:
14433
14434 <macro name> "() " <definition>
14435 or
14436 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14437
14438 Spaces may appear only where explicitly indicated, and in the
14439 <definition>.
14440
14441 The Dwarf 2 spec says that an object-like macro's name is always
14442 followed by a space, but versions of GCC around March 2002 omit
14443 the space when the macro's definition is the empty string.
14444
14445 The Dwarf 2 spec says that there should be no spaces between the
14446 formal arguments in a function-like macro's formal argument list,
14447 but versions of GCC around March 2002 include spaces after the
14448 commas. */
14449
14450
14451 /* Find the extent of the macro name. The macro name is terminated
14452 by either a space or null character (for an object-like macro) or
14453 an opening paren (for a function-like macro). */
14454 for (p = body; *p; p++)
14455 if (*p == ' ' || *p == '(')
14456 break;
14457
14458 if (*p == ' ' || *p == '\0')
14459 {
14460 /* It's an object-like macro. */
14461 int name_len = p - body;
14462 char *name = copy_string (body, name_len);
14463 const char *replacement;
14464
14465 if (*p == ' ')
14466 replacement = body + name_len + 1;
14467 else
14468 {
14469 dwarf2_macro_malformed_definition_complaint (body);
14470 replacement = body + name_len;
14471 }
14472
14473 macro_define_object (file, line, name, replacement);
14474
14475 xfree (name);
14476 }
14477 else if (*p == '(')
14478 {
14479 /* It's a function-like macro. */
14480 char *name = copy_string (body, p - body);
14481 int argc = 0;
14482 int argv_size = 1;
14483 char **argv = xmalloc (argv_size * sizeof (*argv));
14484
14485 p++;
14486
14487 p = consume_improper_spaces (p, body);
14488
14489 /* Parse the formal argument list. */
14490 while (*p && *p != ')')
14491 {
14492 /* Find the extent of the current argument name. */
14493 const char *arg_start = p;
14494
14495 while (*p && *p != ',' && *p != ')' && *p != ' ')
14496 p++;
14497
14498 if (! *p || p == arg_start)
14499 dwarf2_macro_malformed_definition_complaint (body);
14500 else
14501 {
14502 /* Make sure argv has room for the new argument. */
14503 if (argc >= argv_size)
14504 {
14505 argv_size *= 2;
14506 argv = xrealloc (argv, argv_size * sizeof (*argv));
14507 }
14508
14509 argv[argc++] = copy_string (arg_start, p - arg_start);
14510 }
14511
14512 p = consume_improper_spaces (p, body);
14513
14514 /* Consume the comma, if present. */
14515 if (*p == ',')
14516 {
14517 p++;
14518
14519 p = consume_improper_spaces (p, body);
14520 }
14521 }
14522
14523 if (*p == ')')
14524 {
14525 p++;
14526
14527 if (*p == ' ')
14528 /* Perfectly formed definition, no complaints. */
14529 macro_define_function (file, line, name,
14530 argc, (const char **) argv,
14531 p + 1);
14532 else if (*p == '\0')
14533 {
14534 /* Complain, but do define it. */
14535 dwarf2_macro_malformed_definition_complaint (body);
14536 macro_define_function (file, line, name,
14537 argc, (const char **) argv,
14538 p);
14539 }
14540 else
14541 /* Just complain. */
14542 dwarf2_macro_malformed_definition_complaint (body);
14543 }
14544 else
14545 /* Just complain. */
14546 dwarf2_macro_malformed_definition_complaint (body);
14547
14548 xfree (name);
14549 {
14550 int i;
14551
14552 for (i = 0; i < argc; i++)
14553 xfree (argv[i]);
14554 }
14555 xfree (argv);
14556 }
14557 else
14558 dwarf2_macro_malformed_definition_complaint (body);
14559 }
14560
14561 /* Skip some bytes from BYTES according to the form given in FORM.
14562 Returns the new pointer. */
14563
14564 static gdb_byte *
14565 skip_form_bytes (bfd *abfd, gdb_byte *bytes,
14566 enum dwarf_form form,
14567 unsigned int offset_size,
14568 struct dwarf2_section_info *section)
14569 {
14570 unsigned int bytes_read;
14571
14572 switch (form)
14573 {
14574 case DW_FORM_data1:
14575 case DW_FORM_flag:
14576 ++bytes;
14577 break;
14578
14579 case DW_FORM_data2:
14580 bytes += 2;
14581 break;
14582
14583 case DW_FORM_data4:
14584 bytes += 4;
14585 break;
14586
14587 case DW_FORM_data8:
14588 bytes += 8;
14589 break;
14590
14591 case DW_FORM_string:
14592 read_direct_string (abfd, bytes, &bytes_read);
14593 bytes += bytes_read;
14594 break;
14595
14596 case DW_FORM_sec_offset:
14597 case DW_FORM_strp:
14598 bytes += offset_size;
14599 break;
14600
14601 case DW_FORM_block:
14602 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
14603 bytes += bytes_read;
14604 break;
14605
14606 case DW_FORM_block1:
14607 bytes += 1 + read_1_byte (abfd, bytes);
14608 break;
14609 case DW_FORM_block2:
14610 bytes += 2 + read_2_bytes (abfd, bytes);
14611 break;
14612 case DW_FORM_block4:
14613 bytes += 4 + read_4_bytes (abfd, bytes);
14614 break;
14615
14616 case DW_FORM_sdata:
14617 case DW_FORM_udata:
14618 bytes = skip_leb128 (abfd, bytes);
14619 break;
14620
14621 default:
14622 {
14623 complain:
14624 complaint (&symfile_complaints,
14625 _("invalid form 0x%x in `%s'"),
14626 form,
14627 section->asection->name);
14628 return NULL;
14629 }
14630 }
14631
14632 return bytes;
14633 }
14634
14635 /* A helper for dwarf_decode_macros that handles skipping an unknown
14636 opcode. Returns an updated pointer to the macro data buffer; or,
14637 on error, issues a complaint and returns NULL. */
14638
14639 static gdb_byte *
14640 skip_unknown_opcode (unsigned int opcode,
14641 gdb_byte **opcode_definitions,
14642 gdb_byte *mac_ptr,
14643 bfd *abfd,
14644 unsigned int offset_size,
14645 struct dwarf2_section_info *section)
14646 {
14647 unsigned int bytes_read, i;
14648 unsigned long arg;
14649 gdb_byte *defn;
14650
14651 if (opcode_definitions[opcode] == NULL)
14652 {
14653 complaint (&symfile_complaints,
14654 _("unrecognized DW_MACFINO opcode 0x%x"),
14655 opcode);
14656 return NULL;
14657 }
14658
14659 defn = opcode_definitions[opcode];
14660 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
14661 defn += bytes_read;
14662
14663 for (i = 0; i < arg; ++i)
14664 {
14665 mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section);
14666 if (mac_ptr == NULL)
14667 {
14668 /* skip_form_bytes already issued the complaint. */
14669 return NULL;
14670 }
14671 }
14672
14673 return mac_ptr;
14674 }
14675
14676 /* A helper function which parses the header of a macro section.
14677 If the macro section is the extended (for now called "GNU") type,
14678 then this updates *OFFSET_SIZE. Returns a pointer to just after
14679 the header, or issues a complaint and returns NULL on error. */
14680
14681 static gdb_byte *
14682 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
14683 bfd *abfd,
14684 gdb_byte *mac_ptr,
14685 unsigned int *offset_size,
14686 int section_is_gnu)
14687 {
14688 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
14689
14690 if (section_is_gnu)
14691 {
14692 unsigned int version, flags;
14693
14694 version = read_2_bytes (abfd, mac_ptr);
14695 if (version != 4)
14696 {
14697 complaint (&symfile_complaints,
14698 _("unrecognized version `%d' in .debug_macro section"),
14699 version);
14700 return NULL;
14701 }
14702 mac_ptr += 2;
14703
14704 flags = read_1_byte (abfd, mac_ptr);
14705 ++mac_ptr;
14706 *offset_size = (flags & 1) ? 8 : 4;
14707
14708 if ((flags & 2) != 0)
14709 /* We don't need the line table offset. */
14710 mac_ptr += *offset_size;
14711
14712 /* Vendor opcode descriptions. */
14713 if ((flags & 4) != 0)
14714 {
14715 unsigned int i, count;
14716
14717 count = read_1_byte (abfd, mac_ptr);
14718 ++mac_ptr;
14719 for (i = 0; i < count; ++i)
14720 {
14721 unsigned int opcode, bytes_read;
14722 unsigned long arg;
14723
14724 opcode = read_1_byte (abfd, mac_ptr);
14725 ++mac_ptr;
14726 opcode_definitions[opcode] = mac_ptr;
14727 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14728 mac_ptr += bytes_read;
14729 mac_ptr += arg;
14730 }
14731 }
14732 }
14733
14734 return mac_ptr;
14735 }
14736
14737 /* A helper for dwarf_decode_macros that handles the GNU extensions,
14738 including DW_GNU_MACINFO_transparent_include. */
14739
14740 static void
14741 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
14742 struct macro_source_file *current_file,
14743 struct line_header *lh, char *comp_dir,
14744 struct dwarf2_section_info *section,
14745 int section_is_gnu,
14746 unsigned int offset_size,
14747 struct objfile *objfile)
14748 {
14749 enum dwarf_macro_record_type macinfo_type;
14750 int at_commandline;
14751 gdb_byte *opcode_definitions[256];
14752
14753 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
14754 &offset_size, section_is_gnu);
14755 if (mac_ptr == NULL)
14756 {
14757 /* We already issued a complaint. */
14758 return;
14759 }
14760
14761 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14762 GDB is still reading the definitions from command line. First
14763 DW_MACINFO_start_file will need to be ignored as it was already executed
14764 to create CURRENT_FILE for the main source holding also the command line
14765 definitions. On first met DW_MACINFO_start_file this flag is reset to
14766 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14767
14768 at_commandline = 1;
14769
14770 do
14771 {
14772 /* Do we at least have room for a macinfo type byte? */
14773 if (mac_ptr >= mac_end)
14774 {
14775 dwarf2_macros_too_long_complaint (section);
14776 break;
14777 }
14778
14779 macinfo_type = read_1_byte (abfd, mac_ptr);
14780 mac_ptr++;
14781
14782 /* Note that we rely on the fact that the corresponding GNU and
14783 DWARF constants are the same. */
14784 switch (macinfo_type)
14785 {
14786 /* A zero macinfo type indicates the end of the macro
14787 information. */
14788 case 0:
14789 break;
14790
14791 case DW_MACRO_GNU_define:
14792 case DW_MACRO_GNU_undef:
14793 case DW_MACRO_GNU_define_indirect:
14794 case DW_MACRO_GNU_undef_indirect:
14795 {
14796 unsigned int bytes_read;
14797 int line;
14798 char *body;
14799 int is_define;
14800
14801 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14802 mac_ptr += bytes_read;
14803
14804 if (macinfo_type == DW_MACRO_GNU_define
14805 || macinfo_type == DW_MACRO_GNU_undef)
14806 {
14807 body = read_direct_string (abfd, mac_ptr, &bytes_read);
14808 mac_ptr += bytes_read;
14809 }
14810 else
14811 {
14812 LONGEST str_offset;
14813
14814 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
14815 mac_ptr += offset_size;
14816
14817 body = read_indirect_string_at_offset (abfd, str_offset);
14818 }
14819
14820 is_define = (macinfo_type == DW_MACRO_GNU_define
14821 || macinfo_type == DW_MACRO_GNU_define_indirect);
14822 if (! current_file)
14823 {
14824 /* DWARF violation as no main source is present. */
14825 complaint (&symfile_complaints,
14826 _("debug info with no main source gives macro %s "
14827 "on line %d: %s"),
14828 is_define ? _("definition") : _("undefinition"),
14829 line, body);
14830 break;
14831 }
14832 if ((line == 0 && !at_commandline)
14833 || (line != 0 && at_commandline))
14834 complaint (&symfile_complaints,
14835 _("debug info gives %s macro %s with %s line %d: %s"),
14836 at_commandline ? _("command-line") : _("in-file"),
14837 is_define ? _("definition") : _("undefinition"),
14838 line == 0 ? _("zero") : _("non-zero"), line, body);
14839
14840 if (is_define)
14841 parse_macro_definition (current_file, line, body);
14842 else
14843 {
14844 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
14845 || macinfo_type == DW_MACRO_GNU_undef_indirect);
14846 macro_undef (current_file, line, body);
14847 }
14848 }
14849 break;
14850
14851 case DW_MACRO_GNU_start_file:
14852 {
14853 unsigned int bytes_read;
14854 int line, file;
14855
14856 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14857 mac_ptr += bytes_read;
14858 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14859 mac_ptr += bytes_read;
14860
14861 if ((line == 0 && !at_commandline)
14862 || (line != 0 && at_commandline))
14863 complaint (&symfile_complaints,
14864 _("debug info gives source %d included "
14865 "from %s at %s line %d"),
14866 file, at_commandline ? _("command-line") : _("file"),
14867 line == 0 ? _("zero") : _("non-zero"), line);
14868
14869 if (at_commandline)
14870 {
14871 /* This DW_MACRO_GNU_start_file was executed in the
14872 pass one. */
14873 at_commandline = 0;
14874 }
14875 else
14876 current_file = macro_start_file (file, line,
14877 current_file, comp_dir,
14878 lh, objfile);
14879 }
14880 break;
14881
14882 case DW_MACRO_GNU_end_file:
14883 if (! current_file)
14884 complaint (&symfile_complaints,
14885 _("macro debug info has an unmatched "
14886 "`close_file' directive"));
14887 else
14888 {
14889 current_file = current_file->included_by;
14890 if (! current_file)
14891 {
14892 enum dwarf_macro_record_type next_type;
14893
14894 /* GCC circa March 2002 doesn't produce the zero
14895 type byte marking the end of the compilation
14896 unit. Complain if it's not there, but exit no
14897 matter what. */
14898
14899 /* Do we at least have room for a macinfo type byte? */
14900 if (mac_ptr >= mac_end)
14901 {
14902 dwarf2_macros_too_long_complaint (section);
14903 return;
14904 }
14905
14906 /* We don't increment mac_ptr here, so this is just
14907 a look-ahead. */
14908 next_type = read_1_byte (abfd, mac_ptr);
14909 if (next_type != 0)
14910 complaint (&symfile_complaints,
14911 _("no terminating 0-type entry for "
14912 "macros in `.debug_macinfo' section"));
14913
14914 return;
14915 }
14916 }
14917 break;
14918
14919 case DW_MACRO_GNU_transparent_include:
14920 {
14921 LONGEST offset;
14922
14923 offset = read_offset_1 (abfd, mac_ptr, offset_size);
14924 mac_ptr += offset_size;
14925
14926 dwarf_decode_macro_bytes (abfd,
14927 section->buffer + offset,
14928 mac_end, current_file,
14929 lh, comp_dir,
14930 section, section_is_gnu,
14931 offset_size, objfile);
14932 }
14933 break;
14934
14935 case DW_MACINFO_vendor_ext:
14936 if (!section_is_gnu)
14937 {
14938 unsigned int bytes_read;
14939 int constant;
14940
14941 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
14942 mac_ptr += bytes_read;
14943 read_direct_string (abfd, mac_ptr, &bytes_read);
14944 mac_ptr += bytes_read;
14945
14946 /* We don't recognize any vendor extensions. */
14947 break;
14948 }
14949 /* FALLTHROUGH */
14950
14951 default:
14952 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
14953 mac_ptr, abfd, offset_size,
14954 section);
14955 if (mac_ptr == NULL)
14956 return;
14957 break;
14958 }
14959 } while (macinfo_type != 0);
14960 }
14961
14962 static void
14963 dwarf_decode_macros (struct line_header *lh, unsigned int offset,
14964 char *comp_dir, bfd *abfd,
14965 struct dwarf2_cu *cu,
14966 struct dwarf2_section_info *section,
14967 int section_is_gnu)
14968 {
14969 gdb_byte *mac_ptr, *mac_end;
14970 struct macro_source_file *current_file = 0;
14971 enum dwarf_macro_record_type macinfo_type;
14972 unsigned int offset_size = cu->header.offset_size;
14973 gdb_byte *opcode_definitions[256];
14974
14975 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
14976 if (section->buffer == NULL)
14977 {
14978 complaint (&symfile_complaints, _("missing %s section"),
14979 section->asection->name);
14980 return;
14981 }
14982
14983 /* First pass: Find the name of the base filename.
14984 This filename is needed in order to process all macros whose definition
14985 (or undefinition) comes from the command line. These macros are defined
14986 before the first DW_MACINFO_start_file entry, and yet still need to be
14987 associated to the base file.
14988
14989 To determine the base file name, we scan the macro definitions until we
14990 reach the first DW_MACINFO_start_file entry. We then initialize
14991 CURRENT_FILE accordingly so that any macro definition found before the
14992 first DW_MACINFO_start_file can still be associated to the base file. */
14993
14994 mac_ptr = section->buffer + offset;
14995 mac_end = section->buffer + section->size;
14996
14997 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
14998 &offset_size, section_is_gnu);
14999 if (mac_ptr == NULL)
15000 {
15001 /* We already issued a complaint. */
15002 return;
15003 }
15004
15005 do
15006 {
15007 /* Do we at least have room for a macinfo type byte? */
15008 if (mac_ptr >= mac_end)
15009 {
15010 /* Complaint is printed during the second pass as GDB will probably
15011 stop the first pass earlier upon finding
15012 DW_MACINFO_start_file. */
15013 break;
15014 }
15015
15016 macinfo_type = read_1_byte (abfd, mac_ptr);
15017 mac_ptr++;
15018
15019 /* Note that we rely on the fact that the corresponding GNU and
15020 DWARF constants are the same. */
15021 switch (macinfo_type)
15022 {
15023 /* A zero macinfo type indicates the end of the macro
15024 information. */
15025 case 0:
15026 break;
15027
15028 case DW_MACRO_GNU_define:
15029 case DW_MACRO_GNU_undef:
15030 /* Only skip the data by MAC_PTR. */
15031 {
15032 unsigned int bytes_read;
15033
15034 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15035 mac_ptr += bytes_read;
15036 read_direct_string (abfd, mac_ptr, &bytes_read);
15037 mac_ptr += bytes_read;
15038 }
15039 break;
15040
15041 case DW_MACRO_GNU_start_file:
15042 {
15043 unsigned int bytes_read;
15044 int line, file;
15045
15046 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15047 mac_ptr += bytes_read;
15048 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15049 mac_ptr += bytes_read;
15050
15051 current_file = macro_start_file (file, line, current_file,
15052 comp_dir, lh, cu->objfile);
15053 }
15054 break;
15055
15056 case DW_MACRO_GNU_end_file:
15057 /* No data to skip by MAC_PTR. */
15058 break;
15059
15060 case DW_MACRO_GNU_define_indirect:
15061 case DW_MACRO_GNU_undef_indirect:
15062 {
15063 unsigned int bytes_read;
15064
15065 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15066 mac_ptr += bytes_read;
15067 mac_ptr += offset_size;
15068 }
15069 break;
15070
15071 case DW_MACRO_GNU_transparent_include:
15072 /* Note that, according to the spec, a transparent include
15073 chain cannot call DW_MACRO_GNU_start_file. So, we can just
15074 skip this opcode. */
15075 mac_ptr += offset_size;
15076 break;
15077
15078 case DW_MACINFO_vendor_ext:
15079 /* Only skip the data by MAC_PTR. */
15080 if (!section_is_gnu)
15081 {
15082 unsigned int bytes_read;
15083
15084 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
15085 mac_ptr += bytes_read;
15086 read_direct_string (abfd, mac_ptr, &bytes_read);
15087 mac_ptr += bytes_read;
15088 }
15089 /* FALLTHROUGH */
15090
15091 default:
15092 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
15093 mac_ptr, abfd, offset_size,
15094 section);
15095 if (mac_ptr == NULL)
15096 return;
15097 break;
15098 }
15099 } while (macinfo_type != 0 && current_file == NULL);
15100
15101 /* Second pass: Process all entries.
15102
15103 Use the AT_COMMAND_LINE flag to determine whether we are still processing
15104 command-line macro definitions/undefinitions. This flag is unset when we
15105 reach the first DW_MACINFO_start_file entry. */
15106
15107 dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end,
15108 current_file, lh, comp_dir, section, section_is_gnu,
15109 offset_size, cu->objfile);
15110 }
15111
15112 /* Check if the attribute's form is a DW_FORM_block*
15113 if so return true else false. */
15114 static int
15115 attr_form_is_block (struct attribute *attr)
15116 {
15117 return (attr == NULL ? 0 :
15118 attr->form == DW_FORM_block1
15119 || attr->form == DW_FORM_block2
15120 || attr->form == DW_FORM_block4
15121 || attr->form == DW_FORM_block
15122 || attr->form == DW_FORM_exprloc);
15123 }
15124
15125 /* Return non-zero if ATTR's value is a section offset --- classes
15126 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
15127 You may use DW_UNSND (attr) to retrieve such offsets.
15128
15129 Section 7.5.4, "Attribute Encodings", explains that no attribute
15130 may have a value that belongs to more than one of these classes; it
15131 would be ambiguous if we did, because we use the same forms for all
15132 of them. */
15133 static int
15134 attr_form_is_section_offset (struct attribute *attr)
15135 {
15136 return (attr->form == DW_FORM_data4
15137 || attr->form == DW_FORM_data8
15138 || attr->form == DW_FORM_sec_offset);
15139 }
15140
15141
15142 /* Return non-zero if ATTR's value falls in the 'constant' class, or
15143 zero otherwise. When this function returns true, you can apply
15144 dwarf2_get_attr_constant_value to it.
15145
15146 However, note that for some attributes you must check
15147 attr_form_is_section_offset before using this test. DW_FORM_data4
15148 and DW_FORM_data8 are members of both the constant class, and of
15149 the classes that contain offsets into other debug sections
15150 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
15151 that, if an attribute's can be either a constant or one of the
15152 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
15153 taken as section offsets, not constants. */
15154 static int
15155 attr_form_is_constant (struct attribute *attr)
15156 {
15157 switch (attr->form)
15158 {
15159 case DW_FORM_sdata:
15160 case DW_FORM_udata:
15161 case DW_FORM_data1:
15162 case DW_FORM_data2:
15163 case DW_FORM_data4:
15164 case DW_FORM_data8:
15165 return 1;
15166 default:
15167 return 0;
15168 }
15169 }
15170
15171 /* A helper function that fills in a dwarf2_loclist_baton. */
15172
15173 static void
15174 fill_in_loclist_baton (struct dwarf2_cu *cu,
15175 struct dwarf2_loclist_baton *baton,
15176 struct attribute *attr)
15177 {
15178 dwarf2_read_section (dwarf2_per_objfile->objfile,
15179 &dwarf2_per_objfile->loc);
15180
15181 baton->per_cu = cu->per_cu;
15182 gdb_assert (baton->per_cu);
15183 /* We don't know how long the location list is, but make sure we
15184 don't run off the edge of the section. */
15185 baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr);
15186 baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr);
15187 baton->base_address = cu->base_address;
15188 }
15189
15190 static void
15191 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
15192 struct dwarf2_cu *cu)
15193 {
15194 if (attr_form_is_section_offset (attr)
15195 /* ".debug_loc" may not exist at all, or the offset may be outside
15196 the section. If so, fall through to the complaint in the
15197 other branch. */
15198 && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
15199 &dwarf2_per_objfile->loc))
15200 {
15201 struct dwarf2_loclist_baton *baton;
15202
15203 baton = obstack_alloc (&cu->objfile->objfile_obstack,
15204 sizeof (struct dwarf2_loclist_baton));
15205
15206 fill_in_loclist_baton (cu, baton, attr);
15207
15208 if (cu->base_known == 0)
15209 complaint (&symfile_complaints,
15210 _("Location list used without "
15211 "specifying the CU base address."));
15212
15213 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
15214 SYMBOL_LOCATION_BATON (sym) = baton;
15215 }
15216 else
15217 {
15218 struct dwarf2_locexpr_baton *baton;
15219
15220 baton = obstack_alloc (&cu->objfile->objfile_obstack,
15221 sizeof (struct dwarf2_locexpr_baton));
15222 baton->per_cu = cu->per_cu;
15223 gdb_assert (baton->per_cu);
15224
15225 if (attr_form_is_block (attr))
15226 {
15227 /* Note that we're just copying the block's data pointer
15228 here, not the actual data. We're still pointing into the
15229 info_buffer for SYM's objfile; right now we never release
15230 that buffer, but when we do clean up properly this may
15231 need to change. */
15232 baton->size = DW_BLOCK (attr)->size;
15233 baton->data = DW_BLOCK (attr)->data;
15234 }
15235 else
15236 {
15237 dwarf2_invalid_attrib_class_complaint ("location description",
15238 SYMBOL_NATURAL_NAME (sym));
15239 baton->size = 0;
15240 baton->data = NULL;
15241 }
15242
15243 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
15244 SYMBOL_LOCATION_BATON (sym) = baton;
15245 }
15246 }
15247
15248 /* Return the OBJFILE associated with the compilation unit CU. If CU
15249 came from a separate debuginfo file, then the master objfile is
15250 returned. */
15251
15252 struct objfile *
15253 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
15254 {
15255 struct objfile *objfile = per_cu->objfile;
15256
15257 /* Return the master objfile, so that we can report and look up the
15258 correct file containing this variable. */
15259 if (objfile->separate_debug_objfile_backlink)
15260 objfile = objfile->separate_debug_objfile_backlink;
15261
15262 return objfile;
15263 }
15264
15265 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
15266 (CU_HEADERP is unused in such case) or prepare a temporary copy at
15267 CU_HEADERP first. */
15268
15269 static const struct comp_unit_head *
15270 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
15271 struct dwarf2_per_cu_data *per_cu)
15272 {
15273 struct objfile *objfile;
15274 struct dwarf2_per_objfile *per_objfile;
15275 gdb_byte *info_ptr;
15276
15277 if (per_cu->cu)
15278 return &per_cu->cu->header;
15279
15280 objfile = per_cu->objfile;
15281 per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15282 info_ptr = per_objfile->info.buffer + per_cu->offset;
15283
15284 memset (cu_headerp, 0, sizeof (*cu_headerp));
15285 read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
15286
15287 return cu_headerp;
15288 }
15289
15290 /* Return the address size given in the compilation unit header for CU. */
15291
15292 CORE_ADDR
15293 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
15294 {
15295 struct comp_unit_head cu_header_local;
15296 const struct comp_unit_head *cu_headerp;
15297
15298 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15299
15300 return cu_headerp->addr_size;
15301 }
15302
15303 /* Return the offset size given in the compilation unit header for CU. */
15304
15305 int
15306 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
15307 {
15308 struct comp_unit_head cu_header_local;
15309 const struct comp_unit_head *cu_headerp;
15310
15311 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
15312
15313 return cu_headerp->offset_size;
15314 }
15315
15316 /* Return the text offset of the CU. The returned offset comes from
15317 this CU's objfile. If this objfile came from a separate debuginfo
15318 file, then the offset may be different from the corresponding
15319 offset in the parent objfile. */
15320
15321 CORE_ADDR
15322 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
15323 {
15324 struct objfile *objfile = per_cu->objfile;
15325
15326 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15327 }
15328
15329 /* Locate the .debug_info compilation unit from CU's objfile which contains
15330 the DIE at OFFSET. Raises an error on failure. */
15331
15332 static struct dwarf2_per_cu_data *
15333 dwarf2_find_containing_comp_unit (unsigned int offset,
15334 struct objfile *objfile)
15335 {
15336 struct dwarf2_per_cu_data *this_cu;
15337 int low, high;
15338
15339 low = 0;
15340 high = dwarf2_per_objfile->n_comp_units - 1;
15341 while (high > low)
15342 {
15343 int mid = low + (high - low) / 2;
15344
15345 if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset)
15346 high = mid;
15347 else
15348 low = mid + 1;
15349 }
15350 gdb_assert (low == high);
15351 if (dwarf2_per_objfile->all_comp_units[low]->offset > offset)
15352 {
15353 if (low == 0)
15354 error (_("Dwarf Error: could not find partial DIE containing "
15355 "offset 0x%lx [in module %s]"),
15356 (long) offset, bfd_get_filename (objfile->obfd));
15357
15358 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset);
15359 return dwarf2_per_objfile->all_comp_units[low-1];
15360 }
15361 else
15362 {
15363 this_cu = dwarf2_per_objfile->all_comp_units[low];
15364 if (low == dwarf2_per_objfile->n_comp_units - 1
15365 && offset >= this_cu->offset + this_cu->length)
15366 error (_("invalid dwarf2 offset %u"), offset);
15367 gdb_assert (offset < this_cu->offset + this_cu->length);
15368 return this_cu;
15369 }
15370 }
15371
15372 /* Locate the compilation unit from OBJFILE which is located at exactly
15373 OFFSET. Raises an error on failure. */
15374
15375 static struct dwarf2_per_cu_data *
15376 dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile)
15377 {
15378 struct dwarf2_per_cu_data *this_cu;
15379
15380 this_cu = dwarf2_find_containing_comp_unit (offset, objfile);
15381 if (this_cu->offset != offset)
15382 error (_("no compilation unit with offset %u."), offset);
15383 return this_cu;
15384 }
15385
15386 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
15387
15388 static void
15389 init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
15390 {
15391 memset (cu, 0, sizeof (*cu));
15392 cu->objfile = objfile;
15393 obstack_init (&cu->comp_unit_obstack);
15394 }
15395
15396 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
15397
15398 static void
15399 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die)
15400 {
15401 struct attribute *attr;
15402
15403 /* Set the language we're debugging. */
15404 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
15405 if (attr)
15406 set_cu_language (DW_UNSND (attr), cu);
15407 else
15408 {
15409 cu->language = language_minimal;
15410 cu->language_defn = language_def (cu->language);
15411 }
15412 }
15413
15414 /* Release one cached compilation unit, CU. We unlink it from the tree
15415 of compilation units, but we don't remove it from the read_in_chain;
15416 the caller is responsible for that.
15417 NOTE: DATA is a void * because this function is also used as a
15418 cleanup routine. */
15419
15420 static void
15421 free_one_comp_unit (void *data)
15422 {
15423 struct dwarf2_cu *cu = data;
15424
15425 if (cu->per_cu != NULL)
15426 cu->per_cu->cu = NULL;
15427 cu->per_cu = NULL;
15428
15429 obstack_free (&cu->comp_unit_obstack, NULL);
15430
15431 xfree (cu);
15432 }
15433
15434 /* This cleanup function is passed the address of a dwarf2_cu on the stack
15435 when we're finished with it. We can't free the pointer itself, but be
15436 sure to unlink it from the cache. Also release any associated storage
15437 and perform cache maintenance.
15438
15439 Only used during partial symbol parsing. */
15440
15441 static void
15442 free_stack_comp_unit (void *data)
15443 {
15444 struct dwarf2_cu *cu = data;
15445
15446 obstack_free (&cu->comp_unit_obstack, NULL);
15447 cu->partial_dies = NULL;
15448
15449 if (cu->per_cu != NULL)
15450 {
15451 /* This compilation unit is on the stack in our caller, so we
15452 should not xfree it. Just unlink it. */
15453 cu->per_cu->cu = NULL;
15454 cu->per_cu = NULL;
15455
15456 /* If we had a per-cu pointer, then we may have other compilation
15457 units loaded, so age them now. */
15458 age_cached_comp_units ();
15459 }
15460 }
15461
15462 /* Free all cached compilation units. */
15463
15464 static void
15465 free_cached_comp_units (void *data)
15466 {
15467 struct dwarf2_per_cu_data *per_cu, **last_chain;
15468
15469 per_cu = dwarf2_per_objfile->read_in_chain;
15470 last_chain = &dwarf2_per_objfile->read_in_chain;
15471 while (per_cu != NULL)
15472 {
15473 struct dwarf2_per_cu_data *next_cu;
15474
15475 next_cu = per_cu->cu->read_in_chain;
15476
15477 free_one_comp_unit (per_cu->cu);
15478 *last_chain = next_cu;
15479
15480 per_cu = next_cu;
15481 }
15482 }
15483
15484 /* Increase the age counter on each cached compilation unit, and free
15485 any that are too old. */
15486
15487 static void
15488 age_cached_comp_units (void)
15489 {
15490 struct dwarf2_per_cu_data *per_cu, **last_chain;
15491
15492 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
15493 per_cu = dwarf2_per_objfile->read_in_chain;
15494 while (per_cu != NULL)
15495 {
15496 per_cu->cu->last_used ++;
15497 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
15498 dwarf2_mark (per_cu->cu);
15499 per_cu = per_cu->cu->read_in_chain;
15500 }
15501
15502 per_cu = dwarf2_per_objfile->read_in_chain;
15503 last_chain = &dwarf2_per_objfile->read_in_chain;
15504 while (per_cu != NULL)
15505 {
15506 struct dwarf2_per_cu_data *next_cu;
15507
15508 next_cu = per_cu->cu->read_in_chain;
15509
15510 if (!per_cu->cu->mark)
15511 {
15512 free_one_comp_unit (per_cu->cu);
15513 *last_chain = next_cu;
15514 }
15515 else
15516 last_chain = &per_cu->cu->read_in_chain;
15517
15518 per_cu = next_cu;
15519 }
15520 }
15521
15522 /* Remove a single compilation unit from the cache. */
15523
15524 static void
15525 free_one_cached_comp_unit (void *target_cu)
15526 {
15527 struct dwarf2_per_cu_data *per_cu, **last_chain;
15528
15529 per_cu = dwarf2_per_objfile->read_in_chain;
15530 last_chain = &dwarf2_per_objfile->read_in_chain;
15531 while (per_cu != NULL)
15532 {
15533 struct dwarf2_per_cu_data *next_cu;
15534
15535 next_cu = per_cu->cu->read_in_chain;
15536
15537 if (per_cu->cu == target_cu)
15538 {
15539 free_one_comp_unit (per_cu->cu);
15540 *last_chain = next_cu;
15541 break;
15542 }
15543 else
15544 last_chain = &per_cu->cu->read_in_chain;
15545
15546 per_cu = next_cu;
15547 }
15548 }
15549
15550 /* Release all extra memory associated with OBJFILE. */
15551
15552 void
15553 dwarf2_free_objfile (struct objfile *objfile)
15554 {
15555 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
15556
15557 if (dwarf2_per_objfile == NULL)
15558 return;
15559
15560 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
15561 free_cached_comp_units (NULL);
15562
15563 if (dwarf2_per_objfile->quick_file_names_table)
15564 htab_delete (dwarf2_per_objfile->quick_file_names_table);
15565
15566 /* Everything else should be on the objfile obstack. */
15567 }
15568
15569 /* A pair of DIE offset and GDB type pointer. We store these
15570 in a hash table separate from the DIEs, and preserve them
15571 when the DIEs are flushed out of cache. */
15572
15573 struct dwarf2_offset_and_type
15574 {
15575 unsigned int offset;
15576 struct type *type;
15577 };
15578
15579 /* Hash function for a dwarf2_offset_and_type. */
15580
15581 static hashval_t
15582 offset_and_type_hash (const void *item)
15583 {
15584 const struct dwarf2_offset_and_type *ofs = item;
15585
15586 return ofs->offset;
15587 }
15588
15589 /* Equality function for a dwarf2_offset_and_type. */
15590
15591 static int
15592 offset_and_type_eq (const void *item_lhs, const void *item_rhs)
15593 {
15594 const struct dwarf2_offset_and_type *ofs_lhs = item_lhs;
15595 const struct dwarf2_offset_and_type *ofs_rhs = item_rhs;
15596
15597 return ofs_lhs->offset == ofs_rhs->offset;
15598 }
15599
15600 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15601 table if necessary. For convenience, return TYPE.
15602
15603 The DIEs reading must have careful ordering to:
15604 * Not cause infite loops trying to read in DIEs as a prerequisite for
15605 reading current DIE.
15606 * Not trying to dereference contents of still incompletely read in types
15607 while reading in other DIEs.
15608 * Enable referencing still incompletely read in types just by a pointer to
15609 the type without accessing its fields.
15610
15611 Therefore caller should follow these rules:
15612 * Try to fetch any prerequisite types we may need to build this DIE type
15613 before building the type and calling set_die_type.
15614 * After building type call set_die_type for current DIE as soon as
15615 possible before fetching more types to complete the current type.
15616 * Make the type as complete as possible before fetching more types. */
15617
15618 static struct type *
15619 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15620 {
15621 struct dwarf2_offset_and_type **slot, ofs;
15622 struct objfile *objfile = cu->objfile;
15623 htab_t *type_hash_ptr;
15624
15625 /* For Ada types, make sure that the gnat-specific data is always
15626 initialized (if not already set). There are a few types where
15627 we should not be doing so, because the type-specific area is
15628 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15629 where the type-specific area is used to store the floatformat).
15630 But this is not a problem, because the gnat-specific information
15631 is actually not needed for these types. */
15632 if (need_gnat_info (cu)
15633 && TYPE_CODE (type) != TYPE_CODE_FUNC
15634 && TYPE_CODE (type) != TYPE_CODE_FLT
15635 && !HAVE_GNAT_AUX_INFO (type))
15636 INIT_GNAT_SPECIFIC (type);
15637
15638 if (cu->per_cu->debug_type_section)
15639 type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash;
15640 else
15641 type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash;
15642
15643 if (*type_hash_ptr == NULL)
15644 {
15645 *type_hash_ptr
15646 = htab_create_alloc_ex (127,
15647 offset_and_type_hash,
15648 offset_and_type_eq,
15649 NULL,
15650 &objfile->objfile_obstack,
15651 hashtab_obstack_allocate,
15652 dummy_obstack_deallocate);
15653 }
15654
15655 ofs.offset = die->offset;
15656 ofs.type = type;
15657 slot = (struct dwarf2_offset_and_type **)
15658 htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT);
15659 if (*slot)
15660 complaint (&symfile_complaints,
15661 _("A problem internal to GDB: DIE 0x%x has type already set"),
15662 die->offset);
15663 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
15664 **slot = ofs;
15665 return type;
15666 }
15667
15668 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15669 table, or return NULL if the die does not have a saved type. */
15670
15671 static struct type *
15672 get_die_type_at_offset (unsigned int offset,
15673 struct dwarf2_per_cu_data *per_cu)
15674 {
15675 struct dwarf2_offset_and_type *slot, ofs;
15676 htab_t type_hash;
15677
15678 if (per_cu->debug_type_section)
15679 type_hash = dwarf2_per_objfile->debug_types_type_hash;
15680 else
15681 type_hash = dwarf2_per_objfile->debug_info_type_hash;
15682 if (type_hash == NULL)
15683 return NULL;
15684
15685 ofs.offset = offset;
15686 slot = htab_find_with_hash (type_hash, &ofs, ofs.offset);
15687 if (slot)
15688 return slot->type;
15689 else
15690 return NULL;
15691 }
15692
15693 /* Look up the type for DIE in the appropriate type_hash table,
15694 or return NULL if DIE does not have a saved type. */
15695
15696 static struct type *
15697 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
15698 {
15699 return get_die_type_at_offset (die->offset, cu->per_cu);
15700 }
15701
15702 /* Add a dependence relationship from CU to REF_PER_CU. */
15703
15704 static void
15705 dwarf2_add_dependence (struct dwarf2_cu *cu,
15706 struct dwarf2_per_cu_data *ref_per_cu)
15707 {
15708 void **slot;
15709
15710 if (cu->dependencies == NULL)
15711 cu->dependencies
15712 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
15713 NULL, &cu->comp_unit_obstack,
15714 hashtab_obstack_allocate,
15715 dummy_obstack_deallocate);
15716
15717 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
15718 if (*slot == NULL)
15719 *slot = ref_per_cu;
15720 }
15721
15722 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15723 Set the mark field in every compilation unit in the
15724 cache that we must keep because we are keeping CU. */
15725
15726 static int
15727 dwarf2_mark_helper (void **slot, void *data)
15728 {
15729 struct dwarf2_per_cu_data *per_cu;
15730
15731 per_cu = (struct dwarf2_per_cu_data *) *slot;
15732
15733 /* cu->dependencies references may not yet have been ever read if QUIT aborts
15734 reading of the chain. As such dependencies remain valid it is not much
15735 useful to track and undo them during QUIT cleanups. */
15736 if (per_cu->cu == NULL)
15737 return 1;
15738
15739 if (per_cu->cu->mark)
15740 return 1;
15741 per_cu->cu->mark = 1;
15742
15743 if (per_cu->cu->dependencies != NULL)
15744 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
15745
15746 return 1;
15747 }
15748
15749 /* Set the mark field in CU and in every other compilation unit in the
15750 cache that we must keep because we are keeping CU. */
15751
15752 static void
15753 dwarf2_mark (struct dwarf2_cu *cu)
15754 {
15755 if (cu->mark)
15756 return;
15757 cu->mark = 1;
15758 if (cu->dependencies != NULL)
15759 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
15760 }
15761
15762 static void
15763 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
15764 {
15765 while (per_cu)
15766 {
15767 per_cu->cu->mark = 0;
15768 per_cu = per_cu->cu->read_in_chain;
15769 }
15770 }
15771
15772 /* Trivial hash function for partial_die_info: the hash value of a DIE
15773 is its offset in .debug_info for this objfile. */
15774
15775 static hashval_t
15776 partial_die_hash (const void *item)
15777 {
15778 const struct partial_die_info *part_die = item;
15779
15780 return part_die->offset;
15781 }
15782
15783 /* Trivial comparison function for partial_die_info structures: two DIEs
15784 are equal if they have the same offset. */
15785
15786 static int
15787 partial_die_eq (const void *item_lhs, const void *item_rhs)
15788 {
15789 const struct partial_die_info *part_die_lhs = item_lhs;
15790 const struct partial_die_info *part_die_rhs = item_rhs;
15791
15792 return part_die_lhs->offset == part_die_rhs->offset;
15793 }
15794
15795 static struct cmd_list_element *set_dwarf2_cmdlist;
15796 static struct cmd_list_element *show_dwarf2_cmdlist;
15797
15798 static void
15799 set_dwarf2_cmd (char *args, int from_tty)
15800 {
15801 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
15802 }
15803
15804 static void
15805 show_dwarf2_cmd (char *args, int from_tty)
15806 {
15807 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
15808 }
15809
15810 /* If section described by INFO was mmapped, munmap it now. */
15811
15812 static void
15813 munmap_section_buffer (struct dwarf2_section_info *info)
15814 {
15815 if (info->map_addr != NULL)
15816 {
15817 #ifdef HAVE_MMAP
15818 int res;
15819
15820 res = munmap (info->map_addr, info->map_len);
15821 gdb_assert (res == 0);
15822 #else
15823 /* Without HAVE_MMAP, we should never be here to begin with. */
15824 gdb_assert_not_reached ("no mmap support");
15825 #endif
15826 }
15827 }
15828
15829 /* munmap debug sections for OBJFILE, if necessary. */
15830
15831 static void
15832 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
15833 {
15834 struct dwarf2_per_objfile *data = d;
15835 int ix;
15836 struct dwarf2_section_info *section;
15837
15838 /* This is sorted according to the order they're defined in to make it easier
15839 to keep in sync. */
15840 munmap_section_buffer (&data->info);
15841 munmap_section_buffer (&data->abbrev);
15842 munmap_section_buffer (&data->line);
15843 munmap_section_buffer (&data->loc);
15844 munmap_section_buffer (&data->macinfo);
15845 munmap_section_buffer (&data->macro);
15846 munmap_section_buffer (&data->str);
15847 munmap_section_buffer (&data->ranges);
15848 munmap_section_buffer (&data->frame);
15849 munmap_section_buffer (&data->eh_frame);
15850 munmap_section_buffer (&data->gdb_index);
15851
15852 for (ix = 0;
15853 VEC_iterate (dwarf2_section_info_def, data->types, ix, section);
15854 ++ix)
15855 munmap_section_buffer (section);
15856
15857 VEC_free (dwarf2_section_info_def, data->types);
15858 }
15859
15860 \f
15861 /* The "save gdb-index" command. */
15862
15863 /* The contents of the hash table we create when building the string
15864 table. */
15865 struct strtab_entry
15866 {
15867 offset_type offset;
15868 const char *str;
15869 };
15870
15871 /* Hash function for a strtab_entry.
15872
15873 Function is used only during write_hash_table so no index format backward
15874 compatibility is needed. */
15875
15876 static hashval_t
15877 hash_strtab_entry (const void *e)
15878 {
15879 const struct strtab_entry *entry = e;
15880 return mapped_index_string_hash (INT_MAX, entry->str);
15881 }
15882
15883 /* Equality function for a strtab_entry. */
15884
15885 static int
15886 eq_strtab_entry (const void *a, const void *b)
15887 {
15888 const struct strtab_entry *ea = a;
15889 const struct strtab_entry *eb = b;
15890 return !strcmp (ea->str, eb->str);
15891 }
15892
15893 /* Create a strtab_entry hash table. */
15894
15895 static htab_t
15896 create_strtab (void)
15897 {
15898 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
15899 xfree, xcalloc, xfree);
15900 }
15901
15902 /* Add a string to the constant pool. Return the string's offset in
15903 host order. */
15904
15905 static offset_type
15906 add_string (htab_t table, struct obstack *cpool, const char *str)
15907 {
15908 void **slot;
15909 struct strtab_entry entry;
15910 struct strtab_entry *result;
15911
15912 entry.str = str;
15913 slot = htab_find_slot (table, &entry, INSERT);
15914 if (*slot)
15915 result = *slot;
15916 else
15917 {
15918 result = XNEW (struct strtab_entry);
15919 result->offset = obstack_object_size (cpool);
15920 result->str = str;
15921 obstack_grow_str0 (cpool, str);
15922 *slot = result;
15923 }
15924 return result->offset;
15925 }
15926
15927 /* An entry in the symbol table. */
15928 struct symtab_index_entry
15929 {
15930 /* The name of the symbol. */
15931 const char *name;
15932 /* The offset of the name in the constant pool. */
15933 offset_type index_offset;
15934 /* A sorted vector of the indices of all the CUs that hold an object
15935 of this name. */
15936 VEC (offset_type) *cu_indices;
15937 };
15938
15939 /* The symbol table. This is a power-of-2-sized hash table. */
15940 struct mapped_symtab
15941 {
15942 offset_type n_elements;
15943 offset_type size;
15944 struct symtab_index_entry **data;
15945 };
15946
15947 /* Hash function for a symtab_index_entry. */
15948
15949 static hashval_t
15950 hash_symtab_entry (const void *e)
15951 {
15952 const struct symtab_index_entry *entry = e;
15953 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
15954 sizeof (offset_type) * VEC_length (offset_type,
15955 entry->cu_indices),
15956 0);
15957 }
15958
15959 /* Equality function for a symtab_index_entry. */
15960
15961 static int
15962 eq_symtab_entry (const void *a, const void *b)
15963 {
15964 const struct symtab_index_entry *ea = a;
15965 const struct symtab_index_entry *eb = b;
15966 int len = VEC_length (offset_type, ea->cu_indices);
15967 if (len != VEC_length (offset_type, eb->cu_indices))
15968 return 0;
15969 return !memcmp (VEC_address (offset_type, ea->cu_indices),
15970 VEC_address (offset_type, eb->cu_indices),
15971 sizeof (offset_type) * len);
15972 }
15973
15974 /* Destroy a symtab_index_entry. */
15975
15976 static void
15977 delete_symtab_entry (void *p)
15978 {
15979 struct symtab_index_entry *entry = p;
15980 VEC_free (offset_type, entry->cu_indices);
15981 xfree (entry);
15982 }
15983
15984 /* Create a hash table holding symtab_index_entry objects. */
15985
15986 static htab_t
15987 create_symbol_hash_table (void)
15988 {
15989 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
15990 delete_symtab_entry, xcalloc, xfree);
15991 }
15992
15993 /* Create a new mapped symtab object. */
15994
15995 static struct mapped_symtab *
15996 create_mapped_symtab (void)
15997 {
15998 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
15999 symtab->n_elements = 0;
16000 symtab->size = 1024;
16001 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16002 return symtab;
16003 }
16004
16005 /* Destroy a mapped_symtab. */
16006
16007 static void
16008 cleanup_mapped_symtab (void *p)
16009 {
16010 struct mapped_symtab *symtab = p;
16011 /* The contents of the array are freed when the other hash table is
16012 destroyed. */
16013 xfree (symtab->data);
16014 xfree (symtab);
16015 }
16016
16017 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
16018 the slot.
16019
16020 Function is used only during write_hash_table so no index format backward
16021 compatibility is needed. */
16022
16023 static struct symtab_index_entry **
16024 find_slot (struct mapped_symtab *symtab, const char *name)
16025 {
16026 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
16027
16028 index = hash & (symtab->size - 1);
16029 step = ((hash * 17) & (symtab->size - 1)) | 1;
16030
16031 for (;;)
16032 {
16033 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
16034 return &symtab->data[index];
16035 index = (index + step) & (symtab->size - 1);
16036 }
16037 }
16038
16039 /* Expand SYMTAB's hash table. */
16040
16041 static void
16042 hash_expand (struct mapped_symtab *symtab)
16043 {
16044 offset_type old_size = symtab->size;
16045 offset_type i;
16046 struct symtab_index_entry **old_entries = symtab->data;
16047
16048 symtab->size *= 2;
16049 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
16050
16051 for (i = 0; i < old_size; ++i)
16052 {
16053 if (old_entries[i])
16054 {
16055 struct symtab_index_entry **slot = find_slot (symtab,
16056 old_entries[i]->name);
16057 *slot = old_entries[i];
16058 }
16059 }
16060
16061 xfree (old_entries);
16062 }
16063
16064 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
16065 is the index of the CU in which the symbol appears. */
16066
16067 static void
16068 add_index_entry (struct mapped_symtab *symtab, const char *name,
16069 offset_type cu_index)
16070 {
16071 struct symtab_index_entry **slot;
16072
16073 ++symtab->n_elements;
16074 if (4 * symtab->n_elements / 3 >= symtab->size)
16075 hash_expand (symtab);
16076
16077 slot = find_slot (symtab, name);
16078 if (!*slot)
16079 {
16080 *slot = XNEW (struct symtab_index_entry);
16081 (*slot)->name = name;
16082 (*slot)->cu_indices = NULL;
16083 }
16084 /* Don't push an index twice. Due to how we add entries we only
16085 have to check the last one. */
16086 if (VEC_empty (offset_type, (*slot)->cu_indices)
16087 || VEC_last (offset_type, (*slot)->cu_indices) != cu_index)
16088 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index);
16089 }
16090
16091 /* Add a vector of indices to the constant pool. */
16092
16093 static offset_type
16094 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
16095 struct symtab_index_entry *entry)
16096 {
16097 void **slot;
16098
16099 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
16100 if (!*slot)
16101 {
16102 offset_type len = VEC_length (offset_type, entry->cu_indices);
16103 offset_type val = MAYBE_SWAP (len);
16104 offset_type iter;
16105 int i;
16106
16107 *slot = entry;
16108 entry->index_offset = obstack_object_size (cpool);
16109
16110 obstack_grow (cpool, &val, sizeof (val));
16111 for (i = 0;
16112 VEC_iterate (offset_type, entry->cu_indices, i, iter);
16113 ++i)
16114 {
16115 val = MAYBE_SWAP (iter);
16116 obstack_grow (cpool, &val, sizeof (val));
16117 }
16118 }
16119 else
16120 {
16121 struct symtab_index_entry *old_entry = *slot;
16122 entry->index_offset = old_entry->index_offset;
16123 entry = old_entry;
16124 }
16125 return entry->index_offset;
16126 }
16127
16128 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
16129 constant pool entries going into the obstack CPOOL. */
16130
16131 static void
16132 write_hash_table (struct mapped_symtab *symtab,
16133 struct obstack *output, struct obstack *cpool)
16134 {
16135 offset_type i;
16136 htab_t symbol_hash_table;
16137 htab_t str_table;
16138
16139 symbol_hash_table = create_symbol_hash_table ();
16140 str_table = create_strtab ();
16141
16142 /* We add all the index vectors to the constant pool first, to
16143 ensure alignment is ok. */
16144 for (i = 0; i < symtab->size; ++i)
16145 {
16146 if (symtab->data[i])
16147 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
16148 }
16149
16150 /* Now write out the hash table. */
16151 for (i = 0; i < symtab->size; ++i)
16152 {
16153 offset_type str_off, vec_off;
16154
16155 if (symtab->data[i])
16156 {
16157 str_off = add_string (str_table, cpool, symtab->data[i]->name);
16158 vec_off = symtab->data[i]->index_offset;
16159 }
16160 else
16161 {
16162 /* While 0 is a valid constant pool index, it is not valid
16163 to have 0 for both offsets. */
16164 str_off = 0;
16165 vec_off = 0;
16166 }
16167
16168 str_off = MAYBE_SWAP (str_off);
16169 vec_off = MAYBE_SWAP (vec_off);
16170
16171 obstack_grow (output, &str_off, sizeof (str_off));
16172 obstack_grow (output, &vec_off, sizeof (vec_off));
16173 }
16174
16175 htab_delete (str_table);
16176 htab_delete (symbol_hash_table);
16177 }
16178
16179 /* Struct to map psymtab to CU index in the index file. */
16180 struct psymtab_cu_index_map
16181 {
16182 struct partial_symtab *psymtab;
16183 unsigned int cu_index;
16184 };
16185
16186 static hashval_t
16187 hash_psymtab_cu_index (const void *item)
16188 {
16189 const struct psymtab_cu_index_map *map = item;
16190
16191 return htab_hash_pointer (map->psymtab);
16192 }
16193
16194 static int
16195 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
16196 {
16197 const struct psymtab_cu_index_map *lhs = item_lhs;
16198 const struct psymtab_cu_index_map *rhs = item_rhs;
16199
16200 return lhs->psymtab == rhs->psymtab;
16201 }
16202
16203 /* Helper struct for building the address table. */
16204 struct addrmap_index_data
16205 {
16206 struct objfile *objfile;
16207 struct obstack *addr_obstack;
16208 htab_t cu_index_htab;
16209
16210 /* Non-zero if the previous_* fields are valid.
16211 We can't write an entry until we see the next entry (since it is only then
16212 that we know the end of the entry). */
16213 int previous_valid;
16214 /* Index of the CU in the table of all CUs in the index file. */
16215 unsigned int previous_cu_index;
16216 /* Start address of the CU. */
16217 CORE_ADDR previous_cu_start;
16218 };
16219
16220 /* Write an address entry to OBSTACK. */
16221
16222 static void
16223 add_address_entry (struct objfile *objfile, struct obstack *obstack,
16224 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
16225 {
16226 offset_type cu_index_to_write;
16227 char addr[8];
16228 CORE_ADDR baseaddr;
16229
16230 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16231
16232 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
16233 obstack_grow (obstack, addr, 8);
16234 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
16235 obstack_grow (obstack, addr, 8);
16236 cu_index_to_write = MAYBE_SWAP (cu_index);
16237 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
16238 }
16239
16240 /* Worker function for traversing an addrmap to build the address table. */
16241
16242 static int
16243 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
16244 {
16245 struct addrmap_index_data *data = datap;
16246 struct partial_symtab *pst = obj;
16247 offset_type cu_index;
16248 void **slot;
16249
16250 if (data->previous_valid)
16251 add_address_entry (data->objfile, data->addr_obstack,
16252 data->previous_cu_start, start_addr,
16253 data->previous_cu_index);
16254
16255 data->previous_cu_start = start_addr;
16256 if (pst != NULL)
16257 {
16258 struct psymtab_cu_index_map find_map, *map;
16259 find_map.psymtab = pst;
16260 map = htab_find (data->cu_index_htab, &find_map);
16261 gdb_assert (map != NULL);
16262 data->previous_cu_index = map->cu_index;
16263 data->previous_valid = 1;
16264 }
16265 else
16266 data->previous_valid = 0;
16267
16268 return 0;
16269 }
16270
16271 /* Write OBJFILE's address map to OBSTACK.
16272 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
16273 in the index file. */
16274
16275 static void
16276 write_address_map (struct objfile *objfile, struct obstack *obstack,
16277 htab_t cu_index_htab)
16278 {
16279 struct addrmap_index_data addrmap_index_data;
16280
16281 /* When writing the address table, we have to cope with the fact that
16282 the addrmap iterator only provides the start of a region; we have to
16283 wait until the next invocation to get the start of the next region. */
16284
16285 addrmap_index_data.objfile = objfile;
16286 addrmap_index_data.addr_obstack = obstack;
16287 addrmap_index_data.cu_index_htab = cu_index_htab;
16288 addrmap_index_data.previous_valid = 0;
16289
16290 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
16291 &addrmap_index_data);
16292
16293 /* It's highly unlikely the last entry (end address = 0xff...ff)
16294 is valid, but we should still handle it.
16295 The end address is recorded as the start of the next region, but that
16296 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
16297 anyway. */
16298 if (addrmap_index_data.previous_valid)
16299 add_address_entry (objfile, obstack,
16300 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
16301 addrmap_index_data.previous_cu_index);
16302 }
16303
16304 /* Add a list of partial symbols to SYMTAB. */
16305
16306 static void
16307 write_psymbols (struct mapped_symtab *symtab,
16308 htab_t psyms_seen,
16309 struct partial_symbol **psymp,
16310 int count,
16311 offset_type cu_index,
16312 int is_static)
16313 {
16314 for (; count-- > 0; ++psymp)
16315 {
16316 void **slot, *lookup;
16317
16318 if (SYMBOL_LANGUAGE (*psymp) == language_ada)
16319 error (_("Ada is not currently supported by the index"));
16320
16321 /* We only want to add a given psymbol once. However, we also
16322 want to account for whether it is global or static. So, we
16323 may add it twice, using slightly different values. */
16324 if (is_static)
16325 {
16326 uintptr_t val = 1 | (uintptr_t) *psymp;
16327
16328 lookup = (void *) val;
16329 }
16330 else
16331 lookup = *psymp;
16332
16333 /* Only add a given psymbol once. */
16334 slot = htab_find_slot (psyms_seen, lookup, INSERT);
16335 if (!*slot)
16336 {
16337 *slot = lookup;
16338 add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index);
16339 }
16340 }
16341 }
16342
16343 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
16344 exception if there is an error. */
16345
16346 static void
16347 write_obstack (FILE *file, struct obstack *obstack)
16348 {
16349 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
16350 file)
16351 != obstack_object_size (obstack))
16352 error (_("couldn't data write to file"));
16353 }
16354
16355 /* Unlink a file if the argument is not NULL. */
16356
16357 static void
16358 unlink_if_set (void *p)
16359 {
16360 char **filename = p;
16361 if (*filename)
16362 unlink (*filename);
16363 }
16364
16365 /* A helper struct used when iterating over debug_types. */
16366 struct signatured_type_index_data
16367 {
16368 struct objfile *objfile;
16369 struct mapped_symtab *symtab;
16370 struct obstack *types_list;
16371 htab_t psyms_seen;
16372 int cu_index;
16373 };
16374
16375 /* A helper function that writes a single signatured_type to an
16376 obstack. */
16377
16378 static int
16379 write_one_signatured_type (void **slot, void *d)
16380 {
16381 struct signatured_type_index_data *info = d;
16382 struct signatured_type *entry = (struct signatured_type *) *slot;
16383 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
16384 struct partial_symtab *psymtab = per_cu->v.psymtab;
16385 gdb_byte val[8];
16386
16387 write_psymbols (info->symtab,
16388 info->psyms_seen,
16389 info->objfile->global_psymbols.list
16390 + psymtab->globals_offset,
16391 psymtab->n_global_syms, info->cu_index,
16392 0);
16393 write_psymbols (info->symtab,
16394 info->psyms_seen,
16395 info->objfile->static_psymbols.list
16396 + psymtab->statics_offset,
16397 psymtab->n_static_syms, info->cu_index,
16398 1);
16399
16400 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset);
16401 obstack_grow (info->types_list, val, 8);
16402 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset);
16403 obstack_grow (info->types_list, val, 8);
16404 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
16405 obstack_grow (info->types_list, val, 8);
16406
16407 ++info->cu_index;
16408
16409 return 1;
16410 }
16411
16412 /* A cleanup function for an htab_t. */
16413
16414 static void
16415 cleanup_htab (void *arg)
16416 {
16417 htab_delete (arg);
16418 }
16419
16420 /* Create an index file for OBJFILE in the directory DIR. */
16421
16422 static void
16423 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
16424 {
16425 struct cleanup *cleanup;
16426 char *filename, *cleanup_filename;
16427 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
16428 struct obstack cu_list, types_cu_list;
16429 int i;
16430 FILE *out_file;
16431 struct mapped_symtab *symtab;
16432 offset_type val, size_of_contents, total_len;
16433 struct stat st;
16434 char buf[8];
16435 htab_t psyms_seen;
16436 htab_t cu_index_htab;
16437 struct psymtab_cu_index_map *psymtab_cu_index_map;
16438
16439 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
16440 return;
16441
16442 if (dwarf2_per_objfile->using_index)
16443 error (_("Cannot use an index to create the index"));
16444
16445 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
16446 error (_("Cannot make an index when the file has multiple .debug_types sections"));
16447
16448 if (stat (objfile->name, &st) < 0)
16449 perror_with_name (objfile->name);
16450
16451 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
16452 INDEX_SUFFIX, (char *) NULL);
16453 cleanup = make_cleanup (xfree, filename);
16454
16455 out_file = fopen (filename, "wb");
16456 if (!out_file)
16457 error (_("Can't open `%s' for writing"), filename);
16458
16459 cleanup_filename = filename;
16460 make_cleanup (unlink_if_set, &cleanup_filename);
16461
16462 symtab = create_mapped_symtab ();
16463 make_cleanup (cleanup_mapped_symtab, symtab);
16464
16465 obstack_init (&addr_obstack);
16466 make_cleanup_obstack_free (&addr_obstack);
16467
16468 obstack_init (&cu_list);
16469 make_cleanup_obstack_free (&cu_list);
16470
16471 obstack_init (&types_cu_list);
16472 make_cleanup_obstack_free (&types_cu_list);
16473
16474 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
16475 NULL, xcalloc, xfree);
16476 make_cleanup (cleanup_htab, psyms_seen);
16477
16478 /* While we're scanning CU's create a table that maps a psymtab pointer
16479 (which is what addrmap records) to its index (which is what is recorded
16480 in the index file). This will later be needed to write the address
16481 table. */
16482 cu_index_htab = htab_create_alloc (100,
16483 hash_psymtab_cu_index,
16484 eq_psymtab_cu_index,
16485 NULL, xcalloc, xfree);
16486 make_cleanup (cleanup_htab, cu_index_htab);
16487 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
16488 xmalloc (sizeof (struct psymtab_cu_index_map)
16489 * dwarf2_per_objfile->n_comp_units);
16490 make_cleanup (xfree, psymtab_cu_index_map);
16491
16492 /* The CU list is already sorted, so we don't need to do additional
16493 work here. Also, the debug_types entries do not appear in
16494 all_comp_units, but only in their own hash table. */
16495 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
16496 {
16497 struct dwarf2_per_cu_data *per_cu
16498 = dwarf2_per_objfile->all_comp_units[i];
16499 struct partial_symtab *psymtab = per_cu->v.psymtab;
16500 gdb_byte val[8];
16501 struct psymtab_cu_index_map *map;
16502 void **slot;
16503
16504 write_psymbols (symtab,
16505 psyms_seen,
16506 objfile->global_psymbols.list + psymtab->globals_offset,
16507 psymtab->n_global_syms, i,
16508 0);
16509 write_psymbols (symtab,
16510 psyms_seen,
16511 objfile->static_psymbols.list + psymtab->statics_offset,
16512 psymtab->n_static_syms, i,
16513 1);
16514
16515 map = &psymtab_cu_index_map[i];
16516 map->psymtab = psymtab;
16517 map->cu_index = i;
16518 slot = htab_find_slot (cu_index_htab, map, INSERT);
16519 gdb_assert (slot != NULL);
16520 gdb_assert (*slot == NULL);
16521 *slot = map;
16522
16523 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset);
16524 obstack_grow (&cu_list, val, 8);
16525 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
16526 obstack_grow (&cu_list, val, 8);
16527 }
16528
16529 /* Dump the address map. */
16530 write_address_map (objfile, &addr_obstack, cu_index_htab);
16531
16532 /* Write out the .debug_type entries, if any. */
16533 if (dwarf2_per_objfile->signatured_types)
16534 {
16535 struct signatured_type_index_data sig_data;
16536
16537 sig_data.objfile = objfile;
16538 sig_data.symtab = symtab;
16539 sig_data.types_list = &types_cu_list;
16540 sig_data.psyms_seen = psyms_seen;
16541 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
16542 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
16543 write_one_signatured_type, &sig_data);
16544 }
16545
16546 obstack_init (&constant_pool);
16547 make_cleanup_obstack_free (&constant_pool);
16548 obstack_init (&symtab_obstack);
16549 make_cleanup_obstack_free (&symtab_obstack);
16550 write_hash_table (symtab, &symtab_obstack, &constant_pool);
16551
16552 obstack_init (&contents);
16553 make_cleanup_obstack_free (&contents);
16554 size_of_contents = 6 * sizeof (offset_type);
16555 total_len = size_of_contents;
16556
16557 /* The version number. */
16558 val = MAYBE_SWAP (5);
16559 obstack_grow (&contents, &val, sizeof (val));
16560
16561 /* The offset of the CU list from the start of the file. */
16562 val = MAYBE_SWAP (total_len);
16563 obstack_grow (&contents, &val, sizeof (val));
16564 total_len += obstack_object_size (&cu_list);
16565
16566 /* The offset of the types CU list from the start of the file. */
16567 val = MAYBE_SWAP (total_len);
16568 obstack_grow (&contents, &val, sizeof (val));
16569 total_len += obstack_object_size (&types_cu_list);
16570
16571 /* The offset of the address table from the start of the file. */
16572 val = MAYBE_SWAP (total_len);
16573 obstack_grow (&contents, &val, sizeof (val));
16574 total_len += obstack_object_size (&addr_obstack);
16575
16576 /* The offset of the symbol table from the start of the file. */
16577 val = MAYBE_SWAP (total_len);
16578 obstack_grow (&contents, &val, sizeof (val));
16579 total_len += obstack_object_size (&symtab_obstack);
16580
16581 /* The offset of the constant pool from the start of the file. */
16582 val = MAYBE_SWAP (total_len);
16583 obstack_grow (&contents, &val, sizeof (val));
16584 total_len += obstack_object_size (&constant_pool);
16585
16586 gdb_assert (obstack_object_size (&contents) == size_of_contents);
16587
16588 write_obstack (out_file, &contents);
16589 write_obstack (out_file, &cu_list);
16590 write_obstack (out_file, &types_cu_list);
16591 write_obstack (out_file, &addr_obstack);
16592 write_obstack (out_file, &symtab_obstack);
16593 write_obstack (out_file, &constant_pool);
16594
16595 fclose (out_file);
16596
16597 /* We want to keep the file, so we set cleanup_filename to NULL
16598 here. See unlink_if_set. */
16599 cleanup_filename = NULL;
16600
16601 do_cleanups (cleanup);
16602 }
16603
16604 /* Implementation of the `save gdb-index' command.
16605
16606 Note that the file format used by this command is documented in the
16607 GDB manual. Any changes here must be documented there. */
16608
16609 static void
16610 save_gdb_index_command (char *arg, int from_tty)
16611 {
16612 struct objfile *objfile;
16613
16614 if (!arg || !*arg)
16615 error (_("usage: save gdb-index DIRECTORY"));
16616
16617 ALL_OBJFILES (objfile)
16618 {
16619 struct stat st;
16620
16621 /* If the objfile does not correspond to an actual file, skip it. */
16622 if (stat (objfile->name, &st) < 0)
16623 continue;
16624
16625 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
16626 if (dwarf2_per_objfile)
16627 {
16628 volatile struct gdb_exception except;
16629
16630 TRY_CATCH (except, RETURN_MASK_ERROR)
16631 {
16632 write_psymtabs_to_index (objfile, arg);
16633 }
16634 if (except.reason < 0)
16635 exception_fprintf (gdb_stderr, except,
16636 _("Error while writing index for `%s': "),
16637 objfile->name);
16638 }
16639 }
16640 }
16641
16642 \f
16643
16644 int dwarf2_always_disassemble;
16645
16646 static void
16647 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
16648 struct cmd_list_element *c, const char *value)
16649 {
16650 fprintf_filtered (file,
16651 _("Whether to always disassemble "
16652 "DWARF expressions is %s.\n"),
16653 value);
16654 }
16655
16656 static void
16657 show_check_physname (struct ui_file *file, int from_tty,
16658 struct cmd_list_element *c, const char *value)
16659 {
16660 fprintf_filtered (file,
16661 _("Whether to check \"physname\" is %s.\n"),
16662 value);
16663 }
16664
16665 void _initialize_dwarf2_read (void);
16666
16667 void
16668 _initialize_dwarf2_read (void)
16669 {
16670 struct cmd_list_element *c;
16671
16672 dwarf2_objfile_data_key
16673 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
16674
16675 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
16676 Set DWARF 2 specific variables.\n\
16677 Configure DWARF 2 variables such as the cache size"),
16678 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
16679 0/*allow-unknown*/, &maintenance_set_cmdlist);
16680
16681 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
16682 Show DWARF 2 specific variables\n\
16683 Show DWARF 2 variables such as the cache size"),
16684 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
16685 0/*allow-unknown*/, &maintenance_show_cmdlist);
16686
16687 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
16688 &dwarf2_max_cache_age, _("\
16689 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16690 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16691 A higher limit means that cached compilation units will be stored\n\
16692 in memory longer, and more total memory will be used. Zero disables\n\
16693 caching, which can slow down startup."),
16694 NULL,
16695 show_dwarf2_max_cache_age,
16696 &set_dwarf2_cmdlist,
16697 &show_dwarf2_cmdlist);
16698
16699 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
16700 &dwarf2_always_disassemble, _("\
16701 Set whether `info address' always disassembles DWARF expressions."), _("\
16702 Show whether `info address' always disassembles DWARF expressions."), _("\
16703 When enabled, DWARF expressions are always printed in an assembly-like\n\
16704 syntax. When disabled, expressions will be printed in a more\n\
16705 conversational style, when possible."),
16706 NULL,
16707 show_dwarf2_always_disassemble,
16708 &set_dwarf2_cmdlist,
16709 &show_dwarf2_cmdlist);
16710
16711 add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
16712 Set debugging of the dwarf2 DIE reader."), _("\
16713 Show debugging of the dwarf2 DIE reader."), _("\
16714 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16715 The value is the maximum depth to print."),
16716 NULL,
16717 NULL,
16718 &setdebuglist, &showdebuglist);
16719
16720 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
16721 Set cross-checking of \"physname\" code against demangler."), _("\
16722 Show cross-checking of \"physname\" code against demangler."), _("\
16723 When enabled, GDB's internal \"physname\" code is checked against\n\
16724 the demangler."),
16725 NULL, show_check_physname,
16726 &setdebuglist, &showdebuglist);
16727
16728 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
16729 _("\
16730 Save a gdb-index file.\n\
16731 Usage: save gdb-index DIRECTORY"),
16732 &save_cmdlist);
16733 set_cmd_completer (c, filename_completer);
16734 }
This page took 0.400465 seconds and 5 git commands to generate.